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 | |
| 13 | #include "llvm/ADT/OwningPtr.h" |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/SmallVector.h" |
Chandler Carruth | 4ffd89f | 2012-12-04 10:37:14 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/StringRef.h" |
| 16 | #include "llvm/CodeGen/ValueTypes.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 | |
Sylvestre Ledru | c8e41c5 | 2012-07-23 08:51:15 +0000 | [diff] [blame] | 38 | /// Matcher - Base class for all 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. |
Craig Topper | 936910d | 2013-10-05 05:38:16 +0000 | [diff] [blame] | 58 | CheckChildSame, // Fail if child not same as prev match. |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 59 | CheckPatternPredicate, |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 60 | CheckPredicate, // Fail if node predicate fails. |
| 61 | CheckOpcode, // Fail if not opcode. |
Chris Lattner | eb66921 | 2010-03-01 06:59:22 +0000 | [diff] [blame] | 62 | SwitchOpcode, // Dispatch based on opcode. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 63 | CheckType, // Fail if not correct type. |
Chris Lattner | cfe2eab | 2010-03-03 06:28:15 +0000 | [diff] [blame] | 64 | SwitchType, // Dispatch based on type. |
Chris Lattner | 23cfda7 | 2010-02-24 20:15:25 +0000 | [diff] [blame] | 65 | CheckChildType, // Fail if child has wrong type. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 66 | CheckInteger, // Fail if wrong val. |
| 67 | CheckCondCode, // Fail if not condcode. |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 68 | CheckValueType, |
| 69 | CheckComplexPat, |
| 70 | CheckAndImm, |
Chris Lattner | e39650a | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 71 | CheckOrImm, |
Chris Lattner | 9a747f1 | 2010-02-17 06:23:39 +0000 | [diff] [blame] | 72 | CheckFoldableChainNode, |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 73 | |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 74 | // Node creation/emisssion. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 75 | EmitInteger, // Create a TargetConstant |
| 76 | EmitStringInteger, // Create a TargetConstant from a string. |
| 77 | EmitRegister, // Create a register. |
| 78 | EmitConvertToTarget, // Convert a imm/fpimm to target imm/fpimm |
| 79 | EmitMergeInputChains, // Merge together a chains for an input. |
| 80 | EmitCopyToReg, // Emit a copytoreg into a physreg. |
| 81 | EmitNode, // Create a DAG node |
| 82 | EmitNodeXForm, // Run a SDNodeXForm |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 83 | MarkGlueResults, // Indicate which interior nodes have glue results. |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 84 | CompleteMatch, // Finish a match and update the results. |
Chris Lattner | 9a21500 | 2010-02-28 20:55:18 +0000 | [diff] [blame] | 85 | MorphNodeTo // Build a node, finish a match and update results. |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 86 | }; |
| 87 | const KindTy Kind; |
Chris Lattner | 8ef9c79 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 88 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 89 | protected: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 90 | Matcher(KindTy K) : Kind(K) {} |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 91 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 92 | virtual ~Matcher() {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 93 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 94 | KindTy getKind() const { return Kind; } |
Chris Lattner | 8ef9c79 | 2010-02-18 02:49:24 +0000 | [diff] [blame] | 95 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 96 | Matcher *getNext() { return Next.get(); } |
| 97 | const Matcher *getNext() const { return Next.get(); } |
| 98 | void setNext(Matcher *C) { Next.reset(C); } |
| 99 | Matcher *takeNext() { return Next.take(); } |
Chris Lattner | 19b5a75 | 2010-02-24 07:31:45 +0000 | [diff] [blame] | 100 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 101 | OwningPtr<Matcher> &getNextPtr() { return Next; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 102 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 103 | bool isEqual(const Matcher *M) const { |
| 104 | if (getKind() != M->getKind()) return false; |
| 105 | return isEqualImpl(M); |
| 106 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 107 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 108 | unsigned getHash() const { |
Chris Lattner | ca56fea | 2010-02-26 07:35:27 +0000 | [diff] [blame] | 109 | // Clear the high bit so we don't conflict with tombstones etc. |
| 110 | return ((getHashImpl() << 4) ^ getKind()) & (~0U>>1); |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 111 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 112 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 113 | /// isSafeToReorderWithPatternPredicate - Return true if it is safe to sink a |
| 114 | /// PatternPredicate node past this one. |
| 115 | virtual bool isSafeToReorderWithPatternPredicate() const { |
| 116 | return false; |
| 117 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 118 | |
Chris Lattner | 48aa575 | 2010-03-07 06:29:26 +0000 | [diff] [blame] | 119 | /// isSimplePredicateNode - Return true if this is a simple predicate that |
| 120 | /// operates on the node or its children without potential side effects or a |
| 121 | /// change of the current node. |
| 122 | bool isSimplePredicateNode() const { |
| 123 | switch (getKind()) { |
| 124 | default: return false; |
| 125 | case CheckSame: |
Craig Topper | 936910d | 2013-10-05 05:38:16 +0000 | [diff] [blame] | 126 | case CheckChildSame: |
Chris Lattner | 48aa575 | 2010-03-07 06:29:26 +0000 | [diff] [blame] | 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 | |
Craig Topper | 78099d1 | 2013-09-25 06:40:22 +0000 | [diff] [blame] | 159 | /// canMoveBeforeNode - Return true if it is safe to move the current matcher |
Chris Lattner | 48aa575 | 2010-03-07 06:29:26 +0000 | [diff] [blame] | 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 | |
Craig Topper | 936910d | 2013-10-05 05:38:16 +0000 | [diff] [blame] | 397 | /// CheckChildSameMatcher - This checks to see if child node is exactly the same |
| 398 | /// node as the specified match that was recorded with 'Record'. This is used |
| 399 | /// when patterns have the same name in them, like '(mul GPR:$in, GPR:$in)'. |
| 400 | class CheckChildSameMatcher : public Matcher { |
| 401 | unsigned ChildNo; |
| 402 | unsigned MatchNumber; |
| 403 | public: |
| 404 | CheckChildSameMatcher(unsigned childno, unsigned matchnumber) |
| 405 | : Matcher(CheckChildSame), ChildNo(childno), MatchNumber(matchnumber) {} |
| 406 | |
| 407 | unsigned getChildNo() const { return ChildNo; } |
| 408 | unsigned getMatchNumber() const { return MatchNumber; } |
| 409 | |
| 410 | static inline bool classof(const Matcher *N) { |
| 411 | return N->getKind() == CheckChildSame; |
| 412 | } |
| 413 | |
| 414 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 415 | |
| 416 | private: |
| 417 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
| 418 | virtual bool isEqualImpl(const Matcher *M) const { |
| 419 | return cast<CheckChildSameMatcher>(M)->ChildNo == ChildNo && |
| 420 | cast<CheckChildSameMatcher>(M)->MatchNumber == MatchNumber; |
| 421 | } |
| 422 | virtual unsigned getHashImpl() const { return (MatchNumber << 2) | ChildNo; } |
| 423 | }; |
| 424 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 425 | /// CheckPatternPredicateMatcher - This checks the target-specific predicate |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 426 | /// to see if the entire pattern is capable of matching. This predicate does |
| 427 | /// 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] | 428 | class CheckPatternPredicateMatcher : public Matcher { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 429 | std::string Predicate; |
| 430 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 431 | CheckPatternPredicateMatcher(StringRef predicate) |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 432 | : Matcher(CheckPatternPredicate), Predicate(predicate) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 433 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 434 | StringRef getPredicate() const { return Predicate; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 435 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 436 | static inline bool classof(const Matcher *N) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 437 | return N->getKind() == CheckPatternPredicate; |
| 438 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 439 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 440 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 441 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 442 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 443 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 444 | virtual bool isEqualImpl(const Matcher *M) const { |
| 445 | return cast<CheckPatternPredicateMatcher>(M)->getPredicate() == Predicate; |
| 446 | } |
| 447 | virtual unsigned getHashImpl() const; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 448 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 449 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 450 | /// CheckPredicateMatcher - This checks the target-specific predicate to |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 451 | /// see if the node is acceptable. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 452 | class CheckPredicateMatcher : public Matcher { |
Chris Lattner | 5437906 | 2011-04-17 21:38:24 +0000 | [diff] [blame] | 453 | TreePattern *Pred; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 454 | public: |
Chris Lattner | 5437906 | 2011-04-17 21:38:24 +0000 | [diff] [blame] | 455 | CheckPredicateMatcher(const TreePredicateFn &pred); |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 456 | |
Chris Lattner | 5437906 | 2011-04-17 21:38:24 +0000 | [diff] [blame] | 457 | TreePredicateFn getPredicate() const; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 458 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 459 | static inline bool classof(const Matcher *N) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 460 | return N->getKind() == CheckPredicate; |
| 461 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 462 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 463 | // TODO: Ok? |
| 464 | //virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 465 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 466 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 467 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 468 | virtual bool isEqualImpl(const Matcher *M) const { |
Chris Lattner | 5437906 | 2011-04-17 21:38:24 +0000 | [diff] [blame] | 469 | return cast<CheckPredicateMatcher>(M)->Pred == Pred; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 470 | } |
| 471 | virtual unsigned getHashImpl() const; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 472 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 473 | |
| 474 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 475 | /// CheckOpcodeMatcher - This checks to see if the current node has the |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 476 | /// specified opcode, if not it fails to match. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 477 | class CheckOpcodeMatcher : public Matcher { |
Chris Lattner | a230f96 | 2010-02-27 21:48:43 +0000 | [diff] [blame] | 478 | const SDNodeInfo &Opcode; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 479 | public: |
Chris Lattner | a230f96 | 2010-02-27 21:48:43 +0000 | [diff] [blame] | 480 | CheckOpcodeMatcher(const SDNodeInfo &opcode) |
| 481 | : Matcher(CheckOpcode), Opcode(opcode) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 482 | |
Chris Lattner | a230f96 | 2010-02-27 21:48:43 +0000 | [diff] [blame] | 483 | const SDNodeInfo &getOpcode() const { return Opcode; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 484 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 485 | static inline bool classof(const Matcher *N) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 486 | return N->getKind() == CheckOpcode; |
| 487 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 488 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 489 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 490 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 491 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 492 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | eb66921 | 2010-03-01 06:59:22 +0000 | [diff] [blame] | 493 | virtual bool isEqualImpl(const Matcher *M) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 494 | virtual unsigned getHashImpl() const; |
Chris Lattner | 82781b9 | 2010-02-27 07:49:13 +0000 | [diff] [blame] | 495 | virtual bool isContradictoryImpl(const Matcher *M) const; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 496 | }; |
Chris Lattner | eb66921 | 2010-03-01 06:59:22 +0000 | [diff] [blame] | 497 | |
| 498 | /// SwitchOpcodeMatcher - Switch based on the current node's opcode, dispatching |
| 499 | /// to one matcher per opcode. If the opcode doesn't match any of the cases, |
| 500 | /// then the match fails. This is semantically equivalent to a Scope node where |
| 501 | /// every child does a CheckOpcode, but is much faster. |
| 502 | class SwitchOpcodeMatcher : public Matcher { |
| 503 | SmallVector<std::pair<const SDNodeInfo*, Matcher*>, 8> Cases; |
| 504 | public: |
| 505 | SwitchOpcodeMatcher(const std::pair<const SDNodeInfo*, Matcher*> *cases, |
| 506 | unsigned numcases) |
| 507 | : Matcher(SwitchOpcode), Cases(cases, cases+numcases) {} |
| 508 | |
| 509 | static inline bool classof(const Matcher *N) { |
| 510 | return N->getKind() == SwitchOpcode; |
| 511 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 512 | |
Chris Lattner | eb66921 | 2010-03-01 06:59:22 +0000 | [diff] [blame] | 513 | unsigned getNumCases() const { return Cases.size(); } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 514 | |
Chris Lattner | eb66921 | 2010-03-01 06:59:22 +0000 | [diff] [blame] | 515 | const SDNodeInfo &getCaseOpcode(unsigned i) const { return *Cases[i].first; } |
| 516 | Matcher *getCaseMatcher(unsigned i) { return Cases[i].second; } |
| 517 | const Matcher *getCaseMatcher(unsigned i) const { return Cases[i].second; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 518 | |
Chris Lattner | eb66921 | 2010-03-01 06:59:22 +0000 | [diff] [blame] | 519 | private: |
| 520 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
| 521 | virtual bool isEqualImpl(const Matcher *M) const { return false; } |
| 522 | virtual unsigned getHashImpl() const { return 4123; } |
| 523 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 524 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 525 | /// CheckTypeMatcher - This checks to see if the current node has the |
Chris Lattner | 084df62 | 2010-03-24 00:41:19 +0000 | [diff] [blame] | 526 | /// specified type at the specified result, if not it fails to match. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 527 | class CheckTypeMatcher : public Matcher { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 528 | MVT::SimpleValueType Type; |
Chris Lattner | 084df62 | 2010-03-24 00:41:19 +0000 | [diff] [blame] | 529 | unsigned ResNo; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 530 | public: |
Chris Lattner | 084df62 | 2010-03-24 00:41:19 +0000 | [diff] [blame] | 531 | CheckTypeMatcher(MVT::SimpleValueType type, unsigned resno) |
| 532 | : Matcher(CheckType), Type(type), ResNo(resno) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 533 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 534 | MVT::SimpleValueType getType() const { return Type; } |
Chris Lattner | 084df62 | 2010-03-24 00:41:19 +0000 | [diff] [blame] | 535 | unsigned getResNo() const { return ResNo; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 536 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 537 | static inline bool classof(const Matcher *N) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 538 | return N->getKind() == CheckType; |
| 539 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 540 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 541 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 542 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 543 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 544 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 545 | virtual bool isEqualImpl(const Matcher *M) const { |
Chris Lattner | 38717f6 | 2010-02-26 08:05:36 +0000 | [diff] [blame] | 546 | return cast<CheckTypeMatcher>(M)->Type == Type; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 547 | } |
| 548 | virtual unsigned getHashImpl() const { return Type; } |
Chris Lattner | 82781b9 | 2010-02-27 07:49:13 +0000 | [diff] [blame] | 549 | virtual bool isContradictoryImpl(const Matcher *M) const; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 550 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 551 | |
Chris Lattner | cfe2eab | 2010-03-03 06:28:15 +0000 | [diff] [blame] | 552 | /// SwitchTypeMatcher - Switch based on the current node's type, dispatching |
| 553 | /// to one matcher per case. If the type doesn't match any of the cases, |
| 554 | /// then the match fails. This is semantically equivalent to a Scope node where |
| 555 | /// every child does a CheckType, but is much faster. |
| 556 | class SwitchTypeMatcher : public Matcher { |
| 557 | SmallVector<std::pair<MVT::SimpleValueType, Matcher*>, 8> Cases; |
| 558 | public: |
| 559 | SwitchTypeMatcher(const std::pair<MVT::SimpleValueType, Matcher*> *cases, |
| 560 | unsigned numcases) |
| 561 | : Matcher(SwitchType), Cases(cases, cases+numcases) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 562 | |
Chris Lattner | cfe2eab | 2010-03-03 06:28:15 +0000 | [diff] [blame] | 563 | static inline bool classof(const Matcher *N) { |
| 564 | return N->getKind() == SwitchType; |
| 565 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 566 | |
Chris Lattner | cfe2eab | 2010-03-03 06:28:15 +0000 | [diff] [blame] | 567 | unsigned getNumCases() const { return Cases.size(); } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 568 | |
Chris Lattner | cfe2eab | 2010-03-03 06:28:15 +0000 | [diff] [blame] | 569 | MVT::SimpleValueType getCaseType(unsigned i) const { return Cases[i].first; } |
| 570 | Matcher *getCaseMatcher(unsigned i) { return Cases[i].second; } |
| 571 | const Matcher *getCaseMatcher(unsigned i) const { return Cases[i].second; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 572 | |
Chris Lattner | cfe2eab | 2010-03-03 06:28:15 +0000 | [diff] [blame] | 573 | private: |
| 574 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
| 575 | virtual bool isEqualImpl(const Matcher *M) const { return false; } |
| 576 | virtual unsigned getHashImpl() const { return 4123; } |
| 577 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 578 | |
| 579 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 580 | /// CheckChildTypeMatcher - This checks to see if a child node has the |
Chris Lattner | 23cfda7 | 2010-02-24 20:15:25 +0000 | [diff] [blame] | 581 | /// specified type, if not it fails to match. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 582 | class CheckChildTypeMatcher : public Matcher { |
Chris Lattner | 23cfda7 | 2010-02-24 20:15:25 +0000 | [diff] [blame] | 583 | unsigned ChildNo; |
| 584 | MVT::SimpleValueType Type; |
| 585 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 586 | CheckChildTypeMatcher(unsigned childno, MVT::SimpleValueType type) |
| 587 | : Matcher(CheckChildType), ChildNo(childno), Type(type) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 588 | |
Chris Lattner | 23cfda7 | 2010-02-24 20:15:25 +0000 | [diff] [blame] | 589 | unsigned getChildNo() const { return ChildNo; } |
| 590 | MVT::SimpleValueType getType() const { return Type; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 591 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 592 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 23cfda7 | 2010-02-24 20:15:25 +0000 | [diff] [blame] | 593 | return N->getKind() == CheckChildType; |
| 594 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 595 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 596 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 597 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 598 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 599 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 600 | virtual bool isEqualImpl(const Matcher *M) const { |
| 601 | return cast<CheckChildTypeMatcher>(M)->ChildNo == ChildNo && |
| 602 | cast<CheckChildTypeMatcher>(M)->Type == Type; |
| 603 | } |
| 604 | virtual unsigned getHashImpl() const { return (Type << 3) | ChildNo; } |
Chris Lattner | 82781b9 | 2010-02-27 07:49:13 +0000 | [diff] [blame] | 605 | virtual bool isContradictoryImpl(const Matcher *M) const; |
Chris Lattner | 23cfda7 | 2010-02-24 20:15:25 +0000 | [diff] [blame] | 606 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 607 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 608 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 609 | /// CheckIntegerMatcher - This checks to see if the current node is a |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 610 | /// ConstantSDNode with the specified integer value, if not it fails to match. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 611 | class CheckIntegerMatcher : public Matcher { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 612 | int64_t Value; |
| 613 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 614 | CheckIntegerMatcher(int64_t value) |
| 615 | : Matcher(CheckInteger), Value(value) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 616 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 617 | int64_t getValue() const { return Value; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 618 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 619 | static inline bool classof(const Matcher *N) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 620 | return N->getKind() == CheckInteger; |
| 621 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 622 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 623 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 624 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 625 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 626 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 627 | virtual bool isEqualImpl(const Matcher *M) const { |
| 628 | return cast<CheckIntegerMatcher>(M)->Value == Value; |
| 629 | } |
| 630 | virtual unsigned getHashImpl() const { return Value; } |
Chris Lattner | 2478962 | 2010-02-27 08:11:15 +0000 | [diff] [blame] | 631 | virtual bool isContradictoryImpl(const Matcher *M) const; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 632 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 633 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 634 | /// CheckCondCodeMatcher - This checks to see if the current node is a |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 635 | /// CondCodeSDNode with the specified condition, if not it fails to match. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 636 | class CheckCondCodeMatcher : public Matcher { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 637 | StringRef CondCodeName; |
| 638 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 639 | CheckCondCodeMatcher(StringRef condcodename) |
| 640 | : Matcher(CheckCondCode), CondCodeName(condcodename) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 641 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 642 | StringRef getCondCodeName() const { return CondCodeName; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 643 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 644 | static inline bool classof(const Matcher *N) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 645 | return N->getKind() == CheckCondCode; |
| 646 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 647 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 648 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 649 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 650 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 651 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 652 | virtual bool isEqualImpl(const Matcher *M) const { |
| 653 | return cast<CheckCondCodeMatcher>(M)->CondCodeName == CondCodeName; |
| 654 | } |
| 655 | virtual unsigned getHashImpl() const; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 656 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 657 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 658 | /// CheckValueTypeMatcher - This checks to see if the current node is a |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 659 | /// VTSDNode with the specified type, if not it fails to match. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 660 | class CheckValueTypeMatcher : public Matcher { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 661 | StringRef TypeName; |
| 662 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 663 | CheckValueTypeMatcher(StringRef type_name) |
| 664 | : Matcher(CheckValueType), TypeName(type_name) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 665 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 666 | StringRef getTypeName() const { return TypeName; } |
| 667 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 668 | static inline bool classof(const Matcher *N) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 669 | return N->getKind() == CheckValueType; |
| 670 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 671 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 672 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 673 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 674 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 675 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 676 | virtual bool isEqualImpl(const Matcher *M) const { |
| 677 | return cast<CheckValueTypeMatcher>(M)->TypeName == TypeName; |
| 678 | } |
| 679 | virtual unsigned getHashImpl() const; |
Chris Lattner | 48aa575 | 2010-03-07 06:29:26 +0000 | [diff] [blame] | 680 | bool isContradictoryImpl(const Matcher *M) const; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 681 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 682 | |
| 683 | |
| 684 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 685 | /// CheckComplexPatMatcher - This node runs the specified ComplexPattern on |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 686 | /// the current node. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 687 | class CheckComplexPatMatcher : public Matcher { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 688 | const ComplexPattern &Pattern; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 689 | |
| 690 | /// MatchNumber - This is the recorded nodes slot that contains the node we |
| 691 | /// want to match against. |
Chris Lattner | 57bf8a4 | 2010-03-04 01:23:08 +0000 | [diff] [blame] | 692 | unsigned MatchNumber; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 693 | |
Chris Lattner | 57bf8a4 | 2010-03-04 01:23:08 +0000 | [diff] [blame] | 694 | /// Name - The name of the node we're matching, for comment emission. |
| 695 | std::string Name; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 696 | |
Chris Lattner | d1aca7c | 2010-03-04 00:28:05 +0000 | [diff] [blame] | 697 | /// FirstResult - This is the first slot in the RecordedNodes list that the |
| 698 | /// result of the match populates. |
| 699 | unsigned FirstResult; |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 700 | public: |
Chris Lattner | 57bf8a4 | 2010-03-04 01:23:08 +0000 | [diff] [blame] | 701 | CheckComplexPatMatcher(const ComplexPattern &pattern, unsigned matchnumber, |
| 702 | const std::string &name, unsigned firstresult) |
| 703 | : Matcher(CheckComplexPat), Pattern(pattern), MatchNumber(matchnumber), |
| 704 | Name(name), FirstResult(firstresult) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 705 | |
Chris Lattner | e609a51 | 2010-02-17 00:31:50 +0000 | [diff] [blame] | 706 | const ComplexPattern &getPattern() const { return Pattern; } |
Chris Lattner | 57bf8a4 | 2010-03-04 01:23:08 +0000 | [diff] [blame] | 707 | unsigned getMatchNumber() const { return MatchNumber; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 708 | |
Chris Lattner | 57bf8a4 | 2010-03-04 01:23:08 +0000 | [diff] [blame] | 709 | const std::string getName() const { return Name; } |
Chris Lattner | d1aca7c | 2010-03-04 00:28:05 +0000 | [diff] [blame] | 710 | unsigned getFirstResult() const { return FirstResult; } |
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() == CheckComplexPat; |
| 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 | // Not safe to move a pattern predicate past a complex pattern. |
| 717 | virtual bool isSafeToReorderWithPatternPredicate() const { return false; } |
| 718 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 719 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 720 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 721 | virtual bool isEqualImpl(const Matcher *M) const { |
Chris Lattner | 57bf8a4 | 2010-03-04 01:23:08 +0000 | [diff] [blame] | 722 | return &cast<CheckComplexPatMatcher>(M)->Pattern == &Pattern && |
| 723 | cast<CheckComplexPatMatcher>(M)->MatchNumber == MatchNumber; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 724 | } |
| 725 | virtual unsigned getHashImpl() const { |
Chris Lattner | 57bf8a4 | 2010-03-04 01:23:08 +0000 | [diff] [blame] | 726 | return (unsigned)(intptr_t)&Pattern ^ MatchNumber; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 727 | } |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 728 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 729 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 730 | /// CheckAndImmMatcher - This checks to see if the current node is an 'and' |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 731 | /// with something equivalent to the specified immediate. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 732 | class CheckAndImmMatcher : public Matcher { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 733 | int64_t Value; |
| 734 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 735 | CheckAndImmMatcher(int64_t value) |
| 736 | : Matcher(CheckAndImm), Value(value) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 737 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 738 | int64_t getValue() const { return Value; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 739 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 740 | static inline bool classof(const Matcher *N) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 741 | return N->getKind() == CheckAndImm; |
| 742 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 743 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 744 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 745 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 746 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 747 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 748 | virtual bool isEqualImpl(const Matcher *M) const { |
| 749 | return cast<CheckAndImmMatcher>(M)->Value == Value; |
| 750 | } |
| 751 | virtual unsigned getHashImpl() const { return Value; } |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 752 | }; |
| 753 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 754 | /// CheckOrImmMatcher - This checks to see if the current node is an 'and' |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 755 | /// with something equivalent to the specified immediate. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 756 | class CheckOrImmMatcher : public Matcher { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 757 | int64_t Value; |
| 758 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 759 | CheckOrImmMatcher(int64_t value) |
| 760 | : Matcher(CheckOrImm), Value(value) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 761 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 762 | int64_t getValue() const { return Value; } |
| 763 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 764 | static inline bool classof(const Matcher *N) { |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 765 | return N->getKind() == CheckOrImm; |
| 766 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 767 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 768 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 769 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 770 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 771 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 772 | virtual bool isEqualImpl(const Matcher *M) const { |
| 773 | return cast<CheckOrImmMatcher>(M)->Value == Value; |
| 774 | } |
| 775 | virtual unsigned getHashImpl() const { return Value; } |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 776 | }; |
Chris Lattner | e39650a | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 777 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 778 | /// CheckFoldableChainNodeMatcher - This checks to see if the current node |
Chris Lattner | 21390d7 | 2010-02-16 19:15:55 +0000 | [diff] [blame] | 779 | /// (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] | 780 | class CheckFoldableChainNodeMatcher : public Matcher { |
Chris Lattner | e39650a | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 781 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 782 | CheckFoldableChainNodeMatcher() |
| 783 | : Matcher(CheckFoldableChainNode) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 784 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 785 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 21390d7 | 2010-02-16 19:15:55 +0000 | [diff] [blame] | 786 | return N->getKind() == CheckFoldableChainNode; |
Chris Lattner | e39650a | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 787 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 788 | |
Chris Lattner | d323fd4 | 2010-02-27 06:22:57 +0000 | [diff] [blame] | 789 | virtual bool isSafeToReorderWithPatternPredicate() const { return true; } |
| 790 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 791 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 792 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 793 | virtual bool isEqualImpl(const Matcher *M) const { return true; } |
| 794 | virtual unsigned getHashImpl() const { return 0; } |
Chris Lattner | e39650a | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 795 | }; |
| 796 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 797 | /// EmitIntegerMatcher - This creates a new TargetConstant. |
| 798 | class EmitIntegerMatcher : public Matcher { |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 799 | int64_t Val; |
| 800 | MVT::SimpleValueType VT; |
| 801 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 802 | EmitIntegerMatcher(int64_t val, MVT::SimpleValueType vt) |
| 803 | : Matcher(EmitInteger), Val(val), VT(vt) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 804 | |
Chris Lattner | 906b499 | 2010-02-19 07:49:56 +0000 | [diff] [blame] | 805 | int64_t getValue() const { return Val; } |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 806 | MVT::SimpleValueType getVT() const { return VT; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 807 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 808 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 809 | return N->getKind() == EmitInteger; |
| 810 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 811 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 812 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 813 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 814 | virtual bool isEqualImpl(const Matcher *M) const { |
| 815 | return cast<EmitIntegerMatcher>(M)->Val == Val && |
| 816 | cast<EmitIntegerMatcher>(M)->VT == VT; |
| 817 | } |
| 818 | virtual unsigned getHashImpl() const { return (Val << 4) | VT; } |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 819 | }; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 820 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 821 | /// EmitStringIntegerMatcher - A target constant whose value is represented |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 822 | /// by a string. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 823 | class EmitStringIntegerMatcher : public Matcher { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 824 | std::string Val; |
| 825 | MVT::SimpleValueType VT; |
| 826 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 827 | EmitStringIntegerMatcher(const std::string &val, MVT::SimpleValueType vt) |
| 828 | : Matcher(EmitStringInteger), Val(val), VT(vt) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 829 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 830 | const std::string &getValue() const { return Val; } |
| 831 | MVT::SimpleValueType getVT() const { return VT; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 832 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 833 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 834 | return N->getKind() == EmitStringInteger; |
| 835 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 836 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 837 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 838 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 839 | virtual bool isEqualImpl(const Matcher *M) const { |
| 840 | return cast<EmitStringIntegerMatcher>(M)->Val == Val && |
| 841 | cast<EmitStringIntegerMatcher>(M)->VT == VT; |
| 842 | } |
| 843 | virtual unsigned getHashImpl() const; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 844 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 845 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 846 | /// EmitRegisterMatcher - This creates a new TargetConstant. |
| 847 | class EmitRegisterMatcher : public Matcher { |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 848 | /// Reg - The def for the register that we're emitting. If this is null, then |
| 849 | /// this is a reference to zero_reg. |
Jim Grosbach | 4a6d735 | 2011-03-11 02:19:02 +0000 | [diff] [blame] | 850 | const CodeGenRegister *Reg; |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 851 | MVT::SimpleValueType VT; |
| 852 | public: |
Jim Grosbach | 4a6d735 | 2011-03-11 02:19:02 +0000 | [diff] [blame] | 853 | EmitRegisterMatcher(const CodeGenRegister *reg, MVT::SimpleValueType vt) |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 854 | : Matcher(EmitRegister), Reg(reg), VT(vt) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 855 | |
Jim Grosbach | 4a6d735 | 2011-03-11 02:19:02 +0000 | [diff] [blame] | 856 | const CodeGenRegister *getReg() const { return Reg; } |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 857 | MVT::SimpleValueType getVT() const { return VT; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 858 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 859 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 860 | return N->getKind() == EmitRegister; |
| 861 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 862 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 863 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 864 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 865 | virtual bool isEqualImpl(const Matcher *M) const { |
| 866 | return cast<EmitRegisterMatcher>(M)->Reg == Reg && |
| 867 | cast<EmitRegisterMatcher>(M)->VT == VT; |
| 868 | } |
| 869 | virtual unsigned getHashImpl() const { |
| 870 | return ((unsigned)(intptr_t)Reg) << 4 | VT; |
| 871 | } |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 872 | }; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 873 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 874 | /// EmitConvertToTargetMatcher - Emit an operation that reads a specified |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 875 | /// recorded node and converts it from being a ISD::Constant to |
| 876 | /// ISD::TargetConstant, likewise for ConstantFP. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 877 | class EmitConvertToTargetMatcher : public Matcher { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 878 | unsigned Slot; |
| 879 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 880 | EmitConvertToTargetMatcher(unsigned slot) |
| 881 | : Matcher(EmitConvertToTarget), Slot(slot) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 882 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 883 | unsigned getSlot() const { return Slot; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 884 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 885 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 886 | return N->getKind() == EmitConvertToTarget; |
| 887 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 888 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 889 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 890 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 891 | virtual bool isEqualImpl(const Matcher *M) const { |
| 892 | return cast<EmitConvertToTargetMatcher>(M)->Slot == Slot; |
| 893 | } |
| 894 | virtual unsigned getHashImpl() const { return Slot; } |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 895 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 896 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 897 | /// EmitMergeInputChainsMatcher - Emit a node that merges a list of input |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 898 | /// chains together with a token factor. The list of nodes are the nodes in the |
| 899 | /// matched pattern that have chain input/outputs. This node adds all input |
| 900 | /// 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] | 901 | class EmitMergeInputChainsMatcher : public Matcher { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 902 | SmallVector<unsigned, 3> ChainNodes; |
| 903 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 904 | EmitMergeInputChainsMatcher(const unsigned *nodes, unsigned NumNodes) |
| 905 | : Matcher(EmitMergeInputChains), ChainNodes(nodes, nodes+NumNodes) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 906 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 907 | unsigned getNumNodes() const { return ChainNodes.size(); } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 908 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 909 | unsigned getNode(unsigned i) const { |
| 910 | assert(i < ChainNodes.size()); |
| 911 | return ChainNodes[i]; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 912 | } |
| 913 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 914 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 915 | return N->getKind() == EmitMergeInputChains; |
| 916 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 917 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 918 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 919 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 920 | virtual bool isEqualImpl(const Matcher *M) const { |
| 921 | return cast<EmitMergeInputChainsMatcher>(M)->ChainNodes == ChainNodes; |
| 922 | } |
| 923 | virtual unsigned getHashImpl() const; |
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 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 926 | /// EmitCopyToRegMatcher - Emit a CopyToReg node from a value to a physreg, |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 927 | /// pushing the chain and glue results. |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 928 | /// |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 929 | class EmitCopyToRegMatcher : public Matcher { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 930 | unsigned SrcSlot; // Value to copy into the physreg. |
| 931 | Record *DestPhysReg; |
| 932 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 933 | EmitCopyToRegMatcher(unsigned srcSlot, Record *destPhysReg) |
| 934 | : Matcher(EmitCopyToReg), SrcSlot(srcSlot), DestPhysReg(destPhysReg) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 935 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 936 | unsigned getSrcSlot() const { return SrcSlot; } |
| 937 | Record *getDestPhysReg() const { return DestPhysReg; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 938 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 939 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 940 | return N->getKind() == EmitCopyToReg; |
| 941 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 942 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 943 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 944 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 945 | virtual bool isEqualImpl(const Matcher *M) const { |
| 946 | return cast<EmitCopyToRegMatcher>(M)->SrcSlot == SrcSlot && |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 947 | cast<EmitCopyToRegMatcher>(M)->DestPhysReg == DestPhysReg; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 948 | } |
| 949 | virtual unsigned getHashImpl() const { |
| 950 | return SrcSlot ^ ((unsigned)(intptr_t)DestPhysReg << 4); |
| 951 | } |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 952 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 953 | |
| 954 | |
| 955 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 956 | /// EmitNodeXFormMatcher - Emit an operation that runs an SDNodeXForm on a |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 957 | /// recorded node and records the result. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 958 | class EmitNodeXFormMatcher : public Matcher { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 959 | unsigned Slot; |
| 960 | Record *NodeXForm; |
| 961 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 962 | EmitNodeXFormMatcher(unsigned slot, Record *nodeXForm) |
| 963 | : Matcher(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 964 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 965 | unsigned getSlot() const { return Slot; } |
| 966 | Record *getNodeXForm() const { return NodeXForm; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 967 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 968 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 969 | return N->getKind() == EmitNodeXForm; |
| 970 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 971 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 972 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 973 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 974 | virtual bool isEqualImpl(const Matcher *M) const { |
| 975 | return cast<EmitNodeXFormMatcher>(M)->Slot == Slot && |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 976 | cast<EmitNodeXFormMatcher>(M)->NodeXForm == NodeXForm; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 977 | } |
| 978 | virtual unsigned getHashImpl() const { |
| 979 | return Slot ^ ((unsigned)(intptr_t)NodeXForm << 4); |
| 980 | } |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 981 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 982 | |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 983 | /// EmitNodeMatcherCommon - Common class shared between EmitNode and |
Chris Lattner | 9a21500 | 2010-02-28 20:55:18 +0000 | [diff] [blame] | 984 | /// MorphNodeTo. |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 985 | class EmitNodeMatcherCommon : public Matcher { |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 986 | std::string OpcodeName; |
| 987 | const SmallVector<MVT::SimpleValueType, 3> VTs; |
| 988 | const SmallVector<unsigned, 6> Operands; |
Chris Lattner | 036609b | 2010-12-23 18:28:41 +0000 | [diff] [blame] | 989 | bool HasChain, HasInGlue, HasOutGlue, HasMemRefs; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 990 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 991 | /// NumFixedArityOperands - If this is a fixed arity node, this is set to -1. |
| 992 | /// If this is a varidic node, this is set to the number of fixed arity |
| 993 | /// operands in the root of the pattern. The rest are appended to this node. |
| 994 | int NumFixedArityOperands; |
| 995 | public: |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 996 | EmitNodeMatcherCommon(const std::string &opcodeName, |
| 997 | const MVT::SimpleValueType *vts, unsigned numvts, |
| 998 | const unsigned *operands, unsigned numops, |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 999 | bool hasChain, bool hasInGlue, bool hasOutGlue, |
Chris Lattner | ff7fb60 | 2010-02-28 21:53:42 +0000 | [diff] [blame] | 1000 | bool hasmemrefs, |
Chris Lattner | 9a21500 | 2010-02-28 20:55:18 +0000 | [diff] [blame] | 1001 | int numfixedarityoperands, bool isMorphNodeTo) |
| 1002 | : Matcher(isMorphNodeTo ? MorphNodeTo : EmitNode), OpcodeName(opcodeName), |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 1003 | VTs(vts, vts+numvts), Operands(operands, operands+numops), |
Chris Lattner | 036609b | 2010-12-23 18:28:41 +0000 | [diff] [blame] | 1004 | HasChain(hasChain), HasInGlue(hasInGlue), HasOutGlue(hasOutGlue), |
Chris Lattner | ff7fb60 | 2010-02-28 21:53:42 +0000 | [diff] [blame] | 1005 | HasMemRefs(hasmemrefs), NumFixedArityOperands(numfixedarityoperands) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1006 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 1007 | const std::string &getOpcodeName() const { return OpcodeName; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1008 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 1009 | unsigned getNumVTs() const { return VTs.size(); } |
| 1010 | MVT::SimpleValueType getVT(unsigned i) const { |
| 1011 | assert(i < VTs.size()); |
| 1012 | return VTs[i]; |
| 1013 | } |
Chris Lattner | c78f2a3 | 2010-02-28 20:49:53 +0000 | [diff] [blame] | 1014 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 1015 | unsigned getNumOperands() const { return Operands.size(); } |
| 1016 | unsigned getOperand(unsigned i) const { |
| 1017 | assert(i < Operands.size()); |
| 1018 | return Operands[i]; |
Chris Lattner | c78f2a3 | 2010-02-28 20:49:53 +0000 | [diff] [blame] | 1019 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1020 | |
Chris Lattner | c78f2a3 | 2010-02-28 20:49:53 +0000 | [diff] [blame] | 1021 | const SmallVectorImpl<MVT::SimpleValueType> &getVTList() const { return VTs; } |
| 1022 | const SmallVectorImpl<unsigned> &getOperandList() const { return Operands; } |
| 1023 | |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1024 | |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 1025 | bool hasChain() const { return HasChain; } |
Chris Lattner | 036609b | 2010-12-23 18:28:41 +0000 | [diff] [blame] | 1026 | bool hasInFlag() const { return HasInGlue; } |
| 1027 | bool hasOutFlag() const { return HasOutGlue; } |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 1028 | bool hasMemRefs() const { return HasMemRefs; } |
| 1029 | int getNumFixedArityOperands() const { return NumFixedArityOperands; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1030 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 1031 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 9a21500 | 2010-02-28 20:55:18 +0000 | [diff] [blame] | 1032 | return N->getKind() == EmitNode || N->getKind() == MorphNodeTo; |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 1033 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1034 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 1035 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 1036 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 1037 | virtual bool isEqualImpl(const Matcher *M) const; |
| 1038 | virtual unsigned getHashImpl() const; |
Chris Lattner | 845c042 | 2010-02-18 22:03:03 +0000 | [diff] [blame] | 1039 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1040 | |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 1041 | /// EmitNodeMatcher - This signals a successful match and generates a node. |
| 1042 | class EmitNodeMatcher : public EmitNodeMatcherCommon { |
David Blaikie | 2d24e2a | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 1043 | virtual void anchor(); |
Chris Lattner | 6281cda | 2010-02-28 02:41:25 +0000 | [diff] [blame] | 1044 | unsigned FirstResultSlot; |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 1045 | public: |
| 1046 | EmitNodeMatcher(const std::string &opcodeName, |
| 1047 | const MVT::SimpleValueType *vts, unsigned numvts, |
| 1048 | const unsigned *operands, unsigned numops, |
Chris Lattner | ff7fb60 | 2010-02-28 21:53:42 +0000 | [diff] [blame] | 1049 | bool hasChain, bool hasInFlag, bool hasOutFlag, |
| 1050 | bool hasmemrefs, |
Chris Lattner | 6281cda | 2010-02-28 02:41:25 +0000 | [diff] [blame] | 1051 | int numfixedarityoperands, unsigned firstresultslot) |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 1052 | : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain, |
Chris Lattner | ff7fb60 | 2010-02-28 21:53:42 +0000 | [diff] [blame] | 1053 | hasInFlag, hasOutFlag, hasmemrefs, |
| 1054 | numfixedarityoperands, false), |
Chris Lattner | 6281cda | 2010-02-28 02:41:25 +0000 | [diff] [blame] | 1055 | FirstResultSlot(firstresultslot) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1056 | |
Chris Lattner | 6281cda | 2010-02-28 02:41:25 +0000 | [diff] [blame] | 1057 | unsigned getFirstResultSlot() const { return FirstResultSlot; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1058 | |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 1059 | static inline bool classof(const Matcher *N) { |
| 1060 | return N->getKind() == EmitNode; |
| 1061 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1062 | |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 1063 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1064 | |
Chris Lattner | 9a21500 | 2010-02-28 20:55:18 +0000 | [diff] [blame] | 1065 | class MorphNodeToMatcher : public EmitNodeMatcherCommon { |
David Blaikie | 2d24e2a | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 1066 | virtual void anchor(); |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 1067 | const PatternToMatch &Pattern; |
| 1068 | public: |
Chris Lattner | 9a21500 | 2010-02-28 20:55:18 +0000 | [diff] [blame] | 1069 | MorphNodeToMatcher(const std::string &opcodeName, |
| 1070 | const MVT::SimpleValueType *vts, unsigned numvts, |
| 1071 | const unsigned *operands, unsigned numops, |
Chris Lattner | ff7fb60 | 2010-02-28 21:53:42 +0000 | [diff] [blame] | 1072 | bool hasChain, bool hasInFlag, bool hasOutFlag, |
| 1073 | bool hasmemrefs, |
Chris Lattner | 9a21500 | 2010-02-28 20:55:18 +0000 | [diff] [blame] | 1074 | int numfixedarityoperands, const PatternToMatch &pattern) |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 1075 | : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain, |
Chris Lattner | ff7fb60 | 2010-02-28 21:53:42 +0000 | [diff] [blame] | 1076 | hasInFlag, hasOutFlag, hasmemrefs, |
| 1077 | numfixedarityoperands, true), |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 1078 | Pattern(pattern) { |
| 1079 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1080 | |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 1081 | const PatternToMatch &getPattern() const { return Pattern; } |
| 1082 | |
| 1083 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 9a21500 | 2010-02-28 20:55:18 +0000 | [diff] [blame] | 1084 | return N->getKind() == MorphNodeTo; |
Chris Lattner | e86097a | 2010-02-28 02:31:26 +0000 | [diff] [blame] | 1085 | } |
| 1086 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1087 | |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 1088 | /// MarkGlueResultsMatcher - This node indicates which non-root nodes in the |
| 1089 | /// pattern produce glue. This allows CompleteMatchMatcher to update them |
| 1090 | /// with the output glue of the resultant code. |
| 1091 | class MarkGlueResultsMatcher : public Matcher { |
| 1092 | SmallVector<unsigned, 3> GlueResultNodes; |
Chris Lattner | 02f7358 | 2010-02-24 05:33:42 +0000 | [diff] [blame] | 1093 | public: |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 1094 | MarkGlueResultsMatcher(const unsigned *nodes, unsigned NumNodes) |
| 1095 | : Matcher(MarkGlueResults), GlueResultNodes(nodes, nodes+NumNodes) {} |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1096 | |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 1097 | unsigned getNumNodes() const { return GlueResultNodes.size(); } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1098 | |
Chris Lattner | 02f7358 | 2010-02-24 05:33:42 +0000 | [diff] [blame] | 1099 | unsigned getNode(unsigned i) const { |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 1100 | assert(i < GlueResultNodes.size()); |
| 1101 | return GlueResultNodes[i]; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 1104 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 1105 | return N->getKind() == MarkGlueResults; |
Chris Lattner | 02f7358 | 2010-02-24 05:33:42 +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 { |
Chris Lattner | 8950bca | 2010-12-23 17:03:20 +0000 | [diff] [blame] | 1111 | return cast<MarkGlueResultsMatcher>(M)->GlueResultNodes == GlueResultNodes; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 1112 | } |
| 1113 | virtual unsigned getHashImpl() const; |
Chris Lattner | 02f7358 | 2010-02-24 05:33:42 +0000 | [diff] [blame] | 1114 | }; |
| 1115 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 1116 | /// CompleteMatchMatcher - Complete a match by replacing the results of the |
Chris Lattner | 77f2e27 | 2010-02-21 06:03:07 +0000 | [diff] [blame] | 1117 | /// pattern with the newly generated nodes. This also prints a comment |
| 1118 | /// indicating the source and dest patterns. |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 1119 | class CompleteMatchMatcher : public Matcher { |
Chris Lattner | 77f2e27 | 2010-02-21 06:03:07 +0000 | [diff] [blame] | 1120 | SmallVector<unsigned, 2> Results; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 1121 | const PatternToMatch &Pattern; |
| 1122 | public: |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 1123 | CompleteMatchMatcher(const unsigned *results, unsigned numresults, |
Chris Lattner | c78f2a3 | 2010-02-28 20:49:53 +0000 | [diff] [blame] | 1124 | const PatternToMatch &pattern) |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 1125 | : Matcher(CompleteMatch), Results(results, results+numresults), |
Chris Lattner | 77f2e27 | 2010-02-21 06:03:07 +0000 | [diff] [blame] | 1126 | Pattern(pattern) {} |
| 1127 | |
| 1128 | unsigned getNumResults() const { return Results.size(); } |
| 1129 | unsigned getResult(unsigned R) const { return Results[R]; } |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 1130 | const PatternToMatch &getPattern() const { return Pattern; } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1131 | |
Chris Lattner | b21ba71 | 2010-02-25 02:04:40 +0000 | [diff] [blame] | 1132 | static inline bool classof(const Matcher *N) { |
Chris Lattner | 77f2e27 | 2010-02-21 06:03:07 +0000 | [diff] [blame] | 1133 | return N->getKind() == CompleteMatch; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 1134 | } |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1135 | |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 1136 | private: |
Chris Lattner | a5028a6 | 2010-02-25 06:53:39 +0000 | [diff] [blame] | 1137 | virtual void printImpl(raw_ostream &OS, unsigned indent) const; |
Chris Lattner | 58aa834 | 2010-02-25 06:49:58 +0000 | [diff] [blame] | 1138 | virtual bool isEqualImpl(const Matcher *M) const { |
| 1139 | return cast<CompleteMatchMatcher>(M)->Results == Results && |
| 1140 | &cast<CompleteMatchMatcher>(M)->Pattern == &Pattern; |
| 1141 | } |
| 1142 | virtual unsigned getHashImpl() const; |
Chris Lattner | 8e946be | 2010-02-21 03:22:59 +0000 | [diff] [blame] | 1143 | }; |
Jim Grosbach | fbadcd0 | 2010-12-21 16:16:00 +0000 | [diff] [blame] | 1144 | |
Chris Lattner | da272d1 | 2010-02-15 08:04:42 +0000 | [diff] [blame] | 1145 | } // end namespace llvm |
| 1146 | |
| 1147 | #endif |