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