blob: 8e1bd749f52555166716d9be4afb3389f73bb3a7 [file] [log] [blame]
Chris Lattnerb02cdaa2010-02-15 08:04:42 +00001//===- 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"
Chris Lattner212e8c82010-02-25 06:49:58 +000013#include "llvm/ADT/StringExtras.h"
Chandler Carruth91d19d82012-12-04 10:37:14 +000014#include "llvm/Support/raw_ostream.h"
15#include "llvm/TableGen/Record.h"
Chris Lattnerb02cdaa2010-02-15 08:04:42 +000016using namespace llvm;
17
David Blaikiea379b1812011-12-20 02:50:00 +000018void Matcher::anchor() { }
19
Chris Lattner2c3f6492010-02-25 02:04:40 +000020void Matcher::dump() const {
Chris Lattner1f2adb62010-02-25 06:53:39 +000021 print(errs(), 0);
Chris Lattnerb02cdaa2010-02-15 08:04:42 +000022}
23
Chris Lattner1f2adb62010-02-25 06:53:39 +000024void Matcher::print(raw_ostream &OS, unsigned indent) const {
25 printImpl(OS, indent);
Chris Lattner186ad802010-02-18 02:53:41 +000026 if (Next)
27 return Next->print(OS, indent);
Chris Lattnerb02cdaa2010-02-15 08:04:42 +000028}
29
Chris Lattnerc577b812010-02-27 07:49:13 +000030void Matcher::printOne(raw_ostream &OS) const {
31 printImpl(OS, 0);
32}
33
Chris Lattner9c791d82010-03-07 06:29:26 +000034/// unlinkNode - Unlink the specified node from this chain. If Other == this,
35/// we unlink the next pointer and return it. Otherwise we unlink Other from
36/// the list and return this.
37Matcher *Matcher::unlinkNode(Matcher *Other) {
38 if (this == Other)
39 return takeNext();
Jim Grosbach65586fe2010-12-21 16:16:00 +000040
Chris Lattner9c791d82010-03-07 06:29:26 +000041 // Scan until we find the predecessor of Other.
42 Matcher *Cur = this;
43 for (; Cur && Cur->getNext() != Other; Cur = Cur->getNext())
44 /*empty*/;
45
Craig Topper24064772014-04-15 07:20:03 +000046 if (!Cur) return nullptr;
Chris Lattner9c791d82010-03-07 06:29:26 +000047 Cur->takeNext();
48 Cur->setNext(Other->takeNext());
49 return this;
50}
51
52/// canMoveBefore - Return true if this matcher is the same as Other, or if
53/// we can move this matcher past all of the nodes in-between Other and this
54/// node. Other must be equal to or before this.
55bool Matcher::canMoveBefore(const Matcher *Other) const {
56 for (;; Other = Other->getNext()) {
57 assert(Other && "Other didn't come before 'this'?");
58 if (this == Other) return true;
59
60 // We have to be able to move this node across the Other node.
61 if (!canMoveBeforeNode(Other))
62 return false;
63 }
64}
65
Craig Topper0ac6f9f2013-09-25 06:40:22 +000066/// canMoveBeforeNode - Return true if it is safe to move the current matcher
Chris Lattner9c791d82010-03-07 06:29:26 +000067/// across the specified one.
68bool Matcher::canMoveBeforeNode(const Matcher *Other) const {
69 // We can move simple predicates before record nodes.
70 if (isSimplePredicateNode())
71 return Other->isSimplePredicateOrRecordNode();
Jim Grosbach65586fe2010-12-21 16:16:00 +000072
Chris Lattner9c791d82010-03-07 06:29:26 +000073 // We can move record nodes across simple predicates.
74 if (isSimplePredicateOrRecordNode())
75 return isSimplePredicateNode();
Jim Grosbach65586fe2010-12-21 16:16:00 +000076
Chris Lattner9c791d82010-03-07 06:29:26 +000077 // We can't move record nodes across each other etc.
78 return false;
79}
80
81
Chris Lattnerf7fc2d82010-02-25 19:00:39 +000082ScopeMatcher::~ScopeMatcher() {
83 for (unsigned i = 0, e = Children.size(); i != e; ++i)
84 delete Children[i];
85}
86
Craig Topper0d16d2d2014-01-29 07:06:07 +000087SwitchOpcodeMatcher::~SwitchOpcodeMatcher() {
88 for (unsigned i = 0, e = Cases.size(); i != e; ++i)
89 delete Cases[i].second;
90}
91
92SwitchTypeMatcher::~SwitchTypeMatcher() {
93 for (unsigned i = 0, e = Cases.size(); i != e; ++i)
94 delete Cases[i].second;
95}
Chris Lattnerf7fc2d82010-02-25 19:00:39 +000096
Chris Lattner514e2922011-04-17 21:38:24 +000097CheckPredicateMatcher::CheckPredicateMatcher(const TreePredicateFn &pred)
98 : Matcher(CheckPredicate), Pred(pred.getOrigPatFragRecord()) {}
99
100TreePredicateFn CheckPredicateMatcher::getPredicate() const {
101 return TreePredicateFn(Pred);
102}
103
104
105
Chris Lattnerf7fc2d82010-02-25 19:00:39 +0000106// printImpl methods.
107
Chris Lattner1f2adb62010-02-25 06:53:39 +0000108void ScopeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerac55f9d2010-02-25 01:56:48 +0000109 OS.indent(indent) << "Scope\n";
Chris Lattner102a8a02010-02-28 20:49:53 +0000110 for (unsigned i = 0, e = getNumChildren(); i != e; ++i) {
Craig Topper24064772014-04-15 07:20:03 +0000111 if (!getChild(i))
Chris Lattner102a8a02010-02-28 20:49:53 +0000112 OS.indent(indent+1) << "NULL POINTER\n";
113 else
114 getChild(i)->print(OS, indent+2);
115 }
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000116}
117
Chris Lattner1f2adb62010-02-25 06:53:39 +0000118void RecordMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000119 OS.indent(indent) << "Record\n";
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000120}
121
Chris Lattner1f2adb62010-02-25 06:53:39 +0000122void RecordChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerab417562010-02-24 07:31:45 +0000123 OS.indent(indent) << "RecordChild: " << ChildNo << '\n';
Chris Lattnerab417562010-02-24 07:31:45 +0000124}
125
Chris Lattner1f2adb62010-02-25 06:53:39 +0000126void RecordMemRefMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000127 OS.indent(indent) << "RecordMemRef\n";
Chris Lattner132df652010-02-21 03:22:59 +0000128}
129
Chris Lattnerf7f9e8c2010-12-23 17:03:20 +0000130void CaptureGlueInputMatcher::printImpl(raw_ostream &OS, unsigned indent) const{
131 OS.indent(indent) << "CaptureGlueInput\n";
Chris Lattner132df652010-02-21 03:22:59 +0000132}
133
Chris Lattner1f2adb62010-02-25 06:53:39 +0000134void MoveChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000135 OS.indent(indent) << "MoveChild " << ChildNo << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000136}
137
Chris Lattner1f2adb62010-02-25 06:53:39 +0000138void MoveParentMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000139 OS.indent(indent) << "MoveParent\n";
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000140}
141
Chris Lattner1f2adb62010-02-25 06:53:39 +0000142void CheckSameMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000143 OS.indent(indent) << "CheckSame " << MatchNumber << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000144}
145
Craig Toppera1bbc322013-10-05 05:38:16 +0000146void CheckChildSameMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
147 OS.indent(indent) << "CheckChild" << ChildNo << "Same\n";
148}
149
Chris Lattner2c3f6492010-02-25 02:04:40 +0000150void CheckPatternPredicateMatcher::
Chris Lattner1f2adb62010-02-25 06:53:39 +0000151printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000152 OS.indent(indent) << "CheckPatternPredicate " << Predicate << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000153}
154
Chris Lattner1f2adb62010-02-25 06:53:39 +0000155void CheckPredicateMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner514e2922011-04-17 21:38:24 +0000156 OS.indent(indent) << "CheckPredicate " << getPredicate().getFnName() << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000157}
158
Chris Lattner1f2adb62010-02-25 06:53:39 +0000159void CheckOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner278606b2010-02-27 21:48:43 +0000160 OS.indent(indent) << "CheckOpcode " << Opcode.getEnumName() << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000161}
162
Chris Lattnerf4d17752010-03-01 06:59:22 +0000163void SwitchOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
164 OS.indent(indent) << "SwitchOpcode: {\n";
165 for (unsigned i = 0, e = Cases.size(); i != e; ++i) {
166 OS.indent(indent) << "case " << Cases[i].first->getEnumName() << ":\n";
167 Cases[i].second->print(OS, indent+2);
168 }
169 OS.indent(indent) << "}\n";
170}
171
172
Chris Lattner1f2adb62010-02-25 06:53:39 +0000173void CheckTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner6c2d1782010-03-24 00:41:19 +0000174 OS.indent(indent) << "CheckType " << getEnumName(Type) << ", ResNo="
175 << ResNo << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000176}
177
Chris Lattner3e1ffd02010-03-03 06:28:15 +0000178void SwitchTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
179 OS.indent(indent) << "SwitchType: {\n";
180 for (unsigned i = 0, e = Cases.size(); i != e; ++i) {
181 OS.indent(indent) << "case " << getEnumName(Cases[i].first) << ":\n";
182 Cases[i].second->print(OS, indent+2);
183 }
184 OS.indent(indent) << "}\n";
185}
186
Chris Lattner1f2adb62010-02-25 06:53:39 +0000187void CheckChildTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner0c95baa2010-02-24 20:15:25 +0000188 OS.indent(indent) << "CheckChildType " << ChildNo << " "
189 << getEnumName(Type) << '\n';
Chris Lattner0c95baa2010-02-24 20:15:25 +0000190}
191
192
Chris Lattner1f2adb62010-02-25 06:53:39 +0000193void CheckIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000194 OS.indent(indent) << "CheckInteger " << Value << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000195}
196
Craig Topper7ca1d182014-02-05 05:44:28 +0000197void CheckChildIntegerMatcher::printImpl(raw_ostream &OS,
198 unsigned indent) const {
199 OS.indent(indent) << "CheckChildInteger " << ChildNo << " " << Value << '\n';
200}
201
Chris Lattner1f2adb62010-02-25 06:53:39 +0000202void CheckCondCodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000203 OS.indent(indent) << "CheckCondCode ISD::" << CondCodeName << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000204}
205
Chris Lattner1f2adb62010-02-25 06:53:39 +0000206void CheckValueTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000207 OS.indent(indent) << "CheckValueType MVT::" << TypeName << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000208}
209
Chris Lattner1f2adb62010-02-25 06:53:39 +0000210void CheckComplexPatMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000211 OS.indent(indent) << "CheckComplexPat " << Pattern.getSelectFunc() << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000212}
213
Chris Lattner1f2adb62010-02-25 06:53:39 +0000214void CheckAndImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000215 OS.indent(indent) << "CheckAndImm " << Value << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000216}
217
Chris Lattner1f2adb62010-02-25 06:53:39 +0000218void CheckOrImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000219 OS.indent(indent) << "CheckOrImm " << Value << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000220}
221
Chris Lattner1f2adb62010-02-25 06:53:39 +0000222void CheckFoldableChainNodeMatcher::printImpl(raw_ostream &OS,
Chris Lattnerf8695c12010-02-16 19:15:55 +0000223 unsigned indent) const {
224 OS.indent(indent) << "CheckFoldableChainNode\n";
Chris Lattneraa7d3e02010-02-16 06:10:58 +0000225}
Chris Lattnerf8a5bb02010-02-17 06:23:39 +0000226
Chris Lattner1f2adb62010-02-25 06:53:39 +0000227void EmitIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Craig Topper6ff46262016-04-17 17:37:33 +0000228 OS.indent(indent) << "EmitInteger " << Val << " VT=" << getEnumName(VT)
229 << '\n';
Chris Lattner132df652010-02-21 03:22:59 +0000230}
231
Chris Lattner2c3f6492010-02-25 02:04:40 +0000232void EmitStringIntegerMatcher::
Chris Lattner1f2adb62010-02-25 06:53:39 +0000233printImpl(raw_ostream &OS, unsigned indent) const {
Craig Topper6ff46262016-04-17 17:37:33 +0000234 OS.indent(indent) << "EmitStringInteger " << Val << " VT=" << getEnumName(VT)
235 << '\n';
Chris Lattner42a7ba72010-02-18 22:03:03 +0000236}
237
Chris Lattner1f2adb62010-02-25 06:53:39 +0000238void EmitRegisterMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000239 OS.indent(indent) << "EmitRegister ";
Chris Lattner42a7ba72010-02-18 22:03:03 +0000240 if (Reg)
241 OS << Reg->getName();
242 else
243 OS << "zero_reg";
Craig Topper6ff46262016-04-17 17:37:33 +0000244 OS << " VT=" << getEnumName(VT) << '\n';
Chris Lattner42a7ba72010-02-18 22:03:03 +0000245}
246
Chris Lattner2c3f6492010-02-25 02:04:40 +0000247void EmitConvertToTargetMatcher::
Chris Lattner1f2adb62010-02-25 06:53:39 +0000248printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000249 OS.indent(indent) << "EmitConvertToTarget " << Slot << '\n';
Chris Lattner132df652010-02-21 03:22:59 +0000250}
251
Chris Lattner2c3f6492010-02-25 02:04:40 +0000252void EmitMergeInputChainsMatcher::
Chris Lattner1f2adb62010-02-25 06:53:39 +0000253printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000254 OS.indent(indent) << "EmitMergeInputChains <todo: args>\n";
Chris Lattner132df652010-02-21 03:22:59 +0000255}
256
Chris Lattner1f2adb62010-02-25 06:53:39 +0000257void EmitCopyToRegMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000258 OS.indent(indent) << "EmitCopyToReg <todo: args>\n";
Chris Lattner132df652010-02-21 03:22:59 +0000259}
260
Chris Lattner1f2adb62010-02-25 06:53:39 +0000261void EmitNodeXFormMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000262 OS.indent(indent) << "EmitNodeXForm " << NodeXForm->getName()
263 << " Slot=" << Slot << '\n';
Chris Lattner132df652010-02-21 03:22:59 +0000264}
265
266
Chris Lattnerc3f80e02010-02-28 02:31:26 +0000267void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, unsigned indent) const {
268 OS.indent(indent);
Chris Lattner9d67dca2010-02-28 20:55:18 +0000269 OS << (isa<MorphNodeToMatcher>(this) ? "MorphNodeTo: " : "EmitNode: ")
Chris Lattnerc3f80e02010-02-28 02:31:26 +0000270 << OpcodeName << ": <todo flags> ";
Chris Lattner132df652010-02-21 03:22:59 +0000271
272 for (unsigned i = 0, e = VTs.size(); i != e; ++i)
273 OS << ' ' << getEnumName(VTs[i]);
274 OS << '(';
275 for (unsigned i = 0, e = Operands.size(); i != e; ++i)
276 OS << Operands[i] << ' ';
277 OS << ")\n";
Chris Lattner132df652010-02-21 03:22:59 +0000278}
279
Chris Lattnerf7f9e8c2010-12-23 17:03:20 +0000280void MarkGlueResultsMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
281 OS.indent(indent) << "MarkGlueResults <todo: args>\n";
Chris Lattner29364372010-02-24 05:33:42 +0000282}
283
Chris Lattner1f2adb62010-02-25 06:53:39 +0000284void CompleteMatchMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner79eaeb42010-02-21 06:03:07 +0000285 OS.indent(indent) << "CompleteMatch <todo args>\n";
Chris Lattner132df652010-02-21 03:22:59 +0000286 OS.indent(indent) << "Src = " << *Pattern.getSrcPattern() << "\n";
287 OS.indent(indent) << "Dst = " << *Pattern.getDstPattern() << "\n";
Chris Lattner132df652010-02-21 03:22:59 +0000288}
289
Chris Lattner212e8c82010-02-25 06:49:58 +0000290// getHashImpl Implementation.
291
292unsigned CheckPatternPredicateMatcher::getHashImpl() const {
293 return HashString(Predicate);
294}
295
296unsigned CheckPredicateMatcher::getHashImpl() const {
Chris Lattner514e2922011-04-17 21:38:24 +0000297 return HashString(getPredicate().getFnName());
Chris Lattner212e8c82010-02-25 06:49:58 +0000298}
299
300unsigned CheckOpcodeMatcher::getHashImpl() const {
Chris Lattner278606b2010-02-27 21:48:43 +0000301 return HashString(Opcode.getEnumName());
Chris Lattner212e8c82010-02-25 06:49:58 +0000302}
303
Chris Lattner212e8c82010-02-25 06:49:58 +0000304unsigned CheckCondCodeMatcher::getHashImpl() const {
305 return HashString(CondCodeName);
306}
307
308unsigned CheckValueTypeMatcher::getHashImpl() const {
309 return HashString(TypeName);
310}
311
312unsigned EmitStringIntegerMatcher::getHashImpl() const {
313 return HashString(Val) ^ VT;
314}
315
316template<typename It>
317static unsigned HashUnsigneds(It I, It E) {
318 unsigned Result = 0;
319 for (; I != E; ++I)
320 Result = (Result<<3) ^ *I;
321 return Result;
322}
323
324unsigned EmitMergeInputChainsMatcher::getHashImpl() const {
325 return HashUnsigneds(ChainNodes.begin(), ChainNodes.end());
326}
327
Chris Lattnerf4d17752010-03-01 06:59:22 +0000328bool CheckOpcodeMatcher::isEqualImpl(const Matcher *M) const {
329 // Note: pointer equality isn't enough here, we have to check the enum names
Jim Grosbach65586fe2010-12-21 16:16:00 +0000330 // to ensure that the nodes are for the same opcode.
Chris Lattnerf4d17752010-03-01 06:59:22 +0000331 return cast<CheckOpcodeMatcher>(M)->Opcode.getEnumName() ==
332 Opcode.getEnumName();
333}
334
Chris Lattnerc3f80e02010-02-28 02:31:26 +0000335bool EmitNodeMatcherCommon::isEqualImpl(const Matcher *m) const {
336 const EmitNodeMatcherCommon *M = cast<EmitNodeMatcherCommon>(m);
Chris Lattner212e8c82010-02-25 06:49:58 +0000337 return M->OpcodeName == OpcodeName && M->VTs == VTs &&
338 M->Operands == Operands && M->HasChain == HasChain &&
Chris Lattner2a0a3b42010-12-23 18:28:41 +0000339 M->HasInGlue == HasInGlue && M->HasOutGlue == HasOutGlue &&
Chris Lattnera8382642010-02-28 21:53:42 +0000340 M->HasMemRefs == HasMemRefs &&
Chris Lattner212e8c82010-02-25 06:49:58 +0000341 M->NumFixedArityOperands == NumFixedArityOperands;
342}
343
Chris Lattnerc3f80e02010-02-28 02:31:26 +0000344unsigned EmitNodeMatcherCommon::getHashImpl() const {
Chris Lattner212e8c82010-02-25 06:49:58 +0000345 return (HashString(OpcodeName) << 4) | Operands.size();
346}
347
348
David Blaikiea379b1812011-12-20 02:50:00 +0000349void EmitNodeMatcher::anchor() { }
350
351void MorphNodeToMatcher::anchor() { }
352
Chris Lattnerf7f9e8c2010-12-23 17:03:20 +0000353unsigned MarkGlueResultsMatcher::getHashImpl() const {
354 return HashUnsigneds(GlueResultNodes.begin(), GlueResultNodes.end());
Chris Lattner212e8c82010-02-25 06:49:58 +0000355}
356
357unsigned CompleteMatchMatcher::getHashImpl() const {
Jim Grosbach65586fe2010-12-21 16:16:00 +0000358 return HashUnsigneds(Results.begin(), Results.end()) ^
Chris Lattner212e8c82010-02-25 06:49:58 +0000359 ((unsigned)(intptr_t)&Pattern << 8);
360}
Chris Lattnerc577b812010-02-27 07:49:13 +0000361
362// isContradictoryImpl Implementations.
363
Chris Lattnerc577b812010-02-27 07:49:13 +0000364static bool TypesAreContradictory(MVT::SimpleValueType T1,
365 MVT::SimpleValueType T2) {
366 // If the two types are the same, then they are the same, so they don't
367 // contradict.
368 if (T1 == T2) return false;
Jim Grosbach65586fe2010-12-21 16:16:00 +0000369
Chris Lattnerc577b812010-02-27 07:49:13 +0000370 // If either type is about iPtr, then they don't conflict unless the other
371 // one is not a scalar integer type.
372 if (T1 == MVT::iPTR)
373 return !MVT(T2).isInteger() || MVT(T2).isVector();
Jim Grosbach65586fe2010-12-21 16:16:00 +0000374
Chris Lattnerc577b812010-02-27 07:49:13 +0000375 if (T2 == MVT::iPTR)
376 return !MVT(T1).isInteger() || MVT(T1).isVector();
Jim Grosbach65586fe2010-12-21 16:16:00 +0000377
Chris Lattnerc577b812010-02-27 07:49:13 +0000378 // Otherwise, they are two different non-iPTR types, they conflict.
379 return true;
380}
381
Chris Lattner99e53b32010-02-28 00:22:30 +0000382bool CheckOpcodeMatcher::isContradictoryImpl(const Matcher *M) const {
383 if (const CheckOpcodeMatcher *COM = dyn_cast<CheckOpcodeMatcher>(M)) {
384 // One node can't have two different opcodes!
Chris Lattnerf4d17752010-03-01 06:59:22 +0000385 // Note: pointer equality isn't enough here, we have to check the enum names
Jim Grosbach65586fe2010-12-21 16:16:00 +0000386 // to ensure that the nodes are for the same opcode.
Chris Lattnerf4d17752010-03-01 06:59:22 +0000387 return COM->getOpcode().getEnumName() != getOpcode().getEnumName();
Chris Lattner99e53b32010-02-28 00:22:30 +0000388 }
Jim Grosbach65586fe2010-12-21 16:16:00 +0000389
Chris Lattner99e53b32010-02-28 00:22:30 +0000390 // If the node has a known type, and if the type we're checking for is
391 // different, then we know they contradict. For example, a check for
392 // ISD::STORE will never be true at the same time a check for Type i32 is.
393 if (const CheckTypeMatcher *CT = dyn_cast<CheckTypeMatcher>(M)) {
Chris Lattner6c2d1782010-03-24 00:41:19 +0000394 // If checking for a result the opcode doesn't have, it can't match.
395 if (CT->getResNo() >= getOpcode().getNumResults())
396 return true;
Jim Grosbach65586fe2010-12-21 16:16:00 +0000397
Chris Lattner6c2d1782010-03-24 00:41:19 +0000398 MVT::SimpleValueType NodeType = getOpcode().getKnownType(CT->getResNo());
Chris Lattnerda5b4ad2010-03-19 01:14:27 +0000399 if (NodeType != MVT::Other)
400 return TypesAreContradictory(NodeType, CT->getType());
Chris Lattner99e53b32010-02-28 00:22:30 +0000401 }
Jim Grosbach65586fe2010-12-21 16:16:00 +0000402
Chris Lattner99e53b32010-02-28 00:22:30 +0000403 return false;
404}
405
Chris Lattnerc577b812010-02-27 07:49:13 +0000406bool CheckTypeMatcher::isContradictoryImpl(const Matcher *M) const {
407 if (const CheckTypeMatcher *CT = dyn_cast<CheckTypeMatcher>(M))
408 return TypesAreContradictory(getType(), CT->getType());
409 return false;
410}
411
412bool CheckChildTypeMatcher::isContradictoryImpl(const Matcher *M) const {
413 if (const CheckChildTypeMatcher *CC = dyn_cast<CheckChildTypeMatcher>(M)) {
414 // If the two checks are about different nodes, we don't know if they
415 // conflict!
416 if (CC->getChildNo() != getChildNo())
417 return false;
Jim Grosbach65586fe2010-12-21 16:16:00 +0000418
Chris Lattnerc577b812010-02-27 07:49:13 +0000419 return TypesAreContradictory(getType(), CC->getType());
420 }
421 return false;
422}
Jim Grosbach65586fe2010-12-21 16:16:00 +0000423
Chris Lattner2586c862010-02-27 08:11:15 +0000424bool CheckIntegerMatcher::isContradictoryImpl(const Matcher *M) const {
425 if (const CheckIntegerMatcher *CIM = dyn_cast<CheckIntegerMatcher>(M))
426 return CIM->getValue() != getValue();
427 return false;
428}
Chris Lattner9c791d82010-03-07 06:29:26 +0000429
Craig Topper7ca1d182014-02-05 05:44:28 +0000430bool CheckChildIntegerMatcher::isContradictoryImpl(const Matcher *M) const {
431 if (const CheckChildIntegerMatcher *CCIM = dyn_cast<CheckChildIntegerMatcher>(M)) {
432 // If the two checks are about different nodes, we don't know if they
433 // conflict!
434 if (CCIM->getChildNo() != getChildNo())
435 return false;
436
437 return CCIM->getValue() != getValue();
438 }
439 return false;
440}
441
Chris Lattner9c791d82010-03-07 06:29:26 +0000442bool CheckValueTypeMatcher::isContradictoryImpl(const Matcher *M) const {
443 if (const CheckValueTypeMatcher *CVT = dyn_cast<CheckValueTypeMatcher>(M))
444 return CVT->getTypeName() != getTypeName();
445 return false;
446}
447