blob: bebd205ad58ff631823ee9700ba56c0e56998000 [file] [log] [blame]
Chris Lattnerb02cdaa2010-02-15 08:04:42 +00001//===- DAGISelMatcher.cpp - Representation of DAG pattern matcher ---------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Chris Lattnerb02cdaa2010-02-15 08:04:42 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "DAGISelMatcher.h"
10#include "CodeGenDAGPatterns.h"
11#include "CodeGenTarget.h"
Chandler Carruth91d19d82012-12-04 10:37:14 +000012#include "llvm/Support/raw_ostream.h"
13#include "llvm/TableGen/Record.h"
Chris Lattnerb02cdaa2010-02-15 08:04:42 +000014using namespace llvm;
15
David Blaikiea379b1812011-12-20 02:50:00 +000016void Matcher::anchor() { }
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
Craig Topper24064772014-04-15 07:20:03 +000044 if (!Cur) return nullptr;
Chris Lattner9c791d82010-03-07 06:29:26 +000045 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
Craig Topper0ac6f9f2013-09-25 06:40:22 +000064/// canMoveBeforeNode - Return true if it is safe to move the current matcher
Chris Lattner9c791d82010-03-07 06:29:26 +000065/// 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() {
Javed Absar776bf1d2017-10-16 06:43:54 +000081 for (Matcher *C : Children)
82 delete C;
Chris Lattnerf7fc2d82010-02-25 19:00:39 +000083}
84
Craig Topper0d16d2d2014-01-29 07:06:07 +000085SwitchOpcodeMatcher::~SwitchOpcodeMatcher() {
Javed Absar776bf1d2017-10-16 06:43:54 +000086 for (auto &C : Cases)
87 delete C.second;
Craig Topper0d16d2d2014-01-29 07:06:07 +000088}
89
90SwitchTypeMatcher::~SwitchTypeMatcher() {
Javed Absar776bf1d2017-10-16 06:43:54 +000091 for (auto &C : Cases)
92 delete C.second;
Craig Topper0d16d2d2014-01-29 07:06:07 +000093}
Chris Lattnerf7fc2d82010-02-25 19:00:39 +000094
Nicolai Haehnle445b0b62018-11-30 14:15:13 +000095CheckPredicateMatcher::CheckPredicateMatcher(
96 const TreePredicateFn &pred, const SmallVectorImpl<unsigned> &Ops)
97 : Matcher(CheckPredicate), Pred(pred.getOrigPatFragRecord()),
98 Operands(Ops.begin(), Ops.end()) {}
Chris Lattner514e2922011-04-17 21:38:24 +000099
100TreePredicateFn CheckPredicateMatcher::getPredicate() const {
101 return TreePredicateFn(Pred);
102}
103
Nicolai Haehnle445b0b62018-11-30 14:15:13 +0000104unsigned CheckPredicateMatcher::getNumOperands() const {
105 return Operands.size();
106}
107
108unsigned CheckPredicateMatcher::getOperandNo(unsigned i) const {
109 assert(i < Operands.size());
110 return Operands[i];
111}
Chris Lattner514e2922011-04-17 21:38:24 +0000112
113
Chris Lattnerf7fc2d82010-02-25 19:00:39 +0000114// printImpl methods.
115
Chris Lattner1f2adb62010-02-25 06:53:39 +0000116void ScopeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerac55f9d2010-02-25 01:56:48 +0000117 OS.indent(indent) << "Scope\n";
Javed Absar776bf1d2017-10-16 06:43:54 +0000118 for (const Matcher *C : Children) {
119 if (!C)
Chris Lattner102a8a02010-02-28 20:49:53 +0000120 OS.indent(indent+1) << "NULL POINTER\n";
121 else
Javed Absar776bf1d2017-10-16 06:43:54 +0000122 C->print(OS, indent+2);
Chris Lattner102a8a02010-02-28 20:49:53 +0000123 }
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000124}
125
Chris Lattner1f2adb62010-02-25 06:53:39 +0000126void RecordMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000127 OS.indent(indent) << "Record\n";
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000128}
129
Chris Lattner1f2adb62010-02-25 06:53:39 +0000130void RecordChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerab417562010-02-24 07:31:45 +0000131 OS.indent(indent) << "RecordChild: " << ChildNo << '\n';
Chris Lattnerab417562010-02-24 07:31:45 +0000132}
133
Chris Lattner1f2adb62010-02-25 06:53:39 +0000134void RecordMemRefMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000135 OS.indent(indent) << "RecordMemRef\n";
Chris Lattner132df652010-02-21 03:22:59 +0000136}
137
Chris Lattnerf7f9e8c2010-12-23 17:03:20 +0000138void CaptureGlueInputMatcher::printImpl(raw_ostream &OS, unsigned indent) const{
139 OS.indent(indent) << "CaptureGlueInput\n";
Chris Lattner132df652010-02-21 03:22:59 +0000140}
141
Chris Lattner1f2adb62010-02-25 06:53:39 +0000142void MoveChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000143 OS.indent(indent) << "MoveChild " << ChildNo << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000144}
145
Chris Lattner1f2adb62010-02-25 06:53:39 +0000146void MoveParentMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000147 OS.indent(indent) << "MoveParent\n";
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000148}
149
Chris Lattner1f2adb62010-02-25 06:53:39 +0000150void CheckSameMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000151 OS.indent(indent) << "CheckSame " << MatchNumber << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000152}
153
Craig Toppera1bbc322013-10-05 05:38:16 +0000154void CheckChildSameMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
155 OS.indent(indent) << "CheckChild" << ChildNo << "Same\n";
156}
157
Chris Lattner2c3f6492010-02-25 02:04:40 +0000158void CheckPatternPredicateMatcher::
Chris Lattner1f2adb62010-02-25 06:53:39 +0000159printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000160 OS.indent(indent) << "CheckPatternPredicate " << Predicate << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000161}
162
Chris Lattner1f2adb62010-02-25 06:53:39 +0000163void CheckPredicateMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner514e2922011-04-17 21:38:24 +0000164 OS.indent(indent) << "CheckPredicate " << getPredicate().getFnName() << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000165}
166
Chris Lattner1f2adb62010-02-25 06:53:39 +0000167void CheckOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner278606b2010-02-27 21:48:43 +0000168 OS.indent(indent) << "CheckOpcode " << Opcode.getEnumName() << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000169}
170
Chris Lattnerf4d17752010-03-01 06:59:22 +0000171void SwitchOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
172 OS.indent(indent) << "SwitchOpcode: {\n";
Javed Absar776bf1d2017-10-16 06:43:54 +0000173 for (const auto &C : Cases) {
174 OS.indent(indent) << "case " << C.first->getEnumName() << ":\n";
175 C.second->print(OS, indent+2);
Chris Lattnerf4d17752010-03-01 06:59:22 +0000176 }
177 OS.indent(indent) << "}\n";
178}
179
180
Chris Lattner1f2adb62010-02-25 06:53:39 +0000181void CheckTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner6c2d1782010-03-24 00:41:19 +0000182 OS.indent(indent) << "CheckType " << getEnumName(Type) << ", ResNo="
183 << ResNo << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000184}
185
Chris Lattner3e1ffd02010-03-03 06:28:15 +0000186void SwitchTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
187 OS.indent(indent) << "SwitchType: {\n";
Javed Absar776bf1d2017-10-16 06:43:54 +0000188 for (const auto &C : Cases) {
189 OS.indent(indent) << "case " << getEnumName(C.first) << ":\n";
190 C.second->print(OS, indent+2);
Chris Lattner3e1ffd02010-03-03 06:28:15 +0000191 }
192 OS.indent(indent) << "}\n";
193}
194
Chris Lattner1f2adb62010-02-25 06:53:39 +0000195void CheckChildTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner0c95baa2010-02-24 20:15:25 +0000196 OS.indent(indent) << "CheckChildType " << ChildNo << " "
197 << getEnumName(Type) << '\n';
Chris Lattner0c95baa2010-02-24 20:15:25 +0000198}
199
200
Chris Lattner1f2adb62010-02-25 06:53:39 +0000201void CheckIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000202 OS.indent(indent) << "CheckInteger " << Value << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000203}
204
Craig Topper7ca1d182014-02-05 05:44:28 +0000205void CheckChildIntegerMatcher::printImpl(raw_ostream &OS,
206 unsigned indent) const {
207 OS.indent(indent) << "CheckChildInteger " << ChildNo << " " << Value << '\n';
208}
209
Chris Lattner1f2adb62010-02-25 06:53:39 +0000210void CheckCondCodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000211 OS.indent(indent) << "CheckCondCode ISD::" << CondCodeName << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000212}
213
Craig Topper8c9724e2019-02-25 03:11:44 +0000214void CheckChild2CondCodeMatcher::printImpl(raw_ostream &OS,
215 unsigned indent) const {
216 OS.indent(indent) << "CheckChild2CondCode ISD::" << CondCodeName << '\n';
217}
218
Chris Lattner1f2adb62010-02-25 06:53:39 +0000219void CheckValueTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000220 OS.indent(indent) << "CheckValueType MVT::" << TypeName << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000221}
222
Chris Lattner1f2adb62010-02-25 06:53:39 +0000223void CheckComplexPatMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000224 OS.indent(indent) << "CheckComplexPat " << Pattern.getSelectFunc() << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000225}
226
Chris Lattner1f2adb62010-02-25 06:53:39 +0000227void CheckAndImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000228 OS.indent(indent) << "CheckAndImm " << Value << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000229}
230
Chris Lattner1f2adb62010-02-25 06:53:39 +0000231void CheckOrImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000232 OS.indent(indent) << "CheckOrImm " << Value << '\n';
Chris Lattnerb02cdaa2010-02-15 08:04:42 +0000233}
234
Chris Lattner1f2adb62010-02-25 06:53:39 +0000235void CheckFoldableChainNodeMatcher::printImpl(raw_ostream &OS,
Chris Lattnerf8695c12010-02-16 19:15:55 +0000236 unsigned indent) const {
237 OS.indent(indent) << "CheckFoldableChainNode\n";
Chris Lattneraa7d3e02010-02-16 06:10:58 +0000238}
Chris Lattnerf8a5bb02010-02-17 06:23:39 +0000239
Craig Topper1a872f22019-03-10 05:21:52 +0000240void CheckImmAllOnesVMatcher::printImpl(raw_ostream &OS,
241 unsigned indent) const {
242 OS.indent(indent) << "CheckAllOnesV\n";
243}
244
245void CheckImmAllZerosVMatcher::printImpl(raw_ostream &OS,
246 unsigned indent) const {
247 OS.indent(indent) << "CheckAllZerosV\n";
248}
249
Chris Lattner1f2adb62010-02-25 06:53:39 +0000250void EmitIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Craig Topper6ff46262016-04-17 17:37:33 +0000251 OS.indent(indent) << "EmitInteger " << Val << " VT=" << getEnumName(VT)
252 << '\n';
Chris Lattner132df652010-02-21 03:22:59 +0000253}
254
Chris Lattner2c3f6492010-02-25 02:04:40 +0000255void EmitStringIntegerMatcher::
Chris Lattner1f2adb62010-02-25 06:53:39 +0000256printImpl(raw_ostream &OS, unsigned indent) const {
Craig Topper6ff46262016-04-17 17:37:33 +0000257 OS.indent(indent) << "EmitStringInteger " << Val << " VT=" << getEnumName(VT)
258 << '\n';
Chris Lattner42a7ba72010-02-18 22:03:03 +0000259}
260
Chris Lattner1f2adb62010-02-25 06:53:39 +0000261void EmitRegisterMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000262 OS.indent(indent) << "EmitRegister ";
Chris Lattner42a7ba72010-02-18 22:03:03 +0000263 if (Reg)
264 OS << Reg->getName();
265 else
266 OS << "zero_reg";
Craig Topper6ff46262016-04-17 17:37:33 +0000267 OS << " VT=" << getEnumName(VT) << '\n';
Chris Lattner42a7ba72010-02-18 22:03:03 +0000268}
269
Chris Lattner2c3f6492010-02-25 02:04:40 +0000270void EmitConvertToTargetMatcher::
Chris Lattner1f2adb62010-02-25 06:53:39 +0000271printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000272 OS.indent(indent) << "EmitConvertToTarget " << Slot << '\n';
Chris Lattner132df652010-02-21 03:22:59 +0000273}
274
Chris Lattner2c3f6492010-02-25 02:04:40 +0000275void EmitMergeInputChainsMatcher::
Chris Lattner1f2adb62010-02-25 06:53:39 +0000276printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000277 OS.indent(indent) << "EmitMergeInputChains <todo: args>\n";
Chris Lattner132df652010-02-21 03:22:59 +0000278}
279
Chris Lattner1f2adb62010-02-25 06:53:39 +0000280void EmitCopyToRegMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000281 OS.indent(indent) << "EmitCopyToReg <todo: args>\n";
Chris Lattner132df652010-02-21 03:22:59 +0000282}
283
Chris Lattner1f2adb62010-02-25 06:53:39 +0000284void EmitNodeXFormMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner132df652010-02-21 03:22:59 +0000285 OS.indent(indent) << "EmitNodeXForm " << NodeXForm->getName()
286 << " Slot=" << Slot << '\n';
Chris Lattner132df652010-02-21 03:22:59 +0000287}
288
289
Chris Lattnerc3f80e02010-02-28 02:31:26 +0000290void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, unsigned indent) const {
291 OS.indent(indent);
Chris Lattner9d67dca2010-02-28 20:55:18 +0000292 OS << (isa<MorphNodeToMatcher>(this) ? "MorphNodeTo: " : "EmitNode: ")
Chris Lattnerc3f80e02010-02-28 02:31:26 +0000293 << OpcodeName << ": <todo flags> ";
Chris Lattner132df652010-02-21 03:22:59 +0000294
295 for (unsigned i = 0, e = VTs.size(); i != e; ++i)
296 OS << ' ' << getEnumName(VTs[i]);
297 OS << '(';
298 for (unsigned i = 0, e = Operands.size(); i != e; ++i)
299 OS << Operands[i] << ' ';
300 OS << ")\n";
Chris Lattner132df652010-02-21 03:22:59 +0000301}
302
Chris Lattner1f2adb62010-02-25 06:53:39 +0000303void CompleteMatchMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
Chris Lattner79eaeb42010-02-21 06:03:07 +0000304 OS.indent(indent) << "CompleteMatch <todo args>\n";
Chris Lattner132df652010-02-21 03:22:59 +0000305 OS.indent(indent) << "Src = " << *Pattern.getSrcPattern() << "\n";
306 OS.indent(indent) << "Dst = " << *Pattern.getDstPattern() << "\n";
Chris Lattner132df652010-02-21 03:22:59 +0000307}
308
Chris Lattnerf4d17752010-03-01 06:59:22 +0000309bool CheckOpcodeMatcher::isEqualImpl(const Matcher *M) const {
310 // Note: pointer equality isn't enough here, we have to check the enum names
Jim Grosbach65586fe2010-12-21 16:16:00 +0000311 // to ensure that the nodes are for the same opcode.
Chris Lattnerf4d17752010-03-01 06:59:22 +0000312 return cast<CheckOpcodeMatcher>(M)->Opcode.getEnumName() ==
313 Opcode.getEnumName();
314}
315
Chris Lattnerc3f80e02010-02-28 02:31:26 +0000316bool EmitNodeMatcherCommon::isEqualImpl(const Matcher *m) const {
317 const EmitNodeMatcherCommon *M = cast<EmitNodeMatcherCommon>(m);
Chris Lattner212e8c82010-02-25 06:49:58 +0000318 return M->OpcodeName == OpcodeName && M->VTs == VTs &&
319 M->Operands == Operands && M->HasChain == HasChain &&
Chris Lattner2a0a3b42010-12-23 18:28:41 +0000320 M->HasInGlue == HasInGlue && M->HasOutGlue == HasOutGlue &&
Chris Lattnera8382642010-02-28 21:53:42 +0000321 M->HasMemRefs == HasMemRefs &&
Chris Lattner212e8c82010-02-25 06:49:58 +0000322 M->NumFixedArityOperands == NumFixedArityOperands;
323}
324
David Blaikiea379b1812011-12-20 02:50:00 +0000325void EmitNodeMatcher::anchor() { }
326
327void MorphNodeToMatcher::anchor() { }
328
Chris Lattnerc577b812010-02-27 07:49:13 +0000329// isContradictoryImpl Implementations.
330
Chris Lattnerc577b812010-02-27 07:49:13 +0000331static bool TypesAreContradictory(MVT::SimpleValueType T1,
332 MVT::SimpleValueType T2) {
333 // If the two types are the same, then they are the same, so they don't
334 // contradict.
335 if (T1 == T2) return false;
Jim Grosbach65586fe2010-12-21 16:16:00 +0000336
Chris Lattnerc577b812010-02-27 07:49:13 +0000337 // If either type is about iPtr, then they don't conflict unless the other
338 // one is not a scalar integer type.
339 if (T1 == MVT::iPTR)
340 return !MVT(T2).isInteger() || MVT(T2).isVector();
Jim Grosbach65586fe2010-12-21 16:16:00 +0000341
Chris Lattnerc577b812010-02-27 07:49:13 +0000342 if (T2 == MVT::iPTR)
343 return !MVT(T1).isInteger() || MVT(T1).isVector();
Jim Grosbach65586fe2010-12-21 16:16:00 +0000344
Chris Lattnerc577b812010-02-27 07:49:13 +0000345 // Otherwise, they are two different non-iPTR types, they conflict.
346 return true;
347}
348
Chris Lattner99e53b32010-02-28 00:22:30 +0000349bool CheckOpcodeMatcher::isContradictoryImpl(const Matcher *M) const {
350 if (const CheckOpcodeMatcher *COM = dyn_cast<CheckOpcodeMatcher>(M)) {
351 // One node can't have two different opcodes!
Chris Lattnerf4d17752010-03-01 06:59:22 +0000352 // Note: pointer equality isn't enough here, we have to check the enum names
Jim Grosbach65586fe2010-12-21 16:16:00 +0000353 // to ensure that the nodes are for the same opcode.
Chris Lattnerf4d17752010-03-01 06:59:22 +0000354 return COM->getOpcode().getEnumName() != getOpcode().getEnumName();
Chris Lattner99e53b32010-02-28 00:22:30 +0000355 }
Jim Grosbach65586fe2010-12-21 16:16:00 +0000356
Chris Lattner99e53b32010-02-28 00:22:30 +0000357 // If the node has a known type, and if the type we're checking for is
358 // different, then we know they contradict. For example, a check for
359 // ISD::STORE will never be true at the same time a check for Type i32 is.
360 if (const CheckTypeMatcher *CT = dyn_cast<CheckTypeMatcher>(M)) {
Chris Lattner6c2d1782010-03-24 00:41:19 +0000361 // If checking for a result the opcode doesn't have, it can't match.
362 if (CT->getResNo() >= getOpcode().getNumResults())
363 return true;
Jim Grosbach65586fe2010-12-21 16:16:00 +0000364
Chris Lattner6c2d1782010-03-24 00:41:19 +0000365 MVT::SimpleValueType NodeType = getOpcode().getKnownType(CT->getResNo());
Chris Lattnerda5b4ad2010-03-19 01:14:27 +0000366 if (NodeType != MVT::Other)
367 return TypesAreContradictory(NodeType, CT->getType());
Chris Lattner99e53b32010-02-28 00:22:30 +0000368 }
Jim Grosbach65586fe2010-12-21 16:16:00 +0000369
Chris Lattner99e53b32010-02-28 00:22:30 +0000370 return false;
371}
372
Chris Lattnerc577b812010-02-27 07:49:13 +0000373bool CheckTypeMatcher::isContradictoryImpl(const Matcher *M) const {
374 if (const CheckTypeMatcher *CT = dyn_cast<CheckTypeMatcher>(M))
375 return TypesAreContradictory(getType(), CT->getType());
376 return false;
377}
378
379bool CheckChildTypeMatcher::isContradictoryImpl(const Matcher *M) const {
380 if (const CheckChildTypeMatcher *CC = dyn_cast<CheckChildTypeMatcher>(M)) {
381 // If the two checks are about different nodes, we don't know if they
382 // conflict!
383 if (CC->getChildNo() != getChildNo())
384 return false;
Jim Grosbach65586fe2010-12-21 16:16:00 +0000385
Chris Lattnerc577b812010-02-27 07:49:13 +0000386 return TypesAreContradictory(getType(), CC->getType());
387 }
388 return false;
389}
Jim Grosbach65586fe2010-12-21 16:16:00 +0000390
Chris Lattner2586c862010-02-27 08:11:15 +0000391bool CheckIntegerMatcher::isContradictoryImpl(const Matcher *M) const {
392 if (const CheckIntegerMatcher *CIM = dyn_cast<CheckIntegerMatcher>(M))
393 return CIM->getValue() != getValue();
394 return false;
395}
Chris Lattner9c791d82010-03-07 06:29:26 +0000396
Craig Topper7ca1d182014-02-05 05:44:28 +0000397bool CheckChildIntegerMatcher::isContradictoryImpl(const Matcher *M) const {
398 if (const CheckChildIntegerMatcher *CCIM = dyn_cast<CheckChildIntegerMatcher>(M)) {
399 // If the two checks are about different nodes, we don't know if they
400 // conflict!
401 if (CCIM->getChildNo() != getChildNo())
402 return false;
403
404 return CCIM->getValue() != getValue();
405 }
406 return false;
407}
408
Chris Lattner9c791d82010-03-07 06:29:26 +0000409bool CheckValueTypeMatcher::isContradictoryImpl(const Matcher *M) const {
410 if (const CheckValueTypeMatcher *CVT = dyn_cast<CheckValueTypeMatcher>(M))
411 return CVT->getTypeName() != getTypeName();
412 return false;
413}
414
Craig Toppera2b144f2019-03-10 06:44:09 +0000415bool CheckImmAllOnesVMatcher::isContradictoryImpl(const Matcher *M) const {
416 // AllZeros is contradictory.
Craig Topper81d16562019-03-11 16:51:37 +0000417 return isa<CheckImmAllZerosVMatcher>(M);
Craig Toppera2b144f2019-03-10 06:44:09 +0000418}
419
420bool CheckImmAllZerosVMatcher::isContradictoryImpl(const Matcher *M) const {
421 // AllOnes is contradictory.
Craig Topper81d16562019-03-11 16:51:37 +0000422 return isa<CheckImmAllOnesVMatcher>(M);
Craig Toppera2b144f2019-03-10 06:44:09 +0000423}