summaryrefslogtreecommitdiff
path: root/compiler/optimizing/optimizing_unit_test.h
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2024-08-13 10:59:26 +0000
committer Vladimir Marko <vmarko@google.com> 2024-08-14 13:46:06 +0000
commit3b6024d5db60c891c5ef6dc18cc17f8ece56c796 (patch)
treef3ec7d0d8543e28db82f9d9f1e3c58421b68458b /compiler/optimizing/optimizing_unit_test.h
parent4910586af2f208262dd1f8225f42fa6f6e95d355 (diff)
Clean up condition simplification.
Leave condition construction in the `HGraph` but move the rest of the condition simplification code to the simplifier where it belongs. Also clean up simplifier tests and a few other gtests. Note that `SuperblockClonerTest.IndividualInstrCloner` now clones an additional `HGoto` from the entry block. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Change-Id: I73ee8c227c1c100ac7eb9d4a3813c61ad928b6dd
Diffstat (limited to 'compiler/optimizing/optimizing_unit_test.h')
-rw-r--r--compiler/optimizing/optimizing_unit_test.h53
1 files changed, 44 insertions, 9 deletions
diff --git a/compiler/optimizing/optimizing_unit_test.h b/compiler/optimizing/optimizing_unit_test.h
index c8412b876b..f0a279ca4d 100644
--- a/compiler/optimizing/optimizing_unit_test.h
+++ b/compiler/optimizing/optimizing_unit_test.h
@@ -219,7 +219,6 @@ class OptimizingUnitTestHelper {
: pool_and_allocator_(new ArenaPoolAndAllocator()),
graph_(nullptr),
entry_block_(nullptr),
- return_block_(nullptr),
exit_block_(nullptr) { }
ArenaAllocator* GetAllocator() { return pool_and_allocator_->GetAllocator(); }
@@ -290,20 +289,57 @@ class OptimizingUnitTestHelper {
}
}
- void InitGraph(VariableSizedHandleScope* handles = nullptr) {
+ // Create simple graph with "entry", "main" and "exit" blocks, return the "main" block.
+ // Adds `HGoto` to the "entry" block and `HExit` to the "exit block. Leaves "main" block empty.
+ HBasicBlock* InitEntryMainExitGraph(VariableSizedHandleScope* handles = nullptr) {
CreateGraph(handles);
entry_block_ = AddNewBlock();
- return_block_ = AddNewBlock();
+ HBasicBlock* main_block = AddNewBlock();
exit_block_ = AddNewBlock();
graph_->SetEntryBlock(entry_block_);
graph_->SetExitBlock(exit_block_);
- entry_block_->AddSuccessor(return_block_);
- return_block_->AddSuccessor(exit_block_);
+ entry_block_->AddSuccessor(main_block);
+ main_block->AddSuccessor(exit_block_);
- return_block_->AddInstruction(new (GetAllocator()) HReturnVoid());
- exit_block_->AddInstruction(new (GetAllocator()) HExit());
+ MakeGoto(entry_block_);
+ MakeExit(exit_block_);
+
+ return main_block;
+ }
+
+ // Creates a graph identical to `InitEntryMainExitGraph()` and adds `HReturnVoid`.
+ HBasicBlock* InitEntryMainExitGraphWithReturnVoid(VariableSizedHandleScope* handles = nullptr) {
+ HBasicBlock* return_block = InitEntryMainExitGraph(handles);
+ MakeReturnVoid(return_block);
+ return return_block;
+ }
+
+ // Insert "if_block", "then_block" and "else_block" before a given `merge_block`. Return the
+ // new blocks. Adds `HGoto` to "then_block" and "else_block". Adds `HIf` to the "if_block"
+ // if the caller provides a `condition`.
+ std::tuple<HBasicBlock*, HBasicBlock*, HBasicBlock*> CreateDiamondPattern(
+ HBasicBlock* merge_block, HInstruction* condition = nullptr) {
+ HBasicBlock* if_block = AddNewBlock();
+ HBasicBlock* then_block = AddNewBlock();
+ HBasicBlock* else_block = AddNewBlock();
+
+ HBasicBlock* predecessor = merge_block->GetSinglePredecessor();
+ predecessor->ReplaceSuccessor(merge_block, if_block);
+
+ if_block->AddSuccessor(then_block);
+ if_block->AddSuccessor(else_block);
+ then_block->AddSuccessor(merge_block);
+ else_block->AddSuccessor(merge_block);
+
+ if (condition != nullptr) {
+ MakeIf(if_block, condition);
+ }
+ MakeGoto(then_block);
+ MakeGoto(else_block);
+
+ return {if_block, then_block, else_block};
}
HBasicBlock* AddNewBlock() {
@@ -676,7 +712,7 @@ class OptimizingUnitTestHelper {
HParameterValue* MakeParam(DataType::Type type, std::optional<dex::TypeIndex> ti = std::nullopt) {
HParameterValue* val = new (GetAllocator()) HParameterValue(
graph_->GetDexFile(), ti ? *ti : DefaultTypeIndexForType(type), param_count_++, type);
- graph_->GetEntryBlock()->AddInstruction(val);
+ AddOrInsertInstruction(graph_->GetEntryBlock(), val);
return val;
}
@@ -693,7 +729,6 @@ class OptimizingUnitTestHelper {
HGraph* graph_;
HBasicBlock* entry_block_;
- HBasicBlock* return_block_;
HBasicBlock* exit_block_;
size_t param_count_ = 0;