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