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/induction_var_analysis.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/induction_var_analysis.cc')
-rw-r--r-- | compiler/optimizing/induction_var_analysis.cc | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/compiler/optimizing/induction_var_analysis.cc b/compiler/optimizing/induction_var_analysis.cc index be6c268f5d..e54d12b931 100644 --- a/compiler/optimizing/induction_var_analysis.cc +++ b/compiler/optimizing/induction_var_analysis.cc @@ -89,12 +89,14 @@ static bool IsGuardedBy(const HLoopInformation* loop, if (!control->IsIf()) { return false; } - HIf* ifs = control->AsIf(); + // TODO: Remove "OrNull". + HIf* ifs = control->AsIfOrNull(); HInstruction* if_expr = ifs->InputAt(0); if (if_expr->IsCondition()) { + // TODO: Remove "OrNull". IfCondition other_cmp = ifs->IfTrueSuccessor() == entry - ? if_expr->AsCondition()->GetCondition() - : if_expr->AsCondition()->GetOppositeCondition(); + ? if_expr->AsConditionOrNull()->GetCondition() + : if_expr->AsConditionOrNull()->GetOppositeCondition(); if (if_expr->InputAt(0) == a && if_expr->InputAt(1) == b) { return cmp == other_cmp; } else if (if_expr->InputAt(1) == a && if_expr->InputAt(0) == b) { @@ -435,9 +437,10 @@ void HInductionVarAnalysis::ClassifyTrivial(const HLoopInformation* loop, } else if (instruction->IsSelect()) { info = TransferPhi(loop, instruction, /*input_index*/ 0, /*adjust_input_size*/ 1); } else if (instruction->IsTypeConversion()) { + // TODO: Remove "OrNull". info = TransferConversion(LookupInfo(loop, instruction->InputAt(0)), - instruction->AsTypeConversion()->GetInputType(), - instruction->AsTypeConversion()->GetResultType()); + instruction->AsTypeConversionOrNull()->GetInputType(), + instruction->AsTypeConversionOrNull()->GetResultType()); } else if (instruction->IsBoundsCheck()) { info = LookupInfo(loop, instruction->InputAt(0)); // Pass-through. } @@ -473,7 +476,8 @@ void HInductionVarAnalysis::ClassifyNonTrivial(const HLoopInformation* loop, // Store interesting cycle in each loop phi. for (size_t i = 0; i < size; i++) { if (scc[i]->IsLoopHeaderPhi()) { - AssignCycle(scc[i]->AsPhi(), ArrayRef<HInstruction* const>(scc)); + // TODO: Remove "OrNull". + AssignCycle(scc[i]->AsPhiOrNull(), ArrayRef<HInstruction* const>(scc)); } } @@ -548,7 +552,8 @@ void HInductionVarAnalysis::ClassifyNonTrivial(const HLoopInformation* loop, // Select acts like Phi. update = SolvePhi(instruction, /*input_index=*/ 0, /*adjust_input_size=*/ 1, cycle); } else if (instruction->IsTypeConversion()) { - update = SolveConversion(loop, phi, instruction->AsTypeConversion(), cycle, &type); + // TODO: Remove "OrNull". + update = SolveConversion(loop, phi, instruction->AsTypeConversionOrNull(), cycle, &type); } if (update == nullptr) { return; @@ -998,7 +1003,8 @@ HInductionVarAnalysis::InductionInfo* HInductionVarAnalysis::SolveConversion( void HInductionVarAnalysis::VisitControl(const HLoopInformation* loop) { HInstruction* control = loop->GetHeader()->GetLastInstruction(); if (control->IsIf()) { - HIf* ifs = control->AsIf(); + // TODO: Remove "OrNull". + HIf* ifs = control->AsIfOrNull(); HBasicBlock* if_true = ifs->IfTrueSuccessor(); HBasicBlock* if_false = ifs->IfFalseSuccessor(); HInstruction* if_expr = ifs->InputAt(0); @@ -1006,7 +1012,8 @@ void HInductionVarAnalysis::VisitControl(const HLoopInformation* loop) { // loop-header: .... // if (condition) goto X if (if_expr->IsCondition()) { - HCondition* condition = if_expr->AsCondition(); + // TODO: Remove "OrNull". + HCondition* condition = if_expr->AsConditionOrNull(); const HBasicBlock* context = condition->GetBlock(); InductionInfo* a = LookupInfo(loop, condition->InputAt(0)); InductionInfo* b = LookupInfo(loop, condition->InputAt(1)); @@ -1252,7 +1259,8 @@ bool HInductionVarAnalysis::RewriteBreakLoop(const HBasicBlock* context, return false; } // Simple terminating i != U condition, used nowhere else. - HIf* ifs = loop->GetHeader()->GetLastInstruction()->AsIf(); + // TODO: Remove "OrNull". + HIf* ifs = loop->GetHeader()->GetLastInstruction()->AsIfOrNull(); HInstruction* cond = ifs->InputAt(0); if (ifs->GetPrevious() != cond || !cond->HasOnlyOneNonEnvironmentUse()) { return false; @@ -1515,9 +1523,11 @@ bool HInductionVarAnalysis::InductionEqual(InductionInfo* info1, std::string HInductionVarAnalysis::FetchToString(HInstruction* fetch) { DCHECK(fetch != nullptr); if (fetch->IsIntConstant()) { - return std::to_string(fetch->AsIntConstant()->GetValue()); + // TODO: Remove "OrNull". + return std::to_string(fetch->AsIntConstantOrNull()->GetValue()); } else if (fetch->IsLongConstant()) { - return std::to_string(fetch->AsLongConstant()->GetValue()); + // TODO: Remove "OrNull". + return std::to_string(fetch->AsLongConstantOrNull()->GetValue()); } return std::to_string(fetch->GetId()) + ":" + fetch->DebugName(); } @@ -1609,7 +1619,8 @@ void HInductionVarAnalysis::CalculateLoopHeaderPhisInARow( // If the input is not a loop header phi, we only have 1 (current_phi). int current_value = 1; if (current_phi->InputAt(index)->IsLoopHeaderPhi()) { - HPhi* loop_header_phi = current_phi->InputAt(index)->AsPhi(); + // TODO: Remove "OrNull". + HPhi* loop_header_phi = current_phi->InputAt(index)->AsPhiOrNull(); auto it = cached_values.find(loop_header_phi); if (it != cached_values.end()) { current_value += it->second; @@ -1650,7 +1661,8 @@ bool HInductionVarAnalysis::IsPathologicalCase() { for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) { DCHECK(it.Current()->IsLoopHeaderPhi()); - HPhi* phi = it.Current()->AsPhi(); + // TODO: Remove "OrNull". + HPhi* phi = it.Current()->AsPhiOrNull(); CalculateLoopHeaderPhisInARow(phi, cached_values, local_allocator); DCHECK(cached_values.find(phi) != cached_values.end()) << " we should have a value for Phi " << phi->GetId() |