Chris Lattner | da272d1 | 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 | 050a03d | 2010-02-16 07:21:10 +0000 | [diff] [blame] | 13 | #include "llvm/CodeGen/ValueTypes.h" |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/OwningPtr.h" |
| 15 | #include "llvm/ADT/StringRef.h" |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/SmallVector.h" |
Chris Lattner | 050a03d | 2010-02-16 07:21:10 +0000 | [diff] [blame] | 17 | #include "llvm/Support/Casting.h" |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 18 | |
| 19 | namespace llvm { |
Jim Grosbach | 4a6d735 | 2011-03-11 02:19:02 +0000 | [diff] [blame] | 20 | struct CodeGenRegister; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 21 | class CodeGenDAGPatterns; |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 22 | class Matcher; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 23 | class PatternToMatch; |
| 24 | class raw_ostream; |
| 25 | class ComplexPattern; |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 26 | class Record; |
Chris Lattner | a230f96 | 2010-02-27 21:48:43 +0000 | [diff] [blame] | 27 | class SDNodeInfo; |
Chris Lattner | 5437906 | 2011-04-17 21:38:24 +0000 | [diff] [blame] | 28 | class TreePredicateFn; |
| 29 | class TreePattern; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 30 | |
Chris Lattner | fa342fa | 2010-03-01 07:17:40 +0000 | [diff] [blame] | 31 | Matcher *ConvertPatternToMatcher(const PatternToMatch &Pattern,unsigned Variant, |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 32 | const CodeGenDAGPatterns &CGP); |
Chris Lattner | c78f2a3 | 2010-02-28 20:49:53 +0000 | [diff] [blame] | 33 | Matcher *OptimizeMatcher(Matcher *Matcher, const CodeGenDAGPatterns &CGP); |
Chris Lattner | 4d0c931 | 2010-03-01 01:54:19 +0000 | [diff] [blame] | 34 | void EmitMatcherTable(const Matcher *Matcher, const CodeGenDAGPatterns &CGP, |
Jim Grosbach | 4a6d735 | 2011-03-11 02:19:02 +0000 | [diff] [blame] | 35 | raw_ostream &OS); |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 36 | |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 37 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 38 | /// Matcher - Base class for all the the DAG ISel Matcher representation |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 39 | /// nodes. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 40 | class Matcher { |
Chris Lattner | bd8227f | 2010-02-18 02:53:41 +0000 | [diff] [blame] | 41 | // The next matcher node that is executed after this one. Null if this is the |
| 42 | // last stage of a match. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 43 | OwningPtr<Matcher> Next; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 44 | public: |
| 45 | enum KindTy { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 46 | // Matcher state manipulation. |
Chris Lattner | 60df53e | 2010-02-25 01:56:48 +0000 | [diff] [blame] | 47 | Scope, // Push a checking scope. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 48 | RecordNode, // Record the current node. |
Chris Lattner | 19b5a75 | 2010-02-24 07:31:45 +0000 | [diff] [blame] | 49 | RecordChild, // Record a child of the current node. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 50 | RecordMemRef, // Record the memref in the current node. |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 51 | CaptureGlueInput, // If the current node has an input glue, save it. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 52 | MoveChild, // Move current node to specified child. |
| 53 | MoveParent, // Move current node to parent. |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 54 | |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 55 | // Predicate checking. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 56 | CheckSame, // Fail if not same as prev match. |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 57 | CheckPatternPredicate, |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 58 | CheckPredicate, // Fail if node predicate fails. |
| 59 | CheckOpcode, // Fail if not opcode. |
Chris Lattner | eb66921 | 2010-03-01 06:59:22 +0000 | [diff] [blame] | 60 | SwitchOpcode, // Dispatch based on opcode. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 61 | CheckType, // Fail if not correct type. |
Chris Lattner | cfe2eab | 2010-03-03 06:28:15 +0000 | [diff] [blame] | 62 | SwitchType, // Dispatch based on type. |
Chris Lattner | 23cfda7 | 2010-02-24 20:15:25 +0000 | [diff] [blame] | 63 | CheckChildType, // Fail if child has wrong type. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 64 | CheckInteger, // Fail if wrong val. |
| 65 | CheckCondCode, // Fail if not condcode. |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 66 | CheckValueType, |
| 67 | CheckComplexPat, |
| 68 | CheckAndImm, |
Chris Lattner | e39650a | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 69 | CheckOrImm, |
Chris Lattner | 9a747f1 | 2010-02-17 06:23:39 +0000 | [diff] [blame] | 70 | CheckFoldableChainNode, |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 71 | |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 72 | // Node creation/emisssion. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 73 | EmitInteger, // Create a TargetConstant |
| 74 | EmitStringInteger, // Create a TargetConstant from a string. |
| 75 | EmitRegister, // Create a register. |
| 76 | EmitConvertToTarget, // Convert a imm/fpimm to target imm/fpimm |
| 77 | EmitMergeInputChains, // Merge together a chains for an input. |
| 78 | EmitCopyToReg, // Emit a copytoreg into a physreg. |
| 79 | EmitNode, // Create a DAG node |
| 80 | EmitNodeXForm, // Run a SDNodeXForm |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 81 | MarkGlueResults, // Indicate which interior nodes have glue results. |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 82 | CompleteMatch, // Finish a match and update the results. |
Chris Lattner | 9a21500 | 2010-02-28 20:55:18 +0000 | [diff] [blame] | 83 | MorphNodeTo // Build a node, finish a match and update results. |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 84 | }; |
| 85 | const KindTy Kind; |
Chris Lattner | 8ef9c79 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 86 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 87 | protected: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 88 | Matcher(KindTy K) : Kind(K) {} |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 89 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 90 | virtual ~Matcher() {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 91 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 92 | KindTy getKind() const { return Kind; } |
Chris Lattner | 8ef9c79 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 93 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 94 | Matcher *getNext() { return Next.get(); } |
| 95 | const Matcher *getNext() const { return Next.get(); } |
| 96 | void setNext(Matcher *C) { Next.reset(C); } |
| 97 | Matcher *takeNext() { return Next.take(); } |
Chris Lattner | 19b5a75 | 2010-02-24 07:31:45 +0000 | [diff] [blame] | 98 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 99 | OwningPtr<Matcher> &getNextPtr() { return Next; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 100 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 101 | static inline bool classof(const Matcher *) { return true; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 102 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 103 | bool isEqual(const Matcher *M) const { |
| 104 | if (getKind() != M->getKind()) return false; |
| 105 | return isEqualImpl(M); |
| 106 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 107 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 108 | unsigned getHash() const { |
Chris Lattner | ca56fea | 2010-02-26 07:35:27 +0000 | [diff] [blame] | 109 | // Clear the high bit so we don't conflict with tombstones etc. |
| 110 | return ((getHashImpl() << 4) ^ getKind()) & (~0U>>1); |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 111 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 112 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 113 | /// isSafeToReorderWithPatternPredicate - Return true if it is safe to sink a |
| 114 | /// PatternPredicate node past this one. |
| 115 | virtual bool isSafeToReorderWithPatternPredicate() const { |
| 116 | return false; |
| 117 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 118 | |
Chris Lattner | 48aa575 | 2010-03-07 06:29:26 +0000 | [diff] [blame] | 119 | /// isSimplePredicateNode - Return true if this is a simple predicate that |
| 120 | /// operates on the node or its children without potential side effects or a |
| 121 | /// change of the current node. |
| 122 | bool isSimplePredicateNode() const { |
| 123 | switch (getKind()) { |
| 124 | default: return false; |
| 125 | case CheckSame: |
| 126 | case CheckPatternPredicate: |
| 127 | case CheckPredicate: |
| 128 | case CheckOpcode: |
| 129 | case CheckType: |
| 130 | case CheckChildType: |
| 131 | case CheckInteger: |
| 132 | case CheckCondCode: |
| 133 | case CheckValueType: |
| 134 | case CheckAndImm: |
| 135 | case CheckOrImm: |
| 136 | case CheckFoldableChainNode: |
| 137 | return true; |
| 138 | } |
| 139 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 140 | |
Chris Lattner | 48aa575 | 2010-03-07 06:29:26 +0000 | [diff] [blame] | 141 | /// isSimplePredicateOrRecordNode - Return true if this is a record node or |
| 142 | /// a simple predicate. |
| 143 | bool isSimplePredicateOrRecordNode() const { |
| 144 | return isSimplePredicateNode() || |
| 145 | getKind() == RecordNode || getKind() == RecordChild; |
| 146 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 147 | |
Chris Lattner | 48aa575 | 2010-03-07 06:29:26 +0000 | [diff] [blame] | 148 | /// unlinkNode - Unlink the specified node from this chain. If Other == this, |
| 149 | /// we unlink the next pointer and return it. Otherwise we unlink Other from |
| 150 | /// the list and return this. |
| 151 | Matcher *unlinkNode(Matcher *Other); |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 152 | |
Chris Lattner | 48aa575 | 2010-03-07 06:29:26 +0000 | [diff] [blame] | 153 | /// canMoveBefore - Return true if this matcher is the same as Other, or if |
| 154 | /// we can move this matcher past all of the nodes in-between Other and this |
| 155 | /// node. Other must be equal to or before this. |
| 156 | bool canMoveBefore(const Matcher *Other) const; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 157 | |
Chris Lattner | 48aa575 | 2010-03-07 06:29:26 +0000 | [diff] [blame] | 158 | /// canMoveBefore - Return true if it is safe to move the current matcher |
| 159 | /// across the specified one. |
| 160 | bool canMoveBeforeNode(const Matcher *Other) const; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 161 | |
Chris Lattner | 82781b9 | 2010-02-27 07:49:13 +0000 | [diff] [blame] | 162 | /// isContradictory - Return true of these two matchers could never match on |
| 163 | /// the same node. |
| 164 | bool isContradictory(const Matcher *Other) const { |
| 165 | // Since this predicate is reflexive, we canonicalize the ordering so that |
| 166 | // we always match a node against nodes with kinds that are greater or equal |
| 167 | // to them. For example, we'll pass in a CheckType node as an argument to |
| 168 | // the CheckOpcode method, not the other way around. |
| 169 | if (getKind() < Other->getKind()) |
| 170 | return isContradictoryImpl(Other); |
| 171 | return Other->isContradictoryImpl(this); |
| 172 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 173 | |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 174 | void print(raw_ostream &OS, unsigned indent = 0) const; |
Chris Lattner | 82781b9 | 2010-02-27 07:49:13 +0000 | [diff] [blame] | 175 | void printOne(raw_ostream &OS) const; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 176 | void dump() const; |
Chris Lattner | 8ef9c79 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 177 | protected: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 178 | virtual void printImpl(raw_ostream &OS, unsigned indent) const = 0; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 179 | virtual bool isEqualImpl(const Matcher *M) const = 0; |
| 180 | virtual unsigned getHashImpl() const = 0; |
Chris Lattner | 82781b9 | 2010-02-27 07:49:13 +0000 | [diff] [blame] | 181 | virtual bool isContradictoryImpl(const Matcher *M) const { return false; } |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 182 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 183 | |
Chris Lattner | d6c8472 | 2010-02-25 19:00:39 +0000 | [diff] [blame] | 184 | /// ScopeMatcher - This attempts to match each of its children to find the first |
| 185 | /// one that successfully matches. If one child fails, it tries the next child. |
| 186 | /// If none of the children match then this check fails. It never has a 'next'. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 187 | class ScopeMatcher : public Matcher { |
Chris Lattner | d6c8472 | 2010-02-25 19:00:39 +0000 | [diff] [blame] | 188 | SmallVector<Matcher*, 4> Children; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 189 | public: |
Chris Lattner | d6c8472 | 2010-02-25 19:00:39 +0000 | [diff] [blame] | 190 | ScopeMatcher(Matcher *const *children, unsigned numchildren) |
| 191 | : Matcher(Scope), Children(children, children+numchildren) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 192 | } |
Chris Lattner | d6c8472 | 2010-02-25 19:00:39 +0000 | [diff] [blame] | 193 | virtual ~ScopeMatcher(); |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 194 | |
Chris Lattner | d6c8472 | 2010-02-25 19:00:39 +0000 | [diff] [blame] | 195 | unsigned getNumChildren() const { return Children.size(); } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 196 | |
Chris Lattner | d6c8472 | 2010-02-25 19:00:39 +0000 | [diff] [blame] | 197 | Matcher *getChild(unsigned i) { return Children[i]; } |
| 198 | const Matcher *getChild(unsigned i) const { return Children[i]; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 199 | |
Chris Lattner | d6c8472 | 2010-02-25 19:00:39 +0000 | [diff] [blame] | 200 | void resetChild(unsigned i, Matcher *N) { |
| 201 | delete Children[i]; |
| 202 | Children[i] = N; |
| 203 | } |
| 204 | |
| 205 | Matcher *takeChild(unsigned i) { |
| 206 | Matcher *Res = Children[i]; |
| 207 | Children[i] = 0; |
| 208 | return Res; |
| 209 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 210 | |
Chris Lattner | ca56fea | 2010-02-26 07:35:27 +0000 | [diff] [blame] | 211 | void setNumChildren(unsigned NC) { |
| 212 | if (NC < Children.size()) { |
| 213 | // delete any children we're about to lose pointers to. |
| 214 | for (unsigned i = NC, e = Children.size(); i != e; ++i) |
| 215 | delete Children[i]; |
| 216 | } |
| 217 | Children.resize(NC); |
| 218 | } |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 219 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 220 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 60df53e | 2010-02-25 01:56:48 +0000 | [diff] [blame] | 221 | return N->getKind() == Scope; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 222 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 223 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 224 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 225 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 226 | virtual bool isEqualImpl(const Matcher *M) const { return false; } |
Chris Lattner | d6c8472 | 2010-02-25 19:00:39 +0000 | [diff] [blame] | 227 | virtual unsigned getHashImpl() const { return 12312; } |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 228 | }; |
| 229 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 230 | /// RecordMatcher - Save the current node in the operand list. |
| 231 | class RecordMatcher : public Matcher { |
Chris Lattner | c96087b | 2010-02-17 01:03:09 +0000 | [diff] [blame] | 232 | /// WhatFor - This is a string indicating why we're recording this. This |
| 233 | /// should only be used for comment generation not anything semantic. |
| 234 | std::string WhatFor; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 235 | |
Chris Lattner | 0cebe61 | 2010-03-01 02:24:17 +0000 | [diff] [blame] | 236 | /// ResultNo - The slot number in the RecordedNodes vector that this will be, |
| 237 | /// just printed as a comment. |
| 238 | unsigned ResultNo; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 239 | public: |
Chris Lattner | 0cebe61 | 2010-03-01 02:24:17 +0000 | [diff] [blame] | 240 | RecordMatcher(const std::string &whatfor, unsigned resultNo) |
| 241 | : Matcher(RecordNode), WhatFor(whatfor), ResultNo(resultNo) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 242 | |
Chris Lattner | c642b84 | 2010-02-17 01:27:29 +0000 | [diff] [blame] | 243 | const std::string &getWhatFor() const { return WhatFor; } |
Chris Lattner | 0cebe61 | 2010-03-01 02:24:17 +0000 | [diff] [blame] | 244 | unsigned getResultNo() const { return ResultNo; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 245 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 246 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 247 | return N->getKind() == RecordNode; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 248 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 249 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 250 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 251 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 252 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 253 | virtual bool isEqualImpl(const Matcher *M) const { return true; } |
| 254 | virtual unsigned getHashImpl() const { return 0; } |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 255 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 256 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 257 | /// RecordChildMatcher - Save a numbered child of the current node, or fail |
Chris Lattner | 19b5a75 | 2010-02-24 07:31:45 +0000 | [diff] [blame] | 258 | /// the match if it doesn't exist. This is logically equivalent to: |
| 259 | /// MoveChild N + RecordNode + MoveParent. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 260 | class RecordChildMatcher : public Matcher { |
Chris Lattner | 19b5a75 | 2010-02-24 07:31:45 +0000 | [diff] [blame] | 261 | unsigned ChildNo; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 262 | |
Chris Lattner | 19b5a75 | 2010-02-24 07:31:45 +0000 | [diff] [blame] | 263 | /// WhatFor - This is a string indicating why we're recording this. This |
| 264 | /// should only be used for comment generation not anything semantic. |
| 265 | std::string WhatFor; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 266 | |
Chris Lattner | 0cebe61 | 2010-03-01 02:24:17 +0000 | [diff] [blame] | 267 | /// ResultNo - The slot number in the RecordedNodes vector that this will be, |
| 268 | /// just printed as a comment. |
| 269 | unsigned ResultNo; |
Chris Lattner | 19b5a75 | 2010-02-24 07:31:45 +0000 | [diff] [blame] | 270 | public: |
Chris Lattner | 0cebe61 | 2010-03-01 02:24:17 +0000 | [diff] [blame] | 271 | RecordChildMatcher(unsigned childno, const std::string &whatfor, |
| 272 | unsigned resultNo) |
| 273 | : Matcher(RecordChild), ChildNo(childno), WhatFor(whatfor), |
| 274 | ResultNo(resultNo) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 275 | |
Chris Lattner | 19b5a75 | 2010-02-24 07:31:45 +0000 | [diff] [blame] | 276 | unsigned getChildNo() const { return ChildNo; } |
| 277 | const std::string &getWhatFor() const { return WhatFor; } |
Chris Lattner | 0cebe61 | 2010-03-01 02:24:17 +0000 | [diff] [blame] | 278 | unsigned getResultNo() const { return ResultNo; } |
| 279 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 280 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 19b5a75 | 2010-02-24 07:31:45 +0000 | [diff] [blame] | 281 | return N->getKind() == RecordChild; |
| 282 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 283 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 284 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 285 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 286 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 287 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 288 | virtual bool isEqualImpl(const Matcher *M) const { |
| 289 | return cast<RecordChildMatcher>(M)->getChildNo() == getChildNo(); |
| 290 | } |
| 291 | virtual unsigned getHashImpl() const { return getChildNo(); } |
Chris Lattner | 19b5a75 | 2010-02-24 07:31:45 +0000 | [diff] [blame] | 292 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 293 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 294 | /// RecordMemRefMatcher - Save the current node's memref. |
| 295 | class RecordMemRefMatcher : public Matcher { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 296 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 297 | RecordMemRefMatcher() : Matcher(RecordMemRef) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 298 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 299 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 300 | return N->getKind() == RecordMemRef; |
| 301 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 302 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 303 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 304 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 305 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 306 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 307 | virtual bool isEqualImpl(const Matcher *M) const { return true; } |
| 308 | virtual unsigned getHashImpl() const { return 0; } |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 309 | }; |
| 310 | |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 311 | |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 312 | /// CaptureGlueInputMatcher - If the current record has a glue input, record |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 313 | /// it so that it is used as an input to the generated code. |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 314 | class CaptureGlueInputMatcher : public Matcher { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 315 | public: |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 316 | CaptureGlueInputMatcher() : Matcher(CaptureGlueInput) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 317 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 318 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 319 | return N->getKind() == CaptureGlueInput; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 320 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 321 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 322 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 323 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 324 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 325 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 326 | virtual bool isEqualImpl(const Matcher *M) const { return true; } |
| 327 | virtual unsigned getHashImpl() const { return 0; } |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 328 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 329 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 330 | /// MoveChildMatcher - This tells the interpreter to move into the |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 331 | /// specified child node. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 332 | class MoveChildMatcher : public Matcher { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 333 | unsigned ChildNo; |
| 334 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 335 | MoveChildMatcher(unsigned childNo) : Matcher(MoveChild), ChildNo(childNo) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 336 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 337 | unsigned getChildNo() const { return ChildNo; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 338 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 339 | static inline bool classof(const Matcher *N) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 340 | return N->getKind() == MoveChild; |
| 341 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 342 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 343 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 344 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 345 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 346 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 347 | virtual bool isEqualImpl(const Matcher *M) const { |
| 348 | return cast<MoveChildMatcher>(M)->getChildNo() == getChildNo(); |
| 349 | } |
| 350 | virtual unsigned getHashImpl() const { return getChildNo(); } |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 351 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 352 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 353 | /// MoveParentMatcher - This tells the interpreter to move to the parent |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 354 | /// of the current node. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 355 | class MoveParentMatcher : public Matcher { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 356 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 357 | MoveParentMatcher() : Matcher(MoveParent) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 358 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 359 | static inline bool classof(const Matcher *N) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 360 | return N->getKind() == MoveParent; |
| 361 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 362 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 363 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 364 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 365 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 366 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 367 | virtual bool isEqualImpl(const Matcher *M) const { return true; } |
| 368 | virtual unsigned getHashImpl() const { return 0; } |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 369 | }; |
| 370 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 371 | /// CheckSameMatcher - This checks to see if this node is exactly the same |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 372 | /// node as the specified match that was recorded with 'Record'. This is used |
| 373 | /// when patterns have the same name in them, like '(mul GPR:$in, GPR:$in)'. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 374 | class CheckSameMatcher : public Matcher { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 375 | unsigned MatchNumber; |
| 376 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 377 | CheckSameMatcher(unsigned matchnumber) |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 378 | : Matcher(CheckSame), MatchNumber(matchnumber) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 379 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 380 | unsigned getMatchNumber() const { return MatchNumber; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 381 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 382 | static inline bool classof(const Matcher *N) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 383 | return N->getKind() == CheckSame; |
| 384 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 385 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 386 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 387 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 388 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 389 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 390 | virtual bool isEqualImpl(const Matcher *M) const { |
| 391 | return cast<CheckSameMatcher>(M)->getMatchNumber() == getMatchNumber(); |
| 392 | } |
| 393 | virtual unsigned getHashImpl() const { return getMatchNumber(); } |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 394 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 395 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 396 | /// CheckPatternPredicateMatcher - This checks the target-specific predicate |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 397 | /// to see if the entire pattern is capable of matching. This predicate does |
| 398 | /// not take a node as input. This is used for subtarget feature checks etc. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 399 | class CheckPatternPredicateMatcher : public Matcher { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 400 | std::string Predicate; |
| 401 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 402 | CheckPatternPredicateMatcher(StringRef predicate) |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 403 | : Matcher(CheckPatternPredicate), Predicate(predicate) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 404 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 405 | StringRef getPredicate() const { return Predicate; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 406 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 407 | static inline bool classof(const Matcher *N) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 408 | return N->getKind() == CheckPatternPredicate; |
| 409 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 410 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 411 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 412 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 413 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 414 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 415 | virtual bool isEqualImpl(const Matcher *M) const { |
| 416 | return cast<CheckPatternPredicateMatcher>(M)->getPredicate() == Predicate; |
| 417 | } |
| 418 | virtual unsigned getHashImpl() const; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 419 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 420 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 421 | /// CheckPredicateMatcher - This checks the target-specific predicate to |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 422 | /// see if the node is acceptable. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 423 | class CheckPredicateMatcher : public Matcher { |
Chris Lattner | 5437906 | 2011-04-17 21:38:24 +0000 | [diff] [blame] | 424 | TreePattern *Pred; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 425 | public: |
Chris Lattner | 5437906 | 2011-04-17 21:38:24 +0000 | [diff] [blame] | 426 | CheckPredicateMatcher(const TreePredicateFn &pred); |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 427 | |
Chris Lattner | 5437906 | 2011-04-17 21:38:24 +0000 | [diff] [blame] | 428 | TreePredicateFn getPredicate() const; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 429 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 430 | static inline bool classof(const Matcher *N) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 431 | return N->getKind() == CheckPredicate; |
| 432 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 433 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 434 | // TODO: Ok? |
| 435 | //virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 436 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 437 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 438 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 439 | virtual bool isEqualImpl(const Matcher *M) const { |
Chris Lattner | 5437906 | 2011-04-17 21:38:24 +0000 | [diff] [blame] | 440 | return cast<CheckPredicateMatcher>(M)->Pred == Pred; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 441 | } |
| 442 | virtual unsigned getHashImpl() const; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 443 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 444 | |
| 445 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 446 | /// CheckOpcodeMatcher - This checks to see if the current node has the |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 447 | /// specified opcode, if not it fails to match. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 448 | class CheckOpcodeMatcher : public Matcher { |
Chris Lattner | a230f96 | 2010-02-27 21:48:43 +0000 | [diff] [blame] | 449 | const SDNodeInfo &Opcode; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 450 | public: |
Chris Lattner | a230f96 | 2010-02-27 21:48:43 +0000 | [diff] [blame] | 451 | CheckOpcodeMatcher(const SDNodeInfo &opcode) |
| 452 | : Matcher(CheckOpcode), Opcode(opcode) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 453 | |
Chris Lattner | a230f96 | 2010-02-27 21:48:43 +0000 | [diff] [blame] | 454 | const SDNodeInfo &getOpcode() const { return Opcode; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 455 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 456 | static inline bool classof(const Matcher *N) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 457 | return N->getKind() == CheckOpcode; |
| 458 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 459 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 460 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 461 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 462 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 463 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | eb66921 | 2010-03-01 06:59:22 +0000 | [diff] [blame] | 464 | virtual bool isEqualImpl(const Matcher *M) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 465 | virtual unsigned getHashImpl() const; |
Chris Lattner | 82781b9 | 2010-02-27 07:49:13 +0000 | [diff] [blame] | 466 | virtual bool isContradictoryImpl(const Matcher *M) const; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 467 | }; |
Chris Lattner | eb66921 | 2010-03-01 06:59:22 +0000 | [diff] [blame] | 468 | |
| 469 | /// SwitchOpcodeMatcher - Switch based on the current node's opcode, dispatching |
| 470 | /// to one matcher per opcode. If the opcode doesn't match any of the cases, |
| 471 | /// then the match fails. This is semantically equivalent to a Scope node where |
| 472 | /// every child does a CheckOpcode, but is much faster. |
| 473 | class SwitchOpcodeMatcher : public Matcher { |
| 474 | SmallVector<std::pair<const SDNodeInfo*, Matcher*>, 8> Cases; |
| 475 | public: |
| 476 | SwitchOpcodeMatcher(const std::pair<const SDNodeInfo*, Matcher*> *cases, |
| 477 | unsigned numcases) |
| 478 | : Matcher(SwitchOpcode), Cases(cases, cases+numcases) {} |
| 479 | |
| 480 | static inline bool classof(const Matcher *N) { |
| 481 | return N->getKind() == SwitchOpcode; |
| 482 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 483 | |
Chris Lattner | eb66921 | 2010-03-01 06:59:22 +0000 | [diff] [blame] | 484 | unsigned getNumCases() const { return Cases.size(); } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 485 | |
Chris Lattner | eb66921 | 2010-03-01 06:59:22 +0000 | [diff] [blame] | 486 | const SDNodeInfo &getCaseOpcode(unsigned i) const { return *Cases[i].first; } |
| 487 | Matcher *getCaseMatcher(unsigned i) { return Cases[i].second; } |
| 488 | const Matcher *getCaseMatcher(unsigned i) const { return Cases[i].second; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 489 | |
Chris Lattner | eb66921 | 2010-03-01 06:59:22 +0000 | [diff] [blame] | 490 | private: |
| 491 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
| 492 | virtual bool isEqualImpl(const Matcher *M) const { return false; } |
| 493 | virtual unsigned getHashImpl() const { return 4123; } |
| 494 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 495 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 496 | /// CheckTypeMatcher - This checks to see if the current node has the |
Chris Lattner | 084df62 | 2010-03-24 00:41:19 +0000 | [diff] [blame] | 497 | /// specified type at the specified result, if not it fails to match. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 498 | class CheckTypeMatcher : public Matcher { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 499 | MVT::SimpleValueType Type; |
Chris Lattner | 084df62 | 2010-03-24 00:41:19 +0000 | [diff] [blame] | 500 | unsigned ResNo; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 501 | public: |
Chris Lattner | 084df62 | 2010-03-24 00:41:19 +0000 | [diff] [blame] | 502 | CheckTypeMatcher(MVT::SimpleValueType type, unsigned resno) |
| 503 | : Matcher(CheckType), Type(type), ResNo(resno) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 504 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 505 | MVT::SimpleValueType getType() const { return Type; } |
Chris Lattner | 084df62 | 2010-03-24 00:41:19 +0000 | [diff] [blame] | 506 | unsigned getResNo() const { return ResNo; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 507 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 508 | static inline bool classof(const Matcher *N) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 509 | return N->getKind() == CheckType; |
| 510 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 511 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 512 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 513 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 514 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 515 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 516 | virtual bool isEqualImpl(const Matcher *M) const { |
Chris Lattner | 38717f6 | 2010-02-26 08:05:36 +0000 | [diff] [blame] | 517 | return cast<CheckTypeMatcher>(M)->Type == Type; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 518 | } |
| 519 | virtual unsigned getHashImpl() const { return Type; } |
Chris Lattner | 82781b9 | 2010-02-27 07:49:13 +0000 | [diff] [blame] | 520 | virtual bool isContradictoryImpl(const Matcher *M) const; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 521 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 522 | |
Chris Lattner | cfe2eab | 2010-03-03 06:28:15 +0000 | [diff] [blame] | 523 | /// SwitchTypeMatcher - Switch based on the current node's type, dispatching |
| 524 | /// to one matcher per case. If the type doesn't match any of the cases, |
| 525 | /// then the match fails. This is semantically equivalent to a Scope node where |
| 526 | /// every child does a CheckType, but is much faster. |
| 527 | class SwitchTypeMatcher : public Matcher { |
| 528 | SmallVector<std::pair<MVT::SimpleValueType, Matcher*>, 8> Cases; |
| 529 | public: |
| 530 | SwitchTypeMatcher(const std::pair<MVT::SimpleValueType, Matcher*> *cases, |
| 531 | unsigned numcases) |
| 532 | : Matcher(SwitchType), Cases(cases, cases+numcases) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 533 | |
Chris Lattner | cfe2eab | 2010-03-03 06:28:15 +0000 | [diff] [blame] | 534 | static inline bool classof(const Matcher *N) { |
| 535 | return N->getKind() == SwitchType; |
| 536 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 537 | |
Chris Lattner | cfe2eab | 2010-03-03 06:28:15 +0000 | [diff] [blame] | 538 | unsigned getNumCases() const { return Cases.size(); } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 539 | |
Chris Lattner | cfe2eab | 2010-03-03 06:28:15 +0000 | [diff] [blame] | 540 | MVT::SimpleValueType getCaseType(unsigned i) const { return Cases[i].first; } |
| 541 | Matcher *getCaseMatcher(unsigned i) { return Cases[i].second; } |
| 542 | const Matcher *getCaseMatcher(unsigned i) const { return Cases[i].second; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 543 | |
Chris Lattner | cfe2eab | 2010-03-03 06:28:15 +0000 | [diff] [blame] | 544 | private: |
| 545 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
| 546 | virtual bool isEqualImpl(const Matcher *M) const { return false; } |
| 547 | virtual unsigned getHashImpl() const { return 4123; } |
| 548 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 549 | |
| 550 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 551 | /// CheckChildTypeMatcher - This checks to see if a child node has the |
Chris Lattner | 23cfda7 | 2010-02-24 20:15:25 +0000 | [diff] [blame] | 552 | /// specified type, if not it fails to match. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 553 | class CheckChildTypeMatcher : public Matcher { |
Chris Lattner | 23cfda7 | 2010-02-24 20:15:25 +0000 | [diff] [blame] | 554 | unsigned ChildNo; |
| 555 | MVT::SimpleValueType Type; |
| 556 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 557 | CheckChildTypeMatcher(unsigned childno, MVT::SimpleValueType type) |
| 558 | : Matcher(CheckChildType), ChildNo(childno), Type(type) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 559 | |
Chris Lattner | 23cfda7 | 2010-02-24 20:15:25 +0000 | [diff] [blame] | 560 | unsigned getChildNo() const { return ChildNo; } |
| 561 | MVT::SimpleValueType getType() const { return Type; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 562 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 563 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 23cfda7 | 2010-02-24 20:15:25 +0000 | [diff] [blame] | 564 | return N->getKind() == CheckChildType; |
| 565 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 566 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 567 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 568 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 569 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 570 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 571 | virtual bool isEqualImpl(const Matcher *M) const { |
| 572 | return cast<CheckChildTypeMatcher>(M)->ChildNo == ChildNo && |
| 573 | cast<CheckChildTypeMatcher>(M)->Type == Type; |
| 574 | } |
| 575 | virtual unsigned getHashImpl() const { return (Type << 3) | ChildNo; } |
Chris Lattner | 82781b9 | 2010-02-27 07:49:13 +0000 | [diff] [blame] | 576 | virtual bool isContradictoryImpl(const Matcher *M) const; |
Chris Lattner | 23cfda7 | 2010-02-24 20:15:25 +0000 | [diff] [blame] | 577 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 578 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 579 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 580 | /// CheckIntegerMatcher - This checks to see if the current node is a |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 581 | /// ConstantSDNode with the specified integer value, if not it fails to match. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 582 | class CheckIntegerMatcher : public Matcher { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 583 | int64_t Value; |
| 584 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 585 | CheckIntegerMatcher(int64_t value) |
| 586 | : Matcher(CheckInteger), Value(value) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 587 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 588 | int64_t getValue() const { return Value; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 589 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 590 | static inline bool classof(const Matcher *N) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 591 | return N->getKind() == CheckInteger; |
| 592 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 593 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 594 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 595 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 596 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 597 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 598 | virtual bool isEqualImpl(const Matcher *M) const { |
| 599 | return cast<CheckIntegerMatcher>(M)->Value == Value; |
| 600 | } |
| 601 | virtual unsigned getHashImpl() const { return Value; } |
Chris Lattner | 2478962 | 2010-02-27 08:11:15 +0000 | [diff] [blame] | 602 | virtual bool isContradictoryImpl(const Matcher *M) const; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 603 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 604 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 605 | /// CheckCondCodeMatcher - This checks to see if the current node is a |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 606 | /// CondCodeSDNode with the specified condition, if not it fails to match. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 607 | class CheckCondCodeMatcher : public Matcher { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 608 | StringRef CondCodeName; |
| 609 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 610 | CheckCondCodeMatcher(StringRef condcodename) |
| 611 | : Matcher(CheckCondCode), CondCodeName(condcodename) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 612 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 613 | StringRef getCondCodeName() const { return CondCodeName; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 614 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 615 | static inline bool classof(const Matcher *N) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 616 | return N->getKind() == CheckCondCode; |
| 617 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 618 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 619 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 620 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 621 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 622 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 623 | virtual bool isEqualImpl(const Matcher *M) const { |
| 624 | return cast<CheckCondCodeMatcher>(M)->CondCodeName == CondCodeName; |
| 625 | } |
| 626 | virtual unsigned getHashImpl() const; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 627 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 628 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 629 | /// CheckValueTypeMatcher - This checks to see if the current node is a |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 630 | /// VTSDNode with the specified type, if not it fails to match. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 631 | class CheckValueTypeMatcher : public Matcher { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 632 | StringRef TypeName; |
| 633 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 634 | CheckValueTypeMatcher(StringRef type_name) |
| 635 | : Matcher(CheckValueType), TypeName(type_name) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 636 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 637 | StringRef getTypeName() const { return TypeName; } |
| 638 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 639 | static inline bool classof(const Matcher *N) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 640 | return N->getKind() == CheckValueType; |
| 641 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 642 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 643 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 644 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 645 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 646 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 647 | virtual bool isEqualImpl(const Matcher *M) const { |
| 648 | return cast<CheckValueTypeMatcher>(M)->TypeName == TypeName; |
| 649 | } |
| 650 | virtual unsigned getHashImpl() const; |
Chris Lattner | 48aa575 | 2010-03-07 06:29:26 +0000 | [diff] [blame] | 651 | bool isContradictoryImpl(const Matcher *M) const; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 652 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 653 | |
| 654 | |
| 655 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 656 | /// CheckComplexPatMatcher - This node runs the specified ComplexPattern on |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 657 | /// the current node. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 658 | class CheckComplexPatMatcher : public Matcher { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 659 | const ComplexPattern &Pattern; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 660 | |
| 661 | /// MatchNumber - This is the recorded nodes slot that contains the node we |
| 662 | /// want to match against. |
Chris Lattner | 57bf8a4 | 2010-03-04 01:23:08 +0000 | [diff] [blame] | 663 | unsigned MatchNumber; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 664 | |
Chris Lattner | 57bf8a4 | 2010-03-04 01:23:08 +0000 | [diff] [blame] | 665 | /// Name - The name of the node we're matching, for comment emission. |
| 666 | std::string Name; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 667 | |
Chris Lattner | d1aca7c | 2010-03-04 00:28:05 +0000 | [diff] [blame] | 668 | /// FirstResult - This is the first slot in the RecordedNodes list that the |
| 669 | /// result of the match populates. |
| 670 | unsigned FirstResult; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 671 | public: |
Chris Lattner | 57bf8a4 | 2010-03-04 01:23:08 +0000 | [diff] [blame] | 672 | CheckComplexPatMatcher(const ComplexPattern &pattern, unsigned matchnumber, |
| 673 | const std::string &name, unsigned firstresult) |
| 674 | : Matcher(CheckComplexPat), Pattern(pattern), MatchNumber(matchnumber), |
| 675 | Name(name), FirstResult(firstresult) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 676 | |
Chris Lattner | e609a51 | 2010-02-17 00:31:50 +0000 | [diff] [blame] | 677 | const ComplexPattern &getPattern() const { return Pattern; } |
Chris Lattner | 57bf8a4 | 2010-03-04 01:23:08 +0000 | [diff] [blame] | 678 | unsigned getMatchNumber() const { return MatchNumber; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 679 | |
Chris Lattner | 57bf8a4 | 2010-03-04 01:23:08 +0000 | [diff] [blame] | 680 | const std::string getName() const { return Name; } |
Chris Lattner | d1aca7c | 2010-03-04 00:28:05 +0000 | [diff] [blame] | 681 | unsigned getFirstResult() const { return FirstResult; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 682 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 683 | static inline bool classof(const Matcher *N) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 684 | return N->getKind() == CheckComplexPat; |
| 685 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 686 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 687 | // Not safe to move a pattern predicate past a complex pattern. |
| 688 | virtual bool isSafeToReorderWithPatternPredicate() const { return false; } |
| 689 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 690 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 691 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 692 | virtual bool isEqualImpl(const Matcher *M) const { |
Chris Lattner | 57bf8a4 | 2010-03-04 01:23:08 +0000 | [diff] [blame] | 693 | return &cast<CheckComplexPatMatcher>(M)->Pattern == &Pattern && |
| 694 | cast<CheckComplexPatMatcher>(M)->MatchNumber == MatchNumber; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 695 | } |
| 696 | virtual unsigned getHashImpl() const { |
Chris Lattner | 57bf8a4 | 2010-03-04 01:23:08 +0000 | [diff] [blame] | 697 | return (unsigned)(intptr_t)&Pattern ^ MatchNumber; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 698 | } |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 699 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 700 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 701 | /// CheckAndImmMatcher - This checks to see if the current node is an 'and' |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 702 | /// with something equivalent to the specified immediate. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 703 | class CheckAndImmMatcher : public Matcher { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 704 | int64_t Value; |
| 705 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 706 | CheckAndImmMatcher(int64_t value) |
| 707 | : Matcher(CheckAndImm), Value(value) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 708 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 709 | int64_t getValue() const { return Value; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 710 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 711 | static inline bool classof(const Matcher *N) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 712 | return N->getKind() == CheckAndImm; |
| 713 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 714 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 715 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 716 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 717 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 718 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 719 | virtual bool isEqualImpl(const Matcher *M) const { |
| 720 | return cast<CheckAndImmMatcher>(M)->Value == Value; |
| 721 | } |
| 722 | virtual unsigned getHashImpl() const { return Value; } |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 723 | }; |
| 724 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 725 | /// CheckOrImmMatcher - This checks to see if the current node is an 'and' |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 726 | /// with something equivalent to the specified immediate. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 727 | class CheckOrImmMatcher : public Matcher { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 728 | int64_t Value; |
| 729 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 730 | CheckOrImmMatcher(int64_t value) |
| 731 | : Matcher(CheckOrImm), Value(value) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 732 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 733 | int64_t getValue() const { return Value; } |
| 734 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 735 | static inline bool classof(const Matcher *N) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 736 | return N->getKind() == CheckOrImm; |
| 737 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 738 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 739 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 740 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 741 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 742 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 743 | virtual bool isEqualImpl(const Matcher *M) const { |
| 744 | return cast<CheckOrImmMatcher>(M)->Value == Value; |
| 745 | } |
| 746 | virtual unsigned getHashImpl() const { return Value; } |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 747 | }; |
Chris Lattner | e39650a | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 748 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 749 | /// CheckFoldableChainNodeMatcher - This checks to see if the current node |
Chris Lattner | 21390d7 | 2010-02-16 19:15:55 +0000 | [diff] [blame] | 750 | /// (which defines a chain operand) is safe to fold into a larger pattern. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 751 | class CheckFoldableChainNodeMatcher : public Matcher { |
Chris Lattner | e39650a | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 752 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 753 | CheckFoldableChainNodeMatcher() |
| 754 | : Matcher(CheckFoldableChainNode) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 755 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 756 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 21390d7 | 2010-02-16 19:15:55 +0000 | [diff] [blame] | 757 | return N->getKind() == CheckFoldableChainNode; |
Chris Lattner | e39650a | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 758 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 759 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 760 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 761 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 762 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 763 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 764 | virtual bool isEqualImpl(const Matcher *M) const { return true; } |
| 765 | virtual unsigned getHashImpl() const { return 0; } |
Chris Lattner | e39650a | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 766 | }; |
| 767 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 768 | /// EmitIntegerMatcher - This creates a new TargetConstant. |
| 769 | class EmitIntegerMatcher : public Matcher { |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 770 | int64_t Val; |
| 771 | MVT::SimpleValueType VT; |
| 772 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 773 | EmitIntegerMatcher(int64_t val, MVT::SimpleValueType vt) |
| 774 | : Matcher(EmitInteger), Val(val), VT(vt) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 775 | |
Chris Lattner | 906b499 | 2010-02-19 07:49:56 +0000 | [diff] [blame] | 776 | int64_t getValue() const { return Val; } |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 777 | MVT::SimpleValueType getVT() const { return VT; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 778 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 779 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 780 | return N->getKind() == EmitInteger; |
| 781 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 782 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 783 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 784 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 785 | virtual bool isEqualImpl(const Matcher *M) const { |
| 786 | return cast<EmitIntegerMatcher>(M)->Val == Val && |
| 787 | cast<EmitIntegerMatcher>(M)->VT == VT; |
| 788 | } |
| 789 | virtual unsigned getHashImpl() const { return (Val << 4) | VT; } |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 790 | }; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 791 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 792 | /// EmitStringIntegerMatcher - A target constant whose value is represented |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 793 | /// by a string. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 794 | class EmitStringIntegerMatcher : public Matcher { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 795 | std::string Val; |
| 796 | MVT::SimpleValueType VT; |
| 797 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 798 | EmitStringIntegerMatcher(const std::string &val, MVT::SimpleValueType vt) |
| 799 | : Matcher(EmitStringInteger), Val(val), VT(vt) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 800 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 801 | const std::string &getValue() const { return Val; } |
| 802 | MVT::SimpleValueType getVT() const { return VT; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 803 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 804 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 805 | return N->getKind() == EmitStringInteger; |
| 806 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 807 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 808 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 809 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 810 | virtual bool isEqualImpl(const Matcher *M) const { |
| 811 | return cast<EmitStringIntegerMatcher>(M)->Val == Val && |
| 812 | cast<EmitStringIntegerMatcher>(M)->VT == VT; |
| 813 | } |
| 814 | virtual unsigned getHashImpl() const; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 815 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 816 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 817 | /// EmitRegisterMatcher - This creates a new TargetConstant. |
| 818 | class EmitRegisterMatcher : public Matcher { |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 819 | /// Reg - The def for the register that we're emitting. If this is null, then |
| 820 | /// this is a reference to zero_reg. |
Jim Grosbach | 4a6d735 | 2011-03-11 02:19:02 +0000 | [diff] [blame] | 821 | const CodeGenRegister *Reg; |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 822 | MVT::SimpleValueType VT; |
| 823 | public: |
Jim Grosbach | 4a6d735 | 2011-03-11 02:19:02 +0000 | [diff] [blame] | 824 | EmitRegisterMatcher(const CodeGenRegister *reg, MVT::SimpleValueType vt) |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 825 | : Matcher(EmitRegister), Reg(reg), VT(vt) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 826 | |
Jim Grosbach | 4a6d735 | 2011-03-11 02:19:02 +0000 | [diff] [blame] | 827 | const CodeGenRegister *getReg() const { return Reg; } |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 828 | MVT::SimpleValueType getVT() const { return VT; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 829 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 830 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 831 | return N->getKind() == EmitRegister; |
| 832 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 833 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 834 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 835 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 836 | virtual bool isEqualImpl(const Matcher *M) const { |
| 837 | return cast<EmitRegisterMatcher>(M)->Reg == Reg && |
| 838 | cast<EmitRegisterMatcher>(M)->VT == VT; |
| 839 | } |
| 840 | virtual unsigned getHashImpl() const { |
| 841 | return ((unsigned)(intptr_t)Reg) << 4 | VT; |
| 842 | } |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 843 | }; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 844 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 845 | /// EmitConvertToTargetMatcher - Emit an operation that reads a specified |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 846 | /// recorded node and converts it from being a ISD::Constant to |
| 847 | /// ISD::TargetConstant, likewise for ConstantFP. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 848 | class EmitConvertToTargetMatcher : public Matcher { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 849 | unsigned Slot; |
| 850 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 851 | EmitConvertToTargetMatcher(unsigned slot) |
| 852 | : Matcher(EmitConvertToTarget), Slot(slot) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 853 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 854 | unsigned getSlot() const { return Slot; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 855 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 856 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 857 | return N->getKind() == EmitConvertToTarget; |
| 858 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 859 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 860 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 861 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 862 | virtual bool isEqualImpl(const Matcher *M) const { |
| 863 | return cast<EmitConvertToTargetMatcher>(M)->Slot == Slot; |
| 864 | } |
| 865 | virtual unsigned getHashImpl() const { return Slot; } |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 866 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 867 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 868 | /// EmitMergeInputChainsMatcher - Emit a node that merges a list of input |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 869 | /// chains together with a token factor. The list of nodes are the nodes in the |
| 870 | /// matched pattern that have chain input/outputs. This node adds all input |
| 871 | /// chains of these nodes if they are not themselves a node in the pattern. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 872 | class EmitMergeInputChainsMatcher : public Matcher { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 873 | SmallVector<unsigned, 3> ChainNodes; |
| 874 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 875 | EmitMergeInputChainsMatcher(const unsigned *nodes, unsigned NumNodes) |
| 876 | : Matcher(EmitMergeInputChains), ChainNodes(nodes, nodes+NumNodes) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 877 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 878 | unsigned getNumNodes() const { return ChainNodes.size(); } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 879 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 880 | unsigned getNode(unsigned i) const { |
| 881 | assert(i < ChainNodes.size()); |
| 882 | return ChainNodes[i]; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 883 | } |
| 884 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 885 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 886 | return N->getKind() == EmitMergeInputChains; |
| 887 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 888 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 889 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 890 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 891 | virtual bool isEqualImpl(const Matcher *M) const { |
| 892 | return cast<EmitMergeInputChainsMatcher>(M)->ChainNodes == ChainNodes; |
| 893 | } |
| 894 | virtual unsigned getHashImpl() const; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 895 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 896 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 897 | /// EmitCopyToRegMatcher - Emit a CopyToReg node from a value to a physreg, |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 898 | /// pushing the chain and glue results. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 899 | /// |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 900 | class EmitCopyToRegMatcher : public Matcher { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 901 | unsigned SrcSlot; // Value to copy into the physreg. |
| 902 | Record *DestPhysReg; |
| 903 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 904 | EmitCopyToRegMatcher(unsigned srcSlot, Record *destPhysReg) |
| 905 | : Matcher(EmitCopyToReg), SrcSlot(srcSlot), DestPhysReg(destPhysReg) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 906 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 907 | unsigned getSrcSlot() const { return SrcSlot; } |
| 908 | Record *getDestPhysReg() const { return DestPhysReg; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 909 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 910 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 911 | return N->getKind() == EmitCopyToReg; |
| 912 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 913 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 914 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 915 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 916 | virtual bool isEqualImpl(const Matcher *M) const { |
| 917 | return cast<EmitCopyToRegMatcher>(M)->SrcSlot == SrcSlot && |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 918 | cast<EmitCopyToRegMatcher>(M)->DestPhysReg == DestPhysReg; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 919 | } |
| 920 | virtual unsigned getHashImpl() const { |
| 921 | return SrcSlot ^ ((unsigned)(intptr_t)DestPhysReg << 4); |
| 922 | } |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 923 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 924 | |
| 925 | |
| 926 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 927 | /// EmitNodeXFormMatcher - Emit an operation that runs an SDNodeXForm on a |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 928 | /// recorded node and records the result. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 929 | class EmitNodeXFormMatcher : public Matcher { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 930 | unsigned Slot; |
| 931 | Record *NodeXForm; |
| 932 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 933 | EmitNodeXFormMatcher(unsigned slot, Record *nodeXForm) |
| 934 | : Matcher(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 935 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 936 | unsigned getSlot() const { return Slot; } |
| 937 | Record *getNodeXForm() const { return NodeXForm; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 938 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 939 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 940 | return N->getKind() == EmitNodeXForm; |
| 941 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 942 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 943 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 944 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 945 | virtual bool isEqualImpl(const Matcher *M) const { |
| 946 | return cast<EmitNodeXFormMatcher>(M)->Slot == Slot && |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 947 | cast<EmitNodeXFormMatcher>(M)->NodeXForm == NodeXForm; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 948 | } |
| 949 | virtual unsigned getHashImpl() const { |
| 950 | return Slot ^ ((unsigned)(intptr_t)NodeXForm << 4); |
| 951 | } |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 952 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 953 | |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 954 | /// EmitNodeMatcherCommon - Common class shared between EmitNode and |
Chris Lattner | 9a21500 | 2010-02-28 20:55:18 +0000 | [diff] [blame] | 955 | /// MorphNodeTo. |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 956 | class EmitNodeMatcherCommon : public Matcher { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 957 | std::string OpcodeName; |
| 958 | const SmallVector<MVT::SimpleValueType, 3> VTs; |
| 959 | const SmallVector<unsigned, 6> Operands; |
Chris Lattner | 036609b | 2010-12-23 18:28:41 +0000 | [diff] [blame] | 960 | bool HasChain, HasInGlue, HasOutGlue, HasMemRefs; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 961 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 962 | /// NumFixedArityOperands - If this is a fixed arity node, this is set to -1. |
| 963 | /// If this is a varidic node, this is set to the number of fixed arity |
| 964 | /// operands in the root of the pattern. The rest are appended to this node. |
| 965 | int NumFixedArityOperands; |
| 966 | public: |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 967 | EmitNodeMatcherCommon(const std::string &opcodeName, |
| 968 | const MVT::SimpleValueType *vts, unsigned numvts, |
| 969 | const unsigned *operands, unsigned numops, |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 970 | bool hasChain, bool hasInGlue, bool hasOutGlue, |
Chris Lattner | ff7fb60 | 2010-02-28 21:53:42 +0000 | [diff] [blame] | 971 | bool hasmemrefs, |
Chris Lattner | 9a21500 | 2010-02-28 20:55:18 +0000 | [diff] [blame] | 972 | int numfixedarityoperands, bool isMorphNodeTo) |
| 973 | : Matcher(isMorphNodeTo ? MorphNodeTo : EmitNode), OpcodeName(opcodeName), |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 974 | VTs(vts, vts+numvts), Operands(operands, operands+numops), |
Chris Lattner | 036609b | 2010-12-23 18:28:41 +0000 | [diff] [blame] | 975 | HasChain(hasChain), HasInGlue(hasInGlue), HasOutGlue(hasOutGlue), |
Chris Lattner | ff7fb60 | 2010-02-28 21:53:42 +0000 | [diff] [blame] | 976 | HasMemRefs(hasmemrefs), NumFixedArityOperands(numfixedarityoperands) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 977 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 978 | const std::string &getOpcodeName() const { return OpcodeName; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 979 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 980 | unsigned getNumVTs() const { return VTs.size(); } |
| 981 | MVT::SimpleValueType getVT(unsigned i) const { |
| 982 | assert(i < VTs.size()); |
| 983 | return VTs[i]; |
| 984 | } |
Chris Lattner | c78f2a3 | 2010-02-28 20:49:53 +0000 | [diff] [blame] | 985 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 986 | unsigned getNumOperands() const { return Operands.size(); } |
| 987 | unsigned getOperand(unsigned i) const { |
| 988 | assert(i < Operands.size()); |
| 989 | return Operands[i]; |
Chris Lattner | c78f2a3 | 2010-02-28 20:49:53 +0000 | [diff] [blame] | 990 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 991 | |
Chris Lattner | c78f2a3 | 2010-02-28 20:49:53 +0000 | [diff] [blame] | 992 | const SmallVectorImpl<MVT::SimpleValueType> &getVTList() const { return VTs; } |
| 993 | const SmallVectorImpl<unsigned> &getOperandList() const { return Operands; } |
| 994 | |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 995 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 996 | bool hasChain() const { return HasChain; } |
Chris Lattner | 036609b | 2010-12-23 18:28:41 +0000 | [diff] [blame] | 997 | bool hasInFlag() const { return HasInGlue; } |
| 998 | bool hasOutFlag() const { return HasOutGlue; } |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 999 | bool hasMemRefs() const { return HasMemRefs; } |
| 1000 | int getNumFixedArityOperands() const { return NumFixedArityOperands; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1001 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 1002 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 9a21500 | 2010-02-28 20:55:18 +0000 | [diff] [blame] | 1003 | return N->getKind() == EmitNode || N->getKind() == MorphNodeTo; |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 1004 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1005 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 1006 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 1007 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 1008 | virtual bool isEqualImpl(const Matcher *M) const; |
| 1009 | virtual unsigned getHashImpl() const; |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 1010 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1011 | |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 1012 | /// EmitNodeMatcher - This signals a successful match and generates a node. |
| 1013 | class EmitNodeMatcher : public EmitNodeMatcherCommon { |
Chris Lattner | 6281cda | 2010-02-28 02:41:25 +0000 | [diff] [blame] | 1014 | unsigned FirstResultSlot; |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 1015 | public: |
| 1016 | EmitNodeMatcher(const std::string &opcodeName, |
| 1017 | const MVT::SimpleValueType *vts, unsigned numvts, |
| 1018 | const unsigned *operands, unsigned numops, |
Chris Lattner | ff7fb60 | 2010-02-28 21:53:42 +0000 | [diff] [blame] | 1019 | bool hasChain, bool hasInFlag, bool hasOutFlag, |
| 1020 | bool hasmemrefs, |
Chris Lattner | 6281cda | 2010-02-28 02:41:25 +0000 | [diff] [blame] | 1021 | int numfixedarityoperands, unsigned firstresultslot) |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 1022 | : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain, |
Chris Lattner | ff7fb60 | 2010-02-28 21:53:42 +0000 | [diff] [blame] | 1023 | hasInFlag, hasOutFlag, hasmemrefs, |
| 1024 | numfixedarityoperands, false), |
Chris Lattner | 6281cda | 2010-02-28 02:41:25 +0000 | [diff] [blame] | 1025 | FirstResultSlot(firstresultslot) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1026 | |
Chris Lattner | 6281cda | 2010-02-28 02:41:25 +0000 | [diff] [blame] | 1027 | unsigned getFirstResultSlot() const { return FirstResultSlot; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1028 | |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 1029 | static inline bool classof(const Matcher *N) { |
| 1030 | return N->getKind() == EmitNode; |
| 1031 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1032 | |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 1033 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1034 | |
Chris Lattner | 9a21500 | 2010-02-28 20:55:18 +0000 | [diff] [blame] | 1035 | class MorphNodeToMatcher : public EmitNodeMatcherCommon { |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 1036 | const PatternToMatch &Pattern; |
| 1037 | public: |
Chris Lattner | 9a21500 | 2010-02-28 20:55:18 +0000 | [diff] [blame] | 1038 | MorphNodeToMatcher(const std::string &opcodeName, |
| 1039 | const MVT::SimpleValueType *vts, unsigned numvts, |
| 1040 | const unsigned *operands, unsigned numops, |
Chris Lattner | ff7fb60 | 2010-02-28 21:53:42 +0000 | [diff] [blame] | 1041 | bool hasChain, bool hasInFlag, bool hasOutFlag, |
| 1042 | bool hasmemrefs, |
Chris Lattner | 9a21500 | 2010-02-28 20:55:18 +0000 | [diff] [blame] | 1043 | int numfixedarityoperands, const PatternToMatch &pattern) |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 1044 | : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain, |
Chris Lattner | ff7fb60 | 2010-02-28 21:53:42 +0000 | [diff] [blame] | 1045 | hasInFlag, hasOutFlag, hasmemrefs, |
| 1046 | numfixedarityoperands, true), |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 1047 | Pattern(pattern) { |
| 1048 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1049 | |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 1050 | const PatternToMatch &getPattern() const { return Pattern; } |
| 1051 | |
| 1052 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 9a21500 | 2010-02-28 20:55:18 +0000 | [diff] [blame] | 1053 | return N->getKind() == MorphNodeTo; |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 1054 | } |
| 1055 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1056 | |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 1057 | /// MarkGlueResultsMatcher - This node indicates which non-root nodes in the |
| 1058 | /// pattern produce glue. This allows CompleteMatchMatcher to update them |
| 1059 | /// with the output glue of the resultant code. |
| 1060 | class MarkGlueResultsMatcher : public Matcher { |
| 1061 | SmallVector<unsigned, 3> GlueResultNodes; |
Chris Lattner | 02f7358 | 2010-02-24 05:33:42 +0000 | [diff] [blame] | 1062 | public: |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 1063 | MarkGlueResultsMatcher(const unsigned *nodes, unsigned NumNodes) |
| 1064 | : Matcher(MarkGlueResults), GlueResultNodes(nodes, nodes+NumNodes) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1065 | |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 1066 | unsigned getNumNodes() const { return GlueResultNodes.size(); } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1067 | |
Chris Lattner | 02f7358 | 2010-02-24 05:33:42 +0000 | [diff] [blame] | 1068 | unsigned getNode(unsigned i) const { |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 1069 | assert(i < GlueResultNodes.size()); |
| 1070 | return GlueResultNodes[i]; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 1073 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 1074 | return N->getKind() == MarkGlueResults; |
Chris Lattner | 02f7358 | 2010-02-24 05:33:42 +0000 | [diff] [blame] | 1075 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1076 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 1077 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 1078 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 1079 | virtual bool isEqualImpl(const Matcher *M) const { |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 1080 | return cast<MarkGlueResultsMatcher>(M)->GlueResultNodes == GlueResultNodes; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 1081 | } |
| 1082 | virtual unsigned getHashImpl() const; |
Chris Lattner | 02f7358 | 2010-02-24 05:33:42 +0000 | [diff] [blame] | 1083 | }; |
| 1084 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 1085 | /// CompleteMatchMatcher - Complete a match by replacing the results of the |
Chris Lattner | 77f2e27 | 2010-02-21 06:03:07 +0000 | [diff] [blame] | 1086 | /// pattern with the newly generated nodes. This also prints a comment |
| 1087 | /// indicating the source and dest patterns. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 1088 | class CompleteMatchMatcher : public Matcher { |
Chris Lattner | 77f2e27 | 2010-02-21 06:03:07 +0000 | [diff] [blame] | 1089 | SmallVector<unsigned, 2> Results; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 1090 | const PatternToMatch &Pattern; |
| 1091 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 1092 | CompleteMatchMatcher(const unsigned *results, unsigned numresults, |
Chris Lattner | c78f2a3 | 2010-02-28 20:49:53 +0000 | [diff] [blame] | 1093 | const PatternToMatch &pattern) |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 1094 | : Matcher(CompleteMatch), Results(results, results+numresults), |
Chris Lattner | 77f2e27 | 2010-02-21 06:03:07 +0000 | [diff] [blame] | 1095 | Pattern(pattern) {} |
| 1096 | |
| 1097 | unsigned getNumResults() const { return Results.size(); } |
| 1098 | unsigned getResult(unsigned R) const { return Results[R]; } |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 1099 | const PatternToMatch &getPattern() const { return Pattern; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1100 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 1101 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 77f2e27 | 2010-02-21 06:03:07 +0000 | [diff] [blame] | 1102 | return N->getKind() == CompleteMatch; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 1103 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1104 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 1105 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 1106 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 1107 | virtual bool isEqualImpl(const Matcher *M) const { |
| 1108 | return cast<CompleteMatchMatcher>(M)->Results == Results && |
| 1109 | &cast<CompleteMatchMatcher>(M)->Pattern == &Pattern; |
| 1110 | } |
| 1111 | virtual unsigned getHashImpl() const; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 1112 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1113 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 1114 | } // end namespace llvm |
| 1115 | |
| 1116 | #endif |