From 79dc217688a774fc532584f6551a0aec8b45bc4a Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Wed, 5 Apr 2023 10:33:07 +0000 Subject: 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 --- compiler/optimizing/intrinsics_utils.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'compiler/optimizing/intrinsics_utils.h') diff --git a/compiler/optimizing/intrinsics_utils.h b/compiler/optimizing/intrinsics_utils.h index 13cabdafed..5422275ba7 100644 --- a/compiler/optimizing/intrinsics_utils.h +++ b/compiler/optimizing/intrinsics_utils.h @@ -63,16 +63,19 @@ class IntrinsicSlowPath : public TSlowPathCode { Location method_loc = MoveArguments(codegen); if (invoke_->IsInvokeStaticOrDirect()) { - HInvokeStaticOrDirect* invoke_static_or_direct = invoke_->AsInvokeStaticOrDirect(); + // TODO: Remove "OrNull". + HInvokeStaticOrDirect* invoke_static_or_direct = invoke_->AsInvokeStaticOrDirectOrNull(); DCHECK_NE(invoke_static_or_direct->GetMethodLoadKind(), MethodLoadKind::kRecursive); DCHECK_NE(invoke_static_or_direct->GetCodePtrLocation(), CodePtrLocation::kCallCriticalNative); codegen->GenerateStaticOrDirectCall(invoke_static_or_direct, method_loc, this); } else if (invoke_->IsInvokeVirtual()) { - codegen->GenerateVirtualCall(invoke_->AsInvokeVirtual(), method_loc, this); + // TODO: Remove "OrNull". + codegen->GenerateVirtualCall(invoke_->AsInvokeVirtualOrNull(), method_loc, this); } else { DCHECK(invoke_->IsInvokePolymorphic()); - codegen->GenerateInvokePolymorphicCall(invoke_->AsInvokePolymorphic(), this); + // TODO: Remove "OrNull". + codegen->GenerateInvokePolymorphicCall(invoke_->AsInvokePolymorphicOrNull(), this); } // Copy the result back to the expected output. @@ -113,7 +116,8 @@ static inline size_t GetExpectedVarHandleCoordinatesCount(HInvoke *invoke) { static inline DataType::Type GetDataTypeFromShorty(HInvoke* invoke, uint32_t index) { DCHECK(invoke->IsInvokePolymorphic()); const DexFile* dex_file = invoke->GetMethodReference().dex_file; - const char* shorty = dex_file->GetShorty(invoke->AsInvokePolymorphic()->GetProtoIndex()); + // TODO: Remove "OrNull". + const char* shorty = dex_file->GetShorty(invoke->AsInvokePolymorphicOrNull()->GetProtoIndex()); DCHECK_LT(index, strlen(shorty)); return DataType::FromShorty(shorty[index]); @@ -206,10 +210,12 @@ static inline ArtField* GetBootImageVarHandleField(HInvoke* invoke) var_handle_instruction = var_handle_instruction->InputAt(0); } DCHECK(var_handle_instruction->IsStaticFieldGet()); - ArtField* field = var_handle_instruction->AsStaticFieldGet()->GetFieldInfo().GetField(); + // TODO: Remove "OrNull". + ArtField* field = var_handle_instruction->AsStaticFieldGetOrNull()->GetFieldInfo().GetField(); DCHECK(field->IsStatic()); DCHECK(field->IsFinal()); - DCHECK(var_handle_instruction->InputAt(0)->AsLoadClass()->IsInBootImage()); + // TODO: Remove "OrNull". + DCHECK(var_handle_instruction->InputAt(0)->AsLoadClassOrNull()->IsInBootImage()); ObjPtr var_handle = field->GetObject(field->GetDeclaringClass()); DCHECK(var_handle->GetClass() == (GetExpectedVarHandleCoordinatesCount(invoke) == 0u -- cgit v1.2.3-59-g8ed1b