blob: bd77907a9bd907c3319dcc7c8f37ac83e7178e88 [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"
Peter Collingbourne7c788882011-10-01 16:41:13 +000013#include "llvm/TableGen/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
David Blaikie2d24e2a2011-12-20 02:50:00 +000018void Matcher::anchor() { }
19
Chris Lattnerb21ba712010-02-25 02:04:40 +000020void Matcher::dump() const {
Chris Lattnera5028a62010-02-25 06:53:39 +000021 print(errs(), 0);
Chris Lattnerda272d12010-02-15 08:04:42 +000022}
23
Chris Lattnera5028a62010-02-25 06:53:39 +000024void Matcher::print(raw_ostream &OS, unsigned indent) const {
25 printImpl(OS, indent);
Chris Lattnerbd8227f2010-02-18 02:53:41 +000026 if (Next)
27 return Next->print(OS, indent);
Chris Lattnerda272d12010-02-15 08:04:42 +000028}
29
Chris Lattner82781b92010-02-27 07:49:13 +000030void Matcher::printOne(raw_ostream &OS) const {
31 printImpl(OS, 0);
32}
33
Chris Lattner48aa5752010-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 Grosbachfbadcd02010-12-21 16:16:00 +000040
Chris Lattner48aa5752010-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
46 if (Cur == 0) return 0;
47 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
66/// canMoveBefore - Return true if it is safe to move the current matcher
67/// 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 Grosbachfbadcd02010-12-21 16:16:00 +000072
Chris Lattner48aa5752010-03-07 06:29:26 +000073 // We can move record nodes across simple predicates.
74 if (isSimplePredicateOrRecordNode())
75 return isSimplePredicateNode();
Jim Grosbachfbadcd02010-12-21 16:16:00 +000076
Chris Lattner48aa5752010-03-07 06:29:26 +000077 // We can't move record nodes across each other etc.
78 return false;
79}
80
81
Chris Lattnerd6c84722010-02-25 19:00:39 +000082ScopeMatcher::~ScopeMatcher() {
83 for (unsigned i = 0, e = Children.size(); i != e; ++i)
84 delete Children[i];
85}
86
87
Chris Lattner54379062011-04-17 21:38:24 +000088CheckPredicateMatcher::CheckPredicateMatcher(const TreePredicateFn &pred)
89 : Matcher(CheckPredicate), Pred(pred.getOrigPatFragRecord()) {}
90
91TreePredicateFn CheckPredicateMatcher::getPredicate() const {
92 return TreePredicateFn(Pred);
93}
94
95
96
Chris Lattnerd6c84722010-02-25 19:00:39 +000097// printImpl methods.
98
Chris Lattnera5028a62010-02-25 06:53:39 +000099void ScopeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner60df53e2010-02-25 01:56:48 +0000100 OS.indent(indent) << "Scope\n";
Chris Lattnerc78f2a32010-02-28 20:49:53 +0000101 for (unsigned i = 0, e = getNumChildren(); i != e; ++i) {
102 if (getChild(i) == 0)
103 OS.indent(indent+1) << "NULL POINTER\n";
104 else
105 getChild(i)->print(OS, indent+2);
106 }
Chris Lattnerda272d12010-02-15 08:04:42 +0000107}
108
Chris Lattnera5028a62010-02-25 06:53:39 +0000109void RecordMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000110 OS.indent(indent) << "Record\n";
Chris Lattnerda272d12010-02-15 08:04:42 +0000111}
112
Chris Lattnera5028a62010-02-25 06:53:39 +0000113void RecordChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner19b5a752010-02-24 07:31:45 +0000114 OS.indent(indent) << "RecordChild: " << ChildNo << '\n';
Chris Lattner19b5a752010-02-24 07:31:45 +0000115}
116
Chris Lattnera5028a62010-02-25 06:53:39 +0000117void RecordMemRefMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000118 OS.indent(indent) << "RecordMemRef\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000119}
120
Chris Lattner8950bca2010-12-23 17:03:20 +0000121void CaptureGlueInputMatcher::printImpl(raw_ostream &OS, unsigned indent) const{
122 OS.indent(indent) << "CaptureGlueInput\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000123}
124
Chris Lattnera5028a62010-02-25 06:53:39 +0000125void MoveChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000126 OS.indent(indent) << "MoveChild " << ChildNo << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000127}
128
Chris Lattnera5028a62010-02-25 06:53:39 +0000129void MoveParentMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000130 OS.indent(indent) << "MoveParent\n";
Chris Lattnerda272d12010-02-15 08:04:42 +0000131}
132
Chris Lattnera5028a62010-02-25 06:53:39 +0000133void CheckSameMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000134 OS.indent(indent) << "CheckSame " << MatchNumber << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000135}
136
Chris Lattnerb21ba712010-02-25 02:04:40 +0000137void CheckPatternPredicateMatcher::
Chris Lattnera5028a62010-02-25 06:53:39 +0000138printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000139 OS.indent(indent) << "CheckPatternPredicate " << Predicate << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000140}
141
Chris Lattnera5028a62010-02-25 06:53:39 +0000142void CheckPredicateMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner54379062011-04-17 21:38:24 +0000143 OS.indent(indent) << "CheckPredicate " << getPredicate().getFnName() << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000144}
145
Chris Lattnera5028a62010-02-25 06:53:39 +0000146void CheckOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnera230f962010-02-27 21:48:43 +0000147 OS.indent(indent) << "CheckOpcode " << Opcode.getEnumName() << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000148}
149
Chris Lattnereb669212010-03-01 06:59:22 +0000150void SwitchOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
151 OS.indent(indent) << "SwitchOpcode: {\n";
152 for (unsigned i = 0, e = Cases.size(); i != e; ++i) {
153 OS.indent(indent) << "case " << Cases[i].first->getEnumName() << ":\n";
154 Cases[i].second->print(OS, indent+2);
155 }
156 OS.indent(indent) << "}\n";
157}
158
159
Chris Lattnera5028a62010-02-25 06:53:39 +0000160void CheckTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner084df622010-03-24 00:41:19 +0000161 OS.indent(indent) << "CheckType " << getEnumName(Type) << ", ResNo="
162 << ResNo << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000163}
164
Chris Lattnercfe2eab2010-03-03 06:28:15 +0000165void SwitchTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
166 OS.indent(indent) << "SwitchType: {\n";
167 for (unsigned i = 0, e = Cases.size(); i != e; ++i) {
168 OS.indent(indent) << "case " << getEnumName(Cases[i].first) << ":\n";
169 Cases[i].second->print(OS, indent+2);
170 }
171 OS.indent(indent) << "}\n";
172}
173
Chris Lattnera5028a62010-02-25 06:53:39 +0000174void CheckChildTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner23cfda72010-02-24 20:15:25 +0000175 OS.indent(indent) << "CheckChildType " << ChildNo << " "
176 << getEnumName(Type) << '\n';
Chris Lattner23cfda72010-02-24 20:15:25 +0000177}
178
179
Chris Lattnera5028a62010-02-25 06:53:39 +0000180void CheckIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000181 OS.indent(indent) << "CheckInteger " << Value << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000182}
183
Chris Lattnera5028a62010-02-25 06:53:39 +0000184void CheckCondCodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000185 OS.indent(indent) << "CheckCondCode ISD::" << CondCodeName << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000186}
187
Chris Lattnera5028a62010-02-25 06:53:39 +0000188void CheckValueTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000189 OS.indent(indent) << "CheckValueType MVT::" << TypeName << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000190}
191
Chris Lattnera5028a62010-02-25 06:53:39 +0000192void CheckComplexPatMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000193 OS.indent(indent) << "CheckComplexPat " << Pattern.getSelectFunc() << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000194}
195
Chris Lattnera5028a62010-02-25 06:53:39 +0000196void CheckAndImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000197 OS.indent(indent) << "CheckAndImm " << Value << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000198}
199
Chris Lattnera5028a62010-02-25 06:53:39 +0000200void CheckOrImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000201 OS.indent(indent) << "CheckOrImm " << Value << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000202}
203
Chris Lattnera5028a62010-02-25 06:53:39 +0000204void CheckFoldableChainNodeMatcher::printImpl(raw_ostream &OS,
Chris Lattner21390d72010-02-16 19:15:55 +0000205 unsigned indent) const {
206 OS.indent(indent) << "CheckFoldableChainNode\n";
Chris Lattnere39650a2010-02-16 06:10:58 +0000207}
Chris Lattner9a747f12010-02-17 06:23:39 +0000208
Chris Lattnera5028a62010-02-25 06:53:39 +0000209void EmitIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000210 OS.indent(indent) << "EmitInteger " << Val << " VT=" << VT << '\n';
Chris Lattner8e946be2010-02-21 03:22:59 +0000211}
212
Chris Lattnerb21ba712010-02-25 02:04:40 +0000213void EmitStringIntegerMatcher::
Chris Lattnera5028a62010-02-25 06:53:39 +0000214printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000215 OS.indent(indent) << "EmitStringInteger " << Val << " VT=" << VT << '\n';
Chris Lattner845c0422010-02-18 22:03:03 +0000216}
217
Chris Lattnera5028a62010-02-25 06:53:39 +0000218void EmitRegisterMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000219 OS.indent(indent) << "EmitRegister ";
Chris Lattner845c0422010-02-18 22:03:03 +0000220 if (Reg)
221 OS << Reg->getName();
222 else
223 OS << "zero_reg";
224 OS << " VT=" << VT << '\n';
Chris Lattner845c0422010-02-18 22:03:03 +0000225}
226
Chris Lattnerb21ba712010-02-25 02:04:40 +0000227void EmitConvertToTargetMatcher::
Chris Lattnera5028a62010-02-25 06:53:39 +0000228printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000229 OS.indent(indent) << "EmitConvertToTarget " << Slot << '\n';
Chris Lattner8e946be2010-02-21 03:22:59 +0000230}
231
Chris Lattnerb21ba712010-02-25 02:04:40 +0000232void EmitMergeInputChainsMatcher::
Chris Lattnera5028a62010-02-25 06:53:39 +0000233printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000234 OS.indent(indent) << "EmitMergeInputChains <todo: args>\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000235}
236
Chris Lattnera5028a62010-02-25 06:53:39 +0000237void EmitCopyToRegMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000238 OS.indent(indent) << "EmitCopyToReg <todo: args>\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000239}
240
Chris Lattnera5028a62010-02-25 06:53:39 +0000241void EmitNodeXFormMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000242 OS.indent(indent) << "EmitNodeXForm " << NodeXForm->getName()
243 << " Slot=" << Slot << '\n';
Chris Lattner8e946be2010-02-21 03:22:59 +0000244}
245
246
Chris Lattnere86097a2010-02-28 02:31:26 +0000247void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, unsigned indent) const {
248 OS.indent(indent);
Chris Lattner9a215002010-02-28 20:55:18 +0000249 OS << (isa<MorphNodeToMatcher>(this) ? "MorphNodeTo: " : "EmitNode: ")
Chris Lattnere86097a2010-02-28 02:31:26 +0000250 << OpcodeName << ": <todo flags> ";
Chris Lattner8e946be2010-02-21 03:22:59 +0000251
252 for (unsigned i = 0, e = VTs.size(); i != e; ++i)
253 OS << ' ' << getEnumName(VTs[i]);
254 OS << '(';
255 for (unsigned i = 0, e = Operands.size(); i != e; ++i)
256 OS << Operands[i] << ' ';
257 OS << ")\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000258}
259
Chris Lattner8950bca2010-12-23 17:03:20 +0000260void MarkGlueResultsMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
261 OS.indent(indent) << "MarkGlueResults <todo: args>\n";
Chris Lattner02f73582010-02-24 05:33:42 +0000262}
263
Chris Lattnera5028a62010-02-25 06:53:39 +0000264void CompleteMatchMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner77f2e272010-02-21 06:03:07 +0000265 OS.indent(indent) << "CompleteMatch <todo args>\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000266 OS.indent(indent) << "Src = " << *Pattern.getSrcPattern() << "\n";
267 OS.indent(indent) << "Dst = " << *Pattern.getDstPattern() << "\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000268}
269
Chris Lattner58aa8342010-02-25 06:49:58 +0000270// getHashImpl Implementation.
271
272unsigned CheckPatternPredicateMatcher::getHashImpl() const {
273 return HashString(Predicate);
274}
275
276unsigned CheckPredicateMatcher::getHashImpl() const {
Chris Lattner54379062011-04-17 21:38:24 +0000277 return HashString(getPredicate().getFnName());
Chris Lattner58aa8342010-02-25 06:49:58 +0000278}
279
280unsigned CheckOpcodeMatcher::getHashImpl() const {
Chris Lattnera230f962010-02-27 21:48:43 +0000281 return HashString(Opcode.getEnumName());
Chris Lattner58aa8342010-02-25 06:49:58 +0000282}
283
Chris Lattner58aa8342010-02-25 06:49:58 +0000284unsigned CheckCondCodeMatcher::getHashImpl() const {
285 return HashString(CondCodeName);
286}
287
288unsigned CheckValueTypeMatcher::getHashImpl() const {
289 return HashString(TypeName);
290}
291
292unsigned EmitStringIntegerMatcher::getHashImpl() const {
293 return HashString(Val) ^ VT;
294}
295
296template<typename It>
297static unsigned HashUnsigneds(It I, It E) {
298 unsigned Result = 0;
299 for (; I != E; ++I)
300 Result = (Result<<3) ^ *I;
301 return Result;
302}
303
304unsigned EmitMergeInputChainsMatcher::getHashImpl() const {
305 return HashUnsigneds(ChainNodes.begin(), ChainNodes.end());
306}
307
Chris Lattnereb669212010-03-01 06:59:22 +0000308bool CheckOpcodeMatcher::isEqualImpl(const Matcher *M) const {
309 // Note: pointer equality isn't enough here, we have to check the enum names
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000310 // to ensure that the nodes are for the same opcode.
Chris Lattnereb669212010-03-01 06:59:22 +0000311 return cast<CheckOpcodeMatcher>(M)->Opcode.getEnumName() ==
312 Opcode.getEnumName();
313}
314
Chris Lattnere86097a2010-02-28 02:31:26 +0000315bool EmitNodeMatcherCommon::isEqualImpl(const Matcher *m) const {
316 const EmitNodeMatcherCommon *M = cast<EmitNodeMatcherCommon>(m);
Chris Lattner58aa8342010-02-25 06:49:58 +0000317 return M->OpcodeName == OpcodeName && M->VTs == VTs &&
318 M->Operands == Operands && M->HasChain == HasChain &&
Chris Lattner036609b2010-12-23 18:28:41 +0000319 M->HasInGlue == HasInGlue && M->HasOutGlue == HasOutGlue &&
Chris Lattnerff7fb602010-02-28 21:53:42 +0000320 M->HasMemRefs == HasMemRefs &&
Chris Lattner58aa8342010-02-25 06:49:58 +0000321 M->NumFixedArityOperands == NumFixedArityOperands;
322}
323
Chris Lattnere86097a2010-02-28 02:31:26 +0000324unsigned EmitNodeMatcherCommon::getHashImpl() const {
Chris Lattner58aa8342010-02-25 06:49:58 +0000325 return (HashString(OpcodeName) << 4) | Operands.size();
326}
327
328
David Blaikie2d24e2a2011-12-20 02:50:00 +0000329void EmitNodeMatcher::anchor() { }
330
331void MorphNodeToMatcher::anchor() { }
332
Chris Lattner8950bca2010-12-23 17:03:20 +0000333unsigned MarkGlueResultsMatcher::getHashImpl() const {
334 return HashUnsigneds(GlueResultNodes.begin(), GlueResultNodes.end());
Chris Lattner58aa8342010-02-25 06:49:58 +0000335}
336
337unsigned CompleteMatchMatcher::getHashImpl() const {
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000338 return HashUnsigneds(Results.begin(), Results.end()) ^
Chris Lattner58aa8342010-02-25 06:49:58 +0000339 ((unsigned)(intptr_t)&Pattern << 8);
340}
Chris Lattner82781b92010-02-27 07:49:13 +0000341
342// isContradictoryImpl Implementations.
343
Chris Lattner82781b92010-02-27 07:49:13 +0000344static bool TypesAreContradictory(MVT::SimpleValueType T1,
345 MVT::SimpleValueType T2) {
346 // If the two types are the same, then they are the same, so they don't
347 // contradict.
348 if (T1 == T2) return false;
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000349
Chris Lattner82781b92010-02-27 07:49:13 +0000350 // If either type is about iPtr, then they don't conflict unless the other
351 // one is not a scalar integer type.
352 if (T1 == MVT::iPTR)
353 return !MVT(T2).isInteger() || MVT(T2).isVector();
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000354
Chris Lattner82781b92010-02-27 07:49:13 +0000355 if (T2 == MVT::iPTR)
356 return !MVT(T1).isInteger() || MVT(T1).isVector();
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000357
Chris Lattner82781b92010-02-27 07:49:13 +0000358 // Otherwise, they are two different non-iPTR types, they conflict.
359 return true;
360}
361
Chris Lattner22579812010-02-28 00:22:30 +0000362bool CheckOpcodeMatcher::isContradictoryImpl(const Matcher *M) const {
363 if (const CheckOpcodeMatcher *COM = dyn_cast<CheckOpcodeMatcher>(M)) {
364 // One node can't have two different opcodes!
Chris Lattnereb669212010-03-01 06:59:22 +0000365 // Note: pointer equality isn't enough here, we have to check the enum names
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000366 // to ensure that the nodes are for the same opcode.
Chris Lattnereb669212010-03-01 06:59:22 +0000367 return COM->getOpcode().getEnumName() != getOpcode().getEnumName();
Chris Lattner22579812010-02-28 00:22:30 +0000368 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000369
Chris Lattner22579812010-02-28 00:22:30 +0000370 // If the node has a known type, and if the type we're checking for is
371 // different, then we know they contradict. For example, a check for
372 // ISD::STORE will never be true at the same time a check for Type i32 is.
373 if (const CheckTypeMatcher *CT = dyn_cast<CheckTypeMatcher>(M)) {
Chris Lattner084df622010-03-24 00:41:19 +0000374 // If checking for a result the opcode doesn't have, it can't match.
375 if (CT->getResNo() >= getOpcode().getNumResults())
376 return true;
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000377
Chris Lattner084df622010-03-24 00:41:19 +0000378 MVT::SimpleValueType NodeType = getOpcode().getKnownType(CT->getResNo());
Chris Lattneraac5b5b2010-03-19 01:14:27 +0000379 if (NodeType != MVT::Other)
380 return TypesAreContradictory(NodeType, CT->getType());
Chris Lattner22579812010-02-28 00:22:30 +0000381 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000382
Chris Lattner22579812010-02-28 00:22:30 +0000383 return false;
384}
385
Chris Lattner82781b92010-02-27 07:49:13 +0000386bool CheckTypeMatcher::isContradictoryImpl(const Matcher *M) const {
387 if (const CheckTypeMatcher *CT = dyn_cast<CheckTypeMatcher>(M))
388 return TypesAreContradictory(getType(), CT->getType());
389 return false;
390}
391
392bool CheckChildTypeMatcher::isContradictoryImpl(const Matcher *M) const {
393 if (const CheckChildTypeMatcher *CC = dyn_cast<CheckChildTypeMatcher>(M)) {
394 // If the two checks are about different nodes, we don't know if they
395 // conflict!
396 if (CC->getChildNo() != getChildNo())
397 return false;
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000398
Chris Lattner82781b92010-02-27 07:49:13 +0000399 return TypesAreContradictory(getType(), CC->getType());
400 }
401 return false;
402}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000403
Chris Lattner24789622010-02-27 08:11:15 +0000404bool CheckIntegerMatcher::isContradictoryImpl(const Matcher *M) const {
405 if (const CheckIntegerMatcher *CIM = dyn_cast<CheckIntegerMatcher>(M))
406 return CIM->getValue() != getValue();
407 return false;
408}
Chris Lattner48aa5752010-03-07 06:29:26 +0000409
410bool CheckValueTypeMatcher::isContradictoryImpl(const Matcher *M) const {
411 if (const CheckValueTypeMatcher *CVT = dyn_cast<CheckValueTypeMatcher>(M))
412 return CVT->getTypeName() != getTypeName();
413 return false;
414}
415