From cde6497d286337de2ed21c71c85157e2745b742b Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Tue, 25 Apr 2023 16:40:06 +0000 Subject: Optimizing: Add `HInstruction::As##type()`. After the old implementation was renamed in https://android-review.googlesource.com/2526708 , we introduce a new function with the old name but new behavior, just `DCHECK()`-ing the instruction kind before casting down the pointer. We change appropriate calls from `As##type##OrNull()` to `As##type()` to avoid unncessary run-time checks and reduce the size of libart-compiler.so. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Test: run-gtests.sh Test: testrunner.py --target --optimizing Bug: 181943478 Change-Id: I025681612a77ca2157fed4886ca47f2053975d4e --- compiler/optimizing/code_generator.cc | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'compiler/optimizing/code_generator.cc') diff --git a/compiler/optimizing/code_generator.cc b/compiler/optimizing/code_generator.cc index 07f018b0a9..f90f17f8f5 100644 --- a/compiler/optimizing/code_generator.cc +++ b/compiler/optimizing/code_generator.cc @@ -514,8 +514,7 @@ void CodeGenerator::CreateCommonInvokeLocationSummary( locations->SetOut(visitor->GetReturnLocation(invoke->GetType())); if (invoke->IsInvokeStaticOrDirect()) { - // TODO: Remove "OrNull". - HInvokeStaticOrDirect* call = invoke->AsInvokeStaticOrDirectOrNull(); + HInvokeStaticOrDirect* call = invoke->AsInvokeStaticOrDirect(); MethodLoadKind method_load_kind = call->GetMethodLoadKind(); CodePtrLocation code_ptr_location = call->GetCodePtrLocation(); if (code_ptr_location == CodePtrLocation::kCallCriticalNative) { @@ -999,8 +998,7 @@ void CodeGenerator::AllocateLocations(HInstruction* instruction) { } } else if (locations->Intrinsified() && instruction->IsInvokeStaticOrDirect() && - // TODO: Remove "OrNull". - !instruction->AsInvokeStaticOrDirectOrNull()->HasCurrentMethodInput()) { + !instruction->AsInvokeStaticOrDirect()->HasCurrentMethodInput()) { // A static method call that has been fully intrinsified, and cannot call on the slow // path or refer to the current method directly, no longer needs current method. return; @@ -1234,8 +1232,7 @@ void CodeGenerator::RecordPcInfo(HInstruction* instruction, return; } if (instruction->IsRem()) { - // TODO: Remove "OrNull". - DataType::Type type = instruction->AsRemOrNull()->GetResultType(); + DataType::Type type = instruction->AsRem()->GetResultType(); if ((type == DataType::Type::kFloat32) || (type == DataType::Type::kFloat64)) { return; } @@ -1358,8 +1355,7 @@ void CodeGenerator::RecordCatchBlockInfo() { dex_pc_list_for_verification.push_back(block->GetDexPc()); } DCHECK(block->GetFirstInstruction()->IsNop()); - // TODO: Remove "OrNull". - DCHECK(block->GetFirstInstruction()->AsNopOrNull()->NeedsEnvironment()); + DCHECK(block->GetFirstInstruction()->AsNop()->NeedsEnvironment()); HEnvironment* const environment = block->GetFirstInstruction()->GetEnvironment(); DCHECK(environment != nullptr); HEnvironment* outer_environment = environment; @@ -1418,29 +1414,25 @@ void CodeGenerator::EmitVRegInfo(HEnvironment* environment, case Location::kConstant: { DCHECK_EQ(current, location.GetConstant()); if (current->IsLongConstant()) { - // TODO: Remove "OrNull". - int64_t value = current->AsLongConstantOrNull()->GetValue(); + int64_t value = current->AsLongConstant()->GetValue(); stack_map_stream->AddDexRegisterEntry(Kind::kConstant, Low32Bits(value)); stack_map_stream->AddDexRegisterEntry(Kind::kConstant, High32Bits(value)); ++i; DCHECK_LT(i, environment_size); } else if (current->IsDoubleConstant()) { - // TODO: Remove "OrNull". - int64_t value = bit_cast(current->AsDoubleConstantOrNull()->GetValue()); + int64_t value = bit_cast(current->AsDoubleConstant()->GetValue()); stack_map_stream->AddDexRegisterEntry(Kind::kConstant, Low32Bits(value)); stack_map_stream->AddDexRegisterEntry(Kind::kConstant, High32Bits(value)); ++i; DCHECK_LT(i, environment_size); } else if (current->IsIntConstant()) { - // TODO: Remove "OrNull". - int32_t value = current->AsIntConstantOrNull()->GetValue(); + int32_t value = current->AsIntConstant()->GetValue(); stack_map_stream->AddDexRegisterEntry(Kind::kConstant, value); } else if (current->IsNullConstant()) { stack_map_stream->AddDexRegisterEntry(Kind::kConstant, 0); } else { DCHECK(current->IsFloatConstant()) << current->DebugName(); - // TODO: Remove "OrNull". - int32_t value = bit_cast(current->AsFloatConstantOrNull()->GetValue()); + int32_t value = bit_cast(current->AsFloatConstant()->GetValue()); stack_map_stream->AddDexRegisterEntry(Kind::kConstant, value); } break; @@ -1564,18 +1556,15 @@ void CodeGenerator::EmitVRegInfoOnlyCatchPhis(HEnvironment* environment) { DCHECK_EQ(environment->GetHolder()->GetBlock()->GetFirstInstruction(), environment->GetHolder()); HInstruction* current_phi = environment->GetHolder()->GetBlock()->GetFirstPhi(); for (size_t vreg = 0; vreg < environment->Size(); ++vreg) { - // TODO: Remove "OrNull". - while (current_phi != nullptr && current_phi->AsPhiOrNull()->GetRegNumber() < vreg) { + while (current_phi != nullptr && current_phi->AsPhi()->GetRegNumber() < vreg) { HInstruction* next_phi = current_phi->GetNext(); DCHECK(next_phi == nullptr || - // TODO: Remove "OrNull". - current_phi->AsPhiOrNull()->GetRegNumber() <= next_phi->AsPhiOrNull()->GetRegNumber()) + current_phi->AsPhi()->GetRegNumber() <= next_phi->AsPhi()->GetRegNumber()) << "Phis need to be sorted by vreg number to keep this a linear-time loop."; current_phi = next_phi; } - // TODO: Remove "OrNull". - if (current_phi == nullptr || current_phi->AsPhiOrNull()->GetRegNumber() != vreg) { + if (current_phi == nullptr || current_phi->AsPhi()->GetRegNumber() != vreg) { stack_map_stream->AddDexRegisterEntry(DexRegisterLocation::Kind::kNone, 0); } else { Location location = current_phi->GetLocations()->Out(); -- cgit v1.2.3-59-g8ed1b