blob: c8e005739460c56e74d7bab81a5d3fa24e1f9952 [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"
Chandler Carruth4ffd89f2012-12-04 10:37:14 +000013#include "llvm/Support/raw_ostream.h"
14#include "llvm/TableGen/Record.h"
Chris Lattnerda272d12010-02-15 08:04:42 +000015using namespace llvm;
16
David Blaikie2d24e2a2011-12-20 02:50:00 +000017void Matcher::anchor() { }
18
Chris Lattnerb21ba712010-02-25 02:04:40 +000019void Matcher::dump() const {
Chris Lattnera5028a62010-02-25 06:53:39 +000020 print(errs(), 0);
Chris Lattnerda272d12010-02-15 08:04:42 +000021}
22
Chris Lattnera5028a62010-02-25 06:53:39 +000023void Matcher::print(raw_ostream &OS, unsigned indent) const {
24 printImpl(OS, indent);
Chris Lattnerbd8227f2010-02-18 02:53:41 +000025 if (Next)
26 return Next->print(OS, indent);
Chris Lattnerda272d12010-02-15 08:04:42 +000027}
28
Chris Lattner82781b92010-02-27 07:49:13 +000029void Matcher::printOne(raw_ostream &OS) const {
30 printImpl(OS, 0);
31}
32
Chris Lattner48aa5752010-03-07 06:29:26 +000033/// unlinkNode - Unlink the specified node from this chain. If Other == this,
34/// we unlink the next pointer and return it. Otherwise we unlink Other from
35/// the list and return this.
36Matcher *Matcher::unlinkNode(Matcher *Other) {
37 if (this == Other)
38 return takeNext();
Jim Grosbachfbadcd02010-12-21 16:16:00 +000039
Chris Lattner48aa5752010-03-07 06:29:26 +000040 // Scan until we find the predecessor of Other.
41 Matcher *Cur = this;
42 for (; Cur && Cur->getNext() != Other; Cur = Cur->getNext())
43 /*empty*/;
44
Craig Topper095734c2014-04-15 07:20:03 +000045 if (!Cur) return nullptr;
Chris Lattner48aa5752010-03-07 06:29:26 +000046 Cur->takeNext();
47 Cur->setNext(Other->takeNext());
48 return this;
49}
50
51/// canMoveBefore - Return true if this matcher is the same as Other, or if
52/// we can move this matcher past all of the nodes in-between Other and this
53/// node. Other must be equal to or before this.
54bool Matcher::canMoveBefore(const Matcher *Other) const {
55 for (;; Other = Other->getNext()) {
56 assert(Other && "Other didn't come before 'this'?");
57 if (this == Other) return true;
58
59 // We have to be able to move this node across the Other node.
60 if (!canMoveBeforeNode(Other))
61 return false;
62 }
63}
64
Craig Topper78099d12013-09-25 06:40:22 +000065/// canMoveBeforeNode - Return true if it is safe to move the current matcher
Chris Lattner48aa5752010-03-07 06:29:26 +000066/// across the specified one.
67bool Matcher::canMoveBeforeNode(const Matcher *Other) const {
68 // We can move simple predicates before record nodes.
69 if (isSimplePredicateNode())
70 return Other->isSimplePredicateOrRecordNode();
Jim Grosbachfbadcd02010-12-21 16:16:00 +000071
Chris Lattner48aa5752010-03-07 06:29:26 +000072 // We can move record nodes across simple predicates.
73 if (isSimplePredicateOrRecordNode())
74 return isSimplePredicateNode();
Jim Grosbachfbadcd02010-12-21 16:16:00 +000075
Chris Lattner48aa5752010-03-07 06:29:26 +000076 // We can't move record nodes across each other etc.
77 return false;
78}
79
80
Chris Lattnerd6c84722010-02-25 19:00:39 +000081ScopeMatcher::~ScopeMatcher() {
Javed Absard3a44462017-10-16 06:43:54 +000082 for (Matcher *C : Children)
83 delete C;
Chris Lattnerd6c84722010-02-25 19:00:39 +000084}
85
Craig Topper01a5c172014-01-29 07:06:07 +000086SwitchOpcodeMatcher::~SwitchOpcodeMatcher() {
Javed Absard3a44462017-10-16 06:43:54 +000087 for (auto &C : Cases)
88 delete C.second;
Craig Topper01a5c172014-01-29 07:06:07 +000089}
90
91SwitchTypeMatcher::~SwitchTypeMatcher() {
Javed Absard3a44462017-10-16 06:43:54 +000092 for (auto &C : Cases)
93 delete C.second;
Craig Topper01a5c172014-01-29 07:06:07 +000094}
Chris Lattnerd6c84722010-02-25 19:00:39 +000095
Nicolai Haehnle98272e42018-11-30 14:15:13 +000096CheckPredicateMatcher::CheckPredicateMatcher(
97 const TreePredicateFn &pred, const SmallVectorImpl<unsigned> &Ops)
98 : Matcher(CheckPredicate), Pred(pred.getOrigPatFragRecord()),
99 Operands(Ops.begin(), Ops.end()) {}
Chris Lattner54379062011-04-17 21:38:24 +0000100
101TreePredicateFn CheckPredicateMatcher::getPredicate() const {
102 return TreePredicateFn(Pred);
103}
104
Nicolai Haehnle98272e42018-11-30 14:15:13 +0000105unsigned CheckPredicateMatcher::getNumOperands() const {
106 return Operands.size();
107}
108
109unsigned CheckPredicateMatcher::getOperandNo(unsigned i) const {
110 assert(i < Operands.size());
111 return Operands[i];
112}
Chris Lattner54379062011-04-17 21:38:24 +0000113
114
Chris Lattnerd6c84722010-02-25 19:00:39 +0000115// printImpl methods.
116
Chris Lattnera5028a62010-02-25 06:53:39 +0000117void ScopeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner60df53e2010-02-25 01:56:48 +0000118 OS.indent(indent) << "Scope\n";
Javed Absard3a44462017-10-16 06:43:54 +0000119 for (const Matcher *C : Children) {
120 if (!C)
Chris Lattnerc78f2a32010-02-28 20:49:53 +0000121 OS.indent(indent+1) << "NULL POINTER\n";
122 else
Javed Absard3a44462017-10-16 06:43:54 +0000123 C->print(OS, indent+2);
Chris Lattnerc78f2a32010-02-28 20:49:53 +0000124 }
Chris Lattnerda272d12010-02-15 08:04:42 +0000125}
126
Chris Lattnera5028a62010-02-25 06:53:39 +0000127void RecordMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000128 OS.indent(indent) << "Record\n";
Chris Lattnerda272d12010-02-15 08:04:42 +0000129}
130
Chris Lattnera5028a62010-02-25 06:53:39 +0000131void RecordChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner19b5a752010-02-24 07:31:45 +0000132 OS.indent(indent) << "RecordChild: " << ChildNo << '\n';
Chris Lattner19b5a752010-02-24 07:31:45 +0000133}
134
Chris Lattnera5028a62010-02-25 06:53:39 +0000135void RecordMemRefMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000136 OS.indent(indent) << "RecordMemRef\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000137}
138
Chris Lattner8950bca2010-12-23 17:03:20 +0000139void CaptureGlueInputMatcher::printImpl(raw_ostream &OS, unsigned indent) const{
140 OS.indent(indent) << "CaptureGlueInput\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000141}
142
Chris Lattnera5028a62010-02-25 06:53:39 +0000143void MoveChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000144 OS.indent(indent) << "MoveChild " << ChildNo << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000145}
146
Chris Lattnera5028a62010-02-25 06:53:39 +0000147void MoveParentMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000148 OS.indent(indent) << "MoveParent\n";
Chris Lattnerda272d12010-02-15 08:04:42 +0000149}
150
Chris Lattnera5028a62010-02-25 06:53:39 +0000151void CheckSameMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000152 OS.indent(indent) << "CheckSame " << MatchNumber << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000153}
154
Craig Topper936910d2013-10-05 05:38:16 +0000155void CheckChildSameMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
156 OS.indent(indent) << "CheckChild" << ChildNo << "Same\n";
157}
158
Chris Lattnerb21ba712010-02-25 02:04:40 +0000159void CheckPatternPredicateMatcher::
Chris Lattnera5028a62010-02-25 06:53:39 +0000160printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000161 OS.indent(indent) << "CheckPatternPredicate " << Predicate << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000162}
163
Chris Lattnera5028a62010-02-25 06:53:39 +0000164void CheckPredicateMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner54379062011-04-17 21:38:24 +0000165 OS.indent(indent) << "CheckPredicate " << getPredicate().getFnName() << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000166}
167
Chris Lattnera5028a62010-02-25 06:53:39 +0000168void CheckOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnera230f962010-02-27 21:48:43 +0000169 OS.indent(indent) << "CheckOpcode " << Opcode.getEnumName() << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000170}
171
Chris Lattnereb669212010-03-01 06:59:22 +0000172void SwitchOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
173 OS.indent(indent) << "SwitchOpcode: {\n";
Javed Absard3a44462017-10-16 06:43:54 +0000174 for (const auto &C : Cases) {
175 OS.indent(indent) << "case " << C.first->getEnumName() << ":\n";
176 C.second->print(OS, indent+2);
Chris Lattnereb669212010-03-01 06:59:22 +0000177 }
178 OS.indent(indent) << "}\n";
179}
180
181
Chris Lattnera5028a62010-02-25 06:53:39 +0000182void CheckTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner084df622010-03-24 00:41:19 +0000183 OS.indent(indent) << "CheckType " << getEnumName(Type) << ", ResNo="
184 << ResNo << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000185}
186
Chris Lattnercfe2eab2010-03-03 06:28:15 +0000187void SwitchTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
188 OS.indent(indent) << "SwitchType: {\n";
Javed Absard3a44462017-10-16 06:43:54 +0000189 for (const auto &C : Cases) {
190 OS.indent(indent) << "case " << getEnumName(C.first) << ":\n";
191 C.second->print(OS, indent+2);
Chris Lattnercfe2eab2010-03-03 06:28:15 +0000192 }
193 OS.indent(indent) << "}\n";
194}
195
Chris Lattnera5028a62010-02-25 06:53:39 +0000196void CheckChildTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner23cfda72010-02-24 20:15:25 +0000197 OS.indent(indent) << "CheckChildType " << ChildNo << " "
198 << getEnumName(Type) << '\n';
Chris Lattner23cfda72010-02-24 20:15:25 +0000199}
200
201
Chris Lattnera5028a62010-02-25 06:53:39 +0000202void CheckIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000203 OS.indent(indent) << "CheckInteger " << Value << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000204}
205
Craig Topper3211c862014-02-05 05:44:28 +0000206void CheckChildIntegerMatcher::printImpl(raw_ostream &OS,
207 unsigned indent) const {
208 OS.indent(indent) << "CheckChildInteger " << ChildNo << " " << Value << '\n';
209}
210
Chris Lattnera5028a62010-02-25 06:53:39 +0000211void CheckCondCodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000212 OS.indent(indent) << "CheckCondCode ISD::" << CondCodeName << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000213}
214
Chris Lattnera5028a62010-02-25 06:53:39 +0000215void CheckValueTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000216 OS.indent(indent) << "CheckValueType MVT::" << TypeName << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000217}
218
Chris Lattnera5028a62010-02-25 06:53:39 +0000219void CheckComplexPatMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000220 OS.indent(indent) << "CheckComplexPat " << Pattern.getSelectFunc() << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000221}
222
Chris Lattnera5028a62010-02-25 06:53:39 +0000223void CheckAndImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000224 OS.indent(indent) << "CheckAndImm " << Value << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000225}
226
Chris Lattnera5028a62010-02-25 06:53:39 +0000227void CheckOrImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerda272d12010-02-15 08:04:42 +0000228 OS.indent(indent) << "CheckOrImm " << Value << '\n';
Chris Lattnerda272d12010-02-15 08:04:42 +0000229}
230
Chris Lattnera5028a62010-02-25 06:53:39 +0000231void CheckFoldableChainNodeMatcher::printImpl(raw_ostream &OS,
Chris Lattner21390d72010-02-16 19:15:55 +0000232 unsigned indent) const {
233 OS.indent(indent) << "CheckFoldableChainNode\n";
Chris Lattnere39650a2010-02-16 06:10:58 +0000234}
Chris Lattner9a747f12010-02-17 06:23:39 +0000235
Chris Lattnera5028a62010-02-25 06:53:39 +0000236void EmitIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Craig Topperca891392016-04-17 17:37:33 +0000237 OS.indent(indent) << "EmitInteger " << Val << " VT=" << getEnumName(VT)
238 << '\n';
Chris Lattner8e946be2010-02-21 03:22:59 +0000239}
240
Chris Lattnerb21ba712010-02-25 02:04:40 +0000241void EmitStringIntegerMatcher::
Chris Lattnera5028a62010-02-25 06:53:39 +0000242printImpl(raw_ostream &OS, unsigned indent) const {
Craig Topperca891392016-04-17 17:37:33 +0000243 OS.indent(indent) << "EmitStringInteger " << Val << " VT=" << getEnumName(VT)
244 << '\n';
Chris Lattner845c0422010-02-18 22:03:03 +0000245}
246
Chris Lattnera5028a62010-02-25 06:53:39 +0000247void EmitRegisterMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000248 OS.indent(indent) << "EmitRegister ";
Chris Lattner845c0422010-02-18 22:03:03 +0000249 if (Reg)
250 OS << Reg->getName();
251 else
252 OS << "zero_reg";
Craig Topperca891392016-04-17 17:37:33 +0000253 OS << " VT=" << getEnumName(VT) << '\n';
Chris Lattner845c0422010-02-18 22:03:03 +0000254}
255
Chris Lattnerb21ba712010-02-25 02:04:40 +0000256void EmitConvertToTargetMatcher::
Chris Lattnera5028a62010-02-25 06:53:39 +0000257printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000258 OS.indent(indent) << "EmitConvertToTarget " << Slot << '\n';
Chris Lattner8e946be2010-02-21 03:22:59 +0000259}
260
Chris Lattnerb21ba712010-02-25 02:04:40 +0000261void EmitMergeInputChainsMatcher::
Chris Lattnera5028a62010-02-25 06:53:39 +0000262printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000263 OS.indent(indent) << "EmitMergeInputChains <todo: args>\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000264}
265
Chris Lattnera5028a62010-02-25 06:53:39 +0000266void EmitCopyToRegMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000267 OS.indent(indent) << "EmitCopyToReg <todo: args>\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000268}
269
Chris Lattnera5028a62010-02-25 06:53:39 +0000270void EmitNodeXFormMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner8e946be2010-02-21 03:22:59 +0000271 OS.indent(indent) << "EmitNodeXForm " << NodeXForm->getName()
272 << " Slot=" << Slot << '\n';
Chris Lattner8e946be2010-02-21 03:22:59 +0000273}
274
275
Chris Lattnere86097a2010-02-28 02:31:26 +0000276void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, unsigned indent) const {
277 OS.indent(indent);
Chris Lattner9a215002010-02-28 20:55:18 +0000278 OS << (isa<MorphNodeToMatcher>(this) ? "MorphNodeTo: " : "EmitNode: ")
Chris Lattnere86097a2010-02-28 02:31:26 +0000279 << OpcodeName << ": <todo flags> ";
Chris Lattner8e946be2010-02-21 03:22:59 +0000280
281 for (unsigned i = 0, e = VTs.size(); i != e; ++i)
282 OS << ' ' << getEnumName(VTs[i]);
283 OS << '(';
284 for (unsigned i = 0, e = Operands.size(); i != e; ++i)
285 OS << Operands[i] << ' ';
286 OS << ")\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000287}
288
Chris Lattnera5028a62010-02-25 06:53:39 +0000289void CompleteMatchMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner77f2e272010-02-21 06:03:07 +0000290 OS.indent(indent) << "CompleteMatch <todo args>\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000291 OS.indent(indent) << "Src = " << *Pattern.getSrcPattern() << "\n";
292 OS.indent(indent) << "Dst = " << *Pattern.getDstPattern() << "\n";
Chris Lattner8e946be2010-02-21 03:22:59 +0000293}
294
Chris Lattnereb669212010-03-01 06:59:22 +0000295bool CheckOpcodeMatcher::isEqualImpl(const Matcher *M) const {
296 // Note: pointer equality isn't enough here, we have to check the enum names
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000297 // to ensure that the nodes are for the same opcode.
Chris Lattnereb669212010-03-01 06:59:22 +0000298 return cast<CheckOpcodeMatcher>(M)->Opcode.getEnumName() ==
299 Opcode.getEnumName();
300}
301
Chris Lattnere86097a2010-02-28 02:31:26 +0000302bool EmitNodeMatcherCommon::isEqualImpl(const Matcher *m) const {
303 const EmitNodeMatcherCommon *M = cast<EmitNodeMatcherCommon>(m);
Chris Lattner58aa8342010-02-25 06:49:58 +0000304 return M->OpcodeName == OpcodeName && M->VTs == VTs &&
305 M->Operands == Operands && M->HasChain == HasChain &&
Chris Lattner036609b2010-12-23 18:28:41 +0000306 M->HasInGlue == HasInGlue && M->HasOutGlue == HasOutGlue &&
Chris Lattnerff7fb602010-02-28 21:53:42 +0000307 M->HasMemRefs == HasMemRefs &&
Chris Lattner58aa8342010-02-25 06:49:58 +0000308 M->NumFixedArityOperands == NumFixedArityOperands;
309}
310
David Blaikie2d24e2a2011-12-20 02:50:00 +0000311void EmitNodeMatcher::anchor() { }
312
313void MorphNodeToMatcher::anchor() { }
314
Chris Lattner82781b92010-02-27 07:49:13 +0000315// isContradictoryImpl Implementations.
316
Chris Lattner82781b92010-02-27 07:49:13 +0000317static bool TypesAreContradictory(MVT::SimpleValueType T1,
318 MVT::SimpleValueType T2) {
319 // If the two types are the same, then they are the same, so they don't
320 // contradict.
321 if (T1 == T2) return false;
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000322
Chris Lattner82781b92010-02-27 07:49:13 +0000323 // If either type is about iPtr, then they don't conflict unless the other
324 // one is not a scalar integer type.
325 if (T1 == MVT::iPTR)
326 return !MVT(T2).isInteger() || MVT(T2).isVector();
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000327
Chris Lattner82781b92010-02-27 07:49:13 +0000328 if (T2 == MVT::iPTR)
329 return !MVT(T1).isInteger() || MVT(T1).isVector();
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000330
Chris Lattner82781b92010-02-27 07:49:13 +0000331 // Otherwise, they are two different non-iPTR types, they conflict.
332 return true;
333}
334
Chris Lattner22579812010-02-28 00:22:30 +0000335bool CheckOpcodeMatcher::isContradictoryImpl(const Matcher *M) const {
336 if (const CheckOpcodeMatcher *COM = dyn_cast<CheckOpcodeMatcher>(M)) {
337 // One node can't have two different opcodes!
Chris Lattnereb669212010-03-01 06:59:22 +0000338 // Note: pointer equality isn't enough here, we have to check the enum names
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000339 // to ensure that the nodes are for the same opcode.
Chris Lattnereb669212010-03-01 06:59:22 +0000340 return COM->getOpcode().getEnumName() != getOpcode().getEnumName();
Chris Lattner22579812010-02-28 00:22:30 +0000341 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000342
Chris Lattner22579812010-02-28 00:22:30 +0000343 // If the node has a known type, and if the type we're checking for is
344 // different, then we know they contradict. For example, a check for
345 // ISD::STORE will never be true at the same time a check for Type i32 is.
346 if (const CheckTypeMatcher *CT = dyn_cast<CheckTypeMatcher>(M)) {
Chris Lattner084df622010-03-24 00:41:19 +0000347 // If checking for a result the opcode doesn't have, it can't match.
348 if (CT->getResNo() >= getOpcode().getNumResults())
349 return true;
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000350
Chris Lattner084df622010-03-24 00:41:19 +0000351 MVT::SimpleValueType NodeType = getOpcode().getKnownType(CT->getResNo());
Chris Lattneraac5b5b2010-03-19 01:14:27 +0000352 if (NodeType != MVT::Other)
353 return TypesAreContradictory(NodeType, CT->getType());
Chris Lattner22579812010-02-28 00:22:30 +0000354 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000355
Chris Lattner22579812010-02-28 00:22:30 +0000356 return false;
357}
358
Chris Lattner82781b92010-02-27 07:49:13 +0000359bool CheckTypeMatcher::isContradictoryImpl(const Matcher *M) const {
360 if (const CheckTypeMatcher *CT = dyn_cast<CheckTypeMatcher>(M))
361 return TypesAreContradictory(getType(), CT->getType());
362 return false;
363}
364
365bool CheckChildTypeMatcher::isContradictoryImpl(const Matcher *M) const {
366 if (const CheckChildTypeMatcher *CC = dyn_cast<CheckChildTypeMatcher>(M)) {
367 // If the two checks are about different nodes, we don't know if they
368 // conflict!
369 if (CC->getChildNo() != getChildNo())
370 return false;
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000371
Chris Lattner82781b92010-02-27 07:49:13 +0000372 return TypesAreContradictory(getType(), CC->getType());
373 }
374 return false;
375}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000376
Chris Lattner24789622010-02-27 08:11:15 +0000377bool CheckIntegerMatcher::isContradictoryImpl(const Matcher *M) const {
378 if (const CheckIntegerMatcher *CIM = dyn_cast<CheckIntegerMatcher>(M))
379 return CIM->getValue() != getValue();
380 return false;
381}
Chris Lattner48aa5752010-03-07 06:29:26 +0000382
Craig Topper3211c862014-02-05 05:44:28 +0000383bool CheckChildIntegerMatcher::isContradictoryImpl(const Matcher *M) const {
384 if (const CheckChildIntegerMatcher *CCIM = dyn_cast<CheckChildIntegerMatcher>(M)) {
385 // If the two checks are about different nodes, we don't know if they
386 // conflict!
387 if (CCIM->getChildNo() != getChildNo())
388 return false;
389
390 return CCIM->getValue() != getValue();
391 }
392 return false;
393}
394
Chris Lattner48aa5752010-03-07 06:29:26 +0000395bool CheckValueTypeMatcher::isContradictoryImpl(const Matcher *M) const {
396 if (const CheckValueTypeMatcher *CVT = dyn_cast<CheckValueTypeMatcher>(M))
397 return CVT->getTypeName() != getTypeName();
398 return false;
399}
400