Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 1 | //===- DAGISelMatcher.h - 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 | #ifndef TBLGEN_DAGISELMATCHER_H |
| 11 | #define TBLGEN_DAGISELMATCHER_H |
| 12 | |
Chris Lattner | fdbdc8c | 2010-02-16 07:21:10 +0000 | [diff] [blame] | 13 | #include "llvm/CodeGen/ValueTypes.h" |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/OwningPtr.h" |
| 15 | #include "llvm/ADT/StringRef.h" |
Chris Lattner | 3163ca5 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/SmallVector.h" |
Chris Lattner | fdbdc8c | 2010-02-16 07:21:10 +0000 | [diff] [blame] | 17 | #include "llvm/Support/Casting.h" |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 18 | |
| 19 | namespace llvm { |
| 20 | class CodeGenDAGPatterns; |
| 21 | class MatcherNode; |
| 22 | class PatternToMatch; |
| 23 | class raw_ostream; |
| 24 | class ComplexPattern; |
Chris Lattner | ddfb522 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 25 | class Record; |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 26 | |
| 27 | MatcherNode *ConvertPatternToMatcher(const PatternToMatch &Pattern, |
| 28 | const CodeGenDAGPatterns &CGP); |
Chris Lattner | 3ee1bc4 | 2010-02-24 07:31:45 +0000 | [diff] [blame] | 29 | MatcherNode *OptimizeMatcher(MatcherNode *Matcher); |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 30 | void EmitMatcherTable(const MatcherNode *Matcher, raw_ostream &OS); |
| 31 | |
| 32 | |
| 33 | /// MatcherNode - Base class for all the the DAG ISel Matcher representation |
| 34 | /// nodes. |
| 35 | class MatcherNode { |
Chris Lattner | 78039ec | 2010-02-18 02:53:41 +0000 | [diff] [blame] | 36 | // The next matcher node that is executed after this one. Null if this is the |
| 37 | // last stage of a match. |
| 38 | OwningPtr<MatcherNode> Next; |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 39 | public: |
| 40 | enum KindTy { |
Chris Lattner | 3163ca5 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 41 | // Matcher state manipulation. |
| 42 | Push, // Push a checking scope. |
| 43 | RecordNode, // Record the current node. |
Chris Lattner | 3ee1bc4 | 2010-02-24 07:31:45 +0000 | [diff] [blame] | 44 | RecordChild, // Record a child of the current node. |
Chris Lattner | 3163ca5 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 45 | RecordMemRef, // Record the memref in the current node. |
| 46 | CaptureFlagInput, // If the current node has an input flag, save it. |
| 47 | MoveChild, // Move current node to specified child. |
| 48 | MoveParent, // Move current node to parent. |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 49 | |
Chris Lattner | ddfb522 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 50 | // Predicate checking. |
Chris Lattner | 3163ca5 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 51 | CheckSame, // Fail if not same as prev match. |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 52 | CheckPatternPredicate, |
Chris Lattner | 3163ca5 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 53 | CheckPredicate, // Fail if node predicate fails. |
| 54 | CheckOpcode, // Fail if not opcode. |
Chris Lattner | f58c08e | 2010-02-22 22:30:37 +0000 | [diff] [blame] | 55 | CheckMultiOpcode, // Fail if not in opcode list. |
Chris Lattner | 3163ca5 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 56 | CheckType, // Fail if not correct type. |
Chris Lattner | 3c664b3 | 2010-02-24 20:15:25 +0000 | [diff] [blame] | 57 | CheckChildType, // Fail if child has wrong type. |
Chris Lattner | 3163ca5 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 58 | CheckInteger, // Fail if wrong val. |
| 59 | CheckCondCode, // Fail if not condcode. |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 60 | CheckValueType, |
| 61 | CheckComplexPat, |
| 62 | CheckAndImm, |
Chris Lattner | 9de3948 | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 63 | CheckOrImm, |
Chris Lattner | 283adcb | 2010-02-17 06:23:39 +0000 | [diff] [blame] | 64 | CheckFoldableChainNode, |
Chris Lattner | ddfb522 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 65 | CheckChainCompatible, |
| 66 | |
| 67 | // Node creation/emisssion. |
Chris Lattner | 3163ca5 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 68 | EmitInteger, // Create a TargetConstant |
| 69 | EmitStringInteger, // Create a TargetConstant from a string. |
| 70 | EmitRegister, // Create a register. |
| 71 | EmitConvertToTarget, // Convert a imm/fpimm to target imm/fpimm |
| 72 | EmitMergeInputChains, // Merge together a chains for an input. |
| 73 | EmitCopyToReg, // Emit a copytoreg into a physreg. |
| 74 | EmitNode, // Create a DAG node |
| 75 | EmitNodeXForm, // Run a SDNodeXForm |
Chris Lattner | 69f60c8 | 2010-02-24 05:33:42 +0000 | [diff] [blame] | 76 | MarkFlagResults, // Indicate which interior nodes have flag results. |
Chris Lattner | b085ea1 | 2010-02-21 06:03:07 +0000 | [diff] [blame] | 77 | CompleteMatch // Finish a match and update the results. |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 78 | }; |
| 79 | const KindTy Kind; |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 80 | |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 81 | protected: |
| 82 | MatcherNode(KindTy K) : Kind(K) {} |
| 83 | public: |
| 84 | virtual ~MatcherNode() {} |
| 85 | |
| 86 | KindTy getKind() const { return Kind; } |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 87 | |
Chris Lattner | 78039ec | 2010-02-18 02:53:41 +0000 | [diff] [blame] | 88 | MatcherNode *getNext() { return Next.get(); } |
| 89 | const MatcherNode *getNext() const { return Next.get(); } |
| 90 | void setNext(MatcherNode *C) { Next.reset(C); } |
Chris Lattner | 3ee1bc4 | 2010-02-24 07:31:45 +0000 | [diff] [blame] | 91 | MatcherNode *takeNext() { return Next.take(); } |
| 92 | |
| 93 | OwningPtr<MatcherNode> &getNextPtr() { return Next; } |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 94 | |
| 95 | static inline bool classof(const MatcherNode *) { return true; } |
| 96 | |
| 97 | virtual void print(raw_ostream &OS, unsigned indent = 0) const = 0; |
| 98 | void dump() const; |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 99 | protected: |
Chris Lattner | 78039ec | 2010-02-18 02:53:41 +0000 | [diff] [blame] | 100 | void printNext(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 101 | }; |
| 102 | |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 103 | /// PushMatcherNode - This pushes a failure scope on the stack and evaluates |
Chris Lattner | 78039ec | 2010-02-18 02:53:41 +0000 | [diff] [blame] | 104 | /// 'Next'. If 'Next' fails to match, it pops its scope and attempts to |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 105 | /// match 'Failure'. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 106 | class PushMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 107 | OwningPtr<MatcherNode> Failure; |
| 108 | public: |
Chris Lattner | 78039ec | 2010-02-18 02:53:41 +0000 | [diff] [blame] | 109 | PushMatcherNode(MatcherNode *next = 0, MatcherNode *failure = 0) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 110 | : MatcherNode(Push), Failure(failure) { |
Chris Lattner | 78039ec | 2010-02-18 02:53:41 +0000 | [diff] [blame] | 111 | setNext(next); |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | MatcherNode *getFailure() { return Failure.get(); } |
| 115 | const MatcherNode *getFailure() const { return Failure.get(); } |
| 116 | void setFailure(MatcherNode *N) { Failure.reset(N); } |
Chris Lattner | 3ee1bc4 | 2010-02-24 07:31:45 +0000 | [diff] [blame] | 117 | OwningPtr<MatcherNode> &getFailurePtr() { return Failure; } |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 118 | |
| 119 | static inline bool classof(const MatcherNode *N) { |
| 120 | return N->getKind() == Push; |
| 121 | } |
| 122 | |
| 123 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 124 | }; |
| 125 | |
| 126 | /// RecordMatcherNode - Save the current node in the operand list. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 127 | class RecordMatcherNode : public MatcherNode { |
Chris Lattner | 56cf88d | 2010-02-17 01:03:09 +0000 | [diff] [blame] | 128 | /// WhatFor - This is a string indicating why we're recording this. This |
| 129 | /// should only be used for comment generation not anything semantic. |
| 130 | std::string WhatFor; |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 131 | public: |
Chris Lattner | 086ca52 | 2010-02-17 01:27:29 +0000 | [diff] [blame] | 132 | RecordMatcherNode(const std::string &whatfor) |
Chris Lattner | ddfb522 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 133 | : MatcherNode(RecordNode), WhatFor(whatfor) {} |
Chris Lattner | 56cf88d | 2010-02-17 01:03:09 +0000 | [diff] [blame] | 134 | |
Chris Lattner | 086ca52 | 2010-02-17 01:27:29 +0000 | [diff] [blame] | 135 | const std::string &getWhatFor() const { return WhatFor; } |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 136 | |
| 137 | static inline bool classof(const MatcherNode *N) { |
Chris Lattner | ddfb522 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 138 | return N->getKind() == RecordNode; |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 142 | }; |
| 143 | |
Chris Lattner | 3ee1bc4 | 2010-02-24 07:31:45 +0000 | [diff] [blame] | 144 | /// RecordChildMatcherNode - Save a numbered child of the current node, or fail |
| 145 | /// the match if it doesn't exist. This is logically equivalent to: |
| 146 | /// MoveChild N + RecordNode + MoveParent. |
| 147 | class RecordChildMatcherNode : public MatcherNode { |
| 148 | unsigned ChildNo; |
| 149 | |
| 150 | /// WhatFor - This is a string indicating why we're recording this. This |
| 151 | /// should only be used for comment generation not anything semantic. |
| 152 | std::string WhatFor; |
| 153 | public: |
| 154 | RecordChildMatcherNode(unsigned childno, const std::string &whatfor) |
| 155 | : MatcherNode(RecordChild), ChildNo(childno), WhatFor(whatfor) {} |
| 156 | |
| 157 | unsigned getChildNo() const { return ChildNo; } |
| 158 | const std::string &getWhatFor() const { return WhatFor; } |
| 159 | |
| 160 | static inline bool classof(const MatcherNode *N) { |
| 161 | return N->getKind() == RecordChild; |
| 162 | } |
| 163 | |
| 164 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 165 | }; |
| 166 | |
Chris Lattner | 3163ca5 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 167 | /// RecordMemRefMatcherNode - Save the current node's memref. |
| 168 | class RecordMemRefMatcherNode : public MatcherNode { |
| 169 | public: |
| 170 | RecordMemRefMatcherNode() : MatcherNode(RecordMemRef) {} |
| 171 | |
| 172 | static inline bool classof(const MatcherNode *N) { |
| 173 | return N->getKind() == RecordMemRef; |
| 174 | } |
| 175 | |
| 176 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 177 | }; |
| 178 | |
| 179 | |
| 180 | /// CaptureFlagInputMatcherNode - If the current record has a flag input, record |
| 181 | /// it so that it is used as an input to the generated code. |
| 182 | class CaptureFlagInputMatcherNode : public MatcherNode { |
| 183 | public: |
| 184 | CaptureFlagInputMatcherNode() |
| 185 | : MatcherNode(CaptureFlagInput) {} |
| 186 | |
| 187 | static inline bool classof(const MatcherNode *N) { |
| 188 | return N->getKind() == CaptureFlagInput; |
| 189 | } |
| 190 | |
| 191 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 192 | }; |
| 193 | |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 194 | /// MoveChildMatcherNode - This tells the interpreter to move into the |
| 195 | /// specified child node. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 196 | class MoveChildMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 197 | unsigned ChildNo; |
| 198 | public: |
| 199 | MoveChildMatcherNode(unsigned childNo) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 200 | : MatcherNode(MoveChild), ChildNo(childNo) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 201 | |
| 202 | unsigned getChildNo() const { return ChildNo; } |
| 203 | |
| 204 | static inline bool classof(const MatcherNode *N) { |
| 205 | return N->getKind() == MoveChild; |
| 206 | } |
| 207 | |
| 208 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 209 | }; |
| 210 | |
| 211 | /// MoveParentMatcherNode - This tells the interpreter to move to the parent |
| 212 | /// of the current node. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 213 | class MoveParentMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 214 | public: |
| 215 | MoveParentMatcherNode() |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 216 | : MatcherNode(MoveParent) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 217 | |
| 218 | static inline bool classof(const MatcherNode *N) { |
| 219 | return N->getKind() == MoveParent; |
| 220 | } |
| 221 | |
| 222 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 223 | }; |
| 224 | |
| 225 | /// CheckSameMatcherNode - This checks to see if this node is exactly the same |
| 226 | /// node as the specified match that was recorded with 'Record'. This is used |
| 227 | /// when patterns have the same name in them, like '(mul GPR:$in, GPR:$in)'. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 228 | class CheckSameMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 229 | unsigned MatchNumber; |
| 230 | public: |
| 231 | CheckSameMatcherNode(unsigned matchnumber) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 232 | : MatcherNode(CheckSame), MatchNumber(matchnumber) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 233 | |
| 234 | unsigned getMatchNumber() const { return MatchNumber; } |
| 235 | |
| 236 | static inline bool classof(const MatcherNode *N) { |
| 237 | return N->getKind() == CheckSame; |
| 238 | } |
| 239 | |
| 240 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 241 | }; |
| 242 | |
| 243 | /// CheckPatternPredicateMatcherNode - This checks the target-specific predicate |
| 244 | /// to see if the entire pattern is capable of matching. This predicate does |
| 245 | /// not take a node as input. This is used for subtarget feature checks etc. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 246 | class CheckPatternPredicateMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 247 | std::string Predicate; |
| 248 | public: |
| 249 | CheckPatternPredicateMatcherNode(StringRef predicate) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 250 | : MatcherNode(CheckPatternPredicate), Predicate(predicate) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 251 | |
| 252 | StringRef getPredicate() const { return Predicate; } |
| 253 | |
| 254 | static inline bool classof(const MatcherNode *N) { |
| 255 | return N->getKind() == CheckPatternPredicate; |
| 256 | } |
| 257 | |
| 258 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 259 | }; |
| 260 | |
| 261 | /// CheckPredicateMatcherNode - This checks the target-specific predicate to |
| 262 | /// see if the node is acceptable. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 263 | class CheckPredicateMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 264 | StringRef PredName; |
| 265 | public: |
| 266 | CheckPredicateMatcherNode(StringRef predname) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 267 | : MatcherNode(CheckPredicate), PredName(predname) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 268 | |
| 269 | StringRef getPredicateName() const { return PredName; } |
| 270 | |
| 271 | static inline bool classof(const MatcherNode *N) { |
| 272 | return N->getKind() == CheckPredicate; |
| 273 | } |
| 274 | |
| 275 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 276 | }; |
| 277 | |
| 278 | |
| 279 | /// CheckOpcodeMatcherNode - This checks to see if the current node has the |
| 280 | /// specified opcode, if not it fails to match. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 281 | class CheckOpcodeMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 282 | StringRef OpcodeName; |
| 283 | public: |
| 284 | CheckOpcodeMatcherNode(StringRef opcodename) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 285 | : MatcherNode(CheckOpcode), OpcodeName(opcodename) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 286 | |
| 287 | StringRef getOpcodeName() const { return OpcodeName; } |
| 288 | |
| 289 | static inline bool classof(const MatcherNode *N) { |
| 290 | return N->getKind() == CheckOpcode; |
| 291 | } |
| 292 | |
| 293 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 294 | }; |
| 295 | |
Chris Lattner | f58c08e | 2010-02-22 22:30:37 +0000 | [diff] [blame] | 296 | /// CheckMultiOpcodeMatcherNode - This checks to see if the current node has one |
| 297 | /// of the specified opcode, if not it fails to match. |
| 298 | class CheckMultiOpcodeMatcherNode : public MatcherNode { |
| 299 | SmallVector<StringRef, 4> OpcodeNames; |
| 300 | public: |
| 301 | CheckMultiOpcodeMatcherNode(const StringRef *opcodes, unsigned numops) |
| 302 | : MatcherNode(CheckMultiOpcode), OpcodeNames(opcodes, opcodes+numops) {} |
| 303 | |
| 304 | unsigned getNumOpcodeNames() const { return OpcodeNames.size(); } |
| 305 | StringRef getOpcodeName(unsigned i) const { return OpcodeNames[i]; } |
| 306 | |
| 307 | static inline bool classof(const MatcherNode *N) { |
| 308 | return N->getKind() == CheckMultiOpcode; |
| 309 | } |
| 310 | |
| 311 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 312 | }; |
| 313 | |
| 314 | |
| 315 | |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 316 | /// CheckTypeMatcherNode - This checks to see if the current node has the |
| 317 | /// specified type, if not it fails to match. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 318 | class CheckTypeMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 319 | MVT::SimpleValueType Type; |
| 320 | public: |
| 321 | CheckTypeMatcherNode(MVT::SimpleValueType type) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 322 | : MatcherNode(CheckType), Type(type) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 323 | |
| 324 | MVT::SimpleValueType getType() const { return Type; } |
| 325 | |
| 326 | static inline bool classof(const MatcherNode *N) { |
| 327 | return N->getKind() == CheckType; |
| 328 | } |
| 329 | |
| 330 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 331 | }; |
Chris Lattner | 3c664b3 | 2010-02-24 20:15:25 +0000 | [diff] [blame] | 332 | |
| 333 | /// CheckChildTypeMatcherNode - This checks to see if a child node has the |
| 334 | /// specified type, if not it fails to match. |
| 335 | class CheckChildTypeMatcherNode : public MatcherNode { |
| 336 | unsigned ChildNo; |
| 337 | MVT::SimpleValueType Type; |
| 338 | public: |
| 339 | CheckChildTypeMatcherNode(unsigned childno, MVT::SimpleValueType type) |
| 340 | : MatcherNode(CheckChildType), ChildNo(childno), Type(type) {} |
| 341 | |
| 342 | unsigned getChildNo() const { return ChildNo; } |
| 343 | MVT::SimpleValueType getType() const { return Type; } |
| 344 | |
| 345 | static inline bool classof(const MatcherNode *N) { |
| 346 | return N->getKind() == CheckChildType; |
| 347 | } |
| 348 | |
| 349 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 350 | }; |
| 351 | |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 352 | |
| 353 | /// CheckIntegerMatcherNode - This checks to see if the current node is a |
| 354 | /// ConstantSDNode with the specified integer value, if not it fails to match. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 355 | class CheckIntegerMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 356 | int64_t Value; |
| 357 | public: |
| 358 | CheckIntegerMatcherNode(int64_t value) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 359 | : MatcherNode(CheckInteger), Value(value) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 360 | |
| 361 | int64_t getValue() const { return Value; } |
| 362 | |
| 363 | static inline bool classof(const MatcherNode *N) { |
| 364 | return N->getKind() == CheckInteger; |
| 365 | } |
| 366 | |
| 367 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 368 | }; |
| 369 | |
| 370 | /// CheckCondCodeMatcherNode - This checks to see if the current node is a |
| 371 | /// CondCodeSDNode with the specified condition, if not it fails to match. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 372 | class CheckCondCodeMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 373 | StringRef CondCodeName; |
| 374 | public: |
| 375 | CheckCondCodeMatcherNode(StringRef condcodename) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 376 | : MatcherNode(CheckCondCode), CondCodeName(condcodename) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 377 | |
| 378 | StringRef getCondCodeName() const { return CondCodeName; } |
| 379 | |
| 380 | static inline bool classof(const MatcherNode *N) { |
| 381 | return N->getKind() == CheckCondCode; |
| 382 | } |
| 383 | |
| 384 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 385 | }; |
| 386 | |
| 387 | /// CheckValueTypeMatcherNode - This checks to see if the current node is a |
| 388 | /// VTSDNode with the specified type, if not it fails to match. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 389 | class CheckValueTypeMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 390 | StringRef TypeName; |
| 391 | public: |
| 392 | CheckValueTypeMatcherNode(StringRef type_name) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 393 | : MatcherNode(CheckValueType), TypeName(type_name) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 394 | |
| 395 | StringRef getTypeName() const { return TypeName; } |
| 396 | |
| 397 | static inline bool classof(const MatcherNode *N) { |
| 398 | return N->getKind() == CheckValueType; |
| 399 | } |
| 400 | |
| 401 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 402 | }; |
| 403 | |
| 404 | |
| 405 | |
| 406 | /// CheckComplexPatMatcherNode - This node runs the specified ComplexPattern on |
| 407 | /// the current node. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 408 | class CheckComplexPatMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 409 | const ComplexPattern &Pattern; |
| 410 | public: |
| 411 | CheckComplexPatMatcherNode(const ComplexPattern &pattern) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 412 | : MatcherNode(CheckComplexPat), Pattern(pattern) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 413 | |
Chris Lattner | dc429fd | 2010-02-17 00:31:50 +0000 | [diff] [blame] | 414 | const ComplexPattern &getPattern() const { return Pattern; } |
| 415 | |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 416 | static inline bool classof(const MatcherNode *N) { |
| 417 | return N->getKind() == CheckComplexPat; |
| 418 | } |
| 419 | |
| 420 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 421 | }; |
| 422 | |
| 423 | /// CheckAndImmMatcherNode - This checks to see if the current node is an 'and' |
| 424 | /// with something equivalent to the specified immediate. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 425 | class CheckAndImmMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 426 | int64_t Value; |
| 427 | public: |
| 428 | CheckAndImmMatcherNode(int64_t value) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 429 | : MatcherNode(CheckAndImm), Value(value) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 430 | |
| 431 | int64_t getValue() const { return Value; } |
| 432 | |
| 433 | static inline bool classof(const MatcherNode *N) { |
| 434 | return N->getKind() == CheckAndImm; |
| 435 | } |
| 436 | |
| 437 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 438 | }; |
| 439 | |
| 440 | /// CheckOrImmMatcherNode - This checks to see if the current node is an 'and' |
| 441 | /// with something equivalent to the specified immediate. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 442 | class CheckOrImmMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 443 | int64_t Value; |
| 444 | public: |
| 445 | CheckOrImmMatcherNode(int64_t value) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 446 | : MatcherNode(CheckOrImm), Value(value) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 447 | |
| 448 | int64_t getValue() const { return Value; } |
| 449 | |
| 450 | static inline bool classof(const MatcherNode *N) { |
| 451 | return N->getKind() == CheckOrImm; |
| 452 | } |
| 453 | |
| 454 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 455 | }; |
Chris Lattner | 9de3948 | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 456 | |
Chris Lattner | c6dc8f6 | 2010-02-16 19:15:55 +0000 | [diff] [blame] | 457 | /// CheckFoldableChainNodeMatcherNode - This checks to see if the current node |
| 458 | /// (which defines a chain operand) is safe to fold into a larger pattern. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 459 | class CheckFoldableChainNodeMatcherNode : public MatcherNode { |
Chris Lattner | 9de3948 | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 460 | public: |
Chris Lattner | c6dc8f6 | 2010-02-16 19:15:55 +0000 | [diff] [blame] | 461 | CheckFoldableChainNodeMatcherNode() |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 462 | : MatcherNode(CheckFoldableChainNode) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 463 | |
Chris Lattner | 9de3948 | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 464 | static inline bool classof(const MatcherNode *N) { |
Chris Lattner | c6dc8f6 | 2010-02-16 19:15:55 +0000 | [diff] [blame] | 465 | return N->getKind() == CheckFoldableChainNode; |
Chris Lattner | 9de3948 | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 466 | } |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 467 | |
Chris Lattner | 9de3948 | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 468 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 469 | }; |
| 470 | |
Chris Lattner | 283adcb | 2010-02-17 06:23:39 +0000 | [diff] [blame] | 471 | /// CheckChainCompatibleMatcherNode - Verify that the current node's chain |
| 472 | /// operand is 'compatible' with the specified recorded node's. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 473 | class CheckChainCompatibleMatcherNode : public MatcherNode { |
Chris Lattner | 283adcb | 2010-02-17 06:23:39 +0000 | [diff] [blame] | 474 | unsigned PreviousOp; |
| 475 | public: |
| 476 | CheckChainCompatibleMatcherNode(unsigned previousop) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 477 | : MatcherNode(CheckChainCompatible), PreviousOp(previousop) {} |
Chris Lattner | 283adcb | 2010-02-17 06:23:39 +0000 | [diff] [blame] | 478 | |
| 479 | unsigned getPreviousOp() const { return PreviousOp; } |
| 480 | |
| 481 | static inline bool classof(const MatcherNode *N) { |
| 482 | return N->getKind() == CheckChainCompatible; |
| 483 | } |
| 484 | |
| 485 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 486 | }; |
| 487 | |
Chris Lattner | ddfb522 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 488 | /// EmitIntegerMatcherNode - This creates a new TargetConstant. |
| 489 | class EmitIntegerMatcherNode : public MatcherNode { |
| 490 | int64_t Val; |
| 491 | MVT::SimpleValueType VT; |
| 492 | public: |
| 493 | EmitIntegerMatcherNode(int64_t val, MVT::SimpleValueType vt) |
| 494 | : MatcherNode(EmitInteger), Val(val), VT(vt) {} |
Chris Lattner | 283adcb | 2010-02-17 06:23:39 +0000 | [diff] [blame] | 495 | |
Chris Lattner | 7043e0a | 2010-02-19 07:49:56 +0000 | [diff] [blame] | 496 | int64_t getValue() const { return Val; } |
Chris Lattner | ddfb522 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 497 | MVT::SimpleValueType getVT() const { return VT; } |
| 498 | |
| 499 | static inline bool classof(const MatcherNode *N) { |
| 500 | return N->getKind() == EmitInteger; |
| 501 | } |
| 502 | |
| 503 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 504 | }; |
Chris Lattner | 3163ca5 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 505 | |
| 506 | /// EmitStringIntegerMatcherNode - A target constant whose value is represented |
| 507 | /// by a string. |
| 508 | class EmitStringIntegerMatcherNode : public MatcherNode { |
| 509 | std::string Val; |
| 510 | MVT::SimpleValueType VT; |
| 511 | public: |
| 512 | EmitStringIntegerMatcherNode(const std::string &val, MVT::SimpleValueType vt) |
| 513 | : MatcherNode(EmitStringInteger), Val(val), VT(vt) {} |
| 514 | |
| 515 | const std::string &getValue() const { return Val; } |
| 516 | MVT::SimpleValueType getVT() const { return VT; } |
| 517 | |
| 518 | static inline bool classof(const MatcherNode *N) { |
| 519 | return N->getKind() == EmitStringInteger; |
| 520 | } |
| 521 | |
| 522 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 523 | }; |
Chris Lattner | ddfb522 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 524 | |
| 525 | /// EmitRegisterMatcherNode - This creates a new TargetConstant. |
| 526 | class EmitRegisterMatcherNode : public MatcherNode { |
| 527 | /// Reg - The def for the register that we're emitting. If this is null, then |
| 528 | /// this is a reference to zero_reg. |
| 529 | Record *Reg; |
| 530 | MVT::SimpleValueType VT; |
| 531 | public: |
| 532 | EmitRegisterMatcherNode(Record *reg, MVT::SimpleValueType vt) |
| 533 | : MatcherNode(EmitRegister), Reg(reg), VT(vt) {} |
| 534 | |
| 535 | Record *getReg() const { return Reg; } |
| 536 | MVT::SimpleValueType getVT() const { return VT; } |
| 537 | |
| 538 | static inline bool classof(const MatcherNode *N) { |
| 539 | return N->getKind() == EmitRegister; |
| 540 | } |
| 541 | |
| 542 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 543 | }; |
Chris Lattner | 3163ca5 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 544 | |
| 545 | /// EmitConvertToTargetMatcherNode - Emit an operation that reads a specified |
| 546 | /// recorded node and converts it from being a ISD::Constant to |
| 547 | /// ISD::TargetConstant, likewise for ConstantFP. |
| 548 | class EmitConvertToTargetMatcherNode : public MatcherNode { |
| 549 | unsigned Slot; |
| 550 | public: |
| 551 | EmitConvertToTargetMatcherNode(unsigned slot) |
| 552 | : MatcherNode(EmitConvertToTarget), Slot(slot) {} |
| 553 | |
| 554 | unsigned getSlot() const { return Slot; } |
| 555 | |
| 556 | static inline bool classof(const MatcherNode *N) { |
| 557 | return N->getKind() == EmitConvertToTarget; |
| 558 | } |
| 559 | |
| 560 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 561 | }; |
| 562 | |
| 563 | /// EmitMergeInputChainsMatcherNode - Emit a node that merges a list of input |
| 564 | /// chains together with a token factor. The list of nodes are the nodes in the |
| 565 | /// matched pattern that have chain input/outputs. This node adds all input |
| 566 | /// chains of these nodes if they are not themselves a node in the pattern. |
| 567 | class EmitMergeInputChainsMatcherNode : public MatcherNode { |
| 568 | SmallVector<unsigned, 3> ChainNodes; |
| 569 | public: |
| 570 | EmitMergeInputChainsMatcherNode(const unsigned *nodes, unsigned NumNodes) |
| 571 | : MatcherNode(EmitMergeInputChains), ChainNodes(nodes, nodes+NumNodes) {} |
| 572 | |
| 573 | unsigned getNumNodes() const { return ChainNodes.size(); } |
| 574 | |
| 575 | unsigned getNode(unsigned i) const { |
| 576 | assert(i < ChainNodes.size()); |
| 577 | return ChainNodes[i]; |
| 578 | } |
| 579 | |
| 580 | static inline bool classof(const MatcherNode *N) { |
| 581 | return N->getKind() == EmitMergeInputChains; |
| 582 | } |
| 583 | |
| 584 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 585 | }; |
| 586 | |
| 587 | /// EmitCopyToRegMatcherNode - Emit a CopyToReg node from a value to a physreg, |
| 588 | /// pushing the chain and flag results. |
| 589 | /// |
| 590 | class EmitCopyToRegMatcherNode : public MatcherNode { |
| 591 | unsigned SrcSlot; // Value to copy into the physreg. |
| 592 | Record *DestPhysReg; |
| 593 | public: |
| 594 | EmitCopyToRegMatcherNode(unsigned srcSlot, Record *destPhysReg) |
| 595 | : MatcherNode(EmitCopyToReg), SrcSlot(srcSlot), DestPhysReg(destPhysReg) {} |
| 596 | |
| 597 | unsigned getSrcSlot() const { return SrcSlot; } |
| 598 | Record *getDestPhysReg() const { return DestPhysReg; } |
| 599 | |
| 600 | static inline bool classof(const MatcherNode *N) { |
| 601 | return N->getKind() == EmitCopyToReg; |
| 602 | } |
| 603 | |
| 604 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 605 | }; |
| 606 | |
| 607 | |
| 608 | |
| 609 | /// EmitNodeXFormMatcherNode - Emit an operation that runs an SDNodeXForm on a |
| 610 | /// recorded node and records the result. |
| 611 | class EmitNodeXFormMatcherNode : public MatcherNode { |
| 612 | unsigned Slot; |
| 613 | Record *NodeXForm; |
| 614 | public: |
| 615 | EmitNodeXFormMatcherNode(unsigned slot, Record *nodeXForm) |
| 616 | : MatcherNode(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm) {} |
| 617 | |
| 618 | unsigned getSlot() const { return Slot; } |
| 619 | Record *getNodeXForm() const { return NodeXForm; } |
| 620 | |
| 621 | static inline bool classof(const MatcherNode *N) { |
| 622 | return N->getKind() == EmitNodeXForm; |
| 623 | } |
| 624 | |
| 625 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 626 | }; |
Chris Lattner | ddfb522 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 627 | |
| 628 | /// EmitNodeMatcherNode - This signals a successful match and generates a node. |
| 629 | class EmitNodeMatcherNode : public MatcherNode { |
Chris Lattner | 3163ca5 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 630 | std::string OpcodeName; |
| 631 | const SmallVector<MVT::SimpleValueType, 3> VTs; |
| 632 | const SmallVector<unsigned, 6> Operands; |
| 633 | bool HasChain, HasFlag, HasMemRefs; |
Chris Lattner | ddfb522 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 634 | |
Chris Lattner | 3163ca5 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 635 | /// NumFixedArityOperands - If this is a fixed arity node, this is set to -1. |
| 636 | /// If this is a varidic node, this is set to the number of fixed arity |
| 637 | /// operands in the root of the pattern. The rest are appended to this node. |
| 638 | int NumFixedArityOperands; |
| 639 | public: |
| 640 | EmitNodeMatcherNode(const std::string &opcodeName, |
| 641 | const MVT::SimpleValueType *vts, unsigned numvts, |
| 642 | const unsigned *operands, unsigned numops, |
| 643 | bool hasChain, bool hasFlag, bool hasmemrefs, |
| 644 | int numfixedarityoperands) |
| 645 | : MatcherNode(EmitNode), OpcodeName(opcodeName), |
| 646 | VTs(vts, vts+numvts), Operands(operands, operands+numops), |
| 647 | HasChain(hasChain), HasFlag(hasFlag), HasMemRefs(hasmemrefs), |
| 648 | NumFixedArityOperands(numfixedarityoperands) {} |
| 649 | |
| 650 | const std::string &getOpcodeName() const { return OpcodeName; } |
| 651 | |
| 652 | unsigned getNumVTs() const { return VTs.size(); } |
| 653 | MVT::SimpleValueType getVT(unsigned i) const { |
| 654 | assert(i < VTs.size()); |
| 655 | return VTs[i]; |
| 656 | } |
| 657 | |
| 658 | unsigned getNumOperands() const { return Operands.size(); } |
| 659 | unsigned getOperand(unsigned i) const { |
| 660 | assert(i < Operands.size()); |
| 661 | return Operands[i]; |
| 662 | } |
| 663 | |
| 664 | bool hasChain() const { return HasChain; } |
| 665 | bool hasFlag() const { return HasFlag; } |
| 666 | bool hasMemRefs() const { return HasMemRefs; } |
| 667 | int getNumFixedArityOperands() const { return NumFixedArityOperands; } |
Chris Lattner | ddfb522 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 668 | |
| 669 | static inline bool classof(const MatcherNode *N) { |
| 670 | return N->getKind() == EmitNode; |
| 671 | } |
| 672 | |
| 673 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 674 | }; |
Chris Lattner | b085ea1 | 2010-02-21 06:03:07 +0000 | [diff] [blame] | 675 | |
Chris Lattner | 69f60c8 | 2010-02-24 05:33:42 +0000 | [diff] [blame] | 676 | /// MarkFlagResultsMatcherNode - This node indicates which non-root nodes in the |
| 677 | /// pattern produce flags. This allows CompleteMatchMatcherNode to update them |
| 678 | /// with the output flag of the resultant code. |
| 679 | class MarkFlagResultsMatcherNode : public MatcherNode { |
| 680 | SmallVector<unsigned, 3> FlagResultNodes; |
| 681 | public: |
| 682 | MarkFlagResultsMatcherNode(const unsigned *nodes, unsigned NumNodes) |
| 683 | : MatcherNode(MarkFlagResults), FlagResultNodes(nodes, nodes+NumNodes) {} |
| 684 | |
| 685 | unsigned getNumNodes() const { return FlagResultNodes.size(); } |
| 686 | |
| 687 | unsigned getNode(unsigned i) const { |
| 688 | assert(i < FlagResultNodes.size()); |
| 689 | return FlagResultNodes[i]; |
| 690 | } |
| 691 | |
| 692 | static inline bool classof(const MatcherNode *N) { |
| 693 | return N->getKind() == MarkFlagResults; |
| 694 | } |
| 695 | |
| 696 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 697 | }; |
| 698 | |
Chris Lattner | b085ea1 | 2010-02-21 06:03:07 +0000 | [diff] [blame] | 699 | /// CompleteMatchMatcherNode - Complete a match by replacing the results of the |
| 700 | /// pattern with the newly generated nodes. This also prints a comment |
| 701 | /// indicating the source and dest patterns. |
| 702 | class CompleteMatchMatcherNode : public MatcherNode { |
| 703 | SmallVector<unsigned, 2> Results; |
Chris Lattner | 3163ca5 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 704 | const PatternToMatch &Pattern; |
| 705 | public: |
Chris Lattner | b085ea1 | 2010-02-21 06:03:07 +0000 | [diff] [blame] | 706 | CompleteMatchMatcherNode(const unsigned *results, unsigned numresults, |
| 707 | const PatternToMatch &pattern) |
| 708 | : MatcherNode(CompleteMatch), Results(results, results+numresults), |
| 709 | Pattern(pattern) {} |
| 710 | |
| 711 | unsigned getNumResults() const { return Results.size(); } |
| 712 | unsigned getResult(unsigned R) const { return Results[R]; } |
Chris Lattner | 3163ca5 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 713 | const PatternToMatch &getPattern() const { return Pattern; } |
| 714 | |
| 715 | static inline bool classof(const MatcherNode *N) { |
Chris Lattner | b085ea1 | 2010-02-21 06:03:07 +0000 | [diff] [blame] | 716 | return N->getKind() == CompleteMatch; |
Chris Lattner | 3163ca5 | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 720 | }; |
| 721 | |
Chris Lattner | ddfb522 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 722 | |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 723 | } // end namespace llvm |
| 724 | |
| 725 | #endif |