blob: 5d6a11ae0dc7fccce3c9d95b536e99d4e83ecad6 [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 Lattner58aa8342010-02-25 06:49:58 +000013#include "llvm/ADT/StringExtras.h"
Chandler Carruth4ffd89f2012-12-04 10:37:14 +000014#include "llvm/Support/raw_ostream.h"
15#include "llvm/TableGen/Record.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
Craig Topper78099d12013-09-25 06:40:22 +000066/// canMoveBeforeNode - Return true if it is safe to move the current matcher
Chris Lattner48aa5752010-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 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
Craig Topper936910d2013-10-05 05:38:16 +0000137void CheckChildSameMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
138 OS.indent(indent) << "CheckChild" << ChildNo << "Same\n";
139}
140
Chris Lattnerb21ba712010-02-25 02:04:40 +0000141void CheckPatternPredicateMatcher::
Chris Lattnera5028a62010-02-25 06:53:39 +0000142printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000143 OS.indent(indent) << "CheckPatternPredicate " << Predicate << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000144}
145
Chris Lattnera5028a62010-02-25 06:53:39 +0000146void CheckPredicateMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner54379062011-04-17 21:38:24 +0000147 OS.indent(indent) << "CheckPredicate " << getPredicate().getFnName() << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000148}
149
Chris Lattnera5028a62010-02-25 06:53:39 +0000150void CheckOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnera230f962010-02-27 21:48:43 +0000151 OS.indent(indent) << "CheckOpcode " << Opcode.getEnumName() << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000152}
153
Chris Lattnereb669212010-03-01 06:59:22 +0000154void SwitchOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
155 OS.indent(indent) << "SwitchOpcode: {\n";
156 for (unsigned i = 0, e = Cases.size(); i != e; ++i) {
157 OS.indent(indent) << "case " << Cases[i].first->getEnumName() << ":\n";
158 Cases[i].second->print(OS, indent+2);
159 }
160 OS.indent(indent) << "}\n";
161}
162
163
Chris Lattnera5028a62010-02-25 06:53:39 +0000164void CheckTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner084df622010-03-24 00:41:19 +0000165 OS.indent(indent) << "CheckType " << getEnumName(Type) << ", ResNo="
166 << ResNo << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000167}
168
Chris Lattnercfe2eab2010-03-03 06:28:15 +0000169void SwitchTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
170 OS.indent(indent) << "SwitchType: {\n";
171 for (unsigned i = 0, e = Cases.size(); i != e; ++i) {
172 OS.indent(indent) << "case " << getEnumName(Cases[i].first) << ":\n";
173 Cases[i].second->print(OS, indent+2);
174 }
175 OS.indent(indent) << "}\n";
176}
177
Chris Lattnera5028a62010-02-25 06:53:39 +0000178void CheckChildTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner23cfda72010-02-24 20:15:25 +0000179 OS.indent(indent) << "CheckChildType " << ChildNo << " "
180 << getEnumName(Type) << '\n';
Chris Lattner23cfda72010-02-24 20:15:25 +0000181}
182
183
Chris Lattnera5028a62010-02-25 06:53:39 +0000184void CheckIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000185 OS.indent(indent) << "CheckInteger " << Value << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000186}
187
Chris Lattnera5028a62010-02-25 06:53:39 +0000188void CheckCondCodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000189 OS.indent(indent) << "CheckCondCode ISD::" << CondCodeName << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000190}
191
Chris Lattnera5028a62010-02-25 06:53:39 +0000192void CheckValueTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000193 OS.indent(indent) << "CheckValueType MVT::" << TypeName << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000194}
195
Chris Lattnera5028a62010-02-25 06:53:39 +0000196void CheckComplexPatMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000197 OS.indent(indent) << "CheckComplexPat " << Pattern.getSelectFunc() << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000198}
199
Chris Lattnera5028a62010-02-25 06:53:39 +0000200void CheckAndImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000201 OS.indent(indent) << "CheckAndImm " << Value << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000202}
203
Chris Lattnera5028a62010-02-25 06:53:39 +0000204void CheckOrImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000205 OS.indent(indent) << "CheckOrImm " << Value << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000206}
207
Chris Lattnera5028a62010-02-25 06:53:39 +0000208void CheckFoldableChainNodeMatcher::printImpl(raw_ostream &OS,
Chris Lattner21390d72010-02-16 19:15:55 +0000209 unsigned indent) const {
210 OS.indent(indent) << "CheckFoldableChainNode\n";
Chris Lattnere39650a2010-02-16 06:10:58 +0000211}
Chris Lattner9a747f12010-02-17 06:23:39 +0000212
Chris Lattnera5028a62010-02-25 06:53:39 +0000213void EmitIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000214 OS.indent(indent) << "EmitInteger " << Val << " VT=" << VT << '\n';
Chris Lattner8e946be2010-02-21 03:22:59 +0000215}
216
Chris Lattnerb21ba712010-02-25 02:04:40 +0000217void EmitStringIntegerMatcher::
Chris Lattnera5028a62010-02-25 06:53:39 +0000218printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000219 OS.indent(indent) << "EmitStringInteger " << Val << " VT=" << VT << '\n';
Chris Lattner845c0422010-02-18 22:03:03 +0000220}
221
Chris Lattnera5028a62010-02-25 06:53:39 +0000222void EmitRegisterMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000223 OS.indent(indent) << "EmitRegister ";
Chris Lattner845c0422010-02-18 22:03:03 +0000224 if (Reg)
225 OS << Reg->getName();
226 else
227 OS << "zero_reg";
228 OS << " VT=" << VT << '\n';
Chris Lattner845c0422010-02-18 22:03:03 +0000229}
230
Chris Lattnerb21ba712010-02-25 02:04:40 +0000231void EmitConvertToTargetMatcher::
Chris Lattnera5028a62010-02-25 06:53:39 +0000232printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000233 OS.indent(indent) << "EmitConvertToTarget " << Slot << '\n';
Chris Lattner8e946be2010-02-21 03:22:59 +0000234}
235
Chris Lattnerb21ba712010-02-25 02:04:40 +0000236void EmitMergeInputChainsMatcher::
Chris Lattnera5028a62010-02-25 06:53:39 +0000237printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000238 OS.indent(indent) << "EmitMergeInputChains <todo: args>\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000239}
240
Chris Lattnera5028a62010-02-25 06:53:39 +0000241void EmitCopyToRegMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000242 OS.indent(indent) << "EmitCopyToReg <todo: args>\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000243}
244
Chris Lattnera5028a62010-02-25 06:53:39 +0000245void EmitNodeXFormMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000246 OS.indent(indent) << "EmitNodeXForm " << NodeXForm->getName()
247 << " Slot=" << Slot << '\n';
Chris Lattner8e946be2010-02-21 03:22:59 +0000248}
249
250
Chris Lattnere86097a2010-02-28 02:31:26 +0000251void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, unsigned indent) const {
252 OS.indent(indent);
Chris Lattner9a215002010-02-28 20:55:18 +0000253 OS << (isa<MorphNodeToMatcher>(this) ? "MorphNodeTo: " : "EmitNode: ")
Chris Lattnere86097a2010-02-28 02:31:26 +0000254 << OpcodeName << ": <todo flags> ";
Chris Lattner8e946be2010-02-21 03:22:59 +0000255
256 for (unsigned i = 0, e = VTs.size(); i != e; ++i)
257 OS << ' ' << getEnumName(VTs[i]);
258 OS << '(';
259 for (unsigned i = 0, e = Operands.size(); i != e; ++i)
260 OS << Operands[i] << ' ';
261 OS << ")\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000262}
263
Chris Lattner8950bca2010-12-23 17:03:20 +0000264void MarkGlueResultsMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
265 OS.indent(indent) << "MarkGlueResults <todo: args>\n";
Chris Lattner02f73582010-02-24 05:33:42 +0000266}
267
Chris Lattnera5028a62010-02-25 06:53:39 +0000268void CompleteMatchMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner77f2e272010-02-21 06:03:07 +0000269 OS.indent(indent) << "CompleteMatch <todo args>\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000270 OS.indent(indent) << "Src = " << *Pattern.getSrcPattern() << "\n";
271 OS.indent(indent) << "Dst = " << *Pattern.getDstPattern() << "\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000272}
273
Chris Lattner58aa8342010-02-25 06:49:58 +0000274// getHashImpl Implementation.
275
276unsigned CheckPatternPredicateMatcher::getHashImpl() const {
277 return HashString(Predicate);
278}
279
280unsigned CheckPredicateMatcher::getHashImpl() const {
Chris Lattner54379062011-04-17 21:38:24 +0000281 return HashString(getPredicate().getFnName());
Chris Lattner58aa8342010-02-25 06:49:58 +0000282}
283
284unsigned CheckOpcodeMatcher::getHashImpl() const {
Chris Lattnera230f962010-02-27 21:48:43 +0000285 return HashString(Opcode.getEnumName());
Chris Lattner58aa8342010-02-25 06:49:58 +0000286}
287
Chris Lattner58aa8342010-02-25 06:49:58 +0000288unsigned CheckCondCodeMatcher::getHashImpl() const {
289 return HashString(CondCodeName);
290}
291
292unsigned CheckValueTypeMatcher::getHashImpl() const {
293 return HashString(TypeName);
294}
295
296unsigned EmitStringIntegerMatcher::getHashImpl() const {
297 return HashString(Val) ^ VT;
298}
299
300template<typename It>
301static unsigned HashUnsigneds(It I, It E) {
302 unsigned Result = 0;
303 for (; I != E; ++I)
304 Result = (Result<<3) ^ *I;
305 return Result;
306}
307
308unsigned EmitMergeInputChainsMatcher::getHashImpl() const {
309 return HashUnsigneds(ChainNodes.begin(), ChainNodes.end());
310}
311
Chris Lattnereb669212010-03-01 06:59:22 +0000312bool CheckOpcodeMatcher::isEqualImpl(const Matcher *M) const {
313 // Note: pointer equality isn't enough here, we have to check the enum names
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000314 // to ensure that the nodes are for the same opcode.
Chris Lattnereb669212010-03-01 06:59:22 +0000315 return cast<CheckOpcodeMatcher>(M)->Opcode.getEnumName() ==
316 Opcode.getEnumName();
317}
318
Chris Lattnere86097a2010-02-28 02:31:26 +0000319bool EmitNodeMatcherCommon::isEqualImpl(const Matcher *m) const {
320 const EmitNodeMatcherCommon *M = cast<EmitNodeMatcherCommon>(m);
Chris Lattner58aa8342010-02-25 06:49:58 +0000321 return M->OpcodeName == OpcodeName && M->VTs == VTs &&
322 M->Operands == Operands && M->HasChain == HasChain &&
Chris Lattner036609b2010-12-23 18:28:41 +0000323 M->HasInGlue == HasInGlue && M->HasOutGlue == HasOutGlue &&
Chris Lattnerff7fb602010-02-28 21:53:42 +0000324 M->HasMemRefs == HasMemRefs &&
Chris Lattner58aa8342010-02-25 06:49:58 +0000325 M->NumFixedArityOperands == NumFixedArityOperands;
326}
327
Chris Lattnere86097a2010-02-28 02:31:26 +0000328unsigned EmitNodeMatcherCommon::getHashImpl() const {
Chris Lattner58aa8342010-02-25 06:49:58 +0000329 return (HashString(OpcodeName) << 4) | Operands.size();
330}
331
332
David Blaikie2d24e2a2011-12-20 02:50:00 +0000333void EmitNodeMatcher::anchor() { }
334
335void MorphNodeToMatcher::anchor() { }
336
Chris Lattner8950bca2010-12-23 17:03:20 +0000337unsigned MarkGlueResultsMatcher::getHashImpl() const {
338 return HashUnsigneds(GlueResultNodes.begin(), GlueResultNodes.end());
Chris Lattner58aa8342010-02-25 06:49:58 +0000339}
340
341unsigned CompleteMatchMatcher::getHashImpl() const {
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000342 return HashUnsigneds(Results.begin(), Results.end()) ^
Chris Lattner58aa8342010-02-25 06:49:58 +0000343 ((unsigned)(intptr_t)&Pattern << 8);
344}
Chris Lattner82781b92010-02-27 07:49:13 +0000345
346// isContradictoryImpl Implementations.
347
Chris Lattner82781b92010-02-27 07:49:13 +0000348static bool TypesAreContradictory(MVT::SimpleValueType T1,
349 MVT::SimpleValueType T2) {
350 // If the two types are the same, then they are the same, so they don't
351 // contradict.
352 if (T1 == T2) return false;
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000353
Chris Lattner82781b92010-02-27 07:49:13 +0000354 // If either type is about iPtr, then they don't conflict unless the other
355 // one is not a scalar integer type.
356 if (T1 == MVT::iPTR)
357 return !MVT(T2).isInteger() || MVT(T2).isVector();
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000358
Chris Lattner82781b92010-02-27 07:49:13 +0000359 if (T2 == MVT::iPTR)
360 return !MVT(T1).isInteger() || MVT(T1).isVector();
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000361
Chris Lattner82781b92010-02-27 07:49:13 +0000362 // Otherwise, they are two different non-iPTR types, they conflict.
363 return true;
364}
365
Chris Lattner22579812010-02-28 00:22:30 +0000366bool CheckOpcodeMatcher::isContradictoryImpl(const Matcher *M) const {
367 if (const CheckOpcodeMatcher *COM = dyn_cast<CheckOpcodeMatcher>(M)) {
368 // One node can't have two different opcodes!
Chris Lattnereb669212010-03-01 06:59:22 +0000369 // Note: pointer equality isn't enough here, we have to check the enum names
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000370 // to ensure that the nodes are for the same opcode.
Chris Lattnereb669212010-03-01 06:59:22 +0000371 return COM->getOpcode().getEnumName() != getOpcode().getEnumName();
Chris Lattner22579812010-02-28 00:22:30 +0000372 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000373
Chris Lattner22579812010-02-28 00:22:30 +0000374 // If the node has a known type, and if the type we're checking for is
375 // different, then we know they contradict. For example, a check for
376 // ISD::STORE will never be true at the same time a check for Type i32 is.
377 if (const CheckTypeMatcher *CT = dyn_cast<CheckTypeMatcher>(M)) {
Chris Lattner084df622010-03-24 00:41:19 +0000378 // If checking for a result the opcode doesn't have, it can't match.
379 if (CT->getResNo() >= getOpcode().getNumResults())
380 return true;
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000381
Chris Lattner084df622010-03-24 00:41:19 +0000382 MVT::SimpleValueType NodeType = getOpcode().getKnownType(CT->getResNo());
Chris Lattneraac5b5b2010-03-19 01:14:27 +0000383 if (NodeType != MVT::Other)
384 return TypesAreContradictory(NodeType, CT->getType());
Chris Lattner22579812010-02-28 00:22:30 +0000385 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000386
Chris Lattner22579812010-02-28 00:22:30 +0000387 return false;
388}
389
Chris Lattner82781b92010-02-27 07:49:13 +0000390bool CheckTypeMatcher::isContradictoryImpl(const Matcher *M) const {
391 if (const CheckTypeMatcher *CT = dyn_cast<CheckTypeMatcher>(M))
392 return TypesAreContradictory(getType(), CT->getType());
393 return false;
394}
395
396bool CheckChildTypeMatcher::isContradictoryImpl(const Matcher *M) const {
397 if (const CheckChildTypeMatcher *CC = dyn_cast<CheckChildTypeMatcher>(M)) {
398 // If the two checks are about different nodes, we don't know if they
399 // conflict!
400 if (CC->getChildNo() != getChildNo())
401 return false;
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000402
Chris Lattner82781b92010-02-27 07:49:13 +0000403 return TypesAreContradictory(getType(), CC->getType());
404 }
405 return false;
406}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000407
Chris Lattner24789622010-02-27 08:11:15 +0000408bool CheckIntegerMatcher::isContradictoryImpl(const Matcher *M) const {
409 if (const CheckIntegerMatcher *CIM = dyn_cast<CheckIntegerMatcher>(M))
410 return CIM->getValue() != getValue();
411 return false;
412}
Chris Lattner48aa5752010-03-07 06:29:26 +0000413
414bool CheckValueTypeMatcher::isContradictoryImpl(const Matcher *M) const {
415 if (const CheckValueTypeMatcher *CVT = dyn_cast<CheckValueTypeMatcher>(M))
416 return CVT->getTypeName() != getTypeName();
417 return false;
418}
419