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