xref: /aosp_15_r20/external/llvm/utils/TableGen/DAGISelMatcher.cpp (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===- DAGISelMatcher.cpp - Representation of DAG pattern matcher ---------===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker 
10*9880d681SAndroid Build Coastguard Worker #include "DAGISelMatcher.h"
11*9880d681SAndroid Build Coastguard Worker #include "CodeGenDAGPatterns.h"
12*9880d681SAndroid Build Coastguard Worker #include "CodeGenTarget.h"
13*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/StringExtras.h"
14*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/raw_ostream.h"
15*9880d681SAndroid Build Coastguard Worker #include "llvm/TableGen/Record.h"
16*9880d681SAndroid Build Coastguard Worker using namespace llvm;
17*9880d681SAndroid Build Coastguard Worker 
anchor()18*9880d681SAndroid Build Coastguard Worker void Matcher::anchor() { }
19*9880d681SAndroid Build Coastguard Worker 
dump() const20*9880d681SAndroid Build Coastguard Worker void Matcher::dump() const {
21*9880d681SAndroid Build Coastguard Worker   print(errs(), 0);
22*9880d681SAndroid Build Coastguard Worker }
23*9880d681SAndroid Build Coastguard Worker 
print(raw_ostream & OS,unsigned indent) const24*9880d681SAndroid Build Coastguard Worker void Matcher::print(raw_ostream &OS, unsigned indent) const {
25*9880d681SAndroid Build Coastguard Worker   printImpl(OS, indent);
26*9880d681SAndroid Build Coastguard Worker   if (Next)
27*9880d681SAndroid Build Coastguard Worker     return Next->print(OS, indent);
28*9880d681SAndroid Build Coastguard Worker }
29*9880d681SAndroid Build Coastguard Worker 
printOne(raw_ostream & OS) const30*9880d681SAndroid Build Coastguard Worker void Matcher::printOne(raw_ostream &OS) const {
31*9880d681SAndroid Build Coastguard Worker   printImpl(OS, 0);
32*9880d681SAndroid Build Coastguard Worker }
33*9880d681SAndroid Build Coastguard Worker 
34*9880d681SAndroid Build Coastguard Worker /// unlinkNode - Unlink the specified node from this chain.  If Other == this,
35*9880d681SAndroid Build Coastguard Worker /// we unlink the next pointer and return it.  Otherwise we unlink Other from
36*9880d681SAndroid Build Coastguard Worker /// the list and return this.
unlinkNode(Matcher * Other)37*9880d681SAndroid Build Coastguard Worker Matcher *Matcher::unlinkNode(Matcher *Other) {
38*9880d681SAndroid Build Coastguard Worker   if (this == Other)
39*9880d681SAndroid Build Coastguard Worker     return takeNext();
40*9880d681SAndroid Build Coastguard Worker 
41*9880d681SAndroid Build Coastguard Worker   // Scan until we find the predecessor of Other.
42*9880d681SAndroid Build Coastguard Worker   Matcher *Cur = this;
43*9880d681SAndroid Build Coastguard Worker   for (; Cur && Cur->getNext() != Other; Cur = Cur->getNext())
44*9880d681SAndroid Build Coastguard Worker     /*empty*/;
45*9880d681SAndroid Build Coastguard Worker 
46*9880d681SAndroid Build Coastguard Worker   if (!Cur) return nullptr;
47*9880d681SAndroid Build Coastguard Worker   Cur->takeNext();
48*9880d681SAndroid Build Coastguard Worker   Cur->setNext(Other->takeNext());
49*9880d681SAndroid Build Coastguard Worker   return this;
50*9880d681SAndroid Build Coastguard Worker }
51*9880d681SAndroid Build Coastguard Worker 
52*9880d681SAndroid Build Coastguard Worker /// canMoveBefore - Return true if this matcher is the same as Other, or if
53*9880d681SAndroid Build Coastguard Worker /// we can move this matcher past all of the nodes in-between Other and this
54*9880d681SAndroid Build Coastguard Worker /// node.  Other must be equal to or before this.
canMoveBefore(const Matcher * Other) const55*9880d681SAndroid Build Coastguard Worker bool Matcher::canMoveBefore(const Matcher *Other) const {
56*9880d681SAndroid Build Coastguard Worker   for (;; Other = Other->getNext()) {
57*9880d681SAndroid Build Coastguard Worker     assert(Other && "Other didn't come before 'this'?");
58*9880d681SAndroid Build Coastguard Worker     if (this == Other) return true;
59*9880d681SAndroid Build Coastguard Worker 
60*9880d681SAndroid Build Coastguard Worker     // We have to be able to move this node across the Other node.
61*9880d681SAndroid Build Coastguard Worker     if (!canMoveBeforeNode(Other))
62*9880d681SAndroid Build Coastguard Worker       return false;
63*9880d681SAndroid Build Coastguard Worker   }
64*9880d681SAndroid Build Coastguard Worker }
65*9880d681SAndroid Build Coastguard Worker 
66*9880d681SAndroid Build Coastguard Worker /// canMoveBeforeNode - Return true if it is safe to move the current matcher
67*9880d681SAndroid Build Coastguard Worker /// across the specified one.
canMoveBeforeNode(const Matcher * Other) const68*9880d681SAndroid Build Coastguard Worker bool Matcher::canMoveBeforeNode(const Matcher *Other) const {
69*9880d681SAndroid Build Coastguard Worker   // We can move simple predicates before record nodes.
70*9880d681SAndroid Build Coastguard Worker   if (isSimplePredicateNode())
71*9880d681SAndroid Build Coastguard Worker     return Other->isSimplePredicateOrRecordNode();
72*9880d681SAndroid Build Coastguard Worker 
73*9880d681SAndroid Build Coastguard Worker   // We can move record nodes across simple predicates.
74*9880d681SAndroid Build Coastguard Worker   if (isSimplePredicateOrRecordNode())
75*9880d681SAndroid Build Coastguard Worker     return isSimplePredicateNode();
76*9880d681SAndroid Build Coastguard Worker 
77*9880d681SAndroid Build Coastguard Worker   // We can't move record nodes across each other etc.
78*9880d681SAndroid Build Coastguard Worker   return false;
79*9880d681SAndroid Build Coastguard Worker }
80*9880d681SAndroid Build Coastguard Worker 
81*9880d681SAndroid Build Coastguard Worker 
~ScopeMatcher()82*9880d681SAndroid Build Coastguard Worker ScopeMatcher::~ScopeMatcher() {
83*9880d681SAndroid Build Coastguard Worker   for (unsigned i = 0, e = Children.size(); i != e; ++i)
84*9880d681SAndroid Build Coastguard Worker     delete Children[i];
85*9880d681SAndroid Build Coastguard Worker }
86*9880d681SAndroid Build Coastguard Worker 
~SwitchOpcodeMatcher()87*9880d681SAndroid Build Coastguard Worker SwitchOpcodeMatcher::~SwitchOpcodeMatcher() {
88*9880d681SAndroid Build Coastguard Worker   for (unsigned i = 0, e = Cases.size(); i != e; ++i)
89*9880d681SAndroid Build Coastguard Worker     delete Cases[i].second;
90*9880d681SAndroid Build Coastguard Worker }
91*9880d681SAndroid Build Coastguard Worker 
~SwitchTypeMatcher()92*9880d681SAndroid Build Coastguard Worker SwitchTypeMatcher::~SwitchTypeMatcher() {
93*9880d681SAndroid Build Coastguard Worker   for (unsigned i = 0, e = Cases.size(); i != e; ++i)
94*9880d681SAndroid Build Coastguard Worker     delete Cases[i].second;
95*9880d681SAndroid Build Coastguard Worker }
96*9880d681SAndroid Build Coastguard Worker 
CheckPredicateMatcher(const TreePredicateFn & pred)97*9880d681SAndroid Build Coastguard Worker CheckPredicateMatcher::CheckPredicateMatcher(const TreePredicateFn &pred)
98*9880d681SAndroid Build Coastguard Worker   : Matcher(CheckPredicate), Pred(pred.getOrigPatFragRecord()) {}
99*9880d681SAndroid Build Coastguard Worker 
getPredicate() const100*9880d681SAndroid Build Coastguard Worker TreePredicateFn CheckPredicateMatcher::getPredicate() const {
101*9880d681SAndroid Build Coastguard Worker   return TreePredicateFn(Pred);
102*9880d681SAndroid Build Coastguard Worker }
103*9880d681SAndroid Build Coastguard Worker 
104*9880d681SAndroid Build Coastguard Worker 
105*9880d681SAndroid Build Coastguard Worker 
106*9880d681SAndroid Build Coastguard Worker // printImpl methods.
107*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const108*9880d681SAndroid Build Coastguard Worker void ScopeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
109*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "Scope\n";
110*9880d681SAndroid Build Coastguard Worker   for (unsigned i = 0, e = getNumChildren(); i != e; ++i) {
111*9880d681SAndroid Build Coastguard Worker     if (!getChild(i))
112*9880d681SAndroid Build Coastguard Worker       OS.indent(indent+1) << "NULL POINTER\n";
113*9880d681SAndroid Build Coastguard Worker     else
114*9880d681SAndroid Build Coastguard Worker       getChild(i)->print(OS, indent+2);
115*9880d681SAndroid Build Coastguard Worker   }
116*9880d681SAndroid Build Coastguard Worker }
117*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const118*9880d681SAndroid Build Coastguard Worker void RecordMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
119*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "Record\n";
120*9880d681SAndroid Build Coastguard Worker }
121*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const122*9880d681SAndroid Build Coastguard Worker void RecordChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
123*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "RecordChild: " << ChildNo << '\n';
124*9880d681SAndroid Build Coastguard Worker }
125*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const126*9880d681SAndroid Build Coastguard Worker void RecordMemRefMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
127*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "RecordMemRef\n";
128*9880d681SAndroid Build Coastguard Worker }
129*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const130*9880d681SAndroid Build Coastguard Worker void CaptureGlueInputMatcher::printImpl(raw_ostream &OS, unsigned indent) const{
131*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "CaptureGlueInput\n";
132*9880d681SAndroid Build Coastguard Worker }
133*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const134*9880d681SAndroid Build Coastguard Worker void MoveChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
135*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "MoveChild " << ChildNo << '\n';
136*9880d681SAndroid Build Coastguard Worker }
137*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const138*9880d681SAndroid Build Coastguard Worker void MoveParentMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
139*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "MoveParent\n";
140*9880d681SAndroid Build Coastguard Worker }
141*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const142*9880d681SAndroid Build Coastguard Worker void CheckSameMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
143*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "CheckSame " << MatchNumber << '\n';
144*9880d681SAndroid Build Coastguard Worker }
145*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const146*9880d681SAndroid Build Coastguard Worker void CheckChildSameMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
147*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "CheckChild" << ChildNo << "Same\n";
148*9880d681SAndroid Build Coastguard Worker }
149*9880d681SAndroid Build Coastguard Worker 
150*9880d681SAndroid Build Coastguard Worker void CheckPatternPredicateMatcher::
printImpl(raw_ostream & OS,unsigned indent) const151*9880d681SAndroid Build Coastguard Worker printImpl(raw_ostream &OS, unsigned indent) const {
152*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "CheckPatternPredicate " << Predicate << '\n';
153*9880d681SAndroid Build Coastguard Worker }
154*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const155*9880d681SAndroid Build Coastguard Worker void CheckPredicateMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
156*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "CheckPredicate " << getPredicate().getFnName() << '\n';
157*9880d681SAndroid Build Coastguard Worker }
158*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const159*9880d681SAndroid Build Coastguard Worker void CheckOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
160*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "CheckOpcode " << Opcode.getEnumName() << '\n';
161*9880d681SAndroid Build Coastguard Worker }
162*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const163*9880d681SAndroid Build Coastguard Worker void SwitchOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
164*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "SwitchOpcode: {\n";
165*9880d681SAndroid Build Coastguard Worker   for (unsigned i = 0, e = Cases.size(); i != e; ++i) {
166*9880d681SAndroid Build Coastguard Worker     OS.indent(indent) << "case " << Cases[i].first->getEnumName() << ":\n";
167*9880d681SAndroid Build Coastguard Worker     Cases[i].second->print(OS, indent+2);
168*9880d681SAndroid Build Coastguard Worker   }
169*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "}\n";
170*9880d681SAndroid Build Coastguard Worker }
171*9880d681SAndroid Build Coastguard Worker 
172*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const173*9880d681SAndroid Build Coastguard Worker void CheckTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
174*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "CheckType " << getEnumName(Type) << ", ResNo="
175*9880d681SAndroid Build Coastguard Worker     << ResNo << '\n';
176*9880d681SAndroid Build Coastguard Worker }
177*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const178*9880d681SAndroid Build Coastguard Worker void SwitchTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
179*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "SwitchType: {\n";
180*9880d681SAndroid Build Coastguard Worker   for (unsigned i = 0, e = Cases.size(); i != e; ++i) {
181*9880d681SAndroid Build Coastguard Worker     OS.indent(indent) << "case " << getEnumName(Cases[i].first) << ":\n";
182*9880d681SAndroid Build Coastguard Worker     Cases[i].second->print(OS, indent+2);
183*9880d681SAndroid Build Coastguard Worker   }
184*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "}\n";
185*9880d681SAndroid Build Coastguard Worker }
186*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const187*9880d681SAndroid Build Coastguard Worker void CheckChildTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
188*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "CheckChildType " << ChildNo << " "
189*9880d681SAndroid Build Coastguard Worker     << getEnumName(Type) << '\n';
190*9880d681SAndroid Build Coastguard Worker }
191*9880d681SAndroid Build Coastguard Worker 
192*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const193*9880d681SAndroid Build Coastguard Worker void CheckIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
194*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "CheckInteger " << Value << '\n';
195*9880d681SAndroid Build Coastguard Worker }
196*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const197*9880d681SAndroid Build Coastguard Worker void CheckChildIntegerMatcher::printImpl(raw_ostream &OS,
198*9880d681SAndroid Build Coastguard Worker                                          unsigned indent) const {
199*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "CheckChildInteger " << ChildNo << " " << Value << '\n';
200*9880d681SAndroid Build Coastguard Worker }
201*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const202*9880d681SAndroid Build Coastguard Worker void CheckCondCodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
203*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "CheckCondCode ISD::" << CondCodeName << '\n';
204*9880d681SAndroid Build Coastguard Worker }
205*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const206*9880d681SAndroid Build Coastguard Worker void CheckValueTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
207*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "CheckValueType MVT::" << TypeName << '\n';
208*9880d681SAndroid Build Coastguard Worker }
209*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const210*9880d681SAndroid Build Coastguard Worker void CheckComplexPatMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
211*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "CheckComplexPat " << Pattern.getSelectFunc() << '\n';
212*9880d681SAndroid Build Coastguard Worker }
213*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const214*9880d681SAndroid Build Coastguard Worker void CheckAndImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
215*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "CheckAndImm " << Value << '\n';
216*9880d681SAndroid Build Coastguard Worker }
217*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const218*9880d681SAndroid Build Coastguard Worker void CheckOrImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
219*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "CheckOrImm " << Value << '\n';
220*9880d681SAndroid Build Coastguard Worker }
221*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const222*9880d681SAndroid Build Coastguard Worker void CheckFoldableChainNodeMatcher::printImpl(raw_ostream &OS,
223*9880d681SAndroid Build Coastguard Worker                                               unsigned indent) const {
224*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "CheckFoldableChainNode\n";
225*9880d681SAndroid Build Coastguard Worker }
226*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const227*9880d681SAndroid Build Coastguard Worker void EmitIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
228*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "EmitInteger " << Val << " VT=" << getEnumName(VT)
229*9880d681SAndroid Build Coastguard Worker                     << '\n';
230*9880d681SAndroid Build Coastguard Worker }
231*9880d681SAndroid Build Coastguard Worker 
232*9880d681SAndroid Build Coastguard Worker void EmitStringIntegerMatcher::
printImpl(raw_ostream & OS,unsigned indent) const233*9880d681SAndroid Build Coastguard Worker printImpl(raw_ostream &OS, unsigned indent) const {
234*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "EmitStringInteger " << Val << " VT=" << getEnumName(VT)
235*9880d681SAndroid Build Coastguard Worker                     << '\n';
236*9880d681SAndroid Build Coastguard Worker }
237*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const238*9880d681SAndroid Build Coastguard Worker void EmitRegisterMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
239*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "EmitRegister ";
240*9880d681SAndroid Build Coastguard Worker   if (Reg)
241*9880d681SAndroid Build Coastguard Worker     OS << Reg->getName();
242*9880d681SAndroid Build Coastguard Worker   else
243*9880d681SAndroid Build Coastguard Worker     OS << "zero_reg";
244*9880d681SAndroid Build Coastguard Worker   OS << " VT=" << getEnumName(VT) << '\n';
245*9880d681SAndroid Build Coastguard Worker }
246*9880d681SAndroid Build Coastguard Worker 
247*9880d681SAndroid Build Coastguard Worker void EmitConvertToTargetMatcher::
printImpl(raw_ostream & OS,unsigned indent) const248*9880d681SAndroid Build Coastguard Worker printImpl(raw_ostream &OS, unsigned indent) const {
249*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "EmitConvertToTarget " << Slot << '\n';
250*9880d681SAndroid Build Coastguard Worker }
251*9880d681SAndroid Build Coastguard Worker 
252*9880d681SAndroid Build Coastguard Worker void EmitMergeInputChainsMatcher::
printImpl(raw_ostream & OS,unsigned indent) const253*9880d681SAndroid Build Coastguard Worker printImpl(raw_ostream &OS, unsigned indent) const {
254*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "EmitMergeInputChains <todo: args>\n";
255*9880d681SAndroid Build Coastguard Worker }
256*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const257*9880d681SAndroid Build Coastguard Worker void EmitCopyToRegMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
258*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "EmitCopyToReg <todo: args>\n";
259*9880d681SAndroid Build Coastguard Worker }
260*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const261*9880d681SAndroid Build Coastguard Worker void EmitNodeXFormMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
262*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "EmitNodeXForm " << NodeXForm->getName()
263*9880d681SAndroid Build Coastguard Worker      << " Slot=" << Slot << '\n';
264*9880d681SAndroid Build Coastguard Worker }
265*9880d681SAndroid Build Coastguard Worker 
266*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const267*9880d681SAndroid Build Coastguard Worker void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, unsigned indent) const {
268*9880d681SAndroid Build Coastguard Worker   OS.indent(indent);
269*9880d681SAndroid Build Coastguard Worker   OS << (isa<MorphNodeToMatcher>(this) ? "MorphNodeTo: " : "EmitNode: ")
270*9880d681SAndroid Build Coastguard Worker      << OpcodeName << ": <todo flags> ";
271*9880d681SAndroid Build Coastguard Worker 
272*9880d681SAndroid Build Coastguard Worker   for (unsigned i = 0, e = VTs.size(); i != e; ++i)
273*9880d681SAndroid Build Coastguard Worker     OS << ' ' << getEnumName(VTs[i]);
274*9880d681SAndroid Build Coastguard Worker   OS << '(';
275*9880d681SAndroid Build Coastguard Worker   for (unsigned i = 0, e = Operands.size(); i != e; ++i)
276*9880d681SAndroid Build Coastguard Worker     OS << Operands[i] << ' ';
277*9880d681SAndroid Build Coastguard Worker   OS << ")\n";
278*9880d681SAndroid Build Coastguard Worker }
279*9880d681SAndroid Build Coastguard Worker 
printImpl(raw_ostream & OS,unsigned indent) const280*9880d681SAndroid Build Coastguard Worker void CompleteMatchMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
281*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "CompleteMatch <todo args>\n";
282*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "Src = " << *Pattern.getSrcPattern() << "\n";
283*9880d681SAndroid Build Coastguard Worker   OS.indent(indent) << "Dst = " << *Pattern.getDstPattern() << "\n";
284*9880d681SAndroid Build Coastguard Worker }
285*9880d681SAndroid Build Coastguard Worker 
isEqualImpl(const Matcher * M) const286*9880d681SAndroid Build Coastguard Worker bool CheckOpcodeMatcher::isEqualImpl(const Matcher *M) const {
287*9880d681SAndroid Build Coastguard Worker   // Note: pointer equality isn't enough here, we have to check the enum names
288*9880d681SAndroid Build Coastguard Worker   // to ensure that the nodes are for the same opcode.
289*9880d681SAndroid Build Coastguard Worker   return cast<CheckOpcodeMatcher>(M)->Opcode.getEnumName() ==
290*9880d681SAndroid Build Coastguard Worker           Opcode.getEnumName();
291*9880d681SAndroid Build Coastguard Worker }
292*9880d681SAndroid Build Coastguard Worker 
isEqualImpl(const Matcher * m) const293*9880d681SAndroid Build Coastguard Worker bool EmitNodeMatcherCommon::isEqualImpl(const Matcher *m) const {
294*9880d681SAndroid Build Coastguard Worker   const EmitNodeMatcherCommon *M = cast<EmitNodeMatcherCommon>(m);
295*9880d681SAndroid Build Coastguard Worker   return M->OpcodeName == OpcodeName && M->VTs == VTs &&
296*9880d681SAndroid Build Coastguard Worker          M->Operands == Operands && M->HasChain == HasChain &&
297*9880d681SAndroid Build Coastguard Worker          M->HasInGlue == HasInGlue && M->HasOutGlue == HasOutGlue &&
298*9880d681SAndroid Build Coastguard Worker          M->HasMemRefs == HasMemRefs &&
299*9880d681SAndroid Build Coastguard Worker          M->NumFixedArityOperands == NumFixedArityOperands;
300*9880d681SAndroid Build Coastguard Worker }
301*9880d681SAndroid Build Coastguard Worker 
anchor()302*9880d681SAndroid Build Coastguard Worker void EmitNodeMatcher::anchor() { }
303*9880d681SAndroid Build Coastguard Worker 
anchor()304*9880d681SAndroid Build Coastguard Worker void MorphNodeToMatcher::anchor() { }
305*9880d681SAndroid Build Coastguard Worker 
306*9880d681SAndroid Build Coastguard Worker // isContradictoryImpl Implementations.
307*9880d681SAndroid Build Coastguard Worker 
TypesAreContradictory(MVT::SimpleValueType T1,MVT::SimpleValueType T2)308*9880d681SAndroid Build Coastguard Worker static bool TypesAreContradictory(MVT::SimpleValueType T1,
309*9880d681SAndroid Build Coastguard Worker                                   MVT::SimpleValueType T2) {
310*9880d681SAndroid Build Coastguard Worker   // If the two types are the same, then they are the same, so they don't
311*9880d681SAndroid Build Coastguard Worker   // contradict.
312*9880d681SAndroid Build Coastguard Worker   if (T1 == T2) return false;
313*9880d681SAndroid Build Coastguard Worker 
314*9880d681SAndroid Build Coastguard Worker   // If either type is about iPtr, then they don't conflict unless the other
315*9880d681SAndroid Build Coastguard Worker   // one is not a scalar integer type.
316*9880d681SAndroid Build Coastguard Worker   if (T1 == MVT::iPTR)
317*9880d681SAndroid Build Coastguard Worker     return !MVT(T2).isInteger() || MVT(T2).isVector();
318*9880d681SAndroid Build Coastguard Worker 
319*9880d681SAndroid Build Coastguard Worker   if (T2 == MVT::iPTR)
320*9880d681SAndroid Build Coastguard Worker     return !MVT(T1).isInteger() || MVT(T1).isVector();
321*9880d681SAndroid Build Coastguard Worker 
322*9880d681SAndroid Build Coastguard Worker   // Otherwise, they are two different non-iPTR types, they conflict.
323*9880d681SAndroid Build Coastguard Worker   return true;
324*9880d681SAndroid Build Coastguard Worker }
325*9880d681SAndroid Build Coastguard Worker 
isContradictoryImpl(const Matcher * M) const326*9880d681SAndroid Build Coastguard Worker bool CheckOpcodeMatcher::isContradictoryImpl(const Matcher *M) const {
327*9880d681SAndroid Build Coastguard Worker   if (const CheckOpcodeMatcher *COM = dyn_cast<CheckOpcodeMatcher>(M)) {
328*9880d681SAndroid Build Coastguard Worker     // One node can't have two different opcodes!
329*9880d681SAndroid Build Coastguard Worker     // Note: pointer equality isn't enough here, we have to check the enum names
330*9880d681SAndroid Build Coastguard Worker     // to ensure that the nodes are for the same opcode.
331*9880d681SAndroid Build Coastguard Worker     return COM->getOpcode().getEnumName() != getOpcode().getEnumName();
332*9880d681SAndroid Build Coastguard Worker   }
333*9880d681SAndroid Build Coastguard Worker 
334*9880d681SAndroid Build Coastguard Worker   // If the node has a known type, and if the type we're checking for is
335*9880d681SAndroid Build Coastguard Worker   // different, then we know they contradict.  For example, a check for
336*9880d681SAndroid Build Coastguard Worker   // ISD::STORE will never be true at the same time a check for Type i32 is.
337*9880d681SAndroid Build Coastguard Worker   if (const CheckTypeMatcher *CT = dyn_cast<CheckTypeMatcher>(M)) {
338*9880d681SAndroid Build Coastguard Worker     // If checking for a result the opcode doesn't have, it can't match.
339*9880d681SAndroid Build Coastguard Worker     if (CT->getResNo() >= getOpcode().getNumResults())
340*9880d681SAndroid Build Coastguard Worker       return true;
341*9880d681SAndroid Build Coastguard Worker 
342*9880d681SAndroid Build Coastguard Worker     MVT::SimpleValueType NodeType = getOpcode().getKnownType(CT->getResNo());
343*9880d681SAndroid Build Coastguard Worker     if (NodeType != MVT::Other)
344*9880d681SAndroid Build Coastguard Worker       return TypesAreContradictory(NodeType, CT->getType());
345*9880d681SAndroid Build Coastguard Worker   }
346*9880d681SAndroid Build Coastguard Worker 
347*9880d681SAndroid Build Coastguard Worker   return false;
348*9880d681SAndroid Build Coastguard Worker }
349*9880d681SAndroid Build Coastguard Worker 
isContradictoryImpl(const Matcher * M) const350*9880d681SAndroid Build Coastguard Worker bool CheckTypeMatcher::isContradictoryImpl(const Matcher *M) const {
351*9880d681SAndroid Build Coastguard Worker   if (const CheckTypeMatcher *CT = dyn_cast<CheckTypeMatcher>(M))
352*9880d681SAndroid Build Coastguard Worker     return TypesAreContradictory(getType(), CT->getType());
353*9880d681SAndroid Build Coastguard Worker   return false;
354*9880d681SAndroid Build Coastguard Worker }
355*9880d681SAndroid Build Coastguard Worker 
isContradictoryImpl(const Matcher * M) const356*9880d681SAndroid Build Coastguard Worker bool CheckChildTypeMatcher::isContradictoryImpl(const Matcher *M) const {
357*9880d681SAndroid Build Coastguard Worker   if (const CheckChildTypeMatcher *CC = dyn_cast<CheckChildTypeMatcher>(M)) {
358*9880d681SAndroid Build Coastguard Worker     // If the two checks are about different nodes, we don't know if they
359*9880d681SAndroid Build Coastguard Worker     // conflict!
360*9880d681SAndroid Build Coastguard Worker     if (CC->getChildNo() != getChildNo())
361*9880d681SAndroid Build Coastguard Worker       return false;
362*9880d681SAndroid Build Coastguard Worker 
363*9880d681SAndroid Build Coastguard Worker     return TypesAreContradictory(getType(), CC->getType());
364*9880d681SAndroid Build Coastguard Worker   }
365*9880d681SAndroid Build Coastguard Worker   return false;
366*9880d681SAndroid Build Coastguard Worker }
367*9880d681SAndroid Build Coastguard Worker 
isContradictoryImpl(const Matcher * M) const368*9880d681SAndroid Build Coastguard Worker bool CheckIntegerMatcher::isContradictoryImpl(const Matcher *M) const {
369*9880d681SAndroid Build Coastguard Worker   if (const CheckIntegerMatcher *CIM = dyn_cast<CheckIntegerMatcher>(M))
370*9880d681SAndroid Build Coastguard Worker     return CIM->getValue() != getValue();
371*9880d681SAndroid Build Coastguard Worker   return false;
372*9880d681SAndroid Build Coastguard Worker }
373*9880d681SAndroid Build Coastguard Worker 
isContradictoryImpl(const Matcher * M) const374*9880d681SAndroid Build Coastguard Worker bool CheckChildIntegerMatcher::isContradictoryImpl(const Matcher *M) const {
375*9880d681SAndroid Build Coastguard Worker   if (const CheckChildIntegerMatcher *CCIM = dyn_cast<CheckChildIntegerMatcher>(M)) {
376*9880d681SAndroid Build Coastguard Worker     // If the two checks are about different nodes, we don't know if they
377*9880d681SAndroid Build Coastguard Worker     // conflict!
378*9880d681SAndroid Build Coastguard Worker     if (CCIM->getChildNo() != getChildNo())
379*9880d681SAndroid Build Coastguard Worker       return false;
380*9880d681SAndroid Build Coastguard Worker 
381*9880d681SAndroid Build Coastguard Worker     return CCIM->getValue() != getValue();
382*9880d681SAndroid Build Coastguard Worker   }
383*9880d681SAndroid Build Coastguard Worker   return false;
384*9880d681SAndroid Build Coastguard Worker }
385*9880d681SAndroid Build Coastguard Worker 
isContradictoryImpl(const Matcher * M) const386*9880d681SAndroid Build Coastguard Worker bool CheckValueTypeMatcher::isContradictoryImpl(const Matcher *M) const {
387*9880d681SAndroid Build Coastguard Worker   if (const CheckValueTypeMatcher *CVT = dyn_cast<CheckValueTypeMatcher>(M))
388*9880d681SAndroid Build Coastguard Worker     return CVT->getTypeName() != getTypeName();
389*9880d681SAndroid Build Coastguard Worker   return false;
390*9880d681SAndroid Build Coastguard Worker }
391*9880d681SAndroid Build Coastguard Worker 
392