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 | fdbdc8c | 2010-02-16 07:21:10 +0000 | [diff] [blame] | 16 | #include "llvm/Support/Casting.h" |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 17 | |
| 18 | namespace llvm { |
| 19 | class CodeGenDAGPatterns; |
| 20 | class MatcherNode; |
| 21 | class PatternToMatch; |
| 22 | class raw_ostream; |
| 23 | class ComplexPattern; |
Chris Lattner | ddfb522 | 2010-02-18 22:03:03 +0000 | [diff] [blame^] | 24 | class Record; |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 25 | |
| 26 | MatcherNode *ConvertPatternToMatcher(const PatternToMatch &Pattern, |
| 27 | const CodeGenDAGPatterns &CGP); |
| 28 | |
| 29 | void EmitMatcherTable(const MatcherNode *Matcher, raw_ostream &OS); |
| 30 | |
| 31 | |
| 32 | /// MatcherNode - Base class for all the the DAG ISel Matcher representation |
| 33 | /// nodes. |
| 34 | class MatcherNode { |
Chris Lattner | 78039ec | 2010-02-18 02:53:41 +0000 | [diff] [blame] | 35 | // The next matcher node that is executed after this one. Null if this is the |
| 36 | // last stage of a match. |
| 37 | OwningPtr<MatcherNode> Next; |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 38 | public: |
| 39 | enum KindTy { |
Chris Lattner | ddfb522 | 2010-02-18 22:03:03 +0000 | [diff] [blame^] | 40 | // Stack manipulation. |
| 41 | Push, // Push a checking scope. |
| 42 | RecordNode, // Record the current node. |
| 43 | MoveChild, // Move current node to specified child. |
| 44 | MoveParent, // Move current node to parent. |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 45 | |
Chris Lattner | ddfb522 | 2010-02-18 22:03:03 +0000 | [diff] [blame^] | 46 | // Predicate checking. |
| 47 | CheckSame, // Fail if not same as prev match. |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 48 | CheckPatternPredicate, |
Chris Lattner | ddfb522 | 2010-02-18 22:03:03 +0000 | [diff] [blame^] | 49 | CheckPredicate, // Fail if node predicate fails. |
| 50 | CheckOpcode, // Fail if not opcode. |
| 51 | CheckType, // Fail if not correct type. |
| 52 | CheckInteger, // Fail if wrong val. |
| 53 | CheckCondCode, // Fail if not condcode. |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 54 | CheckValueType, |
| 55 | CheckComplexPat, |
| 56 | CheckAndImm, |
Chris Lattner | 9de3948 | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 57 | CheckOrImm, |
Chris Lattner | 283adcb | 2010-02-17 06:23:39 +0000 | [diff] [blame] | 58 | CheckFoldableChainNode, |
Chris Lattner | ddfb522 | 2010-02-18 22:03:03 +0000 | [diff] [blame^] | 59 | CheckChainCompatible, |
| 60 | |
| 61 | // Node creation/emisssion. |
| 62 | EmitInteger, // Create a TargetConstant |
| 63 | EmitRegister, // Create a register. |
| 64 | EmitNode |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 65 | }; |
| 66 | const KindTy Kind; |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 67 | |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 68 | protected: |
| 69 | MatcherNode(KindTy K) : Kind(K) {} |
| 70 | public: |
| 71 | virtual ~MatcherNode() {} |
| 72 | |
| 73 | KindTy getKind() const { return Kind; } |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 74 | |
Chris Lattner | 78039ec | 2010-02-18 02:53:41 +0000 | [diff] [blame] | 75 | MatcherNode *getNext() { return Next.get(); } |
| 76 | const MatcherNode *getNext() const { return Next.get(); } |
| 77 | void setNext(MatcherNode *C) { Next.reset(C); } |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 78 | |
| 79 | static inline bool classof(const MatcherNode *) { return true; } |
| 80 | |
| 81 | virtual void print(raw_ostream &OS, unsigned indent = 0) const = 0; |
| 82 | void dump() const; |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 83 | protected: |
Chris Lattner | 78039ec | 2010-02-18 02:53:41 +0000 | [diff] [blame] | 84 | void printNext(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 85 | }; |
| 86 | |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 87 | /// PushMatcherNode - This pushes a failure scope on the stack and evaluates |
Chris Lattner | 78039ec | 2010-02-18 02:53:41 +0000 | [diff] [blame] | 88 | /// '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] | 89 | /// match 'Failure'. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 90 | class PushMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 91 | OwningPtr<MatcherNode> Failure; |
| 92 | public: |
Chris Lattner | 78039ec | 2010-02-18 02:53:41 +0000 | [diff] [blame] | 93 | PushMatcherNode(MatcherNode *next = 0, MatcherNode *failure = 0) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 94 | : MatcherNode(Push), Failure(failure) { |
Chris Lattner | 78039ec | 2010-02-18 02:53:41 +0000 | [diff] [blame] | 95 | setNext(next); |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | MatcherNode *getFailure() { return Failure.get(); } |
| 99 | const MatcherNode *getFailure() const { return Failure.get(); } |
| 100 | void setFailure(MatcherNode *N) { Failure.reset(N); } |
| 101 | |
| 102 | static inline bool classof(const MatcherNode *N) { |
| 103 | return N->getKind() == Push; |
| 104 | } |
| 105 | |
| 106 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 107 | }; |
| 108 | |
| 109 | /// RecordMatcherNode - Save the current node in the operand list. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 110 | class RecordMatcherNode : public MatcherNode { |
Chris Lattner | 56cf88d | 2010-02-17 01:03:09 +0000 | [diff] [blame] | 111 | /// WhatFor - This is a string indicating why we're recording this. This |
| 112 | /// should only be used for comment generation not anything semantic. |
| 113 | std::string WhatFor; |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 114 | public: |
Chris Lattner | 086ca52 | 2010-02-17 01:27:29 +0000 | [diff] [blame] | 115 | RecordMatcherNode(const std::string &whatfor) |
Chris Lattner | ddfb522 | 2010-02-18 22:03:03 +0000 | [diff] [blame^] | 116 | : MatcherNode(RecordNode), WhatFor(whatfor) {} |
Chris Lattner | 56cf88d | 2010-02-17 01:03:09 +0000 | [diff] [blame] | 117 | |
Chris Lattner | 086ca52 | 2010-02-17 01:27:29 +0000 | [diff] [blame] | 118 | const std::string &getWhatFor() const { return WhatFor; } |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 119 | |
| 120 | static inline bool classof(const MatcherNode *N) { |
Chris Lattner | ddfb522 | 2010-02-18 22:03:03 +0000 | [diff] [blame^] | 121 | return N->getKind() == RecordNode; |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 125 | }; |
| 126 | |
| 127 | /// MoveChildMatcherNode - This tells the interpreter to move into the |
| 128 | /// specified child node. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 129 | class MoveChildMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 130 | unsigned ChildNo; |
| 131 | public: |
| 132 | MoveChildMatcherNode(unsigned childNo) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 133 | : MatcherNode(MoveChild), ChildNo(childNo) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 134 | |
| 135 | unsigned getChildNo() const { return ChildNo; } |
| 136 | |
| 137 | static inline bool classof(const MatcherNode *N) { |
| 138 | return N->getKind() == MoveChild; |
| 139 | } |
| 140 | |
| 141 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 142 | }; |
| 143 | |
| 144 | /// MoveParentMatcherNode - This tells the interpreter to move to the parent |
| 145 | /// of the current node. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 146 | class MoveParentMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 147 | public: |
| 148 | MoveParentMatcherNode() |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 149 | : MatcherNode(MoveParent) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 150 | |
| 151 | static inline bool classof(const MatcherNode *N) { |
| 152 | return N->getKind() == MoveParent; |
| 153 | } |
| 154 | |
| 155 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 156 | }; |
| 157 | |
| 158 | /// CheckSameMatcherNode - This checks to see if this node is exactly the same |
| 159 | /// node as the specified match that was recorded with 'Record'. This is used |
| 160 | /// 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] | 161 | class CheckSameMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 162 | unsigned MatchNumber; |
| 163 | public: |
| 164 | CheckSameMatcherNode(unsigned matchnumber) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 165 | : MatcherNode(CheckSame), MatchNumber(matchnumber) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 166 | |
| 167 | unsigned getMatchNumber() const { return MatchNumber; } |
| 168 | |
| 169 | static inline bool classof(const MatcherNode *N) { |
| 170 | return N->getKind() == CheckSame; |
| 171 | } |
| 172 | |
| 173 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 174 | }; |
| 175 | |
| 176 | /// CheckPatternPredicateMatcherNode - This checks the target-specific predicate |
| 177 | /// to see if the entire pattern is capable of matching. This predicate does |
| 178 | /// 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] | 179 | class CheckPatternPredicateMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 180 | std::string Predicate; |
| 181 | public: |
| 182 | CheckPatternPredicateMatcherNode(StringRef predicate) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 183 | : MatcherNode(CheckPatternPredicate), Predicate(predicate) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 184 | |
| 185 | StringRef getPredicate() const { return Predicate; } |
| 186 | |
| 187 | static inline bool classof(const MatcherNode *N) { |
| 188 | return N->getKind() == CheckPatternPredicate; |
| 189 | } |
| 190 | |
| 191 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 192 | }; |
| 193 | |
| 194 | /// CheckPredicateMatcherNode - This checks the target-specific predicate to |
| 195 | /// see if the node is acceptable. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 196 | class CheckPredicateMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 197 | StringRef PredName; |
| 198 | public: |
| 199 | CheckPredicateMatcherNode(StringRef predname) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 200 | : MatcherNode(CheckPredicate), PredName(predname) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 201 | |
| 202 | StringRef getPredicateName() const { return PredName; } |
| 203 | |
| 204 | static inline bool classof(const MatcherNode *N) { |
| 205 | return N->getKind() == CheckPredicate; |
| 206 | } |
| 207 | |
| 208 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 209 | }; |
| 210 | |
| 211 | |
| 212 | /// CheckOpcodeMatcherNode - This checks to see if the current node has the |
| 213 | /// specified opcode, if not it fails to match. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 214 | class CheckOpcodeMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 215 | StringRef OpcodeName; |
| 216 | public: |
| 217 | CheckOpcodeMatcherNode(StringRef opcodename) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 218 | : MatcherNode(CheckOpcode), OpcodeName(opcodename) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 219 | |
| 220 | StringRef getOpcodeName() const { return OpcodeName; } |
| 221 | |
| 222 | static inline bool classof(const MatcherNode *N) { |
| 223 | return N->getKind() == CheckOpcode; |
| 224 | } |
| 225 | |
| 226 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 227 | }; |
| 228 | |
| 229 | /// CheckTypeMatcherNode - This checks to see if the current node has the |
| 230 | /// specified type, if not it fails to match. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 231 | class CheckTypeMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 232 | MVT::SimpleValueType Type; |
| 233 | public: |
| 234 | CheckTypeMatcherNode(MVT::SimpleValueType type) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 235 | : MatcherNode(CheckType), Type(type) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 236 | |
| 237 | MVT::SimpleValueType getType() const { return Type; } |
| 238 | |
| 239 | static inline bool classof(const MatcherNode *N) { |
| 240 | return N->getKind() == CheckType; |
| 241 | } |
| 242 | |
| 243 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 244 | }; |
| 245 | |
| 246 | /// CheckIntegerMatcherNode - This checks to see if the current node is a |
| 247 | /// ConstantSDNode with the specified integer value, if not it fails to match. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 248 | class CheckIntegerMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 249 | int64_t Value; |
| 250 | public: |
| 251 | CheckIntegerMatcherNode(int64_t value) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 252 | : MatcherNode(CheckInteger), Value(value) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 253 | |
| 254 | int64_t getValue() const { return Value; } |
| 255 | |
| 256 | static inline bool classof(const MatcherNode *N) { |
| 257 | return N->getKind() == CheckInteger; |
| 258 | } |
| 259 | |
| 260 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 261 | }; |
| 262 | |
| 263 | /// CheckCondCodeMatcherNode - This checks to see if the current node is a |
| 264 | /// CondCodeSDNode with the specified condition, if not it fails to match. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 265 | class CheckCondCodeMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 266 | StringRef CondCodeName; |
| 267 | public: |
| 268 | CheckCondCodeMatcherNode(StringRef condcodename) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 269 | : MatcherNode(CheckCondCode), CondCodeName(condcodename) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 270 | |
| 271 | StringRef getCondCodeName() const { return CondCodeName; } |
| 272 | |
| 273 | static inline bool classof(const MatcherNode *N) { |
| 274 | return N->getKind() == CheckCondCode; |
| 275 | } |
| 276 | |
| 277 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 278 | }; |
| 279 | |
| 280 | /// CheckValueTypeMatcherNode - This checks to see if the current node is a |
| 281 | /// VTSDNode with the specified type, if not it fails to match. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 282 | class CheckValueTypeMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 283 | StringRef TypeName; |
| 284 | public: |
| 285 | CheckValueTypeMatcherNode(StringRef type_name) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 286 | : MatcherNode(CheckValueType), TypeName(type_name) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 287 | |
| 288 | StringRef getTypeName() const { return TypeName; } |
| 289 | |
| 290 | static inline bool classof(const MatcherNode *N) { |
| 291 | return N->getKind() == CheckValueType; |
| 292 | } |
| 293 | |
| 294 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 295 | }; |
| 296 | |
| 297 | |
| 298 | |
| 299 | /// CheckComplexPatMatcherNode - This node runs the specified ComplexPattern on |
| 300 | /// the current node. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 301 | class CheckComplexPatMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 302 | const ComplexPattern &Pattern; |
| 303 | public: |
| 304 | CheckComplexPatMatcherNode(const ComplexPattern &pattern) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 305 | : MatcherNode(CheckComplexPat), Pattern(pattern) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 306 | |
Chris Lattner | dc429fd | 2010-02-17 00:31:50 +0000 | [diff] [blame] | 307 | const ComplexPattern &getPattern() const { return Pattern; } |
| 308 | |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 309 | static inline bool classof(const MatcherNode *N) { |
| 310 | return N->getKind() == CheckComplexPat; |
| 311 | } |
| 312 | |
| 313 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 314 | }; |
| 315 | |
| 316 | /// CheckAndImmMatcherNode - This checks to see if the current node is an 'and' |
| 317 | /// with something equivalent to the specified immediate. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 318 | class CheckAndImmMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 319 | int64_t Value; |
| 320 | public: |
| 321 | CheckAndImmMatcherNode(int64_t value) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 322 | : MatcherNode(CheckAndImm), Value(value) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 323 | |
| 324 | int64_t getValue() const { return Value; } |
| 325 | |
| 326 | static inline bool classof(const MatcherNode *N) { |
| 327 | return N->getKind() == CheckAndImm; |
| 328 | } |
| 329 | |
| 330 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 331 | }; |
| 332 | |
| 333 | /// CheckOrImmMatcherNode - This checks to see if the current node is an 'and' |
| 334 | /// with something equivalent to the specified immediate. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 335 | class CheckOrImmMatcherNode : public MatcherNode { |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 336 | int64_t Value; |
| 337 | public: |
| 338 | CheckOrImmMatcherNode(int64_t value) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 339 | : MatcherNode(CheckOrImm), Value(value) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 340 | |
| 341 | int64_t getValue() const { return Value; } |
| 342 | |
| 343 | static inline bool classof(const MatcherNode *N) { |
| 344 | return N->getKind() == CheckOrImm; |
| 345 | } |
| 346 | |
| 347 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 348 | }; |
Chris Lattner | 9de3948 | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 349 | |
Chris Lattner | c6dc8f6 | 2010-02-16 19:15:55 +0000 | [diff] [blame] | 350 | /// CheckFoldableChainNodeMatcherNode - This checks to see if the current node |
| 351 | /// (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] | 352 | class CheckFoldableChainNodeMatcherNode : public MatcherNode { |
Chris Lattner | 9de3948 | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 353 | public: |
Chris Lattner | c6dc8f6 | 2010-02-16 19:15:55 +0000 | [diff] [blame] | 354 | CheckFoldableChainNodeMatcherNode() |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 355 | : MatcherNode(CheckFoldableChainNode) {} |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 356 | |
Chris Lattner | 9de3948 | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 357 | static inline bool classof(const MatcherNode *N) { |
Chris Lattner | c6dc8f6 | 2010-02-16 19:15:55 +0000 | [diff] [blame] | 358 | return N->getKind() == CheckFoldableChainNode; |
Chris Lattner | 9de3948 | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 359 | } |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 360 | |
Chris Lattner | 9de3948 | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 361 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 362 | }; |
| 363 | |
Chris Lattner | 283adcb | 2010-02-17 06:23:39 +0000 | [diff] [blame] | 364 | /// CheckChainCompatibleMatcherNode - Verify that the current node's chain |
| 365 | /// operand is 'compatible' with the specified recorded node's. |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 366 | class CheckChainCompatibleMatcherNode : public MatcherNode { |
Chris Lattner | 283adcb | 2010-02-17 06:23:39 +0000 | [diff] [blame] | 367 | unsigned PreviousOp; |
| 368 | public: |
| 369 | CheckChainCompatibleMatcherNode(unsigned previousop) |
Chris Lattner | 3b31c98 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 370 | : MatcherNode(CheckChainCompatible), PreviousOp(previousop) {} |
Chris Lattner | 283adcb | 2010-02-17 06:23:39 +0000 | [diff] [blame] | 371 | |
| 372 | unsigned getPreviousOp() const { return PreviousOp; } |
| 373 | |
| 374 | static inline bool classof(const MatcherNode *N) { |
| 375 | return N->getKind() == CheckChainCompatible; |
| 376 | } |
| 377 | |
| 378 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 379 | }; |
| 380 | |
Chris Lattner | ddfb522 | 2010-02-18 22:03:03 +0000 | [diff] [blame^] | 381 | /// EmitIntegerMatcherNode - This creates a new TargetConstant. |
| 382 | class EmitIntegerMatcherNode : public MatcherNode { |
| 383 | int64_t Val; |
| 384 | MVT::SimpleValueType VT; |
| 385 | public: |
| 386 | EmitIntegerMatcherNode(int64_t val, MVT::SimpleValueType vt) |
| 387 | : MatcherNode(EmitInteger), Val(val), VT(vt) {} |
Chris Lattner | 283adcb | 2010-02-17 06:23:39 +0000 | [diff] [blame] | 388 | |
Chris Lattner | ddfb522 | 2010-02-18 22:03:03 +0000 | [diff] [blame^] | 389 | int64_t getVal() const { return Val; } |
| 390 | MVT::SimpleValueType getVT() const { return VT; } |
| 391 | |
| 392 | static inline bool classof(const MatcherNode *N) { |
| 393 | return N->getKind() == EmitInteger; |
| 394 | } |
| 395 | |
| 396 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 397 | }; |
| 398 | |
| 399 | /// EmitRegisterMatcherNode - This creates a new TargetConstant. |
| 400 | class EmitRegisterMatcherNode : public MatcherNode { |
| 401 | /// Reg - The def for the register that we're emitting. If this is null, then |
| 402 | /// this is a reference to zero_reg. |
| 403 | Record *Reg; |
| 404 | MVT::SimpleValueType VT; |
| 405 | public: |
| 406 | EmitRegisterMatcherNode(Record *reg, MVT::SimpleValueType vt) |
| 407 | : MatcherNode(EmitRegister), Reg(reg), VT(vt) {} |
| 408 | |
| 409 | Record *getReg() const { return Reg; } |
| 410 | MVT::SimpleValueType getVT() const { return VT; } |
| 411 | |
| 412 | static inline bool classof(const MatcherNode *N) { |
| 413 | return N->getKind() == EmitRegister; |
| 414 | } |
| 415 | |
| 416 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 417 | }; |
| 418 | |
| 419 | /// EmitNodeMatcherNode - This signals a successful match and generates a node. |
| 420 | class EmitNodeMatcherNode : public MatcherNode { |
| 421 | const PatternToMatch &Pattern; |
| 422 | public: |
| 423 | EmitNodeMatcherNode(const PatternToMatch &pattern) |
| 424 | : MatcherNode(EmitNode), Pattern(pattern) {} |
| 425 | |
| 426 | const PatternToMatch &getPattern() const { return Pattern; } |
| 427 | |
| 428 | static inline bool classof(const MatcherNode *N) { |
| 429 | return N->getKind() == EmitNode; |
| 430 | } |
| 431 | |
| 432 | virtual void print(raw_ostream &OS, unsigned indent = 0) const; |
| 433 | }; |
| 434 | |
Chris Lattner | e7d6e3c | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 435 | } // end namespace llvm |
| 436 | |
| 437 | #endif |