add a new CheckMultiOpcode opcode for checking that a node
[oota-llvm.git] / utils / TableGen / DAGISelMatcher.cpp
1 //===- DAGISelMatcher.cpp - Representation of DAG pattern matcher ---------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "DAGISelMatcher.h"
11 #include "CodeGenDAGPatterns.h"
12 #include "CodeGenTarget.h"
13 #include "Record.h"
14 #include "llvm/Support/raw_ostream.h"
15 using namespace llvm;
16
17 void MatcherNode::dump() const {
18   print(errs());
19 }
20
21 void MatcherNode::printNext(raw_ostream &OS, unsigned indent) const {
22   if (Next)
23     return Next->print(OS, indent);
24 }
25
26
27 void PushMatcherNode::print(raw_ostream &OS, unsigned indent) const {
28   OS.indent(indent) << "Push\n";
29   printNext(OS, indent+2);
30   Failure->print(OS, indent);
31 }
32
33 void RecordMatcherNode::print(raw_ostream &OS, unsigned indent) const {
34   OS.indent(indent) << "Record\n";
35   printNext(OS, indent);
36 }
37
38 void RecordMemRefMatcherNode::print(raw_ostream &OS, unsigned indent) const {
39   OS.indent(indent) << "RecordMemRef\n";
40   printNext(OS, indent);
41 }
42
43 void CaptureFlagInputMatcherNode::print(raw_ostream &OS, unsigned indent) const{
44   OS.indent(indent) << "CaptureFlagInput\n";
45   printNext(OS, indent);
46 }
47
48 void MoveChildMatcherNode::print(raw_ostream &OS, unsigned indent) const {
49   OS.indent(indent) << "MoveChild " << ChildNo << '\n';
50   printNext(OS, indent);
51 }
52
53 void MoveParentMatcherNode::print(raw_ostream &OS, unsigned indent) const {
54   OS.indent(indent) << "MoveParent\n";
55   printNext(OS, indent);
56 }
57
58 void CheckSameMatcherNode::print(raw_ostream &OS, unsigned indent) const {
59   OS.indent(indent) << "CheckSame " << MatchNumber << '\n';
60   printNext(OS, indent);
61 }
62
63 void CheckPatternPredicateMatcherNode::
64 print(raw_ostream &OS, unsigned indent) const {
65   OS.indent(indent) << "CheckPatternPredicate " << Predicate << '\n';
66   printNext(OS, indent);
67 }
68
69 void CheckPredicateMatcherNode::print(raw_ostream &OS, unsigned indent) const {
70   OS.indent(indent) << "CheckPredicate " << PredName << '\n';
71   printNext(OS, indent);
72 }
73
74 void CheckOpcodeMatcherNode::print(raw_ostream &OS, unsigned indent) const {
75   OS.indent(indent) << "CheckOpcode " << OpcodeName << '\n';
76   printNext(OS, indent);
77 }
78
79 void CheckMultiOpcodeMatcherNode::print(raw_ostream &OS, unsigned indent) const {
80   OS.indent(indent) << "CheckMultiOpcode <todo args>\n";
81   printNext(OS, indent);
82 }
83
84 void CheckTypeMatcherNode::print(raw_ostream &OS, unsigned indent) const {
85   OS.indent(indent) << "CheckType " << getEnumName(Type) << '\n';
86   printNext(OS, indent);
87 }
88
89 void CheckIntegerMatcherNode::print(raw_ostream &OS, unsigned indent) const {
90   OS.indent(indent) << "CheckInteger " << Value << '\n';
91   printNext(OS, indent);
92 }
93
94 void CheckCondCodeMatcherNode::print(raw_ostream &OS, unsigned indent) const {
95   OS.indent(indent) << "CheckCondCode ISD::" << CondCodeName << '\n';
96   printNext(OS, indent);
97 }
98
99 void CheckValueTypeMatcherNode::print(raw_ostream &OS, unsigned indent) const {
100   OS.indent(indent) << "CheckValueType MVT::" << TypeName << '\n';
101   printNext(OS, indent);
102 }
103
104 void CheckComplexPatMatcherNode::print(raw_ostream &OS, unsigned indent) const {
105   OS.indent(indent) << "CheckComplexPat " << Pattern.getSelectFunc() << '\n';
106   printNext(OS, indent);
107 }
108
109 void CheckAndImmMatcherNode::print(raw_ostream &OS, unsigned indent) const {
110   OS.indent(indent) << "CheckAndImm " << Value << '\n';
111   printNext(OS, indent);
112 }
113
114 void CheckOrImmMatcherNode::print(raw_ostream &OS, unsigned indent) const {
115   OS.indent(indent) << "CheckOrImm " << Value << '\n';
116   printNext(OS, indent);
117 }
118
119 void CheckFoldableChainNodeMatcherNode::print(raw_ostream &OS,
120                                               unsigned indent) const {
121   OS.indent(indent) << "CheckFoldableChainNode\n";
122   printNext(OS, indent);
123 }
124
125 void CheckChainCompatibleMatcherNode::print(raw_ostream &OS,
126                                               unsigned indent) const {
127   OS.indent(indent) << "CheckChainCompatible " << PreviousOp << "\n";
128   printNext(OS, indent);
129 }
130
131 void EmitIntegerMatcherNode::print(raw_ostream &OS, unsigned indent) const {
132   OS.indent(indent) << "EmitInteger " << Val << " VT=" << VT << '\n';
133   printNext(OS, indent);
134 }
135
136 void EmitStringIntegerMatcherNode::
137 print(raw_ostream &OS, unsigned indent) const {
138   OS.indent(indent) << "EmitStringInteger " << Val << " VT=" << VT << '\n';
139   printNext(OS, indent);
140 }
141
142 void EmitRegisterMatcherNode::print(raw_ostream &OS, unsigned indent) const {
143   OS.indent(indent) << "EmitRegister ";
144   if (Reg)
145     OS << Reg->getName();
146   else
147     OS << "zero_reg";
148   OS << " VT=" << VT << '\n';
149   printNext(OS, indent);
150 }
151
152 void EmitConvertToTargetMatcherNode::
153 print(raw_ostream &OS, unsigned indent) const {
154   OS.indent(indent) << "EmitConvertToTarget " << Slot << '\n';
155   printNext(OS, indent);
156 }
157
158 void EmitMergeInputChainsMatcherNode::
159 print(raw_ostream &OS, unsigned indent) const {
160   OS.indent(indent) << "EmitMergeInputChains <todo: args>\n";
161   printNext(OS, indent);
162 }
163
164 void EmitCopyToRegMatcherNode::print(raw_ostream &OS, unsigned indent) const {
165   OS.indent(indent) << "EmitCopyToReg <todo: args>\n";
166   printNext(OS, indent);
167 }
168
169 void EmitNodeXFormMatcherNode::print(raw_ostream &OS, unsigned indent) const {
170   OS.indent(indent) << "EmitNodeXForm " << NodeXForm->getName()
171      << " Slot=" << Slot << '\n';
172   printNext(OS, indent);
173 }
174
175
176 void EmitNodeMatcherNode::print(raw_ostream &OS, unsigned indent) const {
177   OS.indent(indent) << "EmitNode: " << OpcodeName << ": <todo flags> ";
178
179   for (unsigned i = 0, e = VTs.size(); i != e; ++i)
180     OS << ' ' << getEnumName(VTs[i]);
181   OS << '(';
182   for (unsigned i = 0, e = Operands.size(); i != e; ++i)
183     OS << Operands[i] << ' ';
184   OS << ")\n";
185   printNext(OS, indent);
186 }
187
188 void CompleteMatchMatcherNode::print(raw_ostream &OS, unsigned indent) const {
189   OS.indent(indent) << "CompleteMatch <todo args>\n";
190   OS.indent(indent) << "Src = " << *Pattern.getSrcPattern() << "\n";
191   OS.indent(indent) << "Dst = " << *Pattern.getDstPattern() << "\n";
192   printNext(OS, indent);
193 }
194