blob: b12e1015c33b629befa10776b681c622c5fa5d9f [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 Lattner42a7ba72010-02-18 22:03:03 +000013#include "Record.h"
Chris Lattnerb02cdaa2010-02-15 08:04:42 +000014#include "llvm/Support/raw_ostream.h"
Chris Lattner212e8c82010-02-25 06:49:58 +000015#include "llvm/ADT/StringExtras.h"
Chris Lattnerb02cdaa2010-02-15 08:04:42 +000016using namespace llvm;
17
Chris Lattner2c3f6492010-02-25 02:04:40 +000018void Matcher::dump() const {
Chris Lattner1f2adb62010-02-25 06:53:39 +000019 print(errs(), 0);
Chris Lattnerb02cdaa2010-02-15 08:04:42 +000020}
21
Chris Lattner1f2adb62010-02-25 06:53:39 +000022void Matcher::print(raw_ostream &OS, unsigned indent) const {
23 printImpl(OS, indent);
Chris Lattner186ad802010-02-18 02:53:41 +000024 if (Next)
25 return Next->print(OS, indent);
Chris Lattnerb02cdaa2010-02-15 08:04:42 +000026}
27
Chris Lattnerc577b812010-02-27 07:49:13 +000028void Matcher::printOne(raw_ostream &OS) const {
29 printImpl(OS, 0);
30}
31
Chris Lattner9c791d82010-03-07 06:29:26 +000032/// unlinkNode - Unlink the specified node from this chain. If Other == this,
33/// we unlink the next pointer and return it. Otherwise we unlink Other from
34/// the list and return this.
35Matcher *Matcher::unlinkNode(Matcher *Other) {
36 if (this == Other)
37 return takeNext();
Jim Grosbach65586fe2010-12-21 16:16:00 +000038
Chris Lattner9c791d82010-03-07 06:29:26 +000039 // Scan until we find the predecessor of Other.
40 Matcher *Cur = this;
41 for (; Cur && Cur->getNext() != Other; Cur = Cur->getNext())
42 /*empty*/;
43
44 if (Cur == 0) return 0;
45 Cur->takeNext();
46 Cur->setNext(Other->takeNext());
47 return this;
48}
49
50/// canMoveBefore - Return true if this matcher is the same as Other, or if
51/// we can move this matcher past all of the nodes in-between Other and this
52/// node. Other must be equal to or before this.
53bool Matcher::canMoveBefore(const Matcher *Other) const {
54 for (;; Other = Other->getNext()) {
55 assert(Other && "Other didn't come before 'this'?");
56 if (this == Other) return true;
57
58 // We have to be able to move this node across the Other node.
59 if (!canMoveBeforeNode(Other))
60 return false;
61 }
62}
63
64/// canMoveBefore - Return true if it is safe to move the current matcher
65/// across the specified one.
66bool Matcher::canMoveBeforeNode(const Matcher *Other) const {
67 // We can move simple predicates before record nodes.
68 if (isSimplePredicateNode())
69 return Other->isSimplePredicateOrRecordNode();
Jim Grosbach65586fe2010-12-21 16:16:00 +000070
Chris Lattner9c791d82010-03-07 06:29:26 +000071 // We can move record nodes across simple predicates.
72 if (isSimplePredicateOrRecordNode())
73 return isSimplePredicateNode();
Jim Grosbach65586fe2010-12-21 16:16:00 +000074
Chris Lattner9c791d82010-03-07 06:29:26 +000075 // We can't move record nodes across each other etc.
76 return false;
77}
78
79
Chris Lattnerf7fc2d82010-02-25 19:00:39 +000080ScopeMatcher::~ScopeMatcher() {
81 for (unsigned i = 0, e = Children.size(); i != e; ++i)
82 delete Children[i];
83}
84
85
Chris Lattner514e2922011-04-17 21:38:24 +000086CheckPredicateMatcher::CheckPredicateMatcher(const TreePredicateFn &pred)
87 : Matcher(CheckPredicate), Pred(pred.getOrigPatFragRecord()) {}
88
89TreePredicateFn CheckPredicateMatcher::getPredicate() const {
90 return TreePredicateFn(Pred);
91}
92
93
94
Chris Lattnerf7fc2d82010-02-25 19:00:39 +000095// printImpl methods.
96
Chris Lattner1f2adb62010-02-25 06:53:39 +000097void ScopeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerac55f9d2010-02-25 01:56:48 +000098 OS.indent(indent) << "Scope\n";
Chris Lattner102a8a02010-02-28 20:49:53 +000099 for (unsigned i = 0, e = getNumChildren(); i != e; ++i) {
100 if (getChild(i) == 0)
101 OS.indent(indent+1) << "NULL POINTER\n";
102 else
103 getChild(i)->print(OS, indent+2);
104 }
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000105}
106
Chris Lattner1f2adb62010-02-25 06:53:39 +0000107void RecordMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000108 OS.indent(indent) << "Record\n";
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000109}
110
Chris Lattner1f2adb62010-02-25 06:53:39 +0000111void RecordChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerab417562010-02-24 07:31:45 +0000112 OS.indent(indent) << "RecordChild: " << ChildNo << '\n';
Chris Lattnerab417562010-02-24 07:31:45 +0000113}
114
Chris Lattner1f2adb62010-02-25 06:53:39 +0000115void RecordMemRefMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000116 OS.indent(indent) << "RecordMemRef\n";
Chris Lattner132df652010-02-21 03:22:59 +0000117}
118
Chris Lattnerf7f9e8c2010-12-23 17:03:20 +0000119void CaptureGlueInputMatcher::printImpl(raw_ostream &OS, unsigned indent) const{
120 OS.indent(indent) << "CaptureGlueInput\n";
Chris Lattner132df652010-02-21 03:22:59 +0000121}
122
Chris Lattner1f2adb62010-02-25 06:53:39 +0000123void MoveChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000124 OS.indent(indent) << "MoveChild " << ChildNo << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000125}
126
Chris Lattner1f2adb62010-02-25 06:53:39 +0000127void MoveParentMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000128 OS.indent(indent) << "MoveParent\n";
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000129}
130
Chris Lattner1f2adb62010-02-25 06:53:39 +0000131void CheckSameMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000132 OS.indent(indent) << "CheckSame " << MatchNumber << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000133}
134
Chris Lattner2c3f6492010-02-25 02:04:40 +0000135void CheckPatternPredicateMatcher::
Chris Lattner1f2adb62010-02-25 06:53:39 +0000136printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000137 OS.indent(indent) << "CheckPatternPredicate " << Predicate << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000138}
139
Chris Lattner1f2adb62010-02-25 06:53:39 +0000140void CheckPredicateMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner514e2922011-04-17 21:38:24 +0000141 OS.indent(indent) << "CheckPredicate " << getPredicate().getFnName() << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000142}
143
Chris Lattner1f2adb62010-02-25 06:53:39 +0000144void CheckOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner278606b2010-02-27 21:48:43 +0000145 OS.indent(indent) << "CheckOpcode " << Opcode.getEnumName() << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000146}
147
Chris Lattnerf4d17752010-03-01 06:59:22 +0000148void SwitchOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
149 OS.indent(indent) << "SwitchOpcode: {\n";
150 for (unsigned i = 0, e = Cases.size(); i != e; ++i) {
151 OS.indent(indent) << "case " << Cases[i].first->getEnumName() << ":\n";
152 Cases[i].second->print(OS, indent+2);
153 }
154 OS.indent(indent) << "}\n";
155}
156
157
Chris Lattner1f2adb62010-02-25 06:53:39 +0000158void CheckTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner6c2d1782010-03-24 00:41:19 +0000159 OS.indent(indent) << "CheckType " << getEnumName(Type) << ", ResNo="
160 << ResNo << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000161}
162
Chris Lattner3e1ffd02010-03-03 06:28:15 +0000163void SwitchTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
164 OS.indent(indent) << "SwitchType: {\n";
165 for (unsigned i = 0, e = Cases.size(); i != e; ++i) {
166 OS.indent(indent) << "case " << getEnumName(Cases[i].first) << ":\n";
167 Cases[i].second->print(OS, indent+2);
168 }
169 OS.indent(indent) << "}\n";
170}
171
Chris Lattner1f2adb62010-02-25 06:53:39 +0000172void CheckChildTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner0c95baa2010-02-24 20:15:25 +0000173 OS.indent(indent) << "CheckChildType " << ChildNo << " "
174 << getEnumName(Type) << '\n';
Chris Lattner0c95baa2010-02-24 20:15:25 +0000175}
176
177
Chris Lattner1f2adb62010-02-25 06:53:39 +0000178void CheckIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000179 OS.indent(indent) << "CheckInteger " << Value << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000180}
181
Chris Lattner1f2adb62010-02-25 06:53:39 +0000182void CheckCondCodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000183 OS.indent(indent) << "CheckCondCode ISD::" << CondCodeName << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000184}
185
Chris Lattner1f2adb62010-02-25 06:53:39 +0000186void CheckValueTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000187 OS.indent(indent) << "CheckValueType MVT::" << TypeName << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000188}
189
Chris Lattner1f2adb62010-02-25 06:53:39 +0000190void CheckComplexPatMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000191 OS.indent(indent) << "CheckComplexPat " << Pattern.getSelectFunc() << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000192}
193
Chris Lattner1f2adb62010-02-25 06:53:39 +0000194void CheckAndImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000195 OS.indent(indent) << "CheckAndImm " << Value << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000196}
197
Chris Lattner1f2adb62010-02-25 06:53:39 +0000198void CheckOrImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000199 OS.indent(indent) << "CheckOrImm " << Value << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000200}
201
Chris Lattner1f2adb62010-02-25 06:53:39 +0000202void CheckFoldableChainNodeMatcher::printImpl(raw_ostream &OS,
Chris Lattnerf8695c12010-02-16 19:15:55 +0000203 unsigned indent) const {
204 OS.indent(indent) << "CheckFoldableChainNode\n";
Chris Lattneraa7d3e02010-02-16 06:10:58 +0000205}
Chris Lattnerf8a5bb02010-02-17 06:23:39 +0000206
Chris Lattner1f2adb62010-02-25 06:53:39 +0000207void EmitIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000208 OS.indent(indent) << "EmitInteger " << Val << " VT=" << VT << '\n';
Chris Lattner132df652010-02-21 03:22:59 +0000209}
210
Chris Lattner2c3f6492010-02-25 02:04:40 +0000211void EmitStringIntegerMatcher::
Chris Lattner1f2adb62010-02-25 06:53:39 +0000212printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000213 OS.indent(indent) << "EmitStringInteger " << Val << " VT=" << VT << '\n';
Chris Lattner42a7ba72010-02-18 22:03:03 +0000214}
215
Chris Lattner1f2adb62010-02-25 06:53:39 +0000216void EmitRegisterMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000217 OS.indent(indent) << "EmitRegister ";
Chris Lattner42a7ba72010-02-18 22:03:03 +0000218 if (Reg)
219 OS << Reg->getName();
220 else
221 OS << "zero_reg";
222 OS << " VT=" << VT << '\n';
Chris Lattner42a7ba72010-02-18 22:03:03 +0000223}
224
Chris Lattner2c3f6492010-02-25 02:04:40 +0000225void EmitConvertToTargetMatcher::
Chris Lattner1f2adb62010-02-25 06:53:39 +0000226printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000227 OS.indent(indent) << "EmitConvertToTarget " << Slot << '\n';
Chris Lattner132df652010-02-21 03:22:59 +0000228}
229
Chris Lattner2c3f6492010-02-25 02:04:40 +0000230void EmitMergeInputChainsMatcher::
Chris Lattner1f2adb62010-02-25 06:53:39 +0000231printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000232 OS.indent(indent) << "EmitMergeInputChains <todo: args>\n";
Chris Lattner132df652010-02-21 03:22:59 +0000233}
234
Chris Lattner1f2adb62010-02-25 06:53:39 +0000235void EmitCopyToRegMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000236 OS.indent(indent) << "EmitCopyToReg <todo: args>\n";
Chris Lattner132df652010-02-21 03:22:59 +0000237}
238
Chris Lattner1f2adb62010-02-25 06:53:39 +0000239void EmitNodeXFormMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000240 OS.indent(indent) << "EmitNodeXForm " << NodeXForm->getName()
241 << " Slot=" << Slot << '\n';
Chris Lattner132df652010-02-21 03:22:59 +0000242}
243
244
Chris Lattnerc3f80e02010-02-28 02:31:26 +0000245void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, unsigned indent) const {
246 OS.indent(indent);
Chris Lattner9d67dca2010-02-28 20:55:18 +0000247 OS << (isa<MorphNodeToMatcher>(this) ? "MorphNodeTo: " : "EmitNode: ")
Chris Lattnerc3f80e02010-02-28 02:31:26 +0000248 << OpcodeName << ": <todo flags> ";
Chris Lattner132df652010-02-21 03:22:59 +0000249
250 for (unsigned i = 0, e = VTs.size(); i != e; ++i)
251 OS << ' ' << getEnumName(VTs[i]);
252 OS << '(';
253 for (unsigned i = 0, e = Operands.size(); i != e; ++i)
254 OS << Operands[i] << ' ';
255 OS << ")\n";
Chris Lattner132df652010-02-21 03:22:59 +0000256}
257
Chris Lattnerf7f9e8c2010-12-23 17:03:20 +0000258void MarkGlueResultsMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
259 OS.indent(indent) << "MarkGlueResults <todo: args>\n";
Chris Lattner29364372010-02-24 05:33:42 +0000260}
261
Chris Lattner1f2adb62010-02-25 06:53:39 +0000262void CompleteMatchMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner79eaeb42010-02-21 06:03:07 +0000263 OS.indent(indent) << "CompleteMatch <todo args>\n";
Chris Lattner132df652010-02-21 03:22:59 +0000264 OS.indent(indent) << "Src = " << *Pattern.getSrcPattern() << "\n";
265 OS.indent(indent) << "Dst = " << *Pattern.getDstPattern() << "\n";
Chris Lattner132df652010-02-21 03:22:59 +0000266}
267
Chris Lattner212e8c82010-02-25 06:49:58 +0000268// getHashImpl Implementation.
269
270unsigned CheckPatternPredicateMatcher::getHashImpl() const {
271 return HashString(Predicate);
272}
273
274unsigned CheckPredicateMatcher::getHashImpl() const {
Chris Lattner514e2922011-04-17 21:38:24 +0000275 return HashString(getPredicate().getFnName());
Chris Lattner212e8c82010-02-25 06:49:58 +0000276}
277
278unsigned CheckOpcodeMatcher::getHashImpl() const {
Chris Lattner278606b2010-02-27 21:48:43 +0000279 return HashString(Opcode.getEnumName());
Chris Lattner212e8c82010-02-25 06:49:58 +0000280}
281
Chris Lattner212e8c82010-02-25 06:49:58 +0000282unsigned CheckCondCodeMatcher::getHashImpl() const {
283 return HashString(CondCodeName);
284}
285
286unsigned CheckValueTypeMatcher::getHashImpl() const {
287 return HashString(TypeName);
288}
289
290unsigned EmitStringIntegerMatcher::getHashImpl() const {
291 return HashString(Val) ^ VT;
292}
293
294template<typename It>
295static unsigned HashUnsigneds(It I, It E) {
296 unsigned Result = 0;
297 for (; I != E; ++I)
298 Result = (Result<<3) ^ *I;
299 return Result;
300}
301
302unsigned EmitMergeInputChainsMatcher::getHashImpl() const {
303 return HashUnsigneds(ChainNodes.begin(), ChainNodes.end());
304}
305
Chris Lattnerf4d17752010-03-01 06:59:22 +0000306bool CheckOpcodeMatcher::isEqualImpl(const Matcher *M) const {
307 // Note: pointer equality isn't enough here, we have to check the enum names
Jim Grosbach65586fe2010-12-21 16:16:00 +0000308 // to ensure that the nodes are for the same opcode.
Chris Lattnerf4d17752010-03-01 06:59:22 +0000309 return cast<CheckOpcodeMatcher>(M)->Opcode.getEnumName() ==
310 Opcode.getEnumName();
311}
312
Chris Lattnerc3f80e02010-02-28 02:31:26 +0000313bool EmitNodeMatcherCommon::isEqualImpl(const Matcher *m) const {
314 const EmitNodeMatcherCommon *M = cast<EmitNodeMatcherCommon>(m);
Chris Lattner212e8c82010-02-25 06:49:58 +0000315 return M->OpcodeName == OpcodeName && M->VTs == VTs &&
316 M->Operands == Operands && M->HasChain == HasChain &&
Chris Lattner2a0a3b42010-12-23 18:28:41 +0000317 M->HasInGlue == HasInGlue && M->HasOutGlue == HasOutGlue &&
Chris Lattnera8382642010-02-28 21:53:42 +0000318 M->HasMemRefs == HasMemRefs &&
Chris Lattner212e8c82010-02-25 06:49:58 +0000319 M->NumFixedArityOperands == NumFixedArityOperands;
320}
321
Chris Lattnerc3f80e02010-02-28 02:31:26 +0000322unsigned EmitNodeMatcherCommon::getHashImpl() const {
Chris Lattner212e8c82010-02-25 06:49:58 +0000323 return (HashString(OpcodeName) << 4) | Operands.size();
324}
325
326
Chris Lattnerf7f9e8c2010-12-23 17:03:20 +0000327unsigned MarkGlueResultsMatcher::getHashImpl() const {
328 return HashUnsigneds(GlueResultNodes.begin(), GlueResultNodes.end());
Chris Lattner212e8c82010-02-25 06:49:58 +0000329}
330
331unsigned CompleteMatchMatcher::getHashImpl() const {
Jim Grosbach65586fe2010-12-21 16:16:00 +0000332 return HashUnsigneds(Results.begin(), Results.end()) ^
Chris Lattner212e8c82010-02-25 06:49:58 +0000333 ((unsigned)(intptr_t)&Pattern << 8);
334}
Chris Lattnerc577b812010-02-27 07:49:13 +0000335
336// isContradictoryImpl Implementations.
337
Chris Lattnerc577b812010-02-27 07:49:13 +0000338static bool TypesAreContradictory(MVT::SimpleValueType T1,
339 MVT::SimpleValueType T2) {
340 // If the two types are the same, then they are the same, so they don't
341 // contradict.
342 if (T1 == T2) return false;
Jim Grosbach65586fe2010-12-21 16:16:00 +0000343
Chris Lattnerc577b812010-02-27 07:49:13 +0000344 // If either type is about iPtr, then they don't conflict unless the other
345 // one is not a scalar integer type.
346 if (T1 == MVT::iPTR)
347 return !MVT(T2).isInteger() || MVT(T2).isVector();
Jim Grosbach65586fe2010-12-21 16:16:00 +0000348
Chris Lattnerc577b812010-02-27 07:49:13 +0000349 if (T2 == MVT::iPTR)
350 return !MVT(T1).isInteger() || MVT(T1).isVector();
Jim Grosbach65586fe2010-12-21 16:16:00 +0000351
Chris Lattnerc577b812010-02-27 07:49:13 +0000352 // Otherwise, they are two different non-iPTR types, they conflict.
353 return true;
354}
355
Chris Lattner99e53b32010-02-28 00:22:30 +0000356bool CheckOpcodeMatcher::isContradictoryImpl(const Matcher *M) const {
357 if (const CheckOpcodeMatcher *COM = dyn_cast<CheckOpcodeMatcher>(M)) {
358 // One node can't have two different opcodes!
Chris Lattnerf4d17752010-03-01 06:59:22 +0000359 // Note: pointer equality isn't enough here, we have to check the enum names
Jim Grosbach65586fe2010-12-21 16:16:00 +0000360 // to ensure that the nodes are for the same opcode.
Chris Lattnerf4d17752010-03-01 06:59:22 +0000361 return COM->getOpcode().getEnumName() != getOpcode().getEnumName();
Chris Lattner99e53b32010-02-28 00:22:30 +0000362 }
Jim Grosbach65586fe2010-12-21 16:16:00 +0000363
Chris Lattner99e53b32010-02-28 00:22:30 +0000364 // If the node has a known type, and if the type we're checking for is
365 // different, then we know they contradict. For example, a check for
366 // ISD::STORE will never be true at the same time a check for Type i32 is.
367 if (const CheckTypeMatcher *CT = dyn_cast<CheckTypeMatcher>(M)) {
Chris Lattner6c2d1782010-03-24 00:41:19 +0000368 // If checking for a result the opcode doesn't have, it can't match.
369 if (CT->getResNo() >= getOpcode().getNumResults())
370 return true;
Jim Grosbach65586fe2010-12-21 16:16:00 +0000371
Chris Lattner6c2d1782010-03-24 00:41:19 +0000372 MVT::SimpleValueType NodeType = getOpcode().getKnownType(CT->getResNo());
Chris Lattnerda5b4ad2010-03-19 01:14:27 +0000373 if (NodeType != MVT::Other)
374 return TypesAreContradictory(NodeType, CT->getType());
Chris Lattner99e53b32010-02-28 00:22:30 +0000375 }
Jim Grosbach65586fe2010-12-21 16:16:00 +0000376
Chris Lattner99e53b32010-02-28 00:22:30 +0000377 return false;
378}
379
Chris Lattnerc577b812010-02-27 07:49:13 +0000380bool CheckTypeMatcher::isContradictoryImpl(const Matcher *M) const {
381 if (const CheckTypeMatcher *CT = dyn_cast<CheckTypeMatcher>(M))
382 return TypesAreContradictory(getType(), CT->getType());
383 return false;
384}
385
386bool CheckChildTypeMatcher::isContradictoryImpl(const Matcher *M) const {
387 if (const CheckChildTypeMatcher *CC = dyn_cast<CheckChildTypeMatcher>(M)) {
388 // If the two checks are about different nodes, we don't know if they
389 // conflict!
390 if (CC->getChildNo() != getChildNo())
391 return false;
Jim Grosbach65586fe2010-12-21 16:16:00 +0000392
Chris Lattnerc577b812010-02-27 07:49:13 +0000393 return TypesAreContradictory(getType(), CC->getType());
394 }
395 return false;
396}
Jim Grosbach65586fe2010-12-21 16:16:00 +0000397
Chris Lattner2586c862010-02-27 08:11:15 +0000398bool CheckIntegerMatcher::isContradictoryImpl(const Matcher *M) const {
399 if (const CheckIntegerMatcher *CIM = dyn_cast<CheckIntegerMatcher>(M))
400 return CIM->getValue() != getValue();
401 return false;
402}
Chris Lattner9c791d82010-03-07 06:29:26 +0000403
404bool CheckValueTypeMatcher::isContradictoryImpl(const Matcher *M) const {
405 if (const CheckValueTypeMatcher *CVT = dyn_cast<CheckValueTypeMatcher>(M))
406 return CVT->getTypeName() != getTypeName();
407 return false;
408}
409