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/code_generator.h | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'compiler/optimizing/code_generator.h') diff --git a/compiler/optimizing/code_generator.h b/compiler/optimizing/code_generator.h index 9872efaa4a..59ae213960 100644 --- a/compiler/optimizing/code_generator.h +++ b/compiler/optimizing/code_generator.h @@ -552,37 +552,45 @@ class CodeGenerator : public DeletableArenaObject { static int8_t GetInt8ValueOf(HConstant* constant) { DCHECK(constant->IsIntConstant()); - return constant->AsIntConstant()->GetValue(); + // TODO: Remove "OrNull". + return constant->AsIntConstantOrNull()->GetValue(); } static int16_t GetInt16ValueOf(HConstant* constant) { DCHECK(constant->IsIntConstant()); - return constant->AsIntConstant()->GetValue(); + // TODO: Remove "OrNull". + return constant->AsIntConstantOrNull()->GetValue(); } static int32_t GetInt32ValueOf(HConstant* constant) { if (constant->IsIntConstant()) { - return constant->AsIntConstant()->GetValue(); + // TODO: Remove "OrNull". + return constant->AsIntConstantOrNull()->GetValue(); } else if (constant->IsNullConstant()) { return 0; } else { DCHECK(constant->IsFloatConstant()); - return bit_cast(constant->AsFloatConstant()->GetValue()); + // TODO: Remove "OrNull". + return bit_cast(constant->AsFloatConstantOrNull()->GetValue()); } } static int64_t GetInt64ValueOf(HConstant* constant) { if (constant->IsIntConstant()) { - return constant->AsIntConstant()->GetValue(); + // TODO: Remove "OrNull". + return constant->AsIntConstantOrNull()->GetValue(); } else if (constant->IsNullConstant()) { return 0; } else if (constant->IsFloatConstant()) { - return bit_cast(constant->AsFloatConstant()->GetValue()); + // TODO: Remove "OrNull". + return bit_cast(constant->AsFloatConstantOrNull()->GetValue()); } else if (constant->IsLongConstant()) { - return constant->AsLongConstant()->GetValue(); + // TODO: Remove "OrNull". + return constant->AsLongConstantOrNull()->GetValue(); } else { DCHECK(constant->IsDoubleConstant()); - return bit_cast(constant->AsDoubleConstant()->GetValue()); + // TODO: Remove "OrNull". + return bit_cast(constant->AsDoubleConstantOrNull()->GetValue()); } } -- cgit v1.2.3-59-g8ed1b