blob: b12e1015c33b629befa10776b681c622c5fa5d9f [file] [log] [blame]
Chris Lattnerda272d12010-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 Lattner845c0422010-02-18 22:03:03 +000013#include "Record.h"
Chris Lattnerda272d12010-02-15 08:04:42 +000014#include "llvm/Support/raw_ostream.h"
Chris Lattner58aa8342010-02-25 06:49:58 +000015#include "llvm/ADT/StringExtras.h"
Chris Lattnerda272d12010-02-15 08:04:42 +000016using namespace llvm;
17
Chris Lattnerb21ba712010-02-25 02:04:40 +000018void Matcher::dump() const {
Chris Lattnera5028a62010-02-25 06:53:39 +000019 print(errs(), 0);
Chris Lattnerda272d12010-02-15 08:04:42 +000020}
21
Chris Lattnera5028a62010-02-25 06:53:39 +000022void Matcher::print(raw_ostream &OS, unsigned indent) const {
23 printImpl(OS, indent);
Chris Lattnerbd8227f2010-02-18 02:53:41 +000024 if (Next)
25 return Next->print(OS, indent);
Chris Lattnerda272d12010-02-15 08:04:42 +000026}
27
Chris Lattner82781b92010-02-27 07:49:13 +000028void Matcher::printOne(raw_ostream &OS) const {
29 printImpl(OS, 0);
30}
31
Chris Lattner48aa5752010-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 Grosbachfbadcd02010-12-21 16:16:00 +000038
Chris Lattner48aa5752010-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 Grosbachfbadcd02010-12-21 16:16:00 +000070
Chris Lattner48aa5752010-03-07 06:29:26 +000071 // We can move record nodes across simple predicates.
72 if (isSimplePredicateOrRecordNode())
73 return isSimplePredicateNode();
Jim Grosbachfbadcd02010-12-21 16:16:00 +000074
Chris Lattner48aa5752010-03-07 06:29:26 +000075 // We can't move record nodes across each other etc.
76 return false;
77}
78
79
Chris Lattnerd6c84722010-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 Lattner54379062011-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 Lattnerd6c84722010-02-25 19:00:39 +000095// printImpl methods.
96
Chris Lattnera5028a62010-02-25 06:53:39 +000097void ScopeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner60df53e2010-02-25 01:56:48 +000098 OS.indent(indent) << "Scope\n";
Chris Lattnerc78f2a32010-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 Lattnerda272d12010-02-15 08:04:42 +0000105}
106
Chris Lattnera5028a62010-02-25 06:53:39 +0000107void RecordMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000108 OS.indent(indent) << "Record\n";
Chris Lattnerda272d12010-02-15 08:04:42 +0000109}
110
Chris Lattnera5028a62010-02-25 06:53:39 +0000111void RecordChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner19b5a752010-02-24 07:31:45 +0000112 OS.indent(indent) << "RecordChild: " << ChildNo << '\n';
Chris Lattner19b5a752010-02-24 07:31:45 +0000113}
114
Chris Lattnera5028a62010-02-25 06:53:39 +0000115void RecordMemRefMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000116 OS.indent(indent) << "RecordMemRef\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000117}
118
Chris Lattner8950bca2010-12-23 17:03:20 +0000119void CaptureGlueInputMatcher::printImpl(raw_ostream &OS, unsigned indent) const{
120 OS.indent(indent) << "CaptureGlueInput\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000121}
122
Chris Lattnera5028a62010-02-25 06:53:39 +0000123void MoveChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000124 OS.indent(indent) << "MoveChild " << ChildNo << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000125}
126
Chris Lattnera5028a62010-02-25 06:53:39 +0000127void MoveParentMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000128 OS.indent(indent) << "MoveParent\n";
Chris Lattnerda272d12010-02-15 08:04:42 +0000129}
130
Chris Lattnera5028a62010-02-25 06:53:39 +0000131void CheckSameMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000132 OS.indent(indent) << "CheckSame " << MatchNumber << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000133}
134
Chris Lattnerb21ba712010-02-25 02:04:40 +0000135void CheckPatternPredicateMatcher::
Chris Lattnera5028a62010-02-25 06:53:39 +0000136printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000137 OS.indent(indent) << "CheckPatternPredicate " << Predicate << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000138}
139
Chris Lattnera5028a62010-02-25 06:53:39 +0000140void CheckPredicateMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner54379062011-04-17 21:38:24 +0000141 OS.indent(indent) << "CheckPredicate " << getPredicate().getFnName() << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000142}
143
Chris Lattnera5028a62010-02-25 06:53:39 +0000144void CheckOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnera230f962010-02-27 21:48:43 +0000145 OS.indent(indent) << "CheckOpcode " << Opcode.getEnumName() << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000146}
147
Chris Lattnereb669212010-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 Lattnera5028a62010-02-25 06:53:39 +0000158void CheckTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner084df622010-03-24 00:41:19 +0000159 OS.indent(indent) << "CheckType " << getEnumName(Type) << ", ResNo="
160 << ResNo << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000161}
162
Chris Lattnercfe2eab2010-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 Lattnera5028a62010-02-25 06:53:39 +0000172void CheckChildTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner23cfda72010-02-24 20:15:25 +0000173 OS.indent(indent) << "CheckChildType " << ChildNo << " "
174 << getEnumName(Type) << '\n';
Chris Lattner23cfda72010-02-24 20:15:25 +0000175}
176
177
Chris Lattnera5028a62010-02-25 06:53:39 +0000178void CheckIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000179 OS.indent(indent) << "CheckInteger " << Value << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000180}
181
Chris Lattnera5028a62010-02-25 06:53:39 +0000182void CheckCondCodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000183 OS.indent(indent) << "CheckCondCode ISD::" << CondCodeName << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000184}
185
Chris Lattnera5028a62010-02-25 06:53:39 +0000186void CheckValueTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000187 OS.indent(indent) << "CheckValueType MVT::" << TypeName << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000188}
189
Chris Lattnera5028a62010-02-25 06:53:39 +0000190void CheckComplexPatMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000191 OS.indent(indent) << "CheckComplexPat " << Pattern.getSelectFunc() << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000192}
193
Chris Lattnera5028a62010-02-25 06:53:39 +0000194void CheckAndImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000195 OS.indent(indent) << "CheckAndImm " << Value << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000196}
197
Chris Lattnera5028a62010-02-25 06:53:39 +0000198void CheckOrImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000199 OS.indent(indent) << "CheckOrImm " << Value << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000200}
201
Chris Lattnera5028a62010-02-25 06:53:39 +0000202void CheckFoldableChainNodeMatcher::printImpl(raw_ostream &OS,
Chris Lattner21390d72010-02-16 19:15:55 +0000203 unsigned indent) const {
204 OS.indent(indent) << "CheckFoldableChainNode\n";
Chris Lattnere39650a2010-02-16 06:10:58 +0000205}
Chris Lattner9a747f12010-02-17 06:23:39 +0000206
Chris Lattnera5028a62010-02-25 06:53:39 +0000207void EmitIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000208 OS.indent(indent) << "EmitInteger " << Val << " VT=" << VT << '\n';
Chris Lattner8e946be2010-02-21 03:22:59 +0000209}
210
Chris Lattnerb21ba712010-02-25 02:04:40 +0000211void EmitStringIntegerMatcher::
Chris Lattnera5028a62010-02-25 06:53:39 +0000212printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000213 OS.indent(indent) << "EmitStringInteger " << Val << " VT=" << VT << '\n';
Chris Lattner845c0422010-02-18 22:03:03 +0000214}
215
Chris Lattnera5028a62010-02-25 06:53:39 +0000216void EmitRegisterMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000217 OS.indent(indent) << "EmitRegister ";
Chris Lattner845c0422010-02-18 22:03:03 +0000218 if (Reg)
219 OS << Reg->getName();
220 else
221 OS << "zero_reg";
222 OS << " VT=" << VT << '\n';
Chris Lattner845c0422010-02-18 22:03:03 +0000223}
224
Chris Lattnerb21ba712010-02-25 02:04:40 +0000225void EmitConvertToTargetMatcher::
Chris Lattnera5028a62010-02-25 06:53:39 +0000226printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000227 OS.indent(indent) << "EmitConvertToTarget " << Slot << '\n';
Chris Lattner8e946be2010-02-21 03:22:59 +0000228}
229
Chris Lattnerb21ba712010-02-25 02:04:40 +0000230void EmitMergeInputChainsMatcher::
Chris Lattnera5028a62010-02-25 06:53:39 +0000231printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000232 OS.indent(indent) << "EmitMergeInputChains <todo: args>\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000233}
234
Chris Lattnera5028a62010-02-25 06:53:39 +0000235void EmitCopyToRegMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000236 OS.indent(indent) << "EmitCopyToReg <todo: args>\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000237}
238
Chris Lattnera5028a62010-02-25 06:53:39 +0000239void EmitNodeXFormMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000240 OS.indent(indent) << "EmitNodeXForm " << NodeXForm->getName()
241 << " Slot=" << Slot << '\n';
Chris Lattner8e946be2010-02-21 03:22:59 +0000242}
243
244
Chris Lattnere86097a2010-02-28 02:31:26 +0000245void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, unsigned indent) const {
246 OS.indent(indent);
Chris Lattner9a215002010-02-28 20:55:18 +0000247 OS << (isa<MorphNodeToMatcher>(this) ? "MorphNodeTo: " : "EmitNode: ")
Chris Lattnere86097a2010-02-28 02:31:26 +0000248 << OpcodeName << ": <todo flags> ";
Chris Lattner8e946be2010-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 Lattner8e946be2010-02-21 03:22:59 +0000256}
257
Chris Lattner8950bca2010-12-23 17:03:20 +0000258void MarkGlueResultsMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
259 OS.indent(indent) << "MarkGlueResults <todo: args>\n";
Chris Lattner02f73582010-02-24 05:33:42 +0000260}
261
Chris Lattnera5028a62010-02-25 06:53:39 +0000262void CompleteMatchMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner77f2e272010-02-21 06:03:07 +0000263 OS.indent(indent) << "CompleteMatch <todo args>\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000264 OS.indent(indent) << "Src = " << *Pattern.getSrcPattern() << "\n";
265 OS.indent(indent) << "Dst = " << *Pattern.getDstPattern() << "\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000266}
267
Chris Lattner58aa8342010-02-25 06:49:58 +0000268// getHashImpl Implementation.
269
270unsigned CheckPatternPredicateMatcher::getHashImpl() const {
271 return HashString(Predicate);
272}
273
274unsigned CheckPredicateMatcher::getHashImpl() const {
Chris Lattner54379062011-04-17 21:38:24 +0000275 return HashString(getPredicate().getFnName());
Chris Lattner58aa8342010-02-25 06:49:58 +0000276}
277
278unsigned CheckOpcodeMatcher::getHashImpl() const {
Chris Lattnera230f962010-02-27 21:48:43 +0000279 return HashString(Opcode.getEnumName());
Chris Lattner58aa8342010-02-25 06:49:58 +0000280}
281
Chris Lattner58aa8342010-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 Lattnereb669212010-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 Grosbachfbadcd02010-12-21 16:16:00 +0000308 // to ensure that the nodes are for the same opcode.
Chris Lattnereb669212010-03-01 06:59:22 +0000309 return cast<CheckOpcodeMatcher>(M)->Opcode.getEnumName() ==
310 Opcode.getEnumName();
311}
312
Chris Lattnere86097a2010-02-28 02:31:26 +0000313bool EmitNodeMatcherCommon::isEqualImpl(const Matcher *m) const {
314 const EmitNodeMatcherCommon *M = cast<EmitNodeMatcherCommon>(m);
Chris Lattner58aa8342010-02-25 06:49:58 +0000315 return M->OpcodeName == OpcodeName && M->VTs == VTs &&
316 M->Operands == Operands && M->HasChain == HasChain &&
Chris Lattner036609b2010-12-23 18:28:41 +0000317 M->HasInGlue == HasInGlue && M->HasOutGlue == HasOutGlue &&
Chris Lattnerff7fb602010-02-28 21:53:42 +0000318 M->HasMemRefs == HasMemRefs &&
Chris Lattner58aa8342010-02-25 06:49:58 +0000319 M->NumFixedArityOperands == NumFixedArityOperands;
320}
321
Chris Lattnere86097a2010-02-28 02:31:26 +0000322unsigned EmitNodeMatcherCommon::getHashImpl() const {
Chris Lattner58aa8342010-02-25 06:49:58 +0000323 return (HashString(OpcodeName) << 4) | Operands.size();
324}
325
326
Chris Lattner8950bca2010-12-23 17:03:20 +0000327unsigned MarkGlueResultsMatcher::getHashImpl() const {
328 return HashUnsigneds(GlueResultNodes.begin(), GlueResultNodes.end());
Chris Lattner58aa8342010-02-25 06:49:58 +0000329}
330
331unsigned CompleteMatchMatcher::getHashImpl() const {
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000332 return HashUnsigneds(Results.begin(), Results.end()) ^
Chris Lattner58aa8342010-02-25 06:49:58 +0000333 ((unsigned)(intptr_t)&Pattern << 8);
334}
Chris Lattner82781b92010-02-27 07:49:13 +0000335
336// isContradictoryImpl Implementations.
337
Chris Lattner82781b92010-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 Grosbachfbadcd02010-12-21 16:16:00 +0000343
Chris Lattner82781b92010-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 Grosbachfbadcd02010-12-21 16:16:00 +0000348
Chris Lattner82781b92010-02-27 07:49:13 +0000349 if (T2 == MVT::iPTR)
350 return !MVT(T1).isInteger() || MVT(T1).isVector();
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000351
Chris Lattner82781b92010-02-27 07:49:13 +0000352 // Otherwise, they are two different non-iPTR types, they conflict.
353 return true;
354}
355
Chris Lattner22579812010-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 Lattnereb669212010-03-01 06:59:22 +0000359 // Note: pointer equality isn't enough here, we have to check the enum names
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000360 // to ensure that the nodes are for the same opcode.
Chris Lattnereb669212010-03-01 06:59:22 +0000361 return COM->getOpcode().getEnumName() != getOpcode().getEnumName();
Chris Lattner22579812010-02-28 00:22:30 +0000362 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000363
Chris Lattner22579812010-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 Lattner084df622010-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 Grosbachfbadcd02010-12-21 16:16:00 +0000371
Chris Lattner084df622010-03-24 00:41:19 +0000372 MVT::SimpleValueType NodeType = getOpcode().getKnownType(CT->getResNo());
Chris Lattneraac5b5b2010-03-19 01:14:27 +0000373 if (NodeType != MVT::Other)
374 return TypesAreContradictory(NodeType, CT->getType());
Chris Lattner22579812010-02-28 00:22:30 +0000375 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000376
Chris Lattner22579812010-02-28 00:22:30 +0000377 return false;
378}
379
Chris Lattner82781b92010-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 Grosbachfbadcd02010-12-21 16:16:00 +0000392
Chris Lattner82781b92010-02-27 07:49:13 +0000393 return TypesAreContradictory(getType(), CC->getType());
394 }
395 return false;
396}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000397
Chris Lattner24789622010-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 Lattner48aa5752010-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