Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 1 | //===- DAGISelMatcherGen.cpp - Matcher generator --------------------------===// |
| 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 "Record.h" |
Chris Lattner | 785d16f | 2010-02-17 02:16:19 +0000 | [diff] [blame] | 13 | #include "llvm/ADT/SmallVector.h" |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/StringMap.h" |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 15 | #include <utility> |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 16 | using namespace llvm; |
| 17 | |
Chris Lattner | c94fa4c | 2010-02-19 00:27:40 +0000 | [diff] [blame] | 18 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 19 | /// getRegisterValueType - Look up and return the ValueType of the specified |
| 20 | /// register. If the register is a member of multiple register classes which |
| 21 | /// have different associated types, return MVT::Other. |
| 22 | static MVT::SimpleValueType getRegisterValueType(Record *R, |
| 23 | const CodeGenTarget &T) { |
| 24 | bool FoundRC = false; |
| 25 | MVT::SimpleValueType VT = MVT::Other; |
| 26 | const std::vector<CodeGenRegisterClass> &RCs = T.getRegisterClasses(); |
| 27 | std::vector<Record*>::const_iterator Element; |
| 28 | |
| 29 | for (unsigned rc = 0, e = RCs.size(); rc != e; ++rc) { |
| 30 | const CodeGenRegisterClass &RC = RCs[rc]; |
| 31 | if (!std::count(RC.Elements.begin(), RC.Elements.end(), R)) |
| 32 | continue; |
| 33 | |
| 34 | if (!FoundRC) { |
| 35 | FoundRC = true; |
| 36 | VT = RC.getValueTypeNum(0); |
| 37 | continue; |
Chris Lattner | c94fa4c | 2010-02-19 00:27:40 +0000 | [diff] [blame] | 38 | } |
Chris Lattner | 67ea6a7 | 2010-03-01 22:49:06 +0000 | [diff] [blame^] | 39 | |
| 40 | // If this occurs in multiple register classes, they all have to agree. |
| 41 | assert(VT == RC.getValueTypeNum(0)); |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 42 | } |
| 43 | return VT; |
| 44 | } |
| 45 | |
| 46 | |
| 47 | namespace { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 48 | class MatcherGen { |
| 49 | const PatternToMatch &Pattern; |
| 50 | const CodeGenDAGPatterns &CGP; |
| 51 | |
| 52 | /// PatWithNoTypes - This is a clone of Pattern.getSrcPattern() that starts |
| 53 | /// out with all of the types removed. This allows us to insert type checks |
| 54 | /// as we scan the tree. |
| 55 | TreePatternNode *PatWithNoTypes; |
| 56 | |
| 57 | /// VariableMap - A map from variable names ('$dst') to the recorded operand |
| 58 | /// number that they were captured as. These are biased by 1 to make |
| 59 | /// insertion easier. |
| 60 | StringMap<unsigned> VariableMap; |
Chris Lattner | c94fa4c | 2010-02-19 00:27:40 +0000 | [diff] [blame] | 61 | |
| 62 | /// NextRecordedOperandNo - As we emit opcodes to record matched values in |
| 63 | /// the RecordedNodes array, this keeps track of which slot will be next to |
| 64 | /// record into. |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 65 | unsigned NextRecordedOperandNo; |
| 66 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 67 | /// MatchedChainNodes - This maintains the position in the recorded nodes |
| 68 | /// array of all of the recorded input nodes that have chains. |
| 69 | SmallVector<unsigned, 2> MatchedChainNodes; |
Chris Lattner | 02f7358 | 2010-02-24 05:33:42 +0000 | [diff] [blame] | 70 | |
| 71 | /// MatchedFlagResultNodes - This maintains the position in the recorded |
| 72 | /// nodes array of all of the recorded input nodes that have flag results. |
| 73 | SmallVector<unsigned, 2> MatchedFlagResultNodes; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 74 | |
| 75 | /// PhysRegInputs - List list has an entry for each explicitly specified |
| 76 | /// physreg input to the pattern. The first elt is the Register node, the |
| 77 | /// second is the recorded slot number the input pattern match saved it in. |
| 78 | SmallVector<std::pair<Record*, unsigned>, 2> PhysRegInputs; |
| 79 | |
Chris Lattner | 785d16f | 2010-02-17 02:16:19 +0000 | [diff] [blame] | 80 | /// Matcher - This is the top level of the generated matcher, the result. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 81 | Matcher *TheMatcher; |
Chris Lattner | 785d16f | 2010-02-17 02:16:19 +0000 | [diff] [blame] | 82 | |
| 83 | /// CurPredicate - As we emit matcher nodes, this points to the latest check |
Chris Lattner | bd8227f | 2010-02-18 02:53:41 +0000 | [diff] [blame] | 84 | /// which should have future checks stuck into its Next position. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 85 | Matcher *CurPredicate; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 86 | public: |
| 87 | MatcherGen(const PatternToMatch &pattern, const CodeGenDAGPatterns &cgp); |
| 88 | |
| 89 | ~MatcherGen() { |
| 90 | delete PatWithNoTypes; |
| 91 | } |
| 92 | |
Chris Lattner | fa342fa | 2010-03-01 07:17:40 +0000 | [diff] [blame] | 93 | bool EmitMatcherCode(unsigned Variant); |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 94 | void EmitResultCode(); |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 95 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 96 | Matcher *GetMatcher() const { return TheMatcher; } |
| 97 | Matcher *GetCurPredicate() const { return CurPredicate; } |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 98 | private: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 99 | void AddMatcher(Matcher *NewNode); |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 100 | void InferPossibleTypes(); |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 101 | |
| 102 | // Matcher Generation. |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 103 | void EmitMatchCode(const TreePatternNode *N, TreePatternNode *NodeNoTypes); |
| 104 | void EmitLeafMatchCode(const TreePatternNode *N); |
| 105 | void EmitOperatorMatchCode(const TreePatternNode *N, |
| 106 | TreePatternNode *NodeNoTypes); |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 107 | |
| 108 | // Result Code Generation. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 109 | unsigned getNamedArgumentSlot(StringRef Name) { |
| 110 | unsigned VarMapEntry = VariableMap[Name]; |
| 111 | assert(VarMapEntry != 0 && |
| 112 | "Variable referenced but not defined and not caught earlier!"); |
| 113 | return VarMapEntry-1; |
| 114 | } |
| 115 | |
| 116 | /// GetInstPatternNode - Get the pattern for an instruction. |
| 117 | const TreePatternNode *GetInstPatternNode(const DAGInstruction &Ins, |
| 118 | const TreePatternNode *N); |
| 119 | |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 120 | void EmitResultOperand(const TreePatternNode *N, |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 121 | SmallVectorImpl<unsigned> &ResultOps); |
| 122 | void EmitResultOfNamedOperand(const TreePatternNode *N, |
| 123 | SmallVectorImpl<unsigned> &ResultOps); |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 124 | void EmitResultLeafAsOperand(const TreePatternNode *N, |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 125 | SmallVectorImpl<unsigned> &ResultOps); |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 126 | void EmitResultInstructionAsOperand(const TreePatternNode *N, |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 127 | SmallVectorImpl<unsigned> &ResultOps); |
| 128 | void EmitResultSDNodeXFormAsOperand(const TreePatternNode *N, |
| 129 | SmallVectorImpl<unsigned> &ResultOps); |
| 130 | }; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 131 | |
| 132 | } // end anon namespace. |
| 133 | |
| 134 | MatcherGen::MatcherGen(const PatternToMatch &pattern, |
| 135 | const CodeGenDAGPatterns &cgp) |
Chris Lattner | 853b919 | 2010-02-19 00:33:13 +0000 | [diff] [blame] | 136 | : Pattern(pattern), CGP(cgp), NextRecordedOperandNo(0), |
Chris Lattner | 01bcd94 | 2010-03-01 22:46:42 +0000 | [diff] [blame] | 137 | TheMatcher(0), CurPredicate(0) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 138 | // We need to produce the matcher tree for the patterns source pattern. To do |
| 139 | // this we need to match the structure as well as the types. To do the type |
| 140 | // matching, we want to figure out the fewest number of type checks we need to |
| 141 | // emit. For example, if there is only one integer type supported by a |
| 142 | // target, there should be no type comparisons at all for integer patterns! |
| 143 | // |
| 144 | // To figure out the fewest number of type checks needed, clone the pattern, |
| 145 | // remove the types, then perform type inference on the pattern as a whole. |
| 146 | // If there are unresolved types, emit an explicit check for those types, |
| 147 | // apply the type to the tree, then rerun type inference. Iterate until all |
| 148 | // types are resolved. |
| 149 | // |
| 150 | PatWithNoTypes = Pattern.getSrcPattern()->clone(); |
| 151 | PatWithNoTypes->RemoveAllTypes(); |
| 152 | |
| 153 | // If there are types that are manifestly known, infer them. |
| 154 | InferPossibleTypes(); |
| 155 | } |
| 156 | |
| 157 | /// InferPossibleTypes - As we emit the pattern, we end up generating type |
| 158 | /// checks and applying them to the 'PatWithNoTypes' tree. As we do this, we |
| 159 | /// want to propagate implied types as far throughout the tree as possible so |
| 160 | /// that we avoid doing redundant type checks. This does the type propagation. |
| 161 | void MatcherGen::InferPossibleTypes() { |
| 162 | // TP - Get *SOME* tree pattern, we don't care which. It is only used for |
| 163 | // diagnostics, which we know are impossible at this point. |
| 164 | TreePattern &TP = *CGP.pf_begin()->second; |
| 165 | |
| 166 | try { |
| 167 | bool MadeChange = true; |
| 168 | while (MadeChange) |
| 169 | MadeChange = PatWithNoTypes->ApplyTypeConstraints(TP, |
| 170 | true/*Ignore reg constraints*/); |
| 171 | } catch (...) { |
| 172 | errs() << "Type constraint application shouldn't fail!"; |
| 173 | abort(); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 178 | /// AddMatcher - Add a matcher node to the current graph we're building. |
| 179 | void MatcherGen::AddMatcher(Matcher *NewNode) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 180 | if (CurPredicate != 0) |
Chris Lattner | bd8227f | 2010-02-18 02:53:41 +0000 | [diff] [blame] | 181 | CurPredicate->setNext(NewNode); |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 182 | else |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 183 | TheMatcher = NewNode; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 184 | CurPredicate = NewNode; |
| 185 | } |
| 186 | |
| 187 | |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 188 | //===----------------------------------------------------------------------===// |
| 189 | // Pattern Match Generation |
| 190 | //===----------------------------------------------------------------------===// |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 191 | |
| 192 | /// EmitLeafMatchCode - Generate matching code for leaf nodes. |
| 193 | void MatcherGen::EmitLeafMatchCode(const TreePatternNode *N) { |
| 194 | assert(N->isLeaf() && "Not a leaf?"); |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 195 | |
| 196 | // If there are node predicates for this node, generate their checks. |
| 197 | for (unsigned i = 0, e = N->getPredicateFns().size(); i != e; ++i) |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 198 | AddMatcher(new CheckPredicateMatcher(N->getPredicateFns()[i])); |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 199 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 200 | // Direct match against an integer constant. |
Chris Lattner | bd8965a | 2010-03-01 07:27:07 +0000 | [diff] [blame] | 201 | if (IntInit *II = dynamic_cast<IntInit*>(N->getLeafValue())) { |
| 202 | // If this is the root of the dag we're matching, we emit a redundant opcode |
| 203 | // check to ensure that this gets folded into the normal top-level |
| 204 | // OpcodeSwitch. |
| 205 | if (N == Pattern.getSrcPattern()) { |
| 206 | const SDNodeInfo &NI = CGP.getSDNodeInfo(CGP.getSDNodeNamed("imm")); |
| 207 | AddMatcher(new CheckOpcodeMatcher(NI)); |
| 208 | } |
| 209 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 210 | return AddMatcher(new CheckIntegerMatcher(II->getValue())); |
Chris Lattner | bd8965a | 2010-03-01 07:27:07 +0000 | [diff] [blame] | 211 | } |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 212 | |
| 213 | DefInit *DI = dynamic_cast<DefInit*>(N->getLeafValue()); |
| 214 | if (DI == 0) { |
| 215 | errs() << "Unknown leaf kind: " << *DI << "\n"; |
| 216 | abort(); |
| 217 | } |
| 218 | |
| 219 | Record *LeafRec = DI->getDef(); |
| 220 | if (// Handle register references. Nothing to do here, they always match. |
| 221 | LeafRec->isSubClassOf("RegisterClass") || |
| 222 | LeafRec->isSubClassOf("PointerLikeRegClass") || |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 223 | // Place holder for SRCVALUE nodes. Nothing to do here. |
| 224 | LeafRec->getName() == "srcvalue") |
| 225 | return; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 226 | |
| 227 | // If we have a physreg reference like (mul gpr:$src, EAX) then we need to |
| 228 | // record the register |
| 229 | if (LeafRec->isSubClassOf("Register")) { |
Chris Lattner | 0cebe61 | 2010-03-01 02:24:17 +0000 | [diff] [blame] | 230 | AddMatcher(new RecordMatcher("physreg input "+LeafRec->getName(), |
| 231 | NextRecordedOperandNo)); |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 232 | PhysRegInputs.push_back(std::make_pair(LeafRec, NextRecordedOperandNo++)); |
| 233 | return; |
| 234 | } |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 235 | |
| 236 | if (LeafRec->isSubClassOf("ValueType")) |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 237 | return AddMatcher(new CheckValueTypeMatcher(LeafRec->getName())); |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 238 | |
| 239 | if (LeafRec->isSubClassOf("CondCode")) |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 240 | return AddMatcher(new CheckCondCodeMatcher(LeafRec->getName())); |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 241 | |
| 242 | if (LeafRec->isSubClassOf("ComplexPattern")) { |
Chris Lattner | c2676b2 | 2010-02-17 00:11:30 +0000 | [diff] [blame] | 243 | // We can't model ComplexPattern uses that don't have their name taken yet. |
| 244 | // The OPC_CheckComplexPattern operation implicitly records the results. |
| 245 | if (N->getName().empty()) { |
Chris Lattner | 53a2f60 | 2010-02-16 23:16:25 +0000 | [diff] [blame] | 246 | errs() << "We expect complex pattern uses to have names: " << *N << "\n"; |
| 247 | exit(1); |
| 248 | } |
Chris Lattner | 1f2ed5f | 2010-02-22 22:18:05 +0000 | [diff] [blame] | 249 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 250 | // Handle complex pattern. |
| 251 | const ComplexPattern &CP = CGP.getComplexPattern(LeafRec); |
Chris Lattner | 1f2ed5f | 2010-02-22 22:18:05 +0000 | [diff] [blame] | 252 | |
Chris Lattner | 20df242 | 2010-02-22 23:33:44 +0000 | [diff] [blame] | 253 | // Emit a CheckComplexPat operation, which does the match (aborting if it |
| 254 | // fails) and pushes the matched operands onto the recorded nodes list. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 255 | AddMatcher(new CheckComplexPatMatcher(CP)); |
Chris Lattner | 8dc4f2b | 2010-02-17 06:08:25 +0000 | [diff] [blame] | 256 | |
Chris Lattner | 20df242 | 2010-02-22 23:33:44 +0000 | [diff] [blame] | 257 | // Record the right number of operands. |
| 258 | NextRecordedOperandNo += CP.getNumOperands(); |
| 259 | if (CP.hasProperty(SDNPHasChain)) |
| 260 | ++NextRecordedOperandNo; // Chained node operand. |
| 261 | |
Chris Lattner | 8dc4f2b | 2010-02-17 06:08:25 +0000 | [diff] [blame] | 262 | // If the complex pattern has a chain, then we need to keep track of the |
| 263 | // fact that we just recorded a chain input. The chain input will be |
| 264 | // matched as the last operand of the predicate if it was successful. |
| 265 | if (CP.hasProperty(SDNPHasChain)) { |
| 266 | // It is the last operand recorded. |
| 267 | assert(NextRecordedOperandNo > 1 && |
| 268 | "Should have recorded input/result chains at least!"); |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 269 | MatchedChainNodes.push_back(NextRecordedOperandNo-1); |
Chris Lattner | 9a747f1 | 2010-02-17 06:23:39 +0000 | [diff] [blame] | 270 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 271 | // If we need to check chains, do so, see comment for |
Chris Lattner | 9a747f1 | 2010-02-17 06:23:39 +0000 | [diff] [blame] | 272 | // "NodeHasProperty(SDNPHasChain" below. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 273 | if (MatchedChainNodes.size() > 1) { |
| 274 | // FIXME2: This is broken, we should eliminate this nonsense completely, |
Chris Lattner | 9a747f1 | 2010-02-17 06:23:39 +0000 | [diff] [blame] | 275 | // but we want to produce the same selections that the old matcher does |
| 276 | // for now. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 277 | unsigned PrevOp = MatchedChainNodes[MatchedChainNodes.size()-2]; |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 278 | AddMatcher(new CheckChainCompatibleMatcher(PrevOp)); |
Chris Lattner | 9a747f1 | 2010-02-17 06:23:39 +0000 | [diff] [blame] | 279 | } |
Chris Lattner | 8dc4f2b | 2010-02-17 06:08:25 +0000 | [diff] [blame] | 280 | } |
Chris Lattner | 02f7358 | 2010-02-24 05:33:42 +0000 | [diff] [blame] | 281 | |
| 282 | // TODO: Complex patterns can't have output flags, if they did, we'd want |
| 283 | // to record them. |
Chris Lattner | 8dc4f2b | 2010-02-17 06:08:25 +0000 | [diff] [blame] | 284 | return; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | errs() << "Unknown leaf kind: " << *N << "\n"; |
| 288 | abort(); |
| 289 | } |
| 290 | |
| 291 | void MatcherGen::EmitOperatorMatchCode(const TreePatternNode *N, |
| 292 | TreePatternNode *NodeNoTypes) { |
| 293 | assert(!N->isLeaf() && "Not an operator?"); |
| 294 | const SDNodeInfo &CInfo = CGP.getSDNodeInfo(N->getOperator()); |
| 295 | |
| 296 | // If this is an 'and R, 1234' where the operation is AND/OR and the RHS is |
| 297 | // a constant without a predicate fn that has more that one bit set, handle |
| 298 | // this as a special case. This is usually for targets that have special |
| 299 | // handling of certain large constants (e.g. alpha with it's 8/16/32-bit |
| 300 | // handling stuff). Using these instructions is often far more efficient |
| 301 | // than materializing the constant. Unfortunately, both the instcombiner |
| 302 | // and the dag combiner can often infer that bits are dead, and thus drop |
| 303 | // them from the mask in the dag. For example, it might turn 'AND X, 255' |
| 304 | // into 'AND X, 254' if it knows the low bit is set. Emit code that checks |
| 305 | // to handle this. |
| 306 | if ((N->getOperator()->getName() == "and" || |
| 307 | N->getOperator()->getName() == "or") && |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 308 | N->getChild(1)->isLeaf() && N->getChild(1)->getPredicateFns().empty() && |
| 309 | N->getPredicateFns().empty()) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 310 | if (IntInit *II = dynamic_cast<IntInit*>(N->getChild(1)->getLeafValue())) { |
| 311 | if (!isPowerOf2_32(II->getValue())) { // Don't bother with single bits. |
Chris Lattner | e9eeda8 | 2010-03-01 02:15:34 +0000 | [diff] [blame] | 312 | // If this is at the root of the pattern, we emit a redundant |
| 313 | // CheckOpcode so that the following checks get factored properly under |
| 314 | // a single opcode check. |
| 315 | if (N == Pattern.getSrcPattern()) |
| 316 | AddMatcher(new CheckOpcodeMatcher(CInfo)); |
| 317 | |
| 318 | // Emit the CheckAndImm/CheckOrImm node. |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 319 | if (N->getOperator()->getName() == "and") |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 320 | AddMatcher(new CheckAndImmMatcher(II->getValue())); |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 321 | else |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 322 | AddMatcher(new CheckOrImmMatcher(II->getValue())); |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 323 | |
| 324 | // Match the LHS of the AND as appropriate. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 325 | AddMatcher(new MoveChildMatcher(0)); |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 326 | EmitMatchCode(N->getChild(0), NodeNoTypes->getChild(0)); |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 327 | AddMatcher(new MoveParentMatcher()); |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 328 | return; |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | // Check that the current opcode lines up. |
Chris Lattner | a230f96 | 2010-02-27 21:48:43 +0000 | [diff] [blame] | 334 | AddMatcher(new CheckOpcodeMatcher(CInfo)); |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 335 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 336 | // If there are node predicates for this node, generate their checks. |
| 337 | for (unsigned i = 0, e = N->getPredicateFns().size(); i != e; ++i) |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 338 | AddMatcher(new CheckPredicateMatcher(N->getPredicateFns()[i])); |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 339 | |
| 340 | |
| 341 | // If this node has memory references (i.e. is a load or store), tell the |
| 342 | // interpreter to capture them in the memref array. |
| 343 | if (N->NodeHasProperty(SDNPMemOperand, CGP)) |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 344 | AddMatcher(new RecordMemRefMatcher()); |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 345 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 346 | // If this node has a chain, then the chain is operand #0 is the SDNode, and |
| 347 | // the child numbers of the node are all offset by one. |
| 348 | unsigned OpNo = 0; |
Chris Lattner | 6bc1b51 | 2010-02-16 19:19:58 +0000 | [diff] [blame] | 349 | if (N->NodeHasProperty(SDNPHasChain, CGP)) { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 350 | // Record the node and remember it in our chained nodes list. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 351 | AddMatcher(new RecordMatcher("'" + N->getOperator()->getName() + |
Chris Lattner | 0cebe61 | 2010-03-01 02:24:17 +0000 | [diff] [blame] | 352 | "' chained node", |
| 353 | NextRecordedOperandNo)); |
Chris Lattner | 785d16f | 2010-02-17 02:16:19 +0000 | [diff] [blame] | 354 | // Remember all of the input chains our pattern will match. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 355 | MatchedChainNodes.push_back(NextRecordedOperandNo++); |
Chris Lattner | 785d16f | 2010-02-17 02:16:19 +0000 | [diff] [blame] | 356 | |
| 357 | // If this is the second (e.g. indbr(load) or store(add(load))) or third |
| 358 | // input chain (e.g. (store (add (load, load))) from msp430) we need to make |
| 359 | // sure that folding the chain won't induce cycles in the DAG. This could |
| 360 | // happen if there were an intermediate node between the indbr and load, for |
| 361 | // example. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 362 | if (MatchedChainNodes.size() > 1) { |
| 363 | // FIXME2: This is broken, we should eliminate this nonsense completely, |
Chris Lattner | 9a747f1 | 2010-02-17 06:23:39 +0000 | [diff] [blame] | 364 | // but we want to produce the same selections that the old matcher does |
| 365 | // for now. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 366 | unsigned PrevOp = MatchedChainNodes[MatchedChainNodes.size()-2]; |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 367 | AddMatcher(new CheckChainCompatibleMatcher(PrevOp)); |
Chris Lattner | 9a747f1 | 2010-02-17 06:23:39 +0000 | [diff] [blame] | 368 | } |
Chris Lattner | 785d16f | 2010-02-17 02:16:19 +0000 | [diff] [blame] | 369 | |
Chris Lattner | 2f7ecde | 2010-02-17 01:34:15 +0000 | [diff] [blame] | 370 | // Don't look at the input chain when matching the tree pattern to the |
| 371 | // SDNode. |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 372 | OpNo = 1; |
| 373 | |
Chris Lattner | 6bc1b51 | 2010-02-16 19:19:58 +0000 | [diff] [blame] | 374 | // If this node is not the root and the subtree underneath it produces a |
| 375 | // chain, then the result of matching the node is also produce a chain. |
| 376 | // Beyond that, this means that we're also folding (at least) the root node |
| 377 | // into the node that produce the chain (for example, matching |
| 378 | // "(add reg, (load ptr))" as a add_with_memory on X86). This is |
| 379 | // problematic, if the 'reg' node also uses the load (say, its chain). |
| 380 | // Graphically: |
| 381 | // |
| 382 | // [LD] |
| 383 | // ^ ^ |
| 384 | // | \ DAG's like cheese. |
| 385 | // / | |
| 386 | // / [YY] |
| 387 | // | ^ |
| 388 | // [XX]--/ |
| 389 | // |
| 390 | // It would be invalid to fold XX and LD. In this case, folding the two |
| 391 | // nodes together would induce a cycle in the DAG, making it a 'cyclic DAG' |
| 392 | // To prevent this, we emit a dynamic check for legality before allowing |
| 393 | // this to be folded. |
| 394 | // |
| 395 | const TreePatternNode *Root = Pattern.getSrcPattern(); |
| 396 | if (N != Root) { // Not the root of the pattern. |
Chris Lattner | e39650a | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 397 | // If there is a node between the root and this node, then we definitely |
| 398 | // need to emit the check. |
| 399 | bool NeedCheck = !Root->hasChild(N); |
| 400 | |
| 401 | // If it *is* an immediate child of the root, we can still need a check if |
| 402 | // the root SDNode has multiple inputs. For us, this means that it is an |
| 403 | // intrinsic, has multiple operands, or has other inputs like chain or |
| 404 | // flag). |
| 405 | if (!NeedCheck) { |
| 406 | const SDNodeInfo &PInfo = CGP.getSDNodeInfo(Root->getOperator()); |
| 407 | NeedCheck = |
| 408 | Root->getOperator() == CGP.get_intrinsic_void_sdnode() || |
| 409 | Root->getOperator() == CGP.get_intrinsic_w_chain_sdnode() || |
| 410 | Root->getOperator() == CGP.get_intrinsic_wo_chain_sdnode() || |
| 411 | PInfo.getNumOperands() > 1 || |
| 412 | PInfo.hasProperty(SDNPHasChain) || |
| 413 | PInfo.hasProperty(SDNPInFlag) || |
| 414 | PInfo.hasProperty(SDNPOptInFlag); |
| 415 | } |
| 416 | |
| 417 | if (NeedCheck) |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 418 | AddMatcher(new CheckFoldableChainNodeMatcher()); |
Chris Lattner | e39650a | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 419 | } |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 420 | } |
Chris Lattner | 02f7358 | 2010-02-24 05:33:42 +0000 | [diff] [blame] | 421 | |
| 422 | // If this node has an output flag and isn't the root, remember it. |
| 423 | if (N->NodeHasProperty(SDNPOutFlag, CGP) && |
| 424 | N != Pattern.getSrcPattern()) { |
| 425 | // TODO: This redundantly records nodes with both flags and chains. |
| 426 | |
| 427 | // Record the node and remember it in our chained nodes list. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 428 | AddMatcher(new RecordMatcher("'" + N->getOperator()->getName() + |
Chris Lattner | 0cebe61 | 2010-03-01 02:24:17 +0000 | [diff] [blame] | 429 | "' flag output node", |
| 430 | NextRecordedOperandNo)); |
Chris Lattner | 02f7358 | 2010-02-24 05:33:42 +0000 | [diff] [blame] | 431 | // Remember all of the nodes with output flags our pattern will match. |
| 432 | MatchedFlagResultNodes.push_back(NextRecordedOperandNo++); |
| 433 | } |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 434 | |
| 435 | // If this node is known to have an input flag or if it *might* have an input |
| 436 | // flag, capture it as the flag input of the pattern. |
| 437 | if (N->NodeHasProperty(SDNPOptInFlag, CGP) || |
| 438 | N->NodeHasProperty(SDNPInFlag, CGP)) |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 439 | AddMatcher(new CaptureFlagInputMatcher()); |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 440 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 441 | for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i, ++OpNo) { |
| 442 | // Get the code suitable for matching this child. Move to the child, check |
| 443 | // it then move back to the parent. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 444 | AddMatcher(new MoveChildMatcher(OpNo)); |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 445 | EmitMatchCode(N->getChild(i), NodeNoTypes->getChild(i)); |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 446 | AddMatcher(new MoveParentMatcher()); |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 447 | } |
| 448 | } |
| 449 | |
| 450 | |
| 451 | void MatcherGen::EmitMatchCode(const TreePatternNode *N, |
| 452 | TreePatternNode *NodeNoTypes) { |
| 453 | // If N and NodeNoTypes don't agree on a type, then this is a case where we |
| 454 | // need to do a type check. Emit the check, apply the tyep to NodeNoTypes and |
| 455 | // reinfer any correlated types. |
Chris Lattner | 60c0e37 | 2010-03-01 07:54:59 +0000 | [diff] [blame] | 456 | unsigned NodeType = EEVT::isUnknown; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 457 | if (NodeNoTypes->getExtTypes() != N->getExtTypes()) { |
Chris Lattner | 60c0e37 | 2010-03-01 07:54:59 +0000 | [diff] [blame] | 458 | NodeType = N->getTypeNum(0); |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 459 | NodeNoTypes->setTypes(N->getExtTypes()); |
| 460 | InferPossibleTypes(); |
| 461 | } |
| 462 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 463 | // If this node has a name associated with it, capture it in VariableMap. If |
| 464 | // we already saw this in the pattern, emit code to verify dagness. |
| 465 | if (!N->getName().empty()) { |
| 466 | unsigned &VarMapEntry = VariableMap[N->getName()]; |
| 467 | if (VarMapEntry == 0) { |
Chris Lattner | 20df242 | 2010-02-22 23:33:44 +0000 | [diff] [blame] | 468 | // If it is a named node, we must emit a 'Record' opcode. |
Chris Lattner | 0cebe61 | 2010-03-01 02:24:17 +0000 | [diff] [blame] | 469 | AddMatcher(new RecordMatcher("$" + N->getName(), NextRecordedOperandNo)); |
Chris Lattner | 20df242 | 2010-02-22 23:33:44 +0000 | [diff] [blame] | 470 | VarMapEntry = ++NextRecordedOperandNo; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 471 | } else { |
| 472 | // If we get here, this is a second reference to a specific name. Since |
| 473 | // we already have checked that the first reference is valid, we don't |
| 474 | // have to recursively match it, just check that it's the same as the |
| 475 | // previously named thing. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 476 | AddMatcher(new CheckSameMatcher(VarMapEntry-1)); |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 477 | return; |
| 478 | } |
| 479 | } |
| 480 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 481 | if (N->isLeaf()) |
| 482 | EmitLeafMatchCode(N); |
| 483 | else |
| 484 | EmitOperatorMatchCode(N, NodeNoTypes); |
Chris Lattner | 60c0e37 | 2010-03-01 07:54:59 +0000 | [diff] [blame] | 485 | |
| 486 | if (NodeType != EEVT::isUnknown) |
| 487 | AddMatcher(new CheckTypeMatcher((MVT::SimpleValueType)NodeType)); |
| 488 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 489 | } |
| 490 | |
Chris Lattner | fa342fa | 2010-03-01 07:17:40 +0000 | [diff] [blame] | 491 | /// EmitMatcherCode - Generate the code that matches the predicate of this |
| 492 | /// pattern for the specified Variant. If the variant is invalid this returns |
| 493 | /// true and does not generate code, if it is valid, it returns false. |
| 494 | bool MatcherGen::EmitMatcherCode(unsigned Variant) { |
| 495 | // If the root of the pattern is a ComplexPattern and if it is specified to |
| 496 | // match some number of root opcodes, these are considered to be our variants. |
| 497 | // Depending on which variant we're generating code for, emit the root opcode |
| 498 | // check. |
| 499 | if (const ComplexPattern *CP = |
| 500 | Pattern.getSrcPattern()->getComplexPatternInfo(CGP)) { |
Chris Lattner | fa342fa | 2010-03-01 07:17:40 +0000 | [diff] [blame] | 501 | const std::vector<Record*> &OpNodes = CP->getRootNodes(); |
Chris Lattner | 405f125 | 2010-03-01 22:29:19 +0000 | [diff] [blame] | 502 | assert(!OpNodes.empty() &&"Complex Pattern must specify what it can match"); |
| 503 | if (Variant >= OpNodes.size()) return true; |
| 504 | |
| 505 | AddMatcher(new CheckOpcodeMatcher(CGP.getSDNodeInfo(OpNodes[Variant]))); |
Chris Lattner | fa342fa | 2010-03-01 07:17:40 +0000 | [diff] [blame] | 506 | } else { |
| 507 | if (Variant != 0) return true; |
| 508 | } |
| 509 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 510 | // If the pattern has a predicate on it (e.g. only enabled when a subtarget |
| 511 | // feature is around, do the check). |
Chris Lattner | 2a1263b | 2010-02-25 00:03:03 +0000 | [diff] [blame] | 512 | // FIXME: This should get emitted after the match code below to encourage |
| 513 | // sharing. This can't happen until we get an X86ISD::AddrMode node made by |
| 514 | // dag combine, eliminating the horrible side-effect-full stuff from |
| 515 | // X86's MatchAddress. |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 516 | if (!Pattern.getPredicateCheck().empty()) |
Chris Lattner | fa342fa | 2010-03-01 07:17:40 +0000 | [diff] [blame] | 517 | AddMatcher(new CheckPatternPredicateMatcher(Pattern.getPredicateCheck())); |
| 518 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 519 | // Emit the matcher for the pattern structure and types. |
| 520 | EmitMatchCode(Pattern.getSrcPattern(), PatWithNoTypes); |
Chris Lattner | fa342fa | 2010-03-01 07:17:40 +0000 | [diff] [blame] | 521 | return false; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 525 | //===----------------------------------------------------------------------===// |
| 526 | // Node Result Generation |
| 527 | //===----------------------------------------------------------------------===// |
| 528 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 529 | void MatcherGen::EmitResultOfNamedOperand(const TreePatternNode *N, |
| 530 | SmallVectorImpl<unsigned> &ResultOps){ |
| 531 | assert(!N->getName().empty() && "Operand not named!"); |
| 532 | |
| 533 | unsigned SlotNo = getNamedArgumentSlot(N->getName()); |
| 534 | |
| 535 | // A reference to a complex pattern gets all of the results of the complex |
| 536 | // pattern's match. |
| 537 | if (const ComplexPattern *CP = N->getComplexPatternInfo(CGP)) { |
Chris Lattner | 20df242 | 2010-02-22 23:33:44 +0000 | [diff] [blame] | 538 | // The first slot entry is the node itself, the subsequent entries are the |
| 539 | // matched values. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 540 | for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i) |
Chris Lattner | 20df242 | 2010-02-22 23:33:44 +0000 | [diff] [blame] | 541 | ResultOps.push_back(SlotNo+i+1); |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 542 | return; |
| 543 | } |
| 544 | |
| 545 | // If this is an 'imm' or 'fpimm' node, make sure to convert it to the target |
| 546 | // version of the immediate so that it doesn't get selected due to some other |
| 547 | // node use. |
| 548 | if (!N->isLeaf()) { |
| 549 | StringRef OperatorName = N->getOperator()->getName(); |
| 550 | if (OperatorName == "imm" || OperatorName == "fpimm") { |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 551 | AddMatcher(new EmitConvertToTargetMatcher(SlotNo)); |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 552 | ResultOps.push_back(NextRecordedOperandNo++); |
| 553 | return; |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | ResultOps.push_back(SlotNo); |
| 558 | } |
| 559 | |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 560 | void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode *N, |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 561 | SmallVectorImpl<unsigned> &ResultOps) { |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 562 | assert(N->isLeaf() && "Must be a leaf"); |
| 563 | |
| 564 | if (IntInit *II = dynamic_cast<IntInit*>(N->getLeafValue())) { |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 565 | AddMatcher(new EmitIntegerMatcher(II->getValue(),N->getTypeNum(0))); |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 566 | ResultOps.push_back(NextRecordedOperandNo++); |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 567 | return; |
| 568 | } |
| 569 | |
| 570 | // If this is an explicit register reference, handle it. |
| 571 | if (DefInit *DI = dynamic_cast<DefInit*>(N->getLeafValue())) { |
| 572 | if (DI->getDef()->isSubClassOf("Register")) { |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 573 | AddMatcher(new EmitRegisterMatcher(DI->getDef(), |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 574 | N->getTypeNum(0))); |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 575 | ResultOps.push_back(NextRecordedOperandNo++); |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 576 | return; |
| 577 | } |
| 578 | |
| 579 | if (DI->getDef()->getName() == "zero_reg") { |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 580 | AddMatcher(new EmitRegisterMatcher(0, N->getTypeNum(0))); |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 581 | ResultOps.push_back(NextRecordedOperandNo++); |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 582 | return; |
| 583 | } |
| 584 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 585 | // Handle a reference to a register class. This is used |
| 586 | // in COPY_TO_SUBREG instructions. |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 587 | if (DI->getDef()->isSubClassOf("RegisterClass")) { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 588 | std::string Value = getQualifiedName(DI->getDef()) + "RegClassID"; |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 589 | AddMatcher(new EmitStringIntegerMatcher(Value, MVT::i32)); |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 590 | ResultOps.push_back(NextRecordedOperandNo++); |
| 591 | return; |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 592 | } |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 593 | } |
| 594 | |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 595 | errs() << "unhandled leaf node: \n"; |
| 596 | N->dump(); |
| 597 | } |
| 598 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 599 | /// GetInstPatternNode - Get the pattern for an instruction. |
| 600 | /// |
| 601 | const TreePatternNode *MatcherGen:: |
| 602 | GetInstPatternNode(const DAGInstruction &Inst, const TreePatternNode *N) { |
| 603 | const TreePattern *InstPat = Inst.getPattern(); |
| 604 | |
| 605 | // FIXME2?: Assume actual pattern comes before "implicit". |
| 606 | TreePatternNode *InstPatNode; |
| 607 | if (InstPat) |
| 608 | InstPatNode = InstPat->getTree(0); |
| 609 | else if (/*isRoot*/ N == Pattern.getDstPattern()) |
| 610 | InstPatNode = Pattern.getSrcPattern(); |
| 611 | else |
| 612 | return 0; |
| 613 | |
| 614 | if (InstPatNode && !InstPatNode->isLeaf() && |
| 615 | InstPatNode->getOperator()->getName() == "set") |
| 616 | InstPatNode = InstPatNode->getChild(InstPatNode->getNumChildren()-1); |
| 617 | |
| 618 | return InstPatNode; |
| 619 | } |
| 620 | |
| 621 | void MatcherGen:: |
| 622 | EmitResultInstructionAsOperand(const TreePatternNode *N, |
| 623 | SmallVectorImpl<unsigned> &OutputOps) { |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 624 | Record *Op = N->getOperator(); |
| 625 | const CodeGenTarget &CGT = CGP.getTargetInfo(); |
| 626 | CodeGenInstruction &II = CGT.getInstruction(Op->getName()); |
| 627 | const DAGInstruction &Inst = CGP.getInstruction(Op); |
| 628 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 629 | // If we can, get the pattern for the instruction we're generating. We derive |
| 630 | // a variety of information from this pattern, such as whether it has a chain. |
| 631 | // |
| 632 | // FIXME2: This is extremely dubious for several reasons, not the least of |
| 633 | // which it gives special status to instructions with patterns that Pat<> |
| 634 | // nodes can't duplicate. |
| 635 | const TreePatternNode *InstPatNode = GetInstPatternNode(Inst, N); |
| 636 | |
| 637 | // NodeHasChain - Whether the instruction node we're creating takes chains. |
| 638 | bool NodeHasChain = InstPatNode && |
| 639 | InstPatNode->TreeHasProperty(SDNPHasChain, CGP); |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 640 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 641 | bool isRoot = N == Pattern.getDstPattern(); |
| 642 | |
Chris Lattner | 02f7358 | 2010-02-24 05:33:42 +0000 | [diff] [blame] | 643 | // TreeHasOutFlag - True if this tree has a flag. |
| 644 | bool TreeHasInFlag = false, TreeHasOutFlag = false; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 645 | if (isRoot) { |
| 646 | const TreePatternNode *SrcPat = Pattern.getSrcPattern(); |
Chris Lattner | 02f7358 | 2010-02-24 05:33:42 +0000 | [diff] [blame] | 647 | TreeHasInFlag = SrcPat->TreeHasProperty(SDNPOptInFlag, CGP) || |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 648 | SrcPat->TreeHasProperty(SDNPInFlag, CGP); |
| 649 | |
| 650 | // FIXME2: this is checking the entire pattern, not just the node in |
| 651 | // question, doing this just for the root seems like a total hack. |
Chris Lattner | 02f7358 | 2010-02-24 05:33:42 +0000 | [diff] [blame] | 652 | TreeHasOutFlag = SrcPat->TreeHasProperty(SDNPOutFlag, CGP); |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | // NumResults - This is the number of results produced by the instruction in |
| 656 | // the "outs" list. |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 657 | unsigned NumResults = Inst.getNumResults(); |
| 658 | |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 659 | // Loop over all of the operands of the instruction pattern, emitting code |
| 660 | // to fill them all in. The node 'N' usually has number children equal to |
| 661 | // the number of input operands of the instruction. However, in cases |
| 662 | // where there are predicate operands for an instruction, we need to fill |
| 663 | // in the 'execute always' values. Match up the node operands to the |
| 664 | // instruction operands to do this. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 665 | SmallVector<unsigned, 8> InstOps; |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 666 | for (unsigned ChildNo = 0, InstOpNo = NumResults, e = II.OperandList.size(); |
| 667 | InstOpNo != e; ++InstOpNo) { |
| 668 | |
| 669 | // Determine what to emit for this operand. |
| 670 | Record *OperandNode = II.OperandList[InstOpNo].Rec; |
| 671 | if ((OperandNode->isSubClassOf("PredicateOperand") || |
| 672 | OperandNode->isSubClassOf("OptionalDefOperand")) && |
| 673 | !CGP.getDefaultOperand(OperandNode).DefaultOps.empty()) { |
| 674 | // This is a predicate or optional def operand; emit the |
| 675 | // 'default ops' operands. |
| 676 | const DAGDefaultOperand &DefaultOp = |
| 677 | CGP.getDefaultOperand(II.OperandList[InstOpNo].Rec); |
| 678 | for (unsigned i = 0, e = DefaultOp.DefaultOps.size(); i != e; ++i) |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 679 | EmitResultOperand(DefaultOp.DefaultOps[i], InstOps); |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 680 | continue; |
| 681 | } |
| 682 | |
| 683 | // Otherwise this is a normal operand or a predicate operand without |
| 684 | // 'execute always'; emit it. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 685 | EmitResultOperand(N->getChild(ChildNo), InstOps); |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 686 | ++ChildNo; |
| 687 | } |
| 688 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 689 | // If this node has an input flag or explicitly specified input physregs, we |
| 690 | // need to add chained and flagged copyfromreg nodes and materialize the flag |
| 691 | // input. |
| 692 | if (isRoot && !PhysRegInputs.empty()) { |
| 693 | // Emit all of the CopyToReg nodes for the input physical registers. These |
| 694 | // occur in patterns like (mul:i8 AL:i8, GR8:i8:$src). |
| 695 | for (unsigned i = 0, e = PhysRegInputs.size(); i != e; ++i) |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 696 | AddMatcher(new EmitCopyToRegMatcher(PhysRegInputs[i].second, |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 697 | PhysRegInputs[i].first)); |
| 698 | // Even if the node has no other flag inputs, the resultant node must be |
| 699 | // flagged to the CopyFromReg nodes we just generated. |
Chris Lattner | 02f7358 | 2010-02-24 05:33:42 +0000 | [diff] [blame] | 700 | TreeHasInFlag = true; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | // Result order: node results, chain, flags |
| 704 | |
| 705 | // Determine the result types. |
| 706 | SmallVector<MVT::SimpleValueType, 4> ResultVTs; |
Chris Lattner | 565a6f9 | 2010-02-21 23:54:05 +0000 | [diff] [blame] | 707 | if (NumResults != 0 && N->getTypeNum(0) != MVT::isVoid) { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 708 | // FIXME2: If the node has multiple results, we should add them. For now, |
| 709 | // preserve existing behavior?! |
| 710 | ResultVTs.push_back(N->getTypeNum(0)); |
| 711 | } |
| 712 | |
| 713 | |
| 714 | // If this is the root instruction of a pattern that has physical registers in |
| 715 | // its result pattern, add output VTs for them. For example, X86 has: |
| 716 | // (set AL, (mul ...)) |
| 717 | // This also handles implicit results like: |
| 718 | // (implicit EFLAGS) |
| 719 | if (isRoot && Pattern.getDstRegs().size() != 0) { |
| 720 | for (unsigned i = 0; i != Pattern.getDstRegs().size(); ++i) |
| 721 | if (Pattern.getDstRegs()[i]->isSubClassOf("Register")) |
| 722 | ResultVTs.push_back(getRegisterValueType(Pattern.getDstRegs()[i], CGT)); |
| 723 | } |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 724 | |
| 725 | // FIXME2: Instead of using the isVariadic flag on the instruction, we should |
| 726 | // have an SDNP that indicates variadicism. The TargetInstrInfo isVariadic |
| 727 | // property should be inferred from this when an instruction has a pattern. |
| 728 | int NumFixedArityOperands = -1; |
| 729 | if (isRoot && II.isVariadic) |
| 730 | NumFixedArityOperands = Pattern.getSrcPattern()->getNumChildren(); |
| 731 | |
| 732 | // If this is the root node and any of the nodes matched nodes in the input |
| 733 | // pattern have MemRefs in them, have the interpreter collect them and plop |
| 734 | // them onto this node. |
| 735 | // |
| 736 | // FIXME3: This is actively incorrect for result patterns where the root of |
| 737 | // the pattern is not the memory reference and is also incorrect when the |
| 738 | // result pattern has multiple memory-referencing instructions. For example, |
| 739 | // in the X86 backend, this pattern causes the memrefs to get attached to the |
| 740 | // CVTSS2SDrr instead of the MOVSSrm: |
| 741 | // |
| 742 | // def : Pat<(extloadf32 addr:$src), |
| 743 | // (CVTSS2SDrr (MOVSSrm addr:$src))>; |
| 744 | // |
| 745 | bool NodeHasMemRefs = |
| 746 | isRoot && Pattern.getSrcPattern()->TreeHasProperty(SDNPMemOperand, CGP); |
| 747 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 748 | AddMatcher(new EmitNodeMatcher(II.Namespace+"::"+II.TheDef->getName(), |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 749 | ResultVTs.data(), ResultVTs.size(), |
| 750 | InstOps.data(), InstOps.size(), |
Chris Lattner | ff7fb60 | 2010-02-28 21:53:42 +0000 | [diff] [blame] | 751 | NodeHasChain, TreeHasInFlag, TreeHasOutFlag, |
Chris Lattner | 6281cda | 2010-02-28 02:41:25 +0000 | [diff] [blame] | 752 | NodeHasMemRefs, NumFixedArityOperands, |
| 753 | NextRecordedOperandNo)); |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 754 | |
Chris Lattner | 565a6f9 | 2010-02-21 23:54:05 +0000 | [diff] [blame] | 755 | // The non-chain and non-flag results of the newly emitted node get recorded. |
| 756 | for (unsigned i = 0, e = ResultVTs.size(); i != e; ++i) { |
| 757 | if (ResultVTs[i] == MVT::Other || ResultVTs[i] == MVT::Flag) break; |
Chris Lattner | 77f2e27 | 2010-02-21 06:03:07 +0000 | [diff] [blame] | 758 | OutputOps.push_back(NextRecordedOperandNo++); |
Chris Lattner | 565a6f9 | 2010-02-21 23:54:05 +0000 | [diff] [blame] | 759 | } |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | void MatcherGen:: |
| 763 | EmitResultSDNodeXFormAsOperand(const TreePatternNode *N, |
| 764 | SmallVectorImpl<unsigned> &ResultOps) { |
| 765 | assert(N->getOperator()->isSubClassOf("SDNodeXForm") && "Not SDNodeXForm?"); |
| 766 | |
| 767 | // Emit the operand. |
| 768 | SmallVector<unsigned, 8> InputOps; |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 769 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 770 | // FIXME2: Could easily generalize this to support multiple inputs and outputs |
| 771 | // to the SDNodeXForm. For now we just support one input and one output like |
| 772 | // the old instruction selector. |
| 773 | assert(N->getNumChildren() == 1); |
| 774 | EmitResultOperand(N->getChild(0), InputOps); |
| 775 | |
| 776 | // The input currently must have produced exactly one result. |
| 777 | assert(InputOps.size() == 1 && "Unexpected input to SDNodeXForm"); |
| 778 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 779 | AddMatcher(new EmitNodeXFormMatcher(InputOps[0], N->getOperator())); |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 780 | ResultOps.push_back(NextRecordedOperandNo++); |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | void MatcherGen::EmitResultOperand(const TreePatternNode *N, |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 784 | SmallVectorImpl<unsigned> &ResultOps) { |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 785 | // This is something selected from the pattern we matched. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 786 | if (!N->getName().empty()) |
| 787 | return EmitResultOfNamedOperand(N, ResultOps); |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 788 | |
| 789 | if (N->isLeaf()) |
| 790 | return EmitResultLeafAsOperand(N, ResultOps); |
| 791 | |
| 792 | Record *OpRec = N->getOperator(); |
| 793 | if (OpRec->isSubClassOf("Instruction")) |
| 794 | return EmitResultInstructionAsOperand(N, ResultOps); |
| 795 | if (OpRec->isSubClassOf("SDNodeXForm")) |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 796 | return EmitResultSDNodeXFormAsOperand(N, ResultOps); |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 797 | errs() << "Unknown result node to emit code for: " << *N << '\n'; |
| 798 | throw std::string("Unknown node in result pattern!"); |
| 799 | } |
| 800 | |
| 801 | void MatcherGen::EmitResultCode() { |
Chris Lattner | 01bcd94 | 2010-03-01 22:46:42 +0000 | [diff] [blame] | 802 | // Patterns that match nodes with (potentially multiple) chain inputs have to |
| 803 | // merge them together into a token factor. This informs the generated code |
| 804 | // what all the chained nodes are. |
| 805 | if (!MatchedChainNodes.empty()) |
| 806 | AddMatcher(new EmitMergeInputChainsMatcher |
| 807 | (MatchedChainNodes.data(), MatchedChainNodes.size())); |
| 808 | |
Chris Lattner | 565a6f9 | 2010-02-21 23:54:05 +0000 | [diff] [blame] | 809 | // Codegen the root of the result pattern, capturing the resulting values. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 810 | SmallVector<unsigned, 8> Ops; |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 811 | EmitResultOperand(Pattern.getDstPattern(), Ops); |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 812 | |
Chris Lattner | 565a6f9 | 2010-02-21 23:54:05 +0000 | [diff] [blame] | 813 | // At this point, we have however many values the result pattern produces. |
| 814 | // However, the input pattern might not need all of these. If there are |
| 815 | // excess values at the end (such as condition codes etc) just lop them off. |
| 816 | // This doesn't need to worry about flags or chains, just explicit results. |
| 817 | // |
| 818 | // FIXME2: This doesn't work because there is currently no way to get an |
| 819 | // accurate count of the # results the source pattern sets. This is because |
| 820 | // of the "parallel" construct in X86 land, which looks like this: |
| 821 | // |
| 822 | //def : Pat<(parallel (X86and_flag GR8:$src1, GR8:$src2), |
| 823 | // (implicit EFLAGS)), |
| 824 | // (AND8rr GR8:$src1, GR8:$src2)>; |
| 825 | // |
| 826 | // This idiom means to match the two-result node X86and_flag (which is |
| 827 | // declared as returning a single result, because we can't match multi-result |
| 828 | // nodes yet). In this case, we would have to know that the input has two |
| 829 | // results. However, mul8r is modelled exactly the same way, but without |
| 830 | // implicit defs included. The fix is to support multiple results directly |
| 831 | // and eliminate 'parallel'. |
| 832 | // |
| 833 | // FIXME2: When this is fixed, we should revert the terrible hack in the |
| 834 | // OPC_EmitNode code in the interpreter. |
| 835 | #if 0 |
| 836 | const TreePatternNode *Src = Pattern.getSrcPattern(); |
| 837 | unsigned NumSrcResults = Src->getTypeNum(0) != MVT::isVoid ? 1 : 0; |
| 838 | NumSrcResults += Pattern.getDstRegs().size(); |
| 839 | assert(Ops.size() >= NumSrcResults && "Didn't provide enough results"); |
| 840 | Ops.resize(NumSrcResults); |
| 841 | #endif |
Chris Lattner | 02f7358 | 2010-02-24 05:33:42 +0000 | [diff] [blame] | 842 | |
| 843 | // If the matched pattern covers nodes which define a flag result, emit a node |
| 844 | // that tells the matcher about them so that it can update their results. |
| 845 | if (!MatchedFlagResultNodes.empty()) |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 846 | AddMatcher(new MarkFlagResultsMatcher(MatchedFlagResultNodes.data(), |
Chris Lattner | 4d0c931 | 2010-03-01 01:54:19 +0000 | [diff] [blame] | 847 | MatchedFlagResultNodes.size())); |
Chris Lattner | 02f7358 | 2010-02-24 05:33:42 +0000 | [diff] [blame] | 848 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 849 | AddMatcher(new CompleteMatchMatcher(Ops.data(), Ops.size(), Pattern)); |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | |
Chris Lattner | fa342fa | 2010-03-01 07:17:40 +0000 | [diff] [blame] | 853 | /// ConvertPatternToMatcher - Create the matcher for the specified pattern with |
| 854 | /// the specified variant. If the variant number is invalid, this returns null. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 855 | Matcher *llvm::ConvertPatternToMatcher(const PatternToMatch &Pattern, |
Chris Lattner | fa342fa | 2010-03-01 07:17:40 +0000 | [diff] [blame] | 856 | unsigned Variant, |
Chris Lattner | c78f2a3 | 2010-02-28 20:49:53 +0000 | [diff] [blame] | 857 | const CodeGenDAGPatterns &CGP) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 858 | MatcherGen Gen(Pattern, CGP); |
| 859 | |
| 860 | // Generate the code for the matcher. |
Chris Lattner | fa342fa | 2010-03-01 07:17:40 +0000 | [diff] [blame] | 861 | if (Gen.EmitMatcherCode(Variant)) |
| 862 | return 0; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 863 | |
| 864 | // FIXME2: Kill extra MoveParent commands at the end of the matcher sequence. |
| 865 | // FIXME2: Split result code out to another table, and make the matcher end |
| 866 | // with an "Emit <index>" command. This allows result generation stuff to be |
| 867 | // shared and factored? |
| 868 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 869 | // If the match succeeds, then we generate Pattern. |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 870 | Gen.EmitResultCode(); |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 871 | |
| 872 | // Unconditional match. |
Chris Lattner | b49985a | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 873 | return Gen.GetMatcher(); |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | |
| 877 | |