diff options
author | Daniel Sanders <daniel_l_sanders@apple.com> | 2017-02-01 10:53:10 +0000 |
---|---|---|
committer | Daniel Sanders <daniel_l_sanders@apple.com> | 2017-02-01 10:53:10 +0000 |
commit | 43c882c6f8e06ba37181f63dee84c8c710f50c78 (patch) | |
tree | bbbf2556881fc550aa8f5ce004a89c0d1b8d511a | |
parent | 8c40f5adecda0f27e9822a924d5f23dada0b7d79 (diff) | |
download | bcm5719-llvm-43c882c6f8e06ba37181f63dee84c8c710f50c78.tar.gz bcm5719-llvm-43c882c6f8e06ba37181f63dee84c8c710f50c78.zip |
[globalisel] Make the MatchAction hierarchy consistent with the matchers. NFC.
Reviewers: aditya_nandakumar, rovka, t.p.northover, qcolombet, ab
Subscribers: dberris, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D29321
llvm-svn: 293760
-rw-r--r-- | llvm/utils/TableGen/GlobalISelEmitter.cpp | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/llvm/utils/TableGen/GlobalISelEmitter.cpp b/llvm/utils/TableGen/GlobalISelEmitter.cpp index 2682e26fc8c..1886f75c49c 100644 --- a/llvm/utils/TableGen/GlobalISelEmitter.cpp +++ b/llvm/utils/TableGen/GlobalISelEmitter.cpp @@ -110,16 +110,6 @@ static bool isTrivialOperatorNode(const TreePatternNode *N) { //===- Matchers -----------------------------------------------------------===// -struct MatchAction { - virtual ~MatchAction() {} - virtual void emit(raw_ostream &OS) const = 0; -}; - -raw_ostream &operator<<(raw_ostream &S, const MatchAction &A) { - A.emit(S); - return S; -} - template <class PredicateTy> class PredicateListMatcher { private: typedef std::vector<std::unique_ptr<PredicateTy>> PredicateVec; @@ -293,11 +283,22 @@ public: } }; -struct MutateOpcode : public MatchAction { - MutateOpcode(const CodeGenInstruction *I) : I(I) {} +//===- Actions ------------------------------------------------------------===// + +class MatchAction { +public: + virtual ~MatchAction() {} + virtual void emitCxxActionStmts(raw_ostream &OS) const = 0; +}; + +class MutateOpcodeAction : public MatchAction { +private: const CodeGenInstruction *I; - virtual void emit(raw_ostream &OS) const { +public: + MutateOpcodeAction(const CodeGenInstruction *I) : I(I) {} + + virtual void emitCxxActionStmts(raw_ostream &OS) const { OS << "I.setDesc(TII.get(" << I->Namespace << "::" << I->TheDef->getName() << "));"; } @@ -312,9 +313,9 @@ class RuleMatcher { const PatternToMatch &P; std::vector<std::unique_ptr<InstructionMatcher>> Matchers; + std::vector<std::unique_ptr<MatchAction>> Actions; public: - std::vector<std::unique_ptr<MatchAction>> Actions; RuleMatcher(const PatternToMatch &P) : P(P) {} @@ -323,6 +324,12 @@ public: return *Matchers.back(); } + template <class Kind, class... Args> + Kind &addAction(Args&&... args) { + Actions.emplace_back(llvm::make_unique<Kind>(std::forward<Args>(args)...)); + return *static_cast<Kind *>(Actions.back().get()); + } + void emit(raw_ostream &OS) { if (Matchers.empty()) llvm_unreachable("Unexpected empty matcher!"); @@ -344,8 +351,11 @@ public: Matchers.front()->emitCxxPredicateExpr(OS, "I"); OS << ") {\n"; - for (auto &MA : Actions) - OS << " " << *MA << "\n"; + for (const auto &MA : Actions) { + OS << " "; + MA->emitCxxActionStmts(OS); + OS << "\n"; + } OS << " constrainSelectedInstRegOperands(I, TII, TRI, RBI);\n"; OS << " return true;\n"; @@ -410,7 +420,7 @@ GlobalISelEmitter::runOnPattern(const PatternToMatch &P, raw_ostream &OS) { // The operators look good: match the opcode and mutate it to the new one. InstructionMatcher &InsnMatcher = M.addInstructionMatcher(); InsnMatcher.addPredicate<InstructionOpcodeMatcher>(&SrcGI); - M.Actions.emplace_back(new MutateOpcode(&DstI)); + M.addAction<MutateOpcodeAction>(&DstI); // Next, analyze the children, only accepting patterns that don't require // any change to operands. |