From 21cd7790cb66e29670e85a8733c8ee35aa18bbd6 Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Tue, 18 Feb 2025 15:42:14 +0000 Subject: Optimizing: Remove dead Partial LSE test helpers. Test: m test-art-host-gtest Bug: 298176183 Change-Id: I25a047e20dd4b0388c639c90634e74a5a626d2ac --- compiler/optimizing/optimizing_unit_test.h | 150 ----------------------------- 1 file changed, 150 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 c40b918fee..8dc17f1618 100644 --- a/compiler/optimizing/optimizing_unit_test.h +++ b/compiler/optimizing/optimizing_unit_test.h @@ -1034,156 +1034,6 @@ inline std::ostream& operator<<(std::ostream& oss, const AdjacencyListGraph& alg return alg.Dump(oss); } -class PatternMatchGraphVisitor final : public HGraphVisitor { - private: - struct HandlerWrapper { - public: - virtual ~HandlerWrapper() {} - virtual void operator()(HInstruction* h) = 0; - }; - - template - struct KindWrapper; - -#define GEN_HANDLER(nm, unused) \ - template \ - struct KindWrapper : public HandlerWrapper { \ - public: \ - explicit KindWrapper(F f) : f_(f) {} \ - void operator()(HInstruction* h) override { \ - if constexpr (std::is_invocable_v) { \ - f_(h->As##nm()); \ - } else { \ - LOG(FATAL) << "Incorrect call with " << #nm; \ - } \ - } \ - \ - private: \ - F f_; \ - }; - - FOR_EACH_CONCRETE_INSTRUCTION(GEN_HANDLER) -#undef GEN_HANDLER - - template - std::unique_ptr GetWrapper(HInstruction::InstructionKind kind, F f) { - switch (kind) { -#define GEN_GETTER(nm, unused) \ - case HInstruction::InstructionKind::k##nm: \ - return std::unique_ptr( \ - new KindWrapper(f)); - FOR_EACH_CONCRETE_INSTRUCTION(GEN_GETTER) -#undef GEN_GETTER - default: - LOG(FATAL) << "Unable to handle kind " << kind; - return nullptr; - } - } - - public: - template - explicit PatternMatchGraphVisitor(HGraph* graph, Inst... handlers) : HGraphVisitor(graph) { - FillHandlers(handlers...); - } - - void VisitInstruction(HInstruction* instruction) override { - auto& h = handlers_[instruction->GetKind()]; - if (h.get() != nullptr) { - (*h)(instruction); - } - } - - private: - template - constexpr HInstruction::InstructionKind GetKind() { -#define CHECK_INST(nm, unused) \ - if constexpr (std::is_invocable_v) { \ - return HInstruction::InstructionKind::k##nm; \ - } - FOR_EACH_CONCRETE_INSTRUCTION(CHECK_INST); -#undef CHECK_INST - static_assert(!std::is_invocable_v, - "Use on generic HInstruction not allowed"); -#define STATIC_ASSERT_ABSTRACT(nm, unused) && !std::is_invocable_v - static_assert(true FOR_EACH_ABSTRACT_INSTRUCTION(STATIC_ASSERT_ABSTRACT), - "Must not be abstract instruction"); -#undef STATIC_ASSERT_ABSTRACT -#define STATIC_ASSERT_CONCRETE(nm, unused) || std::is_invocable_v - static_assert(false FOR_EACH_CONCRETE_INSTRUCTION(STATIC_ASSERT_CONCRETE), - "Must be a concrete instruction"); -#undef STATIC_ASSERT_CONCRETE - return HInstruction::InstructionKind::kLastInstructionKind; - } - template - void FillHandlers(First h1) { - HInstruction::InstructionKind type = GetKind(); - CHECK_NE(type, HInstruction::kLastInstructionKind) - << "Unknown instruction kind. Only concrete ones please."; - handlers_[type] = GetWrapper(type, h1); - } - - template - void FillHandlers(First h1, Inst... handlers) { - FillHandlers(h1); - FillHandlers(handlers...); - } - - std::array, HInstruction::InstructionKind::kLastInstructionKind> - handlers_; -}; - -template -std::tuple...> FindAllInstructions( - HGraph* graph, - std::variant> blks = - std::nullopt) { - std::tuple...> res; - PatternMatchGraphVisitor vis( - graph, [&](Target* t) { std::get>(res).push_back(t); }...); - - if (std::holds_alternative>(blks)) { - for (HBasicBlock* blk : std::get>(blks)) { - vis.VisitBasicBlock(blk); - } - } else if (std::holds_alternative(blks)) { - vis.VisitInsertionOrder(); - } else { - vis.VisitBasicBlock(std::get(blks)); - } - return res; -} - -template -std::tuple FindSingleInstructions( - HGraph* graph, - std::variant> blks = - std::nullopt) { - std::tuple res; - PatternMatchGraphVisitor vis(graph, [&](Target* t) { - EXPECT_EQ(std::get(res), nullptr) - << *std::get(res) << " already found but found " << *t << "!"; - std::get(res) = t; - }...); - if (std::holds_alternative>(blks)) { - for (HBasicBlock* blk : std::get>(blks)) { - vis.VisitBasicBlock(blk); - } - } else if (std::holds_alternative(blks)) { - vis.VisitInsertionOrder(); - } else { - vis.VisitBasicBlock(std::get(blks)); - } - return res; -} - -template -Target* FindSingleInstruction( - HGraph* graph, - std::variant> blks = - std::nullopt) { - return std::get(FindSingleInstructions(graph, blks)); -} - } // namespace art #endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_UNIT_TEST_H_ -- cgit v1.2.3-59-g8ed1b