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/select_generator.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/select_generator.cc')
-rw-r--r-- | compiler/optimizing/select_generator.cc | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/compiler/optimizing/select_generator.cc b/compiler/optimizing/select_generator.cc index 07065efbb7..54eac54c01 100644 --- a/compiler/optimizing/select_generator.cc +++ b/compiler/optimizing/select_generator.cc @@ -46,7 +46,9 @@ static bool IsSimpleBlock(HBasicBlock* block) { } else if (instruction->CanBeMoved() && !instruction->HasSideEffects() && !instruction->CanThrow()) { - if (instruction->IsSelect() && instruction->AsSelect()->GetCondition()->GetBlock() == block) { + if (instruction->IsSelect() && + // TODO: Remove "OrNull". + instruction->AsSelectOrNull()->GetCondition()->GetBlock() == block) { // Count one HCondition and HSelect in the same block as a single instruction. // This enables finding nested selects. continue; @@ -75,7 +77,8 @@ static HPhi* GetSinglePhi(HBasicBlock* block, size_t index1, size_t index2) { HPhi* select_phi = nullptr; for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) { - HPhi* phi = it.Current()->AsPhi(); + // TODO: Remove "OrNull". + HPhi* phi = it.Current()->AsPhiOrNull(); if (select_phi == nullptr) { // First phi found. select_phi = phi; @@ -90,7 +93,8 @@ static HPhi* GetSinglePhi(HBasicBlock* block, size_t index1, size_t index2) { bool HSelectGenerator::TryGenerateSelectSimpleDiamondPattern( HBasicBlock* block, ScopedArenaSafeMap<HInstruction*, HSelect*>* cache) { DCHECK(block->GetLastInstruction()->IsIf()); - HIf* if_instruction = block->GetLastInstruction()->AsIf(); + // TODO: Remove "OrNull". + HIf* if_instruction = block->GetLastInstruction()->AsIfOrNull(); HBasicBlock* true_block = if_instruction->IfTrueSuccessor(); HBasicBlock* false_block = if_instruction->IfFalseSuccessor(); DCHECK_NE(true_block, false_block); @@ -216,7 +220,8 @@ bool HSelectGenerator::TryGenerateSelectSimpleDiamondPattern( HBasicBlock* HSelectGenerator::TryFixupDoubleDiamondPattern(HBasicBlock* block) { DCHECK(block->GetLastInstruction()->IsIf()); - HIf* if_instruction = block->GetLastInstruction()->AsIf(); + // TODO: Remove "OrNull". + HIf* if_instruction = block->GetLastInstruction()->AsIfOrNull(); HBasicBlock* true_block = if_instruction->IfTrueSuccessor(); HBasicBlock* false_block = if_instruction->IfFalseSuccessor(); DCHECK_NE(true_block, false_block); @@ -231,7 +236,8 @@ HBasicBlock* HSelectGenerator::TryFixupDoubleDiamondPattern(HBasicBlock* block) // The innner if branch has to be a block with just a comparison and an if. if (!inner_if_block->EndsWithIf() || - inner_if_block->GetLastInstruction()->AsIf()->InputAt(0) != + // TODO: Remove "OrNull". + inner_if_block->GetLastInstruction()->AsIfOrNull()->InputAt(0) != inner_if_block->GetFirstInstruction() || inner_if_block->GetLastInstruction()->GetPrevious() != inner_if_block->GetFirstInstruction() || @@ -239,7 +245,8 @@ HBasicBlock* HSelectGenerator::TryFixupDoubleDiamondPattern(HBasicBlock* block) return nullptr; } - HIf* inner_if_instruction = inner_if_block->GetLastInstruction()->AsIf(); + // TODO: Remove "OrNull". + HIf* inner_if_instruction = inner_if_block->GetLastInstruction()->AsIfOrNull(); HBasicBlock* inner_if_true_block = inner_if_instruction->IfTrueSuccessor(); HBasicBlock* inner_if_false_block = inner_if_instruction->IfFalseSuccessor(); if (!inner_if_true_block->IsSingleGoto() || !inner_if_false_block->IsSingleGoto()) { @@ -262,7 +269,8 @@ HBasicBlock* HSelectGenerator::TryFixupDoubleDiamondPattern(HBasicBlock* block) return nullptr; } - HPhi* first_phi = first_merge->GetFirstPhi()->AsPhi(); + // TODO: Remove "OrNull". + HPhi* first_phi = first_merge->GetFirstPhi()->AsPhiOrNull(); // Second merge is first_merge and the remainder branch merging. It must be phi + goto, or phi + // return. Depending on the first merge, we define the second merge. @@ -284,7 +292,8 @@ HBasicBlock* HSelectGenerator::TryFixupDoubleDiamondPattern(HBasicBlock* block) } size_t index = second_merge->GetPredecessorIndexOf(merges_into_second_merge); - HPhi* second_phi = second_merge->GetFirstPhi()->AsPhi(); + // TODO: Remove "OrNull". + HPhi* second_phi = second_merge->GetFirstPhi()->AsPhiOrNull(); // Merge the phis. first_phi->AddInput(second_phi->InputAt(index)); |