[GlobalISel] Print the matched patterns using an action.
This lets us split out PatternToMatch from the top-level RuleMatcher,
where it doesn't really belong. That, in turn, lets us eventually
generate RuleMatchers from non-SelectionDAG sources.
llvm-svn: 294076
diff --git a/llvm/utils/TableGen/GlobalISelEmitter.cpp b/llvm/utils/TableGen/GlobalISelEmitter.cpp
index 1d16c5c..45567b2 100644
--- a/llvm/utils/TableGen/GlobalISelEmitter.cpp
+++ b/llvm/utils/TableGen/GlobalISelEmitter.cpp
@@ -291,6 +291,19 @@
virtual void emitCxxActionStmts(raw_ostream &OS) const = 0;
};
+/// Generates a comment describing the matched rule being acted upon.
+class DebugCommentAction : public MatchAction {
+private:
+ const PatternToMatch &P;
+
+public:
+ DebugCommentAction(const PatternToMatch &P) : P(P) {}
+
+ virtual void emitCxxActionStmts(raw_ostream &OS) const {
+ OS << "// " << *P.getSrcPattern() << " => " << *P.getDstPattern();
+ }
+};
+
class MutateOpcodeAction : public MatchAction {
private:
const CodeGenInstruction *I;
@@ -310,14 +323,11 @@
/// support multiple positions to support div/rem fusion or load-multiple
/// instructions.
class RuleMatcher {
- const PatternToMatch &P;
-
std::vector<std::unique_ptr<InstructionMatcher>> Matchers;
std::vector<std::unique_ptr<MatchAction>> Actions;
public:
-
- RuleMatcher(const PatternToMatch &P) : P(P) {}
+ RuleMatcher() {}
InstructionMatcher &addInstructionMatcher() {
Matchers.emplace_back(new InstructionMatcher());
@@ -334,9 +344,6 @@
if (Matchers.empty())
llvm_unreachable("Unexpected empty matcher!");
- OS << " // Src: " << *P.getSrcPattern() << "\n"
- << " // Dst: " << *P.getDstPattern() << "\n";
-
// The representation supports rules that require multiple roots such as:
// %ptr(p0) = ...
// %elt0(s32) = G_LOAD %ptr
@@ -385,7 +392,8 @@
GlobalISelEmitter::runOnPattern(const PatternToMatch &P, raw_ostream &OS) {
// Keep track of the matchers and actions to emit.
- RuleMatcher M(P);
+ RuleMatcher M;
+ M.addAction<DebugCommentAction>(P);
// First, analyze the whole pattern.
// If the entire pattern has a predicate (e.g., target features), ignore it.