summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Marko <vmarko@google.com>2024-02-08 09:49:48 +0000
committerVladimĂ­r Marko <vmarko@google.com>2024-02-09 09:05:18 +0000
commitced2fc97ec95f2924059544f13d6ff353973d552 (patch)
tree7131429c7cd6b9a18ef255ce5d7a160ac274c371
parentcea2f596f98b79fafaded1c36c98aa3fa04d5147 (diff)
downloadart-ced2fc97ec95f2924059544f13d6ff353973d552.tar.gz
Clean up `HGraphVisitor::VisitBasicBlock()`.
Skip `HPhi::Accept()` and add functions to visit only Phis or only non-Phi instructions. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 181943478 Change-Id: Iba0690ae70f46d6a2bafa9055b2ae5167e58a2f4
-rw-r--r--compiler/optimizing/constant_folding.cc9
-rw-r--r--compiler/optimizing/constructor_fence_redundancy_elimination.cc4
-rw-r--r--compiler/optimizing/instruction_simplifier.cc2
-rw-r--r--compiler/optimizing/load_store_elimination.cc4
-rw-r--r--compiler/optimizing/nodes.cc12
-rw-r--r--compiler/optimizing/nodes.h3
-rw-r--r--compiler/optimizing/profiling_info_builder.cc5
-rw-r--r--compiler/optimizing/reference_type_propagation.cc9
-rw-r--r--compiler/optimizing/write_barrier_elimination.cc2
9 files changed, 26 insertions, 24 deletions
diff --git a/compiler/optimizing/constant_folding.cc b/compiler/optimizing/constant_folding.cc
index b0a65ca64d..f57d8ade16 100644
--- a/compiler/optimizing/constant_folding.cc
+++ b/compiler/optimizing/constant_folding.cc
@@ -117,12 +117,9 @@ bool HConstantFolding::Run() {
void HConstantFoldingVisitor::VisitBasicBlock(HBasicBlock* block) {
- // Traverse this block's instructions (phis don't need to be
- // processed) in (forward) order and replace the ones that can be
- // statically evaluated by a compile-time counterpart.
- for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) {
- it.Current()->Accept(this);
- }
+ // Traverse this block's instructions (phis don't need to be processed) in (forward) order
+ // and replace the ones that can be statically evaluated by a compile-time counterpart.
+ VisitNonPhiInstructions(block);
}
void HConstantFoldingVisitor::VisitUnaryOperation(HUnaryOperation* inst) {
diff --git a/compiler/optimizing/constructor_fence_redundancy_elimination.cc b/compiler/optimizing/constructor_fence_redundancy_elimination.cc
index 9b3bb91d21..30c33dd5c5 100644
--- a/compiler/optimizing/constructor_fence_redundancy_elimination.cc
+++ b/compiler/optimizing/constructor_fence_redundancy_elimination.cc
@@ -37,8 +37,8 @@ class CFREVisitor final : public HGraphVisitor {
stats_(stats) {}
void VisitBasicBlock(HBasicBlock* block) override {
- // Visit all instructions in block.
- HGraphVisitor::VisitBasicBlock(block);
+ // Visit all non-Phi instructions in the block.
+ VisitNonPhiInstructions(block);
// If there were any unmerged fences left, merge them together,
// the objects are considered 'published' at the end of the block.
diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc
index 44d624883d..d39e9ad32f 100644
--- a/compiler/optimizing/instruction_simplifier.cc
+++ b/compiler/optimizing/instruction_simplifier.cc
@@ -170,7 +170,7 @@ bool InstructionSimplifierVisitor::Run() {
// post order visit, we sometimes need to revisit an instruction index.
do {
simplification_occurred_ = false;
- VisitBasicBlock(block);
+ VisitNonPhiInstructions(block);
if (simplification_occurred_) {
didSimplify = true;
}
diff --git a/compiler/optimizing/load_store_elimination.cc b/compiler/optimizing/load_store_elimination.cc
index 09e23a8552..80cf9e669b 100644
--- a/compiler/optimizing/load_store_elimination.cc
+++ b/compiler/optimizing/load_store_elimination.cc
@@ -1834,8 +1834,8 @@ void LSEVisitor::VisitBasicBlock(HBasicBlock* block) {
} else {
MergePredecessorRecords(block);
}
- // Visit instructions.
- HGraphVisitor::VisitBasicBlock(block);
+ // Visit non-Phi instructions.
+ VisitNonPhiInstructions(block);
}
bool LSEVisitor::MayAliasOnBackEdge(HBasicBlock* loop_header, size_t idx1, size_t idx2) const {
diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc
index 94f197d8f1..c87c78815b 100644
--- a/compiler/optimizing/nodes.cc
+++ b/compiler/optimizing/nodes.cc
@@ -1693,10 +1693,20 @@ void HGraphVisitor::VisitReversePostOrder() {
}
void HGraphVisitor::VisitBasicBlock(HBasicBlock* block) {
+ VisitPhis(block);
+ VisitNonPhiInstructions(block);
+}
+
+void HGraphVisitor::VisitPhis(HBasicBlock* block) {
for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) {
- it.Current()->Accept(this);
+ DCHECK(it.Current()->IsPhi());
+ VisitPhi(it.Current()->AsPhi());
}
+}
+
+void HGraphVisitor::VisitNonPhiInstructions(HBasicBlock* block) {
for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) {
+ DCHECK(!it.Current()->IsPhi());
it.Current()->Accept(this);
}
}
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h
index bf4a66dfc3..4d6b909629 100644
--- a/compiler/optimizing/nodes.h
+++ b/compiler/optimizing/nodes.h
@@ -8572,6 +8572,9 @@ class HGraphVisitor : public ValueObject {
#undef DECLARE_VISIT_INSTRUCTION
protected:
+ void VisitPhis(HBasicBlock* block);
+ void VisitNonPhiInstructions(HBasicBlock* block);
+
OptimizingCompilerStats* stats_;
private:
diff --git a/compiler/optimizing/profiling_info_builder.cc b/compiler/optimizing/profiling_info_builder.cc
index f6cf676813..7faf2bf5be 100644
--- a/compiler/optimizing/profiling_info_builder.cc
+++ b/compiler/optimizing/profiling_info_builder.cc
@@ -33,10 +33,7 @@ void ProfilingInfoBuilder::Run() {
// Order does not matter.
for (HBasicBlock* block : GetGraph()->GetReversePostOrder()) {
// No need to visit the phis.
- for (HInstructionIteratorHandleChanges inst_it(block->GetInstructions()); !inst_it.Done();
- inst_it.Advance()) {
- inst_it.Current()->Accept(this);
- }
+ VisitNonPhiInstructions(block);
}
ScopedObjectAccess soa(Thread::Current());
diff --git a/compiler/optimizing/reference_type_propagation.cc b/compiler/optimizing/reference_type_propagation.cc
index 6f44d45ed4..91a6fd5d3a 100644
--- a/compiler/optimizing/reference_type_propagation.cc
+++ b/compiler/optimizing/reference_type_propagation.cc
@@ -316,16 +316,11 @@ bool ReferenceTypePropagation::Run() {
void ReferenceTypePropagation::RTPVisitor::VisitBasicBlock(HBasicBlock* block) {
// Handle Phis first as there might be instructions in the same block who depend on them.
- for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) {
- VisitPhi(it.Current()->AsPhi());
- }
+ VisitPhis(block);
// Handle instructions. Since RTP may add HBoundType instructions just after the
// last visited instruction, use `HInstructionIteratorHandleChanges` iterator.
- for (HInstructionIteratorHandleChanges it(block->GetInstructions()); !it.Done(); it.Advance()) {
- HInstruction* instr = it.Current();
- instr->Accept(this);
- }
+ VisitNonPhiInstructions(block);
// Add extra nodes to bound types.
BoundTypeForIfNotNull(block);
diff --git a/compiler/optimizing/write_barrier_elimination.cc b/compiler/optimizing/write_barrier_elimination.cc
index 27348cd87d..220eb78e02 100644
--- a/compiler/optimizing/write_barrier_elimination.cc
+++ b/compiler/optimizing/write_barrier_elimination.cc
@@ -38,7 +38,7 @@ class WBEVisitor final : public HGraphVisitor {
// We clear the map to perform this optimization only in the same block. Doing it across blocks
// would entail non-trivial merging of states.
current_write_barriers_.clear();
- HGraphVisitor::VisitBasicBlock(block);
+ VisitNonPhiInstructions(block);
}
void VisitInstanceFieldSet(HInstanceFieldSet* instruction) override {