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