summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
author Santiago Aboy Solanes <solanes@google.com> 2024-11-18 15:51:22 +0000
committer Santiago Aboy Solanes <solanes@google.com> 2025-01-03 07:55:11 -0800
commit8842f9debe16fd1251cd6dbe16fd8c168098c61d (patch)
tree1c0e3df6cff6dbf1a6e24302c7ffe8a4739ee68a /compiler
parent970075bedbf0599cfd1ccea388d654cd68576608 (diff)
Remove superblock cloner's DoVersioning
It was added back in 2020 (r.android.com/1206763) but never used. Test: art/test/testrunner/testrunner.py --host --64 --optimizing -b Change-Id: Iace09f956bd520732588b3623722b74f6559a1fe
Diffstat (limited to 'compiler')
-rw-r--r--compiler/optimizing/superblock_cloner.cc64
-rw-r--r--compiler/optimizing/superblock_cloner.h50
-rw-r--r--compiler/optimizing/superblock_cloner_test.cc46
3 files changed, 11 insertions, 149 deletions
diff --git a/compiler/optimizing/superblock_cloner.cc b/compiler/optimizing/superblock_cloner.cc
index 276d2246cb..a7328a1218 100644
--- a/compiler/optimizing/superblock_cloner.cc
+++ b/compiler/optimizing/superblock_cloner.cc
@@ -227,40 +227,6 @@ void SuperblockCloner::RemapCopyInternalEdge(HBasicBlock* orig_block,
}
}
-bool SuperblockCloner::IsRemapInfoForVersioning() const {
- return remap_incoming_->empty() &&
- remap_orig_internal_->empty() &&
- remap_copy_internal_->empty();
-}
-
-void SuperblockCloner::CopyIncomingEdgesForVersioning() {
- for (uint32_t orig_block_id : orig_bb_set_.Indexes()) {
- HBasicBlock* orig_block = GetBlockById(orig_block_id);
- size_t incoming_edge_count = 0;
- for (HBasicBlock* orig_pred : orig_block->GetPredecessors()) {
- uint32_t orig_pred_id = orig_pred->GetBlockId();
- if (IsInOrigBBSet(orig_pred_id)) {
- continue;
- }
-
- HBasicBlock* copy_block = GetBlockCopy(orig_block);
- // This corresponds to the requirement on the order of predecessors: all the incoming
- // edges must be seen before the internal ones. This is always true for natural loops.
- // TODO: remove this requirement.
- DCHECK_EQ(orig_block->GetPredecessorIndexOf(orig_pred), incoming_edge_count);
- for (HInstructionIterator it(orig_block->GetPhis()); !it.Done(); it.Advance()) {
- HPhi* orig_phi = it.Current()->AsPhi();
- HPhi* copy_phi = GetInstrCopy(orig_phi)->AsPhi();
- HInstruction* orig_phi_input = orig_phi->InputAt(incoming_edge_count);
- // Add the corresponding input of the original phi to the copy one.
- copy_phi->AddInput(orig_phi_input);
- }
- copy_block->AddPredecessor(orig_pred);
- incoming_edge_count++;
- }
- }
-}
-
//
// Local versions of CF calculation/adjustment routines.
//
@@ -484,12 +450,6 @@ void SuperblockCloner::FindAndSetLocalAreaForAdjustments() {
}
void SuperblockCloner::RemapEdgesSuccessors() {
- // By this stage all the blocks have been copied, copy phis - created with no inputs;
- // no copy edges have been created so far.
- if (IsRemapInfoForVersioning()) {
- CopyIncomingEdgesForVersioning();
- }
-
// Redirect incoming edges.
for (HEdge e : *remap_incoming_) {
HBasicBlock* orig_block = GetBlockById(e.GetFrom());
@@ -897,7 +857,7 @@ bool SuperblockCloner::IsSubgraphClonable() const {
return true;
}
-// Checks that loop unrolling/peeling/versioning is being conducted.
+// Checks that loop unrolling/peeling is being conducted.
bool SuperblockCloner::IsFastCase() const {
// Check that all the basic blocks belong to the same loop.
bool flag = false;
@@ -914,15 +874,11 @@ bool SuperblockCloner::IsFastCase() const {
}
}
- // Check that orig_bb_set_ corresponds to loop peeling/unrolling/versioning.
+ // Check that orig_bb_set_ corresponds to loop peeling/unrolling.
if (common_loop_info == nullptr || !orig_bb_set_.SameBitsSet(&common_loop_info->GetBlocks())) {
return false;
}
- if (IsRemapInfoForVersioning()) {
- return true;
- }
-
bool peeling_or_unrolling = false;
HEdgeSet remap_orig_internal(graph_->GetAllocator()->Adapter(kArenaAllocSuperblockCloner));
HEdgeSet remap_copy_internal(graph_->GetAllocator()->Adapter(kArenaAllocSuperblockCloner));
@@ -1171,9 +1127,6 @@ HBasicBlock* LoopClonerHelper::DoLoopTransformationImpl(TransformationKind trans
case TransformationKind::kUnrolling:
oss<< "unrolling";
break;
- case TransformationKind::kVersioning:
- oss << "versioning";
- break;
}
oss << " was applied to the loop <" << loop_header->GetBlockId() << ">.";
LOG(INFO) << oss.str();
@@ -1185,14 +1138,11 @@ HBasicBlock* LoopClonerHelper::DoLoopTransformationImpl(TransformationKind trans
HEdgeSet remap_copy_internal(graph->GetAllocator()->Adapter(kArenaAllocSuperblockCloner));
HEdgeSet remap_incoming(graph->GetAllocator()->Adapter(kArenaAllocSuperblockCloner));
- // No remapping needed for loop versioning.
- if (transformation != TransformationKind::kVersioning) {
- CollectRemappingInfoForPeelUnroll(transformation == TransformationKind::kUnrolling,
- loop_info_,
- &remap_orig_internal,
- &remap_copy_internal,
- &remap_incoming);
- }
+ CollectRemappingInfoForPeelUnroll(transformation == TransformationKind::kUnrolling,
+ loop_info_,
+ &remap_orig_internal,
+ &remap_copy_internal,
+ &remap_incoming);
cloner_.SetSuccessorRemappingInfo(&remap_orig_internal, &remap_copy_internal, &remap_incoming);
cloner_.Run();
diff --git a/compiler/optimizing/superblock_cloner.h b/compiler/optimizing/superblock_cloner.h
index c327867342..d4db0b3852 100644
--- a/compiler/optimizing/superblock_cloner.h
+++ b/compiler/optimizing/superblock_cloner.h
@@ -90,8 +90,7 @@ inline bool IsEdgeValid(HEdge edge, HGraph* graph) {
// fine grain manipulation with IR; data flow and graph properties are resolved/adjusted
// automatically. The clone transformation is defined by specifying a set of basic blocks to copy
// and a set of rules how to treat edges, remap their successors. By using this approach such
-// optimizations as Branch Target Expansion, Loop Peeling, Loop Unrolling, Loop Versioning can be
-// implemented.
+// optimizations as Branch Target Expansion, Loop Peeling, Loop Unrolling can be implemented.
//
// The idea of the transformation is based on "Superblock cloning" technique described in the book
// "Engineering a Compiler. Second Edition", Keith D. Cooper, Linda Torczon, Rice University
@@ -163,7 +162,7 @@ class SuperblockCloner : public ValueObject {
//
// TODO: formally describe the criteria.
//
- // Loop peeling, unrolling and versioning satisfy the criteria.
+ // Loop peeling and unrolling satisfy the criteria.
bool IsFastCase() const;
// Runs the copy algorithm according to the description.
@@ -299,18 +298,6 @@ class SuperblockCloner : public ValueObject {
// Remaps copy internal edge to its origin, adjusts the phi inputs in orig_succ.
void RemapCopyInternalEdge(HBasicBlock* orig_block, HBasicBlock* orig_succ);
- // Checks whether the edges remapping info corresponds to the subgraph versioning case:
- // - none of the incoming edges are to be remapped (they are being duplicated).
- // - none of the internal edges are to be remapped.
- bool IsRemapInfoForVersioning() const;
-
- // Processes incoming edges for subgraph versioning case: for each incoming edge (X, Y) adds
- // an edge (X, Y_1) where Y_1 = Copy(Y) and add corresponding phi input to copy phi.
- //
- // Note: such node X will now have two successors, its unconditional branch instruction
- // will be invalid and should be adjusted to some conditional branch by the client code.
- void CopyIncomingEdgesForVersioning();
-
//
// Local versions of control flow calculation/adjustment routines.
//
@@ -376,7 +363,7 @@ class SuperblockCloner : public ValueObject {
DISALLOW_COPY_AND_ASSIGN(SuperblockCloner);
};
-// Helper class to perform loop peeling/unrolling/versioning.
+// Helper class to perform loop peeling/unrolling.
//
// This helper should be used when correspondence map between original and copied
// basic blocks/instructions are demanded.
@@ -456,40 +443,12 @@ class LoopClonerHelper : public ValueObject {
return DoLoopTransformationImpl(TransformationKind::kUnrolling);
}
- // Perform loop versioning.
- //
- // Control flow of an example (ignoring critical edges splitting).
- //
- // Before After
- //
- // |B| |B|
- // | |
- // v v
- // |1| |1|_________
- // | | |
- // v v v
- // |2|<-\ |2|<-\ |2A|<-\
- // / \ / / \ / / \ /
- // v v/ | v/ | v/
- // | |3| | |3| | |3A|
- // | | __________|
- // | ||
- // v vv
- // |4| |4|
- // | |
- // v v
- // |E| |E|
- HBasicBlock* DoVersioning() {
- return DoLoopTransformationImpl(TransformationKind::kVersioning);
- }
-
HLoopInformation* GetRegionToBeAdjusted() const { return cloner_.GetRegionToBeAdjusted(); }
protected:
enum class TransformationKind {
kPeeling,
kUnrolling,
- kVersioning,
};
// Applies a specific loop transformation to the loop.
@@ -502,7 +461,7 @@ class LoopClonerHelper : public ValueObject {
DISALLOW_COPY_AND_ASSIGN(LoopClonerHelper);
};
-// Helper class to perform loop peeling/unrolling/versioning.
+// Helper class to perform loop peeling/unrolling.
//
// This helper should be used when there is no need to get correspondence information between
// original and copied basic blocks/instructions.
@@ -512,7 +471,6 @@ class LoopClonerSimpleHelper : public ValueObject {
bool IsLoopClonable() const { return helper_.IsLoopClonable(); }
HBasicBlock* DoPeeling() { return helper_.DoPeeling(); }
HBasicBlock* DoUnrolling() { return helper_.DoUnrolling(); }
- HBasicBlock* DoVersioning() { return helper_.DoVersioning(); }
HLoopInformation* GetRegionToBeAdjusted() const { return helper_.GetRegionToBeAdjusted(); }
const SuperblockCloner::HBasicBlockMap* GetBasicBlockMap() const { return &bb_map_; }
diff --git a/compiler/optimizing/superblock_cloner_test.cc b/compiler/optimizing/superblock_cloner_test.cc
index 5190dae033..1bef8a4e9d 100644
--- a/compiler/optimizing/superblock_cloner_test.cc
+++ b/compiler/optimizing/superblock_cloner_test.cc
@@ -301,52 +301,6 @@ TEST_F(SuperblockClonerTest, LoopUnrolling) {
EXPECT_EQ(loop_info->GetBackEdges()[0], bb_map.Get(loop_body));
}
-// Tests SuperblockCloner for loop versioning case.
-//
-// See an ASCII graphics example near LoopClonerHelper::DoVersioning.
-TEST_F(SuperblockClonerTest, LoopVersioning) {
- HBasicBlock* return_block = InitGraphAndParameters();
- auto [preheader, header, loop_body] = CreateWhileLoop(return_block);
- CreateBasicLoopDataFlow(header, loop_body);
- graph_->BuildDominatorTree();
- EXPECT_TRUE(CheckGraph());
-
- HBasicBlockMap bb_map(
- std::less<HBasicBlock*>(), graph_->GetAllocator()->Adapter(kArenaAllocSuperblockCloner));
- HInstructionMap hir_map(
- std::less<HInstruction*>(), graph_->GetAllocator()->Adapter(kArenaAllocSuperblockCloner));
-
- HLoopInformation* loop_info = header->GetLoopInformation();
- HBasicBlock* original_preheader = loop_info->GetPreHeader();
- LoopClonerHelper helper(loop_info, &bb_map, &hir_map, /* induction_range= */ nullptr);
- EXPECT_TRUE(helper.IsLoopClonable());
- HBasicBlock* new_header = helper.DoVersioning();
- EXPECT_EQ(header, new_header);
-
- EXPECT_TRUE(CheckGraph());
-
- HBasicBlock* second_header = bb_map.Get(header);
- HBasicBlock* second_body = bb_map.Get(loop_body);
- HLoopInformation* second_loop_info = second_header->GetLoopInformation();
-
- // Check loop body successors.
- EXPECT_EQ(loop_body->GetSingleSuccessor(), header);
- EXPECT_EQ(second_body->GetSingleSuccessor(), second_header);
-
- // Check loop structure.
- EXPECT_EQ(loop_info, header->GetLoopInformation());
- EXPECT_EQ(loop_info->GetHeader(), header);
- EXPECT_EQ(second_loop_info->GetHeader(), second_header);
-
- EXPECT_EQ(loop_info->GetBackEdges().size(), 1u);
- EXPECT_EQ(second_loop_info->GetBackEdges().size(), 1u);
-
- EXPECT_EQ(loop_info->GetBackEdges()[0], loop_body);
- EXPECT_EQ(second_loop_info->GetBackEdges()[0], second_body);
-
- EXPECT_EQ(original_preheader->GetSuccessors().size(), 2u);
-}
-
// Checks that loop unrolling works fine for a loop with multiple back edges. Tests that after
// the transformation the loop has a single preheader.
TEST_F(SuperblockClonerTest, LoopPeelingMultipleBackEdges) {