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