diff options
author | 2023-04-05 10:33:07 +0000 | |
---|---|---|
committer | 2023-04-27 10:52:39 +0000 | |
commit | 79dc217688a774fc532584f6551a0aec8b45bc4a (patch) | |
tree | 5abfe4bd90364e66b593088ab4d1b407b51dada5 /compiler/optimizing/intrinsics.cc | |
parent | d60aff547dedefc35265ce57707d406e8ccc4dc6 (diff) |
Optimizing: Rename `As##type` to `As##type##OrNull`.
The null type check in the current implementation of
`HInstruction::As##type()` often cannot be optimized away
by clang++. It is therefore beneficial to have two functions
HInstruction::As##type()
HInstruction::As##type##OrNull()
where the first function never returns null but the second
one can return null. The additional text "OrNull" shall also
flag the possibility of yielding null to the developer which
may help avoid bugs similar to what we have seen previously.
This requires renaming the existing function that can return
null and introducing new function that cannot. However,
defining the new function `HInstruction::As##type()` in the
same change as renaming the old one would risk introducing
bugs by missing a rename. Therefore we simply rename the old
function here and the new function shall be introduced in a
separate change with all behavioral changes being explicit.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Test: buildbot-build.sh --target
Bug: 181943478
Change-Id: I4defd85038e28fe3506903ba3f33f723682b3298
Diffstat (limited to 'compiler/optimizing/intrinsics.cc')
-rw-r--r-- | compiler/optimizing/intrinsics.cc | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/compiler/optimizing/intrinsics.cc b/compiler/optimizing/intrinsics.cc index 774deec438..f832d9c8bf 100644 --- a/compiler/optimizing/intrinsics.cc +++ b/compiler/optimizing/intrinsics.cc @@ -151,7 +151,8 @@ static bool CanReferenceBootImageObjects(HInvoke* invoke, const CompilerOptions& // for AOT. This should cover both the testing config (non-PIC boot image) and codegens that // reject PC-relative load kinds and fall back to the runtime call. if (compiler_options.IsAotCompiler() && - !invoke->AsInvokeStaticOrDirect()->HasPcRelativeMethodLoadKind()) { + // TODO: Remove "OrNull". + !invoke->AsInvokeStaticOrDirectOrNull()->HasPcRelativeMethodLoadKind()) { return false; } if (!compiler_options.IsBootImage() && @@ -209,7 +210,8 @@ void IntrinsicVisitor::ComputeIntegerValueOfLocations(HInvoke* invoke, } } if (input->IsIntConstant()) { - int32_t value = input->AsIntConstant()->GetValue(); + // TODO: Remove "OrNull". + int32_t value = input->AsIntConstantOrNull()->GetValue(); if (static_cast<uint32_t>(value) - static_cast<uint32_t>(low) < static_cast<uint32_t>(high - low + 1)) { // No call, we shall use direct pointer to the Integer object. @@ -234,7 +236,8 @@ void IntrinsicVisitor::ComputeIntegerValueOfLocations(HInvoke* invoke, DCHECK(compiler_options.IsAotCompiler()); DCHECK(CheckIntegerCache(self, runtime->GetClassLinker(), boot_image_live_objects, cache)); if (input->IsIntConstant()) { - int32_t value = input->AsIntConstant()->GetValue(); + // TODO: Remove "OrNull". + int32_t value = input->AsIntConstantOrNull()->GetValue(); // Retrieve the `value` from the lowest cached Integer. ObjPtr<mirror::Object> low_integer = IntrinsicObjects::GetIntegerValueOfObject(boot_image_live_objects, 0u); @@ -308,7 +311,8 @@ IntrinsicVisitor::IntegerValueOfInfo IntrinsicVisitor::ComputeIntegerValueOfInfo info.length = dchecked_integral_cast<uint32_t>(high - info.low + 1); if (invoke->InputAt(0)->IsIntConstant()) { - int32_t input_value = invoke->InputAt(0)->AsIntConstant()->GetValue(); + // TODO: Remove "OrNull". + int32_t input_value = invoke->InputAt(0)->AsIntConstantOrNull()->GetValue(); uint32_t index = static_cast<uint32_t>(input_value) - static_cast<uint32_t>(info.low); if (index < static_cast<uint32_t>(info.length)) { info.value_boot_image_reference = IntrinsicObjects::EncodePatch( @@ -343,7 +347,8 @@ IntrinsicVisitor::IntegerValueOfInfo IntrinsicVisitor::ComputeIntegerValueOfInfo IntrinsicObjects::GetIntegerValueOfCache(boot_image_live_objects)->GetLength()); if (invoke->InputAt(0)->IsIntConstant()) { - int32_t input_value = invoke->InputAt(0)->AsIntConstant()->GetValue(); + // TODO: Remove "OrNull". + int32_t input_value = invoke->InputAt(0)->AsIntConstantOrNull()->GetValue(); uint32_t index = static_cast<uint32_t>(input_value) - static_cast<uint32_t>(info.low); if (index < static_cast<uint32_t>(info.length)) { ObjPtr<mirror::Object> integer = |