Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 1 | //===- DAGISelMatcher.cpp - Representation of DAG pattern matcher ---------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // 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 Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "DAGISelMatcher.h" |
| 10 | #include "CodeGenDAGPatterns.h" |
| 11 | #include "CodeGenTarget.h" |
Chandler Carruth | 91d19d8 | 2012-12-04 10:37:14 +0000 | [diff] [blame] | 12 | #include "llvm/Support/raw_ostream.h" |
| 13 | #include "llvm/TableGen/Record.h" |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 14 | using namespace llvm; |
| 15 | |
David Blaikie | a379b181 | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 16 | void Matcher::anchor() { } |
| 17 | |
Chris Lattner | 2c3f649 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 18 | void Matcher::dump() const { |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 19 | print(errs(), 0); |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 20 | } |
| 21 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 22 | void Matcher::print(raw_ostream &OS, unsigned indent) const { |
| 23 | printImpl(OS, indent); |
Chris Lattner | 186ad80 | 2010-02-18 02:53:41 +0000 | [diff] [blame] | 24 | if (Next) |
| 25 | return Next->print(OS, indent); |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 26 | } |
| 27 | |
Chris Lattner | c577b81 | 2010-02-27 07:49:13 +0000 | [diff] [blame] | 28 | void Matcher::printOne(raw_ostream &OS) const { |
| 29 | printImpl(OS, 0); |
| 30 | } |
| 31 | |
Chris Lattner | 9c791d8 | 2010-03-07 06:29:26 +0000 | [diff] [blame] | 32 | /// 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. |
| 35 | Matcher *Matcher::unlinkNode(Matcher *Other) { |
| 36 | if (this == Other) |
| 37 | return takeNext(); |
Jim Grosbach | 65586fe | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 38 | |
Chris Lattner | 9c791d8 | 2010-03-07 06:29:26 +0000 | [diff] [blame] | 39 | // 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 Topper | 2406477 | 2014-04-15 07:20:03 +0000 | [diff] [blame] | 44 | if (!Cur) return nullptr; |
Chris Lattner | 9c791d8 | 2010-03-07 06:29:26 +0000 | [diff] [blame] | 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. |
| 53 | bool 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 Topper | 0ac6f9f | 2013-09-25 06:40:22 +0000 | [diff] [blame] | 64 | /// canMoveBeforeNode - Return true if it is safe to move the current matcher |
Chris Lattner | 9c791d8 | 2010-03-07 06:29:26 +0000 | [diff] [blame] | 65 | /// across the specified one. |
| 66 | bool Matcher::canMoveBeforeNode(const Matcher *Other) const { |
| 67 | // We can move simple predicates before record nodes. |
| 68 | if (isSimplePredicateNode()) |
| 69 | return Other->isSimplePredicateOrRecordNode(); |
Jim Grosbach | 65586fe | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 70 | |
Chris Lattner | 9c791d8 | 2010-03-07 06:29:26 +0000 | [diff] [blame] | 71 | // We can move record nodes across simple predicates. |
| 72 | if (isSimplePredicateOrRecordNode()) |
| 73 | return isSimplePredicateNode(); |
Jim Grosbach | 65586fe | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 74 | |
Chris Lattner | 9c791d8 | 2010-03-07 06:29:26 +0000 | [diff] [blame] | 75 | // We can't move record nodes across each other etc. |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | |
Chris Lattner | f7fc2d8 | 2010-02-25 19:00:39 +0000 | [diff] [blame] | 80 | ScopeMatcher::~ScopeMatcher() { |
Javed Absar | 776bf1d | 2017-10-16 06:43:54 +0000 | [diff] [blame] | 81 | for (Matcher *C : Children) |
| 82 | delete C; |
Chris Lattner | f7fc2d8 | 2010-02-25 19:00:39 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Craig Topper | 0d16d2d | 2014-01-29 07:06:07 +0000 | [diff] [blame] | 85 | SwitchOpcodeMatcher::~SwitchOpcodeMatcher() { |
Javed Absar | 776bf1d | 2017-10-16 06:43:54 +0000 | [diff] [blame] | 86 | for (auto &C : Cases) |
| 87 | delete C.second; |
Craig Topper | 0d16d2d | 2014-01-29 07:06:07 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | SwitchTypeMatcher::~SwitchTypeMatcher() { |
Javed Absar | 776bf1d | 2017-10-16 06:43:54 +0000 | [diff] [blame] | 91 | for (auto &C : Cases) |
| 92 | delete C.second; |
Craig Topper | 0d16d2d | 2014-01-29 07:06:07 +0000 | [diff] [blame] | 93 | } |
Chris Lattner | f7fc2d8 | 2010-02-25 19:00:39 +0000 | [diff] [blame] | 94 | |
Nicolai Haehnle | 445b0b6 | 2018-11-30 14:15:13 +0000 | [diff] [blame] | 95 | CheckPredicateMatcher::CheckPredicateMatcher( |
| 96 | const TreePredicateFn &pred, const SmallVectorImpl<unsigned> &Ops) |
| 97 | : Matcher(CheckPredicate), Pred(pred.getOrigPatFragRecord()), |
| 98 | Operands(Ops.begin(), Ops.end()) {} |
Chris Lattner | 514e292 | 2011-04-17 21:38:24 +0000 | [diff] [blame] | 99 | |
| 100 | TreePredicateFn CheckPredicateMatcher::getPredicate() const { |
| 101 | return TreePredicateFn(Pred); |
| 102 | } |
| 103 | |
Nicolai Haehnle | 445b0b6 | 2018-11-30 14:15:13 +0000 | [diff] [blame] | 104 | unsigned CheckPredicateMatcher::getNumOperands() const { |
| 105 | return Operands.size(); |
| 106 | } |
| 107 | |
| 108 | unsigned CheckPredicateMatcher::getOperandNo(unsigned i) const { |
| 109 | assert(i < Operands.size()); |
| 110 | return Operands[i]; |
| 111 | } |
Chris Lattner | 514e292 | 2011-04-17 21:38:24 +0000 | [diff] [blame] | 112 | |
| 113 | |
Chris Lattner | f7fc2d8 | 2010-02-25 19:00:39 +0000 | [diff] [blame] | 114 | // printImpl methods. |
| 115 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 116 | void ScopeMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | ac55f9d | 2010-02-25 01:56:48 +0000 | [diff] [blame] | 117 | OS.indent(indent) << "Scope\n"; |
Javed Absar | 776bf1d | 2017-10-16 06:43:54 +0000 | [diff] [blame] | 118 | for (const Matcher *C : Children) { |
| 119 | if (!C) |
Chris Lattner | 102a8a0 | 2010-02-28 20:49:53 +0000 | [diff] [blame] | 120 | OS.indent(indent+1) << "NULL POINTER\n"; |
| 121 | else |
Javed Absar | 776bf1d | 2017-10-16 06:43:54 +0000 | [diff] [blame] | 122 | C->print(OS, indent+2); |
Chris Lattner | 102a8a0 | 2010-02-28 20:49:53 +0000 | [diff] [blame] | 123 | } |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 124 | } |
| 125 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 126 | void RecordMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 127 | OS.indent(indent) << "Record\n"; |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 130 | void RecordChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | ab41756 | 2010-02-24 07:31:45 +0000 | [diff] [blame] | 131 | OS.indent(indent) << "RecordChild: " << ChildNo << '\n'; |
Chris Lattner | ab41756 | 2010-02-24 07:31:45 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 134 | void RecordMemRefMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 132df65 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 135 | OS.indent(indent) << "RecordMemRef\n"; |
Chris Lattner | 132df65 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Chris Lattner | f7f9e8c | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 138 | void CaptureGlueInputMatcher::printImpl(raw_ostream &OS, unsigned indent) const{ |
| 139 | OS.indent(indent) << "CaptureGlueInput\n"; |
Chris Lattner | 132df65 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 142 | void MoveChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 143 | OS.indent(indent) << "MoveChild " << ChildNo << '\n'; |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 146 | void MoveParentMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 147 | OS.indent(indent) << "MoveParent\n"; |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 150 | void CheckSameMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 151 | OS.indent(indent) << "CheckSame " << MatchNumber << '\n'; |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Craig Topper | a1bbc32 | 2013-10-05 05:38:16 +0000 | [diff] [blame] | 154 | void CheckChildSameMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
| 155 | OS.indent(indent) << "CheckChild" << ChildNo << "Same\n"; |
| 156 | } |
| 157 | |
Chris Lattner | 2c3f649 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 158 | void CheckPatternPredicateMatcher:: |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 159 | printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 160 | OS.indent(indent) << "CheckPatternPredicate " << Predicate << '\n'; |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 163 | void CheckPredicateMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 514e292 | 2011-04-17 21:38:24 +0000 | [diff] [blame] | 164 | OS.indent(indent) << "CheckPredicate " << getPredicate().getFnName() << '\n'; |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 167 | void CheckOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 278606b | 2010-02-27 21:48:43 +0000 | [diff] [blame] | 168 | OS.indent(indent) << "CheckOpcode " << Opcode.getEnumName() << '\n'; |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Chris Lattner | f4d1775 | 2010-03-01 06:59:22 +0000 | [diff] [blame] | 171 | void SwitchOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
| 172 | OS.indent(indent) << "SwitchOpcode: {\n"; |
Javed Absar | 776bf1d | 2017-10-16 06:43:54 +0000 | [diff] [blame] | 173 | for (const auto &C : Cases) { |
| 174 | OS.indent(indent) << "case " << C.first->getEnumName() << ":\n"; |
| 175 | C.second->print(OS, indent+2); |
Chris Lattner | f4d1775 | 2010-03-01 06:59:22 +0000 | [diff] [blame] | 176 | } |
| 177 | OS.indent(indent) << "}\n"; |
| 178 | } |
| 179 | |
| 180 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 181 | void CheckTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 6c2d178 | 2010-03-24 00:41:19 +0000 | [diff] [blame] | 182 | OS.indent(indent) << "CheckType " << getEnumName(Type) << ", ResNo=" |
| 183 | << ResNo << '\n'; |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Chris Lattner | 3e1ffd0 | 2010-03-03 06:28:15 +0000 | [diff] [blame] | 186 | void SwitchTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
| 187 | OS.indent(indent) << "SwitchType: {\n"; |
Javed Absar | 776bf1d | 2017-10-16 06:43:54 +0000 | [diff] [blame] | 188 | for (const auto &C : Cases) { |
| 189 | OS.indent(indent) << "case " << getEnumName(C.first) << ":\n"; |
| 190 | C.second->print(OS, indent+2); |
Chris Lattner | 3e1ffd0 | 2010-03-03 06:28:15 +0000 | [diff] [blame] | 191 | } |
| 192 | OS.indent(indent) << "}\n"; |
| 193 | } |
| 194 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 195 | void CheckChildTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 0c95baa | 2010-02-24 20:15:25 +0000 | [diff] [blame] | 196 | OS.indent(indent) << "CheckChildType " << ChildNo << " " |
| 197 | << getEnumName(Type) << '\n'; |
Chris Lattner | 0c95baa | 2010-02-24 20:15:25 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 201 | void CheckIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 202 | OS.indent(indent) << "CheckInteger " << Value << '\n'; |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Craig Topper | 7ca1d18 | 2014-02-05 05:44:28 +0000 | [diff] [blame] | 205 | void CheckChildIntegerMatcher::printImpl(raw_ostream &OS, |
| 206 | unsigned indent) const { |
| 207 | OS.indent(indent) << "CheckChildInteger " << ChildNo << " " << Value << '\n'; |
| 208 | } |
| 209 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 210 | void CheckCondCodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 211 | OS.indent(indent) << "CheckCondCode ISD::" << CondCodeName << '\n'; |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Craig Topper | 8c9724e | 2019-02-25 03:11:44 +0000 | [diff] [blame] | 214 | void CheckChild2CondCodeMatcher::printImpl(raw_ostream &OS, |
| 215 | unsigned indent) const { |
| 216 | OS.indent(indent) << "CheckChild2CondCode ISD::" << CondCodeName << '\n'; |
| 217 | } |
| 218 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 219 | void CheckValueTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 220 | OS.indent(indent) << "CheckValueType MVT::" << TypeName << '\n'; |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 223 | void CheckComplexPatMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 224 | OS.indent(indent) << "CheckComplexPat " << Pattern.getSelectFunc() << '\n'; |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 227 | void CheckAndImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 228 | OS.indent(indent) << "CheckAndImm " << Value << '\n'; |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 231 | void CheckOrImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 232 | OS.indent(indent) << "CheckOrImm " << Value << '\n'; |
Chris Lattner | b02cdaa | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 235 | void CheckFoldableChainNodeMatcher::printImpl(raw_ostream &OS, |
Chris Lattner | f8695c1 | 2010-02-16 19:15:55 +0000 | [diff] [blame] | 236 | unsigned indent) const { |
| 237 | OS.indent(indent) << "CheckFoldableChainNode\n"; |
Chris Lattner | aa7d3e0 | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 238 | } |
Chris Lattner | f8a5bb0 | 2010-02-17 06:23:39 +0000 | [diff] [blame] | 239 | |
Craig Topper | 1a872f2 | 2019-03-10 05:21:52 +0000 | [diff] [blame] | 240 | void CheckImmAllOnesVMatcher::printImpl(raw_ostream &OS, |
| 241 | unsigned indent) const { |
| 242 | OS.indent(indent) << "CheckAllOnesV\n"; |
| 243 | } |
| 244 | |
| 245 | void CheckImmAllZerosVMatcher::printImpl(raw_ostream &OS, |
| 246 | unsigned indent) const { |
| 247 | OS.indent(indent) << "CheckAllZerosV\n"; |
| 248 | } |
| 249 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 250 | void EmitIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Craig Topper | 6ff4626 | 2016-04-17 17:37:33 +0000 | [diff] [blame] | 251 | OS.indent(indent) << "EmitInteger " << Val << " VT=" << getEnumName(VT) |
| 252 | << '\n'; |
Chris Lattner | 132df65 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 253 | } |
| 254 | |
Chris Lattner | 2c3f649 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 255 | void EmitStringIntegerMatcher:: |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 256 | printImpl(raw_ostream &OS, unsigned indent) const { |
Craig Topper | 6ff4626 | 2016-04-17 17:37:33 +0000 | [diff] [blame] | 257 | OS.indent(indent) << "EmitStringInteger " << Val << " VT=" << getEnumName(VT) |
| 258 | << '\n'; |
Chris Lattner | 42a7ba7 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 261 | void EmitRegisterMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 132df65 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 262 | OS.indent(indent) << "EmitRegister "; |
Chris Lattner | 42a7ba7 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 263 | if (Reg) |
| 264 | OS << Reg->getName(); |
| 265 | else |
| 266 | OS << "zero_reg"; |
Craig Topper | 6ff4626 | 2016-04-17 17:37:33 +0000 | [diff] [blame] | 267 | OS << " VT=" << getEnumName(VT) << '\n'; |
Chris Lattner | 42a7ba7 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Chris Lattner | 2c3f649 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 270 | void EmitConvertToTargetMatcher:: |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 271 | printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 132df65 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 272 | OS.indent(indent) << "EmitConvertToTarget " << Slot << '\n'; |
Chris Lattner | 132df65 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Chris Lattner | 2c3f649 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 275 | void EmitMergeInputChainsMatcher:: |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 276 | printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 132df65 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 277 | OS.indent(indent) << "EmitMergeInputChains <todo: args>\n"; |
Chris Lattner | 132df65 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 278 | } |
| 279 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 280 | void EmitCopyToRegMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 132df65 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 281 | OS.indent(indent) << "EmitCopyToReg <todo: args>\n"; |
Chris Lattner | 132df65 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 284 | void EmitNodeXFormMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 132df65 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 285 | OS.indent(indent) << "EmitNodeXForm " << NodeXForm->getName() |
| 286 | << " Slot=" << Slot << '\n'; |
Chris Lattner | 132df65 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | |
Chris Lattner | c3f80e0 | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 290 | void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, unsigned indent) const { |
| 291 | OS.indent(indent); |
Chris Lattner | 9d67dca | 2010-02-28 20:55:18 +0000 | [diff] [blame] | 292 | OS << (isa<MorphNodeToMatcher>(this) ? "MorphNodeTo: " : "EmitNode: ") |
Chris Lattner | c3f80e0 | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 293 | << OpcodeName << ": <todo flags> "; |
Chris Lattner | 132df65 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 294 | |
| 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 Lattner | 132df65 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 301 | } |
| 302 | |
Chris Lattner | 1f2adb6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 303 | void CompleteMatchMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 79eaeb4 | 2010-02-21 06:03:07 +0000 | [diff] [blame] | 304 | OS.indent(indent) << "CompleteMatch <todo args>\n"; |
Chris Lattner | 132df65 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 305 | OS.indent(indent) << "Src = " << *Pattern.getSrcPattern() << "\n"; |
| 306 | OS.indent(indent) << "Dst = " << *Pattern.getDstPattern() << "\n"; |
Chris Lattner | 132df65 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Chris Lattner | f4d1775 | 2010-03-01 06:59:22 +0000 | [diff] [blame] | 309 | bool CheckOpcodeMatcher::isEqualImpl(const Matcher *M) const { |
| 310 | // Note: pointer equality isn't enough here, we have to check the enum names |
Jim Grosbach | 65586fe | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 311 | // to ensure that the nodes are for the same opcode. |
Chris Lattner | f4d1775 | 2010-03-01 06:59:22 +0000 | [diff] [blame] | 312 | return cast<CheckOpcodeMatcher>(M)->Opcode.getEnumName() == |
| 313 | Opcode.getEnumName(); |
| 314 | } |
| 315 | |
Chris Lattner | c3f80e0 | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 316 | bool EmitNodeMatcherCommon::isEqualImpl(const Matcher *m) const { |
| 317 | const EmitNodeMatcherCommon *M = cast<EmitNodeMatcherCommon>(m); |
Chris Lattner | 212e8c8 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 318 | return M->OpcodeName == OpcodeName && M->VTs == VTs && |
| 319 | M->Operands == Operands && M->HasChain == HasChain && |
Chris Lattner | 2a0a3b4 | 2010-12-23 18:28:41 +0000 | [diff] [blame] | 320 | M->HasInGlue == HasInGlue && M->HasOutGlue == HasOutGlue && |
Chris Lattner | a838264 | 2010-02-28 21:53:42 +0000 | [diff] [blame] | 321 | M->HasMemRefs == HasMemRefs && |
Chris Lattner | 212e8c8 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 322 | M->NumFixedArityOperands == NumFixedArityOperands; |
| 323 | } |
| 324 | |
David Blaikie | a379b181 | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 325 | void EmitNodeMatcher::anchor() { } |
| 326 | |
| 327 | void MorphNodeToMatcher::anchor() { } |
| 328 | |
Chris Lattner | c577b81 | 2010-02-27 07:49:13 +0000 | [diff] [blame] | 329 | // isContradictoryImpl Implementations. |
| 330 | |
Chris Lattner | c577b81 | 2010-02-27 07:49:13 +0000 | [diff] [blame] | 331 | static 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 Grosbach | 65586fe | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 336 | |
Chris Lattner | c577b81 | 2010-02-27 07:49:13 +0000 | [diff] [blame] | 337 | // 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 Grosbach | 65586fe | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 341 | |
Chris Lattner | c577b81 | 2010-02-27 07:49:13 +0000 | [diff] [blame] | 342 | if (T2 == MVT::iPTR) |
| 343 | return !MVT(T1).isInteger() || MVT(T1).isVector(); |
Jim Grosbach | 65586fe | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 344 | |
Chris Lattner | c577b81 | 2010-02-27 07:49:13 +0000 | [diff] [blame] | 345 | // Otherwise, they are two different non-iPTR types, they conflict. |
| 346 | return true; |
| 347 | } |
| 348 | |
Chris Lattner | 99e53b3 | 2010-02-28 00:22:30 +0000 | [diff] [blame] | 349 | bool 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 Lattner | f4d1775 | 2010-03-01 06:59:22 +0000 | [diff] [blame] | 352 | // Note: pointer equality isn't enough here, we have to check the enum names |
Jim Grosbach | 65586fe | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 353 | // to ensure that the nodes are for the same opcode. |
Chris Lattner | f4d1775 | 2010-03-01 06:59:22 +0000 | [diff] [blame] | 354 | return COM->getOpcode().getEnumName() != getOpcode().getEnumName(); |
Chris Lattner | 99e53b3 | 2010-02-28 00:22:30 +0000 | [diff] [blame] | 355 | } |
Jim Grosbach | 65586fe | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 356 | |
Chris Lattner | 99e53b3 | 2010-02-28 00:22:30 +0000 | [diff] [blame] | 357 | // 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 Lattner | 6c2d178 | 2010-03-24 00:41:19 +0000 | [diff] [blame] | 361 | // If checking for a result the opcode doesn't have, it can't match. |
| 362 | if (CT->getResNo() >= getOpcode().getNumResults()) |
| 363 | return true; |
Jim Grosbach | 65586fe | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 364 | |
Chris Lattner | 6c2d178 | 2010-03-24 00:41:19 +0000 | [diff] [blame] | 365 | MVT::SimpleValueType NodeType = getOpcode().getKnownType(CT->getResNo()); |
Chris Lattner | da5b4ad | 2010-03-19 01:14:27 +0000 | [diff] [blame] | 366 | if (NodeType != MVT::Other) |
| 367 | return TypesAreContradictory(NodeType, CT->getType()); |
Chris Lattner | 99e53b3 | 2010-02-28 00:22:30 +0000 | [diff] [blame] | 368 | } |
Jim Grosbach | 65586fe | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 369 | |
Chris Lattner | 99e53b3 | 2010-02-28 00:22:30 +0000 | [diff] [blame] | 370 | return false; |
| 371 | } |
| 372 | |
Chris Lattner | c577b81 | 2010-02-27 07:49:13 +0000 | [diff] [blame] | 373 | bool 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 | |
| 379 | bool 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 Grosbach | 65586fe | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 385 | |
Chris Lattner | c577b81 | 2010-02-27 07:49:13 +0000 | [diff] [blame] | 386 | return TypesAreContradictory(getType(), CC->getType()); |
| 387 | } |
| 388 | return false; |
| 389 | } |
Jim Grosbach | 65586fe | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 390 | |
Chris Lattner | 2586c86 | 2010-02-27 08:11:15 +0000 | [diff] [blame] | 391 | bool 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 Lattner | 9c791d8 | 2010-03-07 06:29:26 +0000 | [diff] [blame] | 396 | |
Craig Topper | 7ca1d18 | 2014-02-05 05:44:28 +0000 | [diff] [blame] | 397 | bool 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 Lattner | 9c791d8 | 2010-03-07 06:29:26 +0000 | [diff] [blame] | 409 | bool 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 Topper | a2b144f | 2019-03-10 06:44:09 +0000 | [diff] [blame] | 415 | bool CheckImmAllOnesVMatcher::isContradictoryImpl(const Matcher *M) const { |
| 416 | // AllZeros is contradictory. |
Craig Topper | 81d1656 | 2019-03-11 16:51:37 +0000 | [diff] [blame] | 417 | return isa<CheckImmAllZerosVMatcher>(M); |
Craig Topper | a2b144f | 2019-03-10 06:44:09 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | bool CheckImmAllZerosVMatcher::isContradictoryImpl(const Matcher *M) const { |
| 421 | // AllOnes is contradictory. |
Craig Topper | 81d1656 | 2019-03-11 16:51:37 +0000 | [diff] [blame] | 422 | return isa<CheckImmAllOnesVMatcher>(M); |
Craig Topper | a2b144f | 2019-03-10 06:44:09 +0000 | [diff] [blame] | 423 | } |