blob: 9c4079906a383e7e9d79872ec595e7fc6761f419 [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 {
Chris Lattner132df652010-02-21 03:22:59 +0000228 OS.indent(indent) << "EmitInteger " << Val << " VT=" << VT << '\n';
Chris Lattner132df652010-02-21 03:22:59 +0000229}
230
Chris Lattner2c3f6492010-02-25 02:04:40 +0000231void EmitStringIntegerMatcher::
Chris Lattner1f2adb62010-02-25 06:53:39 +0000232printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000233 OS.indent(indent) << "EmitStringInteger " << Val << " VT=" << VT << '\n';
Chris Lattner42a7ba72010-02-18 22:03:03 +0000234}
235
Chris Lattner1f2adb62010-02-25 06:53:39 +0000236void EmitRegisterMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000237 OS.indent(indent) << "EmitRegister ";
Chris Lattner42a7ba72010-02-18 22:03:03 +0000238 if (Reg)
239 OS << Reg->getName();
240 else
241 OS << "zero_reg";
242 OS << " VT=" << VT << '\n';
Chris Lattner42a7ba72010-02-18 22:03:03 +0000243}
244
Chris Lattner2c3f6492010-02-25 02:04:40 +0000245void EmitConvertToTargetMatcher::
Chris Lattner1f2adb62010-02-25 06:53:39 +0000246printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000247 OS.indent(indent) << "EmitConvertToTarget " << Slot << '\n';
Chris Lattner132df652010-02-21 03:22:59 +0000248}
249
Chris Lattner2c3f6492010-02-25 02:04:40 +0000250void EmitMergeInputChainsMatcher::
Chris Lattner1f2adb62010-02-25 06:53:39 +0000251printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000252 OS.indent(indent) << "EmitMergeInputChains <todo: args>\n";
Chris Lattner132df652010-02-21 03:22:59 +0000253}
254
Chris Lattner1f2adb62010-02-25 06:53:39 +0000255void EmitCopyToRegMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000256 OS.indent(indent) << "EmitCopyToReg <todo: args>\n";
Chris Lattner132df652010-02-21 03:22:59 +0000257}
258
Chris Lattner1f2adb62010-02-25 06:53:39 +0000259void EmitNodeXFormMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000260 OS.indent(indent) << "EmitNodeXForm " << NodeXForm->getName()
261 << " Slot=" << Slot << '\n';
Chris Lattner132df652010-02-21 03:22:59 +0000262}
263
264
Chris Lattnerc3f80e02010-02-28 02:31:26 +0000265void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, unsigned indent) const {
266 OS.indent(indent);
Chris Lattner9d67dca2010-02-28 20:55:18 +0000267 OS << (isa<MorphNodeToMatcher>(this) ? "MorphNodeTo: " : "EmitNode: ")
Chris Lattnerc3f80e02010-02-28 02:31:26 +0000268 << OpcodeName << ": <todo flags> ";
Chris Lattner132df652010-02-21 03:22:59 +0000269
270 for (unsigned i = 0, e = VTs.size(); i != e; ++i)
271 OS << ' ' << getEnumName(VTs[i]);
272 OS << '(';
273 for (unsigned i = 0, e = Operands.size(); i != e; ++i)
274 OS << Operands[i] << ' ';
275 OS << ")\n";
Chris Lattner132df652010-02-21 03:22:59 +0000276}
277
Chris Lattnerf7f9e8c2010-12-23 17:03:20 +0000278void MarkGlueResultsMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
279 OS.indent(indent) << "MarkGlueResults <todo: args>\n";
Chris Lattner29364372010-02-24 05:33:42 +0000280}
281
Chris Lattner1f2adb62010-02-25 06:53:39 +0000282void CompleteMatchMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner79eaeb42010-02-21 06:03:07 +0000283 OS.indent(indent) << "CompleteMatch <todo args>\n";
Chris Lattner132df652010-02-21 03:22:59 +0000284 OS.indent(indent) << "Src = " << *Pattern.getSrcPattern() << "\n";
285 OS.indent(indent) << "Dst = " << *Pattern.getDstPattern() << "\n";
Chris Lattner132df652010-02-21 03:22:59 +0000286}
287
Chris Lattner212e8c82010-02-25 06:49:58 +0000288// getHashImpl Implementation.
289
290unsigned CheckPatternPredicateMatcher::getHashImpl() const {
291 return HashString(Predicate);
292}
293
294unsigned CheckPredicateMatcher::getHashImpl() const {
Chris Lattner514e2922011-04-17 21:38:24 +0000295 return HashString(getPredicate().getFnName());
Chris Lattner212e8c82010-02-25 06:49:58 +0000296}
297
298unsigned CheckOpcodeMatcher::getHashImpl() const {
Chris Lattner278606b2010-02-27 21:48:43 +0000299 return HashString(Opcode.getEnumName());
Chris Lattner212e8c82010-02-25 06:49:58 +0000300}
301
Chris Lattner212e8c82010-02-25 06:49:58 +0000302unsigned CheckCondCodeMatcher::getHashImpl() const {
303 return HashString(CondCodeName);
304}
305
306unsigned CheckValueTypeMatcher::getHashImpl() const {
307 return HashString(TypeName);
308}
309
310unsigned EmitStringIntegerMatcher::getHashImpl() const {
311 return HashString(Val) ^ VT;
312}
313
314template<typename It>
315static unsigned HashUnsigneds(It I, It E) {
316 unsigned Result = 0;
317 for (; I != E; ++I)
318 Result = (Result<<3) ^ *I;
319 return Result;
320}
321
322unsigned EmitMergeInputChainsMatcher::getHashImpl() const {
323 return HashUnsigneds(ChainNodes.begin(), ChainNodes.end());
324}
325
Chris Lattnerf4d17752010-03-01 06:59:22 +0000326bool CheckOpcodeMatcher::isEqualImpl(const Matcher *M) const {
327 // Note: pointer equality isn't enough here, we have to check the enum names
Jim Grosbach65586fe2010-12-21 16:16:00 +0000328 // to ensure that the nodes are for the same opcode.
Chris Lattnerf4d17752010-03-01 06:59:22 +0000329 return cast<CheckOpcodeMatcher>(M)->Opcode.getEnumName() ==
330 Opcode.getEnumName();
331}
332
Chris Lattnerc3f80e02010-02-28 02:31:26 +0000333bool EmitNodeMatcherCommon::isEqualImpl(const Matcher *m) const {
334 const EmitNodeMatcherCommon *M = cast<EmitNodeMatcherCommon>(m);
Chris Lattner212e8c82010-02-25 06:49:58 +0000335 return M->OpcodeName == OpcodeName && M->VTs == VTs &&
336 M->Operands == Operands && M->HasChain == HasChain &&
Chris Lattner2a0a3b42010-12-23 18:28:41 +0000337 M->HasInGlue == HasInGlue && M->HasOutGlue == HasOutGlue &&
Chris Lattnera8382642010-02-28 21:53:42 +0000338 M->HasMemRefs == HasMemRefs &&
Chris Lattner212e8c82010-02-25 06:49:58 +0000339 M->NumFixedArityOperands == NumFixedArityOperands;
340}
341
Chris Lattnerc3f80e02010-02-28 02:31:26 +0000342unsigned EmitNodeMatcherCommon::getHashImpl() const {
Chris Lattner212e8c82010-02-25 06:49:58 +0000343 return (HashString(OpcodeName) << 4) | Operands.size();
344}
345
346
David Blaikiea379b1812011-12-20 02:50:00 +0000347void EmitNodeMatcher::anchor() { }
348
349void MorphNodeToMatcher::anchor() { }
350
Chris Lattnerf7f9e8c2010-12-23 17:03:20 +0000351unsigned MarkGlueResultsMatcher::getHashImpl() const {
352 return HashUnsigneds(GlueResultNodes.begin(), GlueResultNodes.end());
Chris Lattner212e8c82010-02-25 06:49:58 +0000353}
354
355unsigned CompleteMatchMatcher::getHashImpl() const {
Jim Grosbach65586fe2010-12-21 16:16:00 +0000356 return HashUnsigneds(Results.begin(), Results.end()) ^
Chris Lattner212e8c82010-02-25 06:49:58 +0000357 ((unsigned)(intptr_t)&Pattern << 8);
358}
Chris Lattnerc577b812010-02-27 07:49:13 +0000359
360// isContradictoryImpl Implementations.
361
Chris Lattnerc577b812010-02-27 07:49:13 +0000362static bool TypesAreContradictory(MVT::SimpleValueType T1,
363 MVT::SimpleValueType T2) {
364 // If the two types are the same, then they are the same, so they don't
365 // contradict.
366 if (T1 == T2) return false;
Jim Grosbach65586fe2010-12-21 16:16:00 +0000367
Chris Lattnerc577b812010-02-27 07:49:13 +0000368 // If either type is about iPtr, then they don't conflict unless the other
369 // one is not a scalar integer type.
370 if (T1 == MVT::iPTR)
371 return !MVT(T2).isInteger() || MVT(T2).isVector();
Jim Grosbach65586fe2010-12-21 16:16:00 +0000372
Chris Lattnerc577b812010-02-27 07:49:13 +0000373 if (T2 == MVT::iPTR)
374 return !MVT(T1).isInteger() || MVT(T1).isVector();
Jim Grosbach65586fe2010-12-21 16:16:00 +0000375
Chris Lattnerc577b812010-02-27 07:49:13 +0000376 // Otherwise, they are two different non-iPTR types, they conflict.
377 return true;
378}
379
Chris Lattner99e53b32010-02-28 00:22:30 +0000380bool CheckOpcodeMatcher::isContradictoryImpl(const Matcher *M) const {
381 if (const CheckOpcodeMatcher *COM = dyn_cast<CheckOpcodeMatcher>(M)) {
382 // One node can't have two different opcodes!
Chris Lattnerf4d17752010-03-01 06:59:22 +0000383 // Note: pointer equality isn't enough here, we have to check the enum names
Jim Grosbach65586fe2010-12-21 16:16:00 +0000384 // to ensure that the nodes are for the same opcode.
Chris Lattnerf4d17752010-03-01 06:59:22 +0000385 return COM->getOpcode().getEnumName() != getOpcode().getEnumName();
Chris Lattner99e53b32010-02-28 00:22:30 +0000386 }
Jim Grosbach65586fe2010-12-21 16:16:00 +0000387
Chris Lattner99e53b32010-02-28 00:22:30 +0000388 // If the node has a known type, and if the type we're checking for is
389 // different, then we know they contradict. For example, a check for
390 // ISD::STORE will never be true at the same time a check for Type i32 is.
391 if (const CheckTypeMatcher *CT = dyn_cast<CheckTypeMatcher>(M)) {
Chris Lattner6c2d1782010-03-24 00:41:19 +0000392 // If checking for a result the opcode doesn't have, it can't match.
393 if (CT->getResNo() >= getOpcode().getNumResults())
394 return true;
Jim Grosbach65586fe2010-12-21 16:16:00 +0000395
Chris Lattner6c2d1782010-03-24 00:41:19 +0000396 MVT::SimpleValueType NodeType = getOpcode().getKnownType(CT->getResNo());
Chris Lattnerda5b4ad2010-03-19 01:14:27 +0000397 if (NodeType != MVT::Other)
398 return TypesAreContradictory(NodeType, CT->getType());
Chris Lattner99e53b32010-02-28 00:22:30 +0000399 }
Jim Grosbach65586fe2010-12-21 16:16:00 +0000400
Chris Lattner99e53b32010-02-28 00:22:30 +0000401 return false;
402}
403
Chris Lattnerc577b812010-02-27 07:49:13 +0000404bool CheckTypeMatcher::isContradictoryImpl(const Matcher *M) const {
405 if (const CheckTypeMatcher *CT = dyn_cast<CheckTypeMatcher>(M))
406 return TypesAreContradictory(getType(), CT->getType());
407 return false;
408}
409
410bool CheckChildTypeMatcher::isContradictoryImpl(const Matcher *M) const {
411 if (const CheckChildTypeMatcher *CC = dyn_cast<CheckChildTypeMatcher>(M)) {
412 // If the two checks are about different nodes, we don't know if they
413 // conflict!
414 if (CC->getChildNo() != getChildNo())
415 return false;
Jim Grosbach65586fe2010-12-21 16:16:00 +0000416
Chris Lattnerc577b812010-02-27 07:49:13 +0000417 return TypesAreContradictory(getType(), CC->getType());
418 }
419 return false;
420}
Jim Grosbach65586fe2010-12-21 16:16:00 +0000421
Chris Lattner2586c862010-02-27 08:11:15 +0000422bool CheckIntegerMatcher::isContradictoryImpl(const Matcher *M) const {
423 if (const CheckIntegerMatcher *CIM = dyn_cast<CheckIntegerMatcher>(M))
424 return CIM->getValue() != getValue();
425 return false;
426}
Chris Lattner9c791d82010-03-07 06:29:26 +0000427
Craig Topper7ca1d182014-02-05 05:44:28 +0000428bool CheckChildIntegerMatcher::isContradictoryImpl(const Matcher *M) const {
429 if (const CheckChildIntegerMatcher *CCIM = dyn_cast<CheckChildIntegerMatcher>(M)) {
430 // If the two checks are about different nodes, we don't know if they
431 // conflict!
432 if (CCIM->getChildNo() != getChildNo())
433 return false;
434
435 return CCIM->getValue() != getValue();
436 }
437 return false;
438}
439
Chris Lattner9c791d82010-03-07 06:29:26 +0000440bool CheckValueTypeMatcher::isContradictoryImpl(const Matcher *M) const {
441 if (const CheckValueTypeMatcher *CVT = dyn_cast<CheckValueTypeMatcher>(M))
442 return CVT->getTypeName() != getTypeName();
443 return false;
444}
445