Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 1 | //===- 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 Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 13 | #include "Record.h" |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 14 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/StringExtras.h" |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 16 | using namespace llvm; |
| 17 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 18 | void Matcher::dump() const { |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 19 | print(errs(), 0); |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 20 | } |
| 21 | |
Chris Lattner | a5028a6 | 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 | bd8227f | 2010-02-18 02:53:41 +0000 | [diff] [blame] | 24 | if (Next) |
| 25 | return Next->print(OS, indent); |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 26 | } |
| 27 | |
Chris Lattner | 82781b9 | 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 | 48aa575 | 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(); |
| 38 | |
| 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 | |
| 44 | if (Cur == 0) return 0; |
| 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 | |
| 64 | /// canMoveBefore - Return true if it is safe to move the current matcher |
| 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(); |
| 70 | |
| 71 | // We can move record nodes across simple predicates. |
| 72 | if (isSimplePredicateOrRecordNode()) |
| 73 | return isSimplePredicateNode(); |
| 74 | |
| 75 | // We can't move record nodes across each other etc. |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | |
Chris Lattner | d6c8472 | 2010-02-25 19:00:39 +0000 | [diff] [blame] | 80 | ScopeMatcher::~ScopeMatcher() { |
| 81 | for (unsigned i = 0, e = Children.size(); i != e; ++i) |
| 82 | delete Children[i]; |
| 83 | } |
| 84 | |
| 85 | |
| 86 | // printImpl methods. |
| 87 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 88 | void ScopeMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 60df53e | 2010-02-25 01:56:48 +0000 | [diff] [blame] | 89 | OS.indent(indent) << "Scope\n"; |
Chris Lattner | c78f2a3 | 2010-02-28 20:49:53 +0000 | [diff] [blame] | 90 | for (unsigned i = 0, e = getNumChildren(); i != e; ++i) { |
| 91 | if (getChild(i) == 0) |
| 92 | OS.indent(indent+1) << "NULL POINTER\n"; |
| 93 | else |
| 94 | getChild(i)->print(OS, indent+2); |
| 95 | } |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 98 | void RecordMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 99 | OS.indent(indent) << "Record\n"; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 102 | void RecordChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 19b5a75 | 2010-02-24 07:31:45 +0000 | [diff] [blame] | 103 | OS.indent(indent) << "RecordChild: " << ChildNo << '\n'; |
Chris Lattner | 19b5a75 | 2010-02-24 07:31:45 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 106 | void RecordMemRefMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 107 | OS.indent(indent) << "RecordMemRef\n"; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 110 | void CaptureFlagInputMatcher::printImpl(raw_ostream &OS, unsigned indent) const{ |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 111 | OS.indent(indent) << "CaptureFlagInput\n"; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 112 | } |
| 113 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 114 | void MoveChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 115 | OS.indent(indent) << "MoveChild " << ChildNo << '\n'; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 118 | void MoveParentMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 119 | OS.indent(indent) << "MoveParent\n"; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 122 | void CheckSameMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 123 | OS.indent(indent) << "CheckSame " << MatchNumber << '\n'; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 124 | } |
| 125 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 126 | void CheckPatternPredicateMatcher:: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 127 | printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 128 | OS.indent(indent) << "CheckPatternPredicate " << Predicate << '\n'; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 131 | void CheckPredicateMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 132 | OS.indent(indent) << "CheckPredicate " << PredName << '\n'; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 135 | void CheckOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | a230f96 | 2010-02-27 21:48:43 +0000 | [diff] [blame] | 136 | OS.indent(indent) << "CheckOpcode " << Opcode.getEnumName() << '\n'; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Chris Lattner | eb66921 | 2010-03-01 06:59:22 +0000 | [diff] [blame] | 139 | void SwitchOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
| 140 | OS.indent(indent) << "SwitchOpcode: {\n"; |
| 141 | for (unsigned i = 0, e = Cases.size(); i != e; ++i) { |
| 142 | OS.indent(indent) << "case " << Cases[i].first->getEnumName() << ":\n"; |
| 143 | Cases[i].second->print(OS, indent+2); |
| 144 | } |
| 145 | OS.indent(indent) << "}\n"; |
| 146 | } |
| 147 | |
| 148 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 149 | void CheckTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 084df62 | 2010-03-24 00:41:19 +0000 | [diff] [blame] | 150 | OS.indent(indent) << "CheckType " << getEnumName(Type) << ", ResNo=" |
| 151 | << ResNo << '\n'; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Chris Lattner | cfe2eab | 2010-03-03 06:28:15 +0000 | [diff] [blame] | 154 | void SwitchTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
| 155 | OS.indent(indent) << "SwitchType: {\n"; |
| 156 | for (unsigned i = 0, e = Cases.size(); i != e; ++i) { |
| 157 | OS.indent(indent) << "case " << getEnumName(Cases[i].first) << ":\n"; |
| 158 | Cases[i].second->print(OS, indent+2); |
| 159 | } |
| 160 | OS.indent(indent) << "}\n"; |
| 161 | } |
| 162 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 163 | void CheckChildTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 23cfda7 | 2010-02-24 20:15:25 +0000 | [diff] [blame] | 164 | OS.indent(indent) << "CheckChildType " << ChildNo << " " |
| 165 | << getEnumName(Type) << '\n'; |
Chris Lattner | 23cfda7 | 2010-02-24 20:15:25 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 169 | void CheckIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 170 | OS.indent(indent) << "CheckInteger " << Value << '\n'; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 173 | void CheckCondCodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 174 | OS.indent(indent) << "CheckCondCode ISD::" << CondCodeName << '\n'; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 177 | void CheckValueTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 178 | OS.indent(indent) << "CheckValueType MVT::" << TypeName << '\n'; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 181 | void CheckComplexPatMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 182 | OS.indent(indent) << "CheckComplexPat " << Pattern.getSelectFunc() << '\n'; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 185 | void CheckAndImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 186 | OS.indent(indent) << "CheckAndImm " << Value << '\n'; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 189 | void CheckOrImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 190 | OS.indent(indent) << "CheckOrImm " << Value << '\n'; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 193 | void CheckFoldableChainNodeMatcher::printImpl(raw_ostream &OS, |
Chris Lattner | 21390d7 | 2010-02-16 19:15:55 +0000 | [diff] [blame] | 194 | unsigned indent) const { |
| 195 | OS.indent(indent) << "CheckFoldableChainNode\n"; |
Chris Lattner | e39650a | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 196 | } |
Chris Lattner | 9a747f1 | 2010-02-17 06:23:39 +0000 | [diff] [blame] | 197 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 198 | void EmitIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 199 | OS.indent(indent) << "EmitInteger " << Val << " VT=" << VT << '\n'; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 202 | void EmitStringIntegerMatcher:: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 203 | printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 204 | OS.indent(indent) << "EmitStringInteger " << Val << " VT=" << VT << '\n'; |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 205 | } |
| 206 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 207 | void EmitRegisterMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 208 | OS.indent(indent) << "EmitRegister "; |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 209 | if (Reg) |
| 210 | OS << Reg->getName(); |
| 211 | else |
| 212 | OS << "zero_reg"; |
| 213 | OS << " VT=" << VT << '\n'; |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 216 | void EmitConvertToTargetMatcher:: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 217 | printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 218 | OS.indent(indent) << "EmitConvertToTarget " << Slot << '\n'; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 221 | void EmitMergeInputChainsMatcher:: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 222 | printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 223 | OS.indent(indent) << "EmitMergeInputChains <todo: args>\n"; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 226 | void EmitCopyToRegMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 227 | OS.indent(indent) << "EmitCopyToReg <todo: args>\n"; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 230 | void EmitNodeXFormMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 231 | OS.indent(indent) << "EmitNodeXForm " << NodeXForm->getName() |
| 232 | << " Slot=" << Slot << '\n'; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 236 | void EmitNodeMatcherCommon::printImpl(raw_ostream &OS, unsigned indent) const { |
| 237 | OS.indent(indent); |
Chris Lattner | 9a21500 | 2010-02-28 20:55:18 +0000 | [diff] [blame] | 238 | OS << (isa<MorphNodeToMatcher>(this) ? "MorphNodeTo: " : "EmitNode: ") |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 239 | << OpcodeName << ": <todo flags> "; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 240 | |
| 241 | for (unsigned i = 0, e = VTs.size(); i != e; ++i) |
| 242 | OS << ' ' << getEnumName(VTs[i]); |
| 243 | OS << '('; |
| 244 | for (unsigned i = 0, e = Operands.size(); i != e; ++i) |
| 245 | OS << Operands[i] << ' '; |
| 246 | OS << ")\n"; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 247 | } |
| 248 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 249 | void MarkFlagResultsMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 02f7358 | 2010-02-24 05:33:42 +0000 | [diff] [blame] | 250 | OS.indent(indent) << "MarkFlagResults <todo: args>\n"; |
Chris Lattner | 02f7358 | 2010-02-24 05:33:42 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 253 | void CompleteMatchMatcher::printImpl(raw_ostream &OS, unsigned indent) const { |
Chris Lattner | 77f2e27 | 2010-02-21 06:03:07 +0000 | [diff] [blame] | 254 | OS.indent(indent) << "CompleteMatch <todo args>\n"; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 255 | OS.indent(indent) << "Src = " << *Pattern.getSrcPattern() << "\n"; |
| 256 | OS.indent(indent) << "Dst = " << *Pattern.getDstPattern() << "\n"; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 259 | // getHashImpl Implementation. |
| 260 | |
| 261 | unsigned CheckPatternPredicateMatcher::getHashImpl() const { |
| 262 | return HashString(Predicate); |
| 263 | } |
| 264 | |
| 265 | unsigned CheckPredicateMatcher::getHashImpl() const { |
| 266 | return HashString(PredName); |
| 267 | } |
| 268 | |
| 269 | unsigned CheckOpcodeMatcher::getHashImpl() const { |
Chris Lattner | a230f96 | 2010-02-27 21:48:43 +0000 | [diff] [blame] | 270 | return HashString(Opcode.getEnumName()); |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 273 | unsigned CheckCondCodeMatcher::getHashImpl() const { |
| 274 | return HashString(CondCodeName); |
| 275 | } |
| 276 | |
| 277 | unsigned CheckValueTypeMatcher::getHashImpl() const { |
| 278 | return HashString(TypeName); |
| 279 | } |
| 280 | |
| 281 | unsigned EmitStringIntegerMatcher::getHashImpl() const { |
| 282 | return HashString(Val) ^ VT; |
| 283 | } |
| 284 | |
| 285 | template<typename It> |
| 286 | static unsigned HashUnsigneds(It I, It E) { |
| 287 | unsigned Result = 0; |
| 288 | for (; I != E; ++I) |
| 289 | Result = (Result<<3) ^ *I; |
| 290 | return Result; |
| 291 | } |
| 292 | |
| 293 | unsigned EmitMergeInputChainsMatcher::getHashImpl() const { |
| 294 | return HashUnsigneds(ChainNodes.begin(), ChainNodes.end()); |
| 295 | } |
| 296 | |
Chris Lattner | eb66921 | 2010-03-01 06:59:22 +0000 | [diff] [blame] | 297 | bool CheckOpcodeMatcher::isEqualImpl(const Matcher *M) const { |
| 298 | // Note: pointer equality isn't enough here, we have to check the enum names |
| 299 | // to ensure that the nodes are for the same opcode. |
| 300 | return cast<CheckOpcodeMatcher>(M)->Opcode.getEnumName() == |
| 301 | Opcode.getEnumName(); |
| 302 | } |
| 303 | |
| 304 | |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 305 | bool EmitNodeMatcherCommon::isEqualImpl(const Matcher *m) const { |
| 306 | const EmitNodeMatcherCommon *M = cast<EmitNodeMatcherCommon>(m); |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 307 | return M->OpcodeName == OpcodeName && M->VTs == VTs && |
| 308 | M->Operands == Operands && M->HasChain == HasChain && |
Chris Lattner | ff7fb60 | 2010-02-28 21:53:42 +0000 | [diff] [blame] | 309 | M->HasInFlag == HasInFlag && M->HasOutFlag == HasOutFlag && |
| 310 | M->HasMemRefs == HasMemRefs && |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 311 | M->NumFixedArityOperands == NumFixedArityOperands; |
| 312 | } |
| 313 | |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 314 | unsigned EmitNodeMatcherCommon::getHashImpl() const { |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 315 | return (HashString(OpcodeName) << 4) | Operands.size(); |
| 316 | } |
| 317 | |
| 318 | |
| 319 | unsigned MarkFlagResultsMatcher::getHashImpl() const { |
| 320 | return HashUnsigneds(FlagResultNodes.begin(), FlagResultNodes.end()); |
| 321 | } |
| 322 | |
| 323 | unsigned CompleteMatchMatcher::getHashImpl() const { |
| 324 | return HashUnsigneds(Results.begin(), Results.end()) ^ |
| 325 | ((unsigned)(intptr_t)&Pattern << 8); |
| 326 | } |
Chris Lattner | 82781b9 | 2010-02-27 07:49:13 +0000 | [diff] [blame] | 327 | |
| 328 | // isContradictoryImpl Implementations. |
| 329 | |
Chris Lattner | 82781b9 | 2010-02-27 07:49:13 +0000 | [diff] [blame] | 330 | static bool TypesAreContradictory(MVT::SimpleValueType T1, |
| 331 | MVT::SimpleValueType T2) { |
| 332 | // If the two types are the same, then they are the same, so they don't |
| 333 | // contradict. |
| 334 | if (T1 == T2) return false; |
| 335 | |
| 336 | // If either type is about iPtr, then they don't conflict unless the other |
| 337 | // one is not a scalar integer type. |
| 338 | if (T1 == MVT::iPTR) |
| 339 | return !MVT(T2).isInteger() || MVT(T2).isVector(); |
| 340 | |
| 341 | if (T2 == MVT::iPTR) |
| 342 | return !MVT(T1).isInteger() || MVT(T1).isVector(); |
| 343 | |
| 344 | // Otherwise, they are two different non-iPTR types, they conflict. |
| 345 | return true; |
| 346 | } |
| 347 | |
Chris Lattner | 2257981 | 2010-02-28 00:22:30 +0000 | [diff] [blame] | 348 | bool CheckOpcodeMatcher::isContradictoryImpl(const Matcher *M) const { |
| 349 | if (const CheckOpcodeMatcher *COM = dyn_cast<CheckOpcodeMatcher>(M)) { |
| 350 | // One node can't have two different opcodes! |
Chris Lattner | eb66921 | 2010-03-01 06:59:22 +0000 | [diff] [blame] | 351 | // Note: pointer equality isn't enough here, we have to check the enum names |
| 352 | // to ensure that the nodes are for the same opcode. |
| 353 | return COM->getOpcode().getEnumName() != getOpcode().getEnumName(); |
Chris Lattner | 2257981 | 2010-02-28 00:22:30 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Chris Lattner | 2257981 | 2010-02-28 00:22:30 +0000 | [diff] [blame] | 356 | // If the node has a known type, and if the type we're checking for is |
| 357 | // different, then we know they contradict. For example, a check for |
| 358 | // ISD::STORE will never be true at the same time a check for Type i32 is. |
| 359 | if (const CheckTypeMatcher *CT = dyn_cast<CheckTypeMatcher>(M)) { |
Chris Lattner | 084df62 | 2010-03-24 00:41:19 +0000 | [diff] [blame] | 360 | // If checking for a result the opcode doesn't have, it can't match. |
| 361 | if (CT->getResNo() >= getOpcode().getNumResults()) |
| 362 | return true; |
| 363 | |
| 364 | MVT::SimpleValueType NodeType = getOpcode().getKnownType(CT->getResNo()); |
Chris Lattner | aac5b5b | 2010-03-19 01:14:27 +0000 | [diff] [blame] | 365 | if (NodeType != MVT::Other) |
| 366 | return TypesAreContradictory(NodeType, CT->getType()); |
Chris Lattner | 2257981 | 2010-02-28 00:22:30 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | return false; |
| 370 | } |
| 371 | |
Chris Lattner | 82781b9 | 2010-02-27 07:49:13 +0000 | [diff] [blame] | 372 | bool CheckTypeMatcher::isContradictoryImpl(const Matcher *M) const { |
| 373 | if (const CheckTypeMatcher *CT = dyn_cast<CheckTypeMatcher>(M)) |
| 374 | return TypesAreContradictory(getType(), CT->getType()); |
| 375 | return false; |
| 376 | } |
| 377 | |
| 378 | bool CheckChildTypeMatcher::isContradictoryImpl(const Matcher *M) const { |
| 379 | if (const CheckChildTypeMatcher *CC = dyn_cast<CheckChildTypeMatcher>(M)) { |
| 380 | // If the two checks are about different nodes, we don't know if they |
| 381 | // conflict! |
| 382 | if (CC->getChildNo() != getChildNo()) |
| 383 | return false; |
| 384 | |
| 385 | return TypesAreContradictory(getType(), CC->getType()); |
| 386 | } |
| 387 | return false; |
| 388 | } |
| 389 | |
Chris Lattner | 2478962 | 2010-02-27 08:11:15 +0000 | [diff] [blame] | 390 | bool CheckIntegerMatcher::isContradictoryImpl(const Matcher *M) const { |
| 391 | if (const CheckIntegerMatcher *CIM = dyn_cast<CheckIntegerMatcher>(M)) |
| 392 | return CIM->getValue() != getValue(); |
| 393 | return false; |
| 394 | } |
Chris Lattner | 48aa575 | 2010-03-07 06:29:26 +0000 | [diff] [blame] | 395 | |
| 396 | bool CheckValueTypeMatcher::isContradictoryImpl(const Matcher *M) const { |
| 397 | if (const CheckValueTypeMatcher *CVT = dyn_cast<CheckValueTypeMatcher>(M)) |
| 398 | return CVT->getTypeName() != getTypeName(); |
| 399 | return false; |
| 400 | } |
| 401 | |