From d661c115a57277e64e8225d2d69629635f7d4e3a Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Wed, 22 Jan 2025 14:23:27 +0000 Subject: Optimizing: Remove `CreateDoWhileLoop()`. And do some other gtest cleanup. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Change-Id: I9d2c3241e5cd9f96722284c4654b8b2fd446b104 --- compiler/optimizing/optimizing_unit_test.h | 57 ++++++++++++++++-------------- 1 file changed, 30 insertions(+), 27 deletions(-) (limited to 'compiler/optimizing/optimizing_unit_test.h') diff --git a/compiler/optimizing/optimizing_unit_test.h b/compiler/optimizing/optimizing_unit_test.h index 8115ea035d..21998b19da 100644 --- a/compiler/optimizing/optimizing_unit_test.h +++ b/compiler/optimizing/optimizing_unit_test.h @@ -90,6 +90,11 @@ inline std::ostream& operator<<(std::ostream& os, const InstructionDumper& id) { #define ASSERT_INS_REMOVED(a) ASSERT_TRUE(IsRemoved(a)) << "Not removed: " << (InstructionDumper{a}) #define ASSERT_INS_RETAINED(a) ASSERT_FALSE(IsRemoved(a)) << "Removed: " << (InstructionDumper{a}) +#define EXPECT_BLOCK_REMOVED(b) EXPECT_TRUE(IsRemoved(b)) << "Not removed: B" << b->GetBlockId() +#define EXPECT_BLOCK_RETAINED(b) EXPECT_FALSE(IsRemoved(b)) << "Removed: B" << b->GetBlockId() +#define ASSERT_BLOCK_REMOVED(b) ASSERT_TRUE(IsRemoved(b)) << "Not removed: B" << b->GetBlockId() +#define ASSERT_BLOCK_RETAINED(b) ASSERT_FALSE(IsRemoved(b)) << "Removed: B" << b->GetBlockId() + inline LiveInterval* BuildInterval(const size_t ranges[][2], size_t number_of_ranges, ScopedArenaAllocator* allocator, @@ -348,6 +353,8 @@ class OptimizingUnitTestHelper { // empty, leaving the construction of an appropriate condition and `HIf` to the caller. // Note: The `loop_exit` shall be the "then" successor of the "loop-header". If the `loop_exit` // is needed as the "else" successor, use `HBlock::SwapSuccessors()` to adjust the order. + // Note: A `do { ... } while (...);` loop pattern has the same block structure, except that + // the `loop_body` is a single-goto block that exists purely to avoid a critical edge. std::tuple CreateWhileLoop(HBasicBlock* loop_exit) { HBasicBlock* pre_header = AddNewBlock(); HBasicBlock* loop_header = AddNewBlock(); @@ -367,28 +374,6 @@ class OptimizingUnitTestHelper { return {pre_header, loop_header, loop_body}; } - // Insert "pre-header" and "loop" blocks before a given `loop_exit` block and connect them in a - // `do { ... } while (...);` loop pattern. Return the new blocks. Adds `HGoto` to the "pre-header" - // block but leaves the "loop" block empty, leaving the construction of an appropriate condition - // and `HIf` to the caller. - // Note: The `loop_exit` shall be the "then" successor of the "loop". If the `loop_exit` - // is needed as the "else" successor, use `HBlock::SwapSuccessors()` to adjust the order. - std::tuple CreateDoWhileLoop(HBasicBlock* loop_exit) { - HBasicBlock* pre_header = AddNewBlock(); - HBasicBlock* loop = AddNewBlock(); - - HBasicBlock* predecessor = loop_exit->GetSinglePredecessor(); - predecessor->ReplaceSuccessor(loop_exit, pre_header); - - pre_header->AddSuccessor(loop); - loop->AddSuccessor(loop_exit); // true successor - loop->AddSuccessor(loop); // false successor - - MakeGoto(pre_header); - - return {pre_header, loop}; - } - // Insert blocks for an irreducible loop before the `loop_exit`: // // @@ -923,6 +908,19 @@ class OptimizingUnitTestHelper { return {phi, add}; } + std::tuple MakeLinearIrreducibleLoopVar(HBasicBlock* left_header, + HBasicBlock* right_header, + HBasicBlock* body, + HInstruction* left_initial, + HInstruction* right_initial, + HInstruction* increment) { + HPhi* left_phi = MakePhi(left_header, {left_initial, /* placeholder */ left_initial}); + HAdd* add = MakeBinOp(body, left_phi->GetType(), left_phi, increment); + HPhi* right_phi = MakePhi(right_header, {right_initial, add}); + left_phi->ReplaceInput(right_phi, 1u); // Update back-edge input. + return {left_phi, right_phi, add}; + } + dex::TypeIndex DefaultTypeIndexForType(DataType::Type type) { switch (type) { case DataType::Type::kBool: @@ -959,6 +957,16 @@ class OptimizingUnitTestHelper { return val; } + // Returns if the `instruction` is removed from the graph. + static inline bool IsRemoved(HInstruction* instruction) { + return instruction->GetBlock() == nullptr; + } + + // Returns if the `block` is removed from the graph. + static inline bool IsRemoved(HBasicBlock* block) { + return block->GetGraph() == nullptr; + } + protected: bool CheckGraph(HGraph* graph, std::ostream& oss) { GraphChecker checker(graph); @@ -1006,11 +1014,6 @@ inline std::string Patch(const std::string& original, const diff_t& diff) { return result; } -// Returns if the instruction is removed from the graph. -inline bool IsRemoved(HInstruction* instruction) { - return instruction->GetBlock() == nullptr; -} - inline std::ostream& operator<<(std::ostream& oss, const AdjacencyListGraph& alg) { return alg.Dump(oss); } -- cgit v1.2.3-59-g8ed1b