summaryrefslogtreecommitdiff
path: root/compiler/optimizing/optimizing_unit_test.h
diff options
context:
space:
mode:
authorVladimir Marko <vmarko@google.com>2020-05-13 17:30:32 +0100
committerVladimir Marko <vmarko@google.com>2020-05-14 08:18:05 +0000
commit5d2311a349f208f056b33da8fc9c950aad1a7ffe (patch)
treec675c1e49da6057ce1ed8f9f453db9881198f30f /compiler/optimizing/optimizing_unit_test.h
parent58520dfba31d6eeef75f5babff15e09aa28e5db8 (diff)
Optimizing: Refactor ImprovedOptimizingUnitTest.
And merge all functionality into OptimizingUnitTest. Test: m test-art-host-gtest Change-Id: I69a4e8c489462700ec0eb9ed93d5cdbdb6147f1a
Diffstat (limited to 'compiler/optimizing/optimizing_unit_test.h')
-rw-r--r--compiler/optimizing/optimizing_unit_test.h112
1 files changed, 52 insertions, 60 deletions
diff --git a/compiler/optimizing/optimizing_unit_test.h b/compiler/optimizing/optimizing_unit_test.h
index 2c757f8535..61e16800e5 100644
--- a/compiler/optimizing/optimizing_unit_test.h
+++ b/compiler/optimizing/optimizing_unit_test.h
@@ -109,7 +109,12 @@ class ArenaPoolAndAllocator {
// multiple inheritance errors from having two gtest as a parent twice.
class OptimizingUnitTestHelper {
public:
- OptimizingUnitTestHelper() : pool_and_allocator_(new ArenaPoolAndAllocator()) { }
+ OptimizingUnitTestHelper()
+ : pool_and_allocator_(new ArenaPoolAndAllocator()),
+ graph_(nullptr),
+ entry_block_(nullptr),
+ return_block_(nullptr),
+ exit_block_(nullptr) { }
ArenaAllocator* GetAllocator() { return pool_and_allocator_->GetAllocator(); }
ArenaStack* GetArenaStack() { return pool_and_allocator_->GetArenaStack(); }
@@ -136,13 +141,14 @@ class OptimizingUnitTestHelper {
/*oat_dex_file*/ nullptr,
/*container*/ nullptr));
- return new (allocator) HGraph(
+ graph_ = new (allocator) HGraph(
allocator,
pool_and_allocator_->GetArenaStack(),
handles,
*dex_files_.back(),
/*method_idx*/-1,
kRuntimeISA);
+ return graph_;
}
// Create a control-flow graph from Dex instructions.
@@ -177,75 +183,53 @@ class OptimizingUnitTestHelper {
}
}
- // Run GraphChecker with all checks.
- //
- // Return: the status whether the run is successful.
- bool CheckGraph(HGraph* graph) {
- return CheckGraph(graph, /*check_ref_type_info=*/true);
- }
-
- // Run GraphChecker with all checks except reference type information checks.
- //
- // Return: the status whether the run is successful.
- bool CheckGraphSkipRefTypeInfoChecks(HGraph* graph) {
- return CheckGraph(graph, /*check_ref_type_info=*/false);
- }
-
- private:
- bool CheckGraph(HGraph* graph, bool check_ref_type_info) {
- GraphChecker checker(graph);
- checker.SetRefTypeInfoCheckEnabled(check_ref_type_info);
- checker.Run();
- checker.Dump(std::cerr);
- return checker.IsValid();
- }
-
- std::vector<std::unique_ptr<const StandardDexFile>> dex_files_;
- std::unique_ptr<ArenaPoolAndAllocator> pool_and_allocator_;
-};
-
-class OptimizingUnitTest : public CommonCompilerTest, public OptimizingUnitTestHelper {};
-
-// OptimizingUnitTest with some handy functions to ease the graph creation.
-class ImprovedOptimizingUnitTest : public OptimizingUnitTest {
- public:
- ImprovedOptimizingUnitTest() : graph_(CreateGraph()),
- entry_block_(nullptr),
- return_block_(nullptr),
- exit_block_(nullptr) {}
-
- virtual ~ImprovedOptimizingUnitTest() {}
-
void InitGraph() {
- entry_block_ = new (GetAllocator()) HBasicBlock(graph_);
- graph_->AddBlock(entry_block_);
- graph_->SetEntryBlock(entry_block_);
-
- return_block_ = new (GetAllocator()) HBasicBlock(graph_);
- graph_->AddBlock(return_block_);
+ CreateGraph();
+ entry_block_ = AddNewBlock();
+ return_block_ = AddNewBlock();
+ exit_block_ = AddNewBlock();
- exit_block_ = new (GetAllocator()) HBasicBlock(graph_);
- graph_->AddBlock(exit_block_);
+ graph_->SetEntryBlock(entry_block_);
graph_->SetExitBlock(exit_block_);
entry_block_->AddSuccessor(return_block_);
return_block_->AddSuccessor(exit_block_);
- CreateParameters();
- for (HInstruction* parameter : parameters_) {
- entry_block_->AddInstruction(parameter);
- }
-
return_block_->AddInstruction(new (GetAllocator()) HReturnVoid());
exit_block_->AddInstruction(new (GetAllocator()) HExit());
}
+ void AddParameter(HInstruction* parameter) {
+ entry_block_->AddInstruction(parameter);
+ parameters_.push_back(parameter);
+ }
+
+ HBasicBlock* AddNewBlock() {
+ HBasicBlock* block = new (GetAllocator()) HBasicBlock(graph_);
+ graph_->AddBlock(block);
+ return block;
+ }
+
+ // Run GraphChecker with all checks.
+ //
+ // Return: the status whether the run is successful.
+ bool CheckGraph(HGraph* graph) {
+ return CheckGraph(graph, /*check_ref_type_info=*/true);
+ }
+
bool CheckGraph() {
- return OptimizingUnitTestHelper::CheckGraph(graph_);
+ return CheckGraph(graph_);
+ }
+
+ // Run GraphChecker with all checks except reference type information checks.
+ //
+ // Return: the status whether the run is successful.
+ bool CheckGraphSkipRefTypeInfoChecks(HGraph* graph) {
+ return CheckGraph(graph, /*check_ref_type_info=*/false);
}
bool CheckGraphSkipRefTypeInfoChecks() {
- return OptimizingUnitTestHelper::CheckGraphSkipRefTypeInfoChecks(graph_);
+ return CheckGraphSkipRefTypeInfoChecks(graph_);
}
HEnvironment* ManuallyBuildEnvFor(HInstruction* instruction,
@@ -263,12 +247,18 @@ class ImprovedOptimizingUnitTest : public OptimizingUnitTest {
}
protected:
- // Create parameters to be added to the graph entry block.
- // Subclasses can override it to create parameters they need.
- virtual void CreateParameters() { /* do nothing */ }
+ bool CheckGraph(HGraph* graph, bool check_ref_type_info) {
+ GraphChecker checker(graph);
+ checker.SetRefTypeInfoCheckEnabled(check_ref_type_info);
+ checker.Run();
+ checker.Dump(std::cerr);
+ return checker.IsValid();
+ }
- HGraph* graph_;
+ std::vector<std::unique_ptr<const StandardDexFile>> dex_files_;
+ std::unique_ptr<ArenaPoolAndAllocator> pool_and_allocator_;
+ HGraph* graph_;
HBasicBlock* entry_block_;
HBasicBlock* return_block_;
HBasicBlock* exit_block_;
@@ -276,6 +266,8 @@ class ImprovedOptimizingUnitTest : public OptimizingUnitTest {
std::vector<HInstruction*> parameters_;
};
+class OptimizingUnitTest : public CommonCompilerTest, public OptimizingUnitTestHelper {};
+
// Naive string diff data type.
typedef std::list<std::pair<std::string, std::string>> diff_t;