blob: 2f26b924d74268e75f0f4e330e18ab0fc3aea482 [file] [log] [blame]
Chris Lattnere7d6e3c2010-02-15 08:04:42 +00001//===- 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 Lattnerfdbdc8c2010-02-16 07:21:10 +000013#include "llvm/CodeGen/ValueTypes.h"
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000014#include "llvm/ADT/OwningPtr.h"
15#include "llvm/ADT/StringRef.h"
Chris Lattner3163ca52010-02-21 03:22:59 +000016#include "llvm/ADT/SmallVector.h"
Chris Lattnerfdbdc8c2010-02-16 07:21:10 +000017#include "llvm/Support/Casting.h"
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000018
19namespace llvm {
20 class CodeGenDAGPatterns;
Chris Lattner9a515172010-02-25 02:04:40 +000021 class Matcher;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000022 class PatternToMatch;
23 class raw_ostream;
24 class ComplexPattern;
Chris Lattnerddfb5222010-02-18 22:03:03 +000025 class Record;
Chris Lattnere9f720b2010-02-27 21:48:43 +000026 class SDNodeInfo;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000027
Chris Lattner9a515172010-02-25 02:04:40 +000028Matcher *ConvertPatternToMatcher(const PatternToMatch &Pattern,
29 const CodeGenDAGPatterns &CGP);
Chris Lattner5cc7a832010-02-28 20:49:53 +000030Matcher *OptimizeMatcher(Matcher *Matcher, const CodeGenDAGPatterns &CGP);
Chris Lattner514d21f2010-03-01 01:54:19 +000031void EmitMatcherTable(const Matcher *Matcher, const CodeGenDAGPatterns &CGP,
32 raw_ostream &OS);
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000033
34
Chris Lattner9a515172010-02-25 02:04:40 +000035/// Matcher - Base class for all the the DAG ISel Matcher representation
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000036/// nodes.
Chris Lattner9a515172010-02-25 02:04:40 +000037class Matcher {
Chris Lattner78039ec2010-02-18 02:53:41 +000038 // The next matcher node that is executed after this one. Null if this is the
39 // last stage of a match.
Chris Lattner9a515172010-02-25 02:04:40 +000040 OwningPtr<Matcher> Next;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000041public:
42 enum KindTy {
Chris Lattner3163ca52010-02-21 03:22:59 +000043 // Matcher state manipulation.
Chris Lattnerac10e4f2010-02-25 01:56:48 +000044 Scope, // Push a checking scope.
Chris Lattner3163ca52010-02-21 03:22:59 +000045 RecordNode, // Record the current node.
Chris Lattner3ee1bc42010-02-24 07:31:45 +000046 RecordChild, // Record a child of the current node.
Chris Lattner3163ca52010-02-21 03:22:59 +000047 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 Lattnere7d6e3c2010-02-15 08:04:42 +000051
Chris Lattnerddfb5222010-02-18 22:03:03 +000052 // Predicate checking.
Chris Lattner3163ca52010-02-21 03:22:59 +000053 CheckSame, // Fail if not same as prev match.
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000054 CheckPatternPredicate,
Chris Lattner3163ca52010-02-21 03:22:59 +000055 CheckPredicate, // Fail if node predicate fails.
56 CheckOpcode, // Fail if not opcode.
Chris Lattnerf58c08e2010-02-22 22:30:37 +000057 CheckMultiOpcode, // Fail if not in opcode list.
Chris Lattner3163ca52010-02-21 03:22:59 +000058 CheckType, // Fail if not correct type.
Chris Lattner3c664b32010-02-24 20:15:25 +000059 CheckChildType, // Fail if child has wrong type.
Chris Lattner3163ca52010-02-21 03:22:59 +000060 CheckInteger, // Fail if wrong val.
61 CheckCondCode, // Fail if not condcode.
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000062 CheckValueType,
63 CheckComplexPat,
64 CheckAndImm,
Chris Lattner9de39482010-02-16 06:10:58 +000065 CheckOrImm,
Chris Lattner283adcb2010-02-17 06:23:39 +000066 CheckFoldableChainNode,
Chris Lattnerddfb5222010-02-18 22:03:03 +000067 CheckChainCompatible,
68
69 // Node creation/emisssion.
Chris Lattner3163ca52010-02-21 03:22:59 +000070 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 Lattner69f60c82010-02-24 05:33:42 +000078 MarkFlagResults, // Indicate which interior nodes have flag results.
Chris Lattner7a1dab42010-02-28 02:31:26 +000079 CompleteMatch, // Finish a match and update the results.
Chris Lattner7dae4af2010-02-28 20:55:18 +000080 MorphNodeTo // Build a node, finish a match and update results.
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000081 };
82 const KindTy Kind;
Chris Lattner3b31c982010-02-18 02:49:24 +000083
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000084protected:
Chris Lattner9a515172010-02-25 02:04:40 +000085 Matcher(KindTy K) : Kind(K) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000086public:
Chris Lattner9a515172010-02-25 02:04:40 +000087 virtual ~Matcher() {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000088
89 KindTy getKind() const { return Kind; }
Chris Lattner3b31c982010-02-18 02:49:24 +000090
Chris Lattner9a515172010-02-25 02:04:40 +000091 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 Lattner3ee1bc42010-02-24 07:31:45 +000095
Chris Lattner9a515172010-02-25 02:04:40 +000096 OwningPtr<Matcher> &getNextPtr() { return Next; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000097
Chris Lattner9a515172010-02-25 02:04:40 +000098 static inline bool classof(const Matcher *) { return true; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000099
Chris Lattner136ab782010-02-25 06:49:58 +0000100 bool isEqual(const Matcher *M) const {
101 if (getKind() != M->getKind()) return false;
102 return isEqualImpl(M);
103 }
104
105 unsigned getHash() const {
Chris Lattner54ee7362010-02-26 07:35:27 +0000106 // Clear the high bit so we don't conflict with tombstones etc.
107 return ((getHashImpl() << 4) ^ getKind()) & (~0U>>1);
Chris Lattner136ab782010-02-25 06:49:58 +0000108 }
109
Chris Lattnerf4950d02010-02-27 06:22:57 +0000110 /// 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 Lattnerddfd5ab2010-02-27 07:49:13 +0000116 /// 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 Lattner392b1bf2010-02-25 06:53:39 +0000128 void print(raw_ostream &OS, unsigned indent = 0) const;
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000129 void printOne(raw_ostream &OS) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000130 void dump() const;
Chris Lattner3b31c982010-02-18 02:49:24 +0000131protected:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000132 virtual void printImpl(raw_ostream &OS, unsigned indent) const = 0;
Chris Lattner136ab782010-02-25 06:49:58 +0000133 virtual bool isEqualImpl(const Matcher *M) const = 0;
134 virtual unsigned getHashImpl() const = 0;
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000135 virtual bool isContradictoryImpl(const Matcher *M) const { return false; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000136};
137
Chris Lattner42363662010-02-25 19:00:39 +0000138/// 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 Lattner9a515172010-02-25 02:04:40 +0000141class ScopeMatcher : public Matcher {
Chris Lattner42363662010-02-25 19:00:39 +0000142 SmallVector<Matcher*, 4> Children;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000143public:
Chris Lattner42363662010-02-25 19:00:39 +0000144 ScopeMatcher(Matcher *const *children, unsigned numchildren)
145 : Matcher(Scope), Children(children, children+numchildren) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000146 }
Chris Lattner42363662010-02-25 19:00:39 +0000147 virtual ~ScopeMatcher();
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000148
Chris Lattner42363662010-02-25 19:00:39 +0000149 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 Lattner54ee7362010-02-26 07:35:27 +0000164
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 Lattnere7d6e3c2010-02-15 08:04:42 +0000173
Chris Lattner9a515172010-02-25 02:04:40 +0000174 static inline bool classof(const Matcher *N) {
Chris Lattnerac10e4f2010-02-25 01:56:48 +0000175 return N->getKind() == Scope;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000176 }
177
Chris Lattner136ab782010-02-25 06:49:58 +0000178private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000179 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000180 virtual bool isEqualImpl(const Matcher *M) const { return false; }
Chris Lattner42363662010-02-25 19:00:39 +0000181 virtual unsigned getHashImpl() const { return 12312; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000182};
183
Chris Lattner9a515172010-02-25 02:04:40 +0000184/// RecordMatcher - Save the current node in the operand list.
185class RecordMatcher : public Matcher {
Chris Lattner56cf88d2010-02-17 01:03:09 +0000186 /// 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 Lattnere7d6e3c2010-02-15 08:04:42 +0000189public:
Chris Lattner9a515172010-02-25 02:04:40 +0000190 RecordMatcher(const std::string &whatfor)
191 : Matcher(RecordNode), WhatFor(whatfor) {}
Chris Lattner56cf88d2010-02-17 01:03:09 +0000192
Chris Lattner086ca522010-02-17 01:27:29 +0000193 const std::string &getWhatFor() const { return WhatFor; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000194
Chris Lattner9a515172010-02-25 02:04:40 +0000195 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000196 return N->getKind() == RecordNode;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000197 }
198
Chris Lattnerf4950d02010-02-27 06:22:57 +0000199 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
Chris Lattner136ab782010-02-25 06:49:58 +0000200private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000201 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000202 virtual bool isEqualImpl(const Matcher *M) const { return true; }
203 virtual unsigned getHashImpl() const { return 0; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000204};
205
Chris Lattner9a515172010-02-25 02:04:40 +0000206/// RecordChildMatcher - Save a numbered child of the current node, or fail
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000207/// the match if it doesn't exist. This is logically equivalent to:
208/// MoveChild N + RecordNode + MoveParent.
Chris Lattner9a515172010-02-25 02:04:40 +0000209class RecordChildMatcher : public Matcher {
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000210 unsigned ChildNo;
211
212 /// WhatFor - This is a string indicating why we're recording this. This
213 /// should only be used for comment generation not anything semantic.
214 std::string WhatFor;
215public:
Chris Lattner9a515172010-02-25 02:04:40 +0000216 RecordChildMatcher(unsigned childno, const std::string &whatfor)
217 : Matcher(RecordChild), ChildNo(childno), WhatFor(whatfor) {}
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000218
219 unsigned getChildNo() const { return ChildNo; }
220 const std::string &getWhatFor() const { return WhatFor; }
221
Chris Lattner9a515172010-02-25 02:04:40 +0000222 static inline bool classof(const Matcher *N) {
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000223 return N->getKind() == RecordChild;
224 }
225
Chris Lattnerf4950d02010-02-27 06:22:57 +0000226 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
227
Chris Lattner136ab782010-02-25 06:49:58 +0000228private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000229 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000230 virtual bool isEqualImpl(const Matcher *M) const {
231 return cast<RecordChildMatcher>(M)->getChildNo() == getChildNo();
232 }
233 virtual unsigned getHashImpl() const { return getChildNo(); }
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000234};
235
Chris Lattner9a515172010-02-25 02:04:40 +0000236/// RecordMemRefMatcher - Save the current node's memref.
237class RecordMemRefMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000238public:
Chris Lattner9a515172010-02-25 02:04:40 +0000239 RecordMemRefMatcher() : Matcher(RecordMemRef) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000240
Chris Lattner9a515172010-02-25 02:04:40 +0000241 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000242 return N->getKind() == RecordMemRef;
243 }
244
Chris Lattnerf4950d02010-02-27 06:22:57 +0000245 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
246
Chris Lattner136ab782010-02-25 06:49:58 +0000247private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000248 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000249 virtual bool isEqualImpl(const Matcher *M) const { return true; }
250 virtual unsigned getHashImpl() const { return 0; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000251};
252
253
Chris Lattner9a515172010-02-25 02:04:40 +0000254/// CaptureFlagInputMatcher - If the current record has a flag input, record
Chris Lattner3163ca52010-02-21 03:22:59 +0000255/// it so that it is used as an input to the generated code.
Chris Lattner9a515172010-02-25 02:04:40 +0000256class CaptureFlagInputMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000257public:
Chris Lattner9a515172010-02-25 02:04:40 +0000258 CaptureFlagInputMatcher() : Matcher(CaptureFlagInput) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000259
Chris Lattner9a515172010-02-25 02:04:40 +0000260 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000261 return N->getKind() == CaptureFlagInput;
262 }
263
Chris Lattnerf4950d02010-02-27 06:22:57 +0000264 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
265
Chris Lattner136ab782010-02-25 06:49:58 +0000266private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000267 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000268 virtual bool isEqualImpl(const Matcher *M) const { return true; }
269 virtual unsigned getHashImpl() const { return 0; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000270};
271
Chris Lattner9a515172010-02-25 02:04:40 +0000272/// MoveChildMatcher - This tells the interpreter to move into the
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000273/// specified child node.
Chris Lattner9a515172010-02-25 02:04:40 +0000274class MoveChildMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000275 unsigned ChildNo;
276public:
Chris Lattner9a515172010-02-25 02:04:40 +0000277 MoveChildMatcher(unsigned childNo) : Matcher(MoveChild), ChildNo(childNo) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000278
279 unsigned getChildNo() const { return ChildNo; }
280
Chris Lattner9a515172010-02-25 02:04:40 +0000281 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000282 return N->getKind() == MoveChild;
283 }
284
Chris Lattnerf4950d02010-02-27 06:22:57 +0000285 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
286
Chris Lattner136ab782010-02-25 06:49:58 +0000287private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000288 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000289 virtual bool isEqualImpl(const Matcher *M) const {
290 return cast<MoveChildMatcher>(M)->getChildNo() == getChildNo();
291 }
292 virtual unsigned getHashImpl() const { return getChildNo(); }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000293};
294
Chris Lattner9a515172010-02-25 02:04:40 +0000295/// MoveParentMatcher - This tells the interpreter to move to the parent
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000296/// of the current node.
Chris Lattner9a515172010-02-25 02:04:40 +0000297class MoveParentMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000298public:
Chris Lattner9a515172010-02-25 02:04:40 +0000299 MoveParentMatcher() : Matcher(MoveParent) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000300
Chris Lattner9a515172010-02-25 02:04:40 +0000301 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000302 return N->getKind() == MoveParent;
303 }
304
Chris Lattnerf4950d02010-02-27 06:22:57 +0000305 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
306
Chris Lattner136ab782010-02-25 06:49:58 +0000307private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000308 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000309 virtual bool isEqualImpl(const Matcher *M) const { return true; }
310 virtual unsigned getHashImpl() const { return 0; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000311};
312
Chris Lattner9a515172010-02-25 02:04:40 +0000313/// CheckSameMatcher - This checks to see if this node is exactly the same
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000314/// node as the specified match that was recorded with 'Record'. This is used
315/// when patterns have the same name in them, like '(mul GPR:$in, GPR:$in)'.
Chris Lattner9a515172010-02-25 02:04:40 +0000316class CheckSameMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000317 unsigned MatchNumber;
318public:
Chris Lattner9a515172010-02-25 02:04:40 +0000319 CheckSameMatcher(unsigned matchnumber)
Chris Lattner136ab782010-02-25 06:49:58 +0000320 : Matcher(CheckSame), MatchNumber(matchnumber) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000321
322 unsigned getMatchNumber() const { return MatchNumber; }
323
Chris Lattner9a515172010-02-25 02:04:40 +0000324 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000325 return N->getKind() == CheckSame;
326 }
327
Chris Lattnerf4950d02010-02-27 06:22:57 +0000328 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
329
Chris Lattner136ab782010-02-25 06:49:58 +0000330private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000331 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000332 virtual bool isEqualImpl(const Matcher *M) const {
333 return cast<CheckSameMatcher>(M)->getMatchNumber() == getMatchNumber();
334 }
335 virtual unsigned getHashImpl() const { return getMatchNumber(); }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000336};
337
Chris Lattner9a515172010-02-25 02:04:40 +0000338/// CheckPatternPredicateMatcher - This checks the target-specific predicate
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000339/// to see if the entire pattern is capable of matching. This predicate does
340/// not take a node as input. This is used for subtarget feature checks etc.
Chris Lattner9a515172010-02-25 02:04:40 +0000341class CheckPatternPredicateMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000342 std::string Predicate;
343public:
Chris Lattner9a515172010-02-25 02:04:40 +0000344 CheckPatternPredicateMatcher(StringRef predicate)
Chris Lattner136ab782010-02-25 06:49:58 +0000345 : Matcher(CheckPatternPredicate), Predicate(predicate) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000346
347 StringRef getPredicate() const { return Predicate; }
348
Chris Lattner9a515172010-02-25 02:04:40 +0000349 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000350 return N->getKind() == CheckPatternPredicate;
351 }
352
Chris Lattnerf4950d02010-02-27 06:22:57 +0000353 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
354
Chris Lattner136ab782010-02-25 06:49:58 +0000355private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000356 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000357 virtual bool isEqualImpl(const Matcher *M) const {
358 return cast<CheckPatternPredicateMatcher>(M)->getPredicate() == Predicate;
359 }
360 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000361};
362
Chris Lattner9a515172010-02-25 02:04:40 +0000363/// CheckPredicateMatcher - This checks the target-specific predicate to
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000364/// see if the node is acceptable.
Chris Lattner9a515172010-02-25 02:04:40 +0000365class CheckPredicateMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000366 StringRef PredName;
367public:
Chris Lattner9a515172010-02-25 02:04:40 +0000368 CheckPredicateMatcher(StringRef predname)
369 : Matcher(CheckPredicate), PredName(predname) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000370
371 StringRef getPredicateName() const { return PredName; }
372
Chris Lattner9a515172010-02-25 02:04:40 +0000373 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000374 return N->getKind() == CheckPredicate;
375 }
376
Chris Lattnerf4950d02010-02-27 06:22:57 +0000377 // TODO: Ok?
378 //virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
379
Chris Lattner136ab782010-02-25 06:49:58 +0000380private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000381 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000382 virtual bool isEqualImpl(const Matcher *M) const {
383 return cast<CheckPredicateMatcher>(M)->PredName == PredName;
384 }
385 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000386};
387
388
Chris Lattner9a515172010-02-25 02:04:40 +0000389/// CheckOpcodeMatcher - This checks to see if the current node has the
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000390/// specified opcode, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000391class CheckOpcodeMatcher : public Matcher {
Chris Lattnere9f720b2010-02-27 21:48:43 +0000392 const SDNodeInfo &Opcode;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000393public:
Chris Lattnere9f720b2010-02-27 21:48:43 +0000394 CheckOpcodeMatcher(const SDNodeInfo &opcode)
395 : Matcher(CheckOpcode), Opcode(opcode) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000396
Chris Lattnere9f720b2010-02-27 21:48:43 +0000397 const SDNodeInfo &getOpcode() const { return Opcode; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000398
Chris Lattner9a515172010-02-25 02:04:40 +0000399 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000400 return N->getKind() == CheckOpcode;
401 }
402
Chris Lattnerf4950d02010-02-27 06:22:57 +0000403 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
404
Chris Lattner136ab782010-02-25 06:49:58 +0000405private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000406 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000407 virtual bool isEqualImpl(const Matcher *M) const {
Chris Lattnere9f720b2010-02-27 21:48:43 +0000408 return &cast<CheckOpcodeMatcher>(M)->Opcode == &Opcode;
Chris Lattner136ab782010-02-25 06:49:58 +0000409 }
410 virtual unsigned getHashImpl() const;
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000411 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000412};
413
Chris Lattner9a515172010-02-25 02:04:40 +0000414/// CheckMultiOpcodeMatcher - This checks to see if the current node has one
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000415/// of the specified opcode, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000416class CheckMultiOpcodeMatcher : public Matcher {
Chris Lattnere9f720b2010-02-27 21:48:43 +0000417 SmallVector<const SDNodeInfo*, 4> Opcodes;
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000418public:
Chris Lattnere9f720b2010-02-27 21:48:43 +0000419 CheckMultiOpcodeMatcher(const SDNodeInfo * const *opcodes, unsigned numops)
420 : Matcher(CheckMultiOpcode), Opcodes(opcodes, opcodes+numops) {}
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000421
Chris Lattnere9f720b2010-02-27 21:48:43 +0000422 unsigned getNumOpcodes() const { return Opcodes.size(); }
423 const SDNodeInfo &getOpcode(unsigned i) const { return *Opcodes[i]; }
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000424
Chris Lattner9a515172010-02-25 02:04:40 +0000425 static inline bool classof(const Matcher *N) {
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000426 return N->getKind() == CheckMultiOpcode;
427 }
428
Chris Lattnerf4950d02010-02-27 06:22:57 +0000429 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
430
Chris Lattner136ab782010-02-25 06:49:58 +0000431private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000432 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000433 virtual bool isEqualImpl(const Matcher *M) const {
Chris Lattnere9f720b2010-02-27 21:48:43 +0000434 return cast<CheckMultiOpcodeMatcher>(M)->Opcodes == Opcodes;
Chris Lattner136ab782010-02-25 06:49:58 +0000435 }
436 virtual unsigned getHashImpl() const;
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000437};
438
439
440
Chris Lattner9a515172010-02-25 02:04:40 +0000441/// CheckTypeMatcher - This checks to see if the current node has the
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000442/// specified type, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000443class CheckTypeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000444 MVT::SimpleValueType Type;
445public:
Chris Lattner9a515172010-02-25 02:04:40 +0000446 CheckTypeMatcher(MVT::SimpleValueType type)
447 : Matcher(CheckType), Type(type) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000448
449 MVT::SimpleValueType getType() const { return Type; }
450
Chris Lattner9a515172010-02-25 02:04:40 +0000451 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000452 return N->getKind() == CheckType;
453 }
454
Chris Lattnerf4950d02010-02-27 06:22:57 +0000455 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
456
Chris Lattner136ab782010-02-25 06:49:58 +0000457private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000458 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000459 virtual bool isEqualImpl(const Matcher *M) const {
Chris Lattner2d0e0792010-02-26 08:05:36 +0000460 return cast<CheckTypeMatcher>(M)->Type == Type;
Chris Lattner136ab782010-02-25 06:49:58 +0000461 }
462 virtual unsigned getHashImpl() const { return Type; }
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000463 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000464};
Chris Lattner3c664b32010-02-24 20:15:25 +0000465
Chris Lattner9a515172010-02-25 02:04:40 +0000466/// CheckChildTypeMatcher - This checks to see if a child node has the
Chris Lattner3c664b32010-02-24 20:15:25 +0000467/// specified type, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000468class CheckChildTypeMatcher : public Matcher {
Chris Lattner3c664b32010-02-24 20:15:25 +0000469 unsigned ChildNo;
470 MVT::SimpleValueType Type;
471public:
Chris Lattner9a515172010-02-25 02:04:40 +0000472 CheckChildTypeMatcher(unsigned childno, MVT::SimpleValueType type)
473 : Matcher(CheckChildType), ChildNo(childno), Type(type) {}
Chris Lattner3c664b32010-02-24 20:15:25 +0000474
475 unsigned getChildNo() const { return ChildNo; }
476 MVT::SimpleValueType getType() const { return Type; }
477
Chris Lattner9a515172010-02-25 02:04:40 +0000478 static inline bool classof(const Matcher *N) {
Chris Lattner3c664b32010-02-24 20:15:25 +0000479 return N->getKind() == CheckChildType;
480 }
481
Chris Lattnerf4950d02010-02-27 06:22:57 +0000482 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
483
Chris Lattner136ab782010-02-25 06:49:58 +0000484private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000485 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000486 virtual bool isEqualImpl(const Matcher *M) const {
487 return cast<CheckChildTypeMatcher>(M)->ChildNo == ChildNo &&
488 cast<CheckChildTypeMatcher>(M)->Type == Type;
489 }
490 virtual unsigned getHashImpl() const { return (Type << 3) | ChildNo; }
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000491 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattner3c664b32010-02-24 20:15:25 +0000492};
493
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000494
Chris Lattner9a515172010-02-25 02:04:40 +0000495/// CheckIntegerMatcher - This checks to see if the current node is a
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000496/// ConstantSDNode with the specified integer value, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000497class CheckIntegerMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000498 int64_t Value;
499public:
Chris Lattner9a515172010-02-25 02:04:40 +0000500 CheckIntegerMatcher(int64_t value)
501 : Matcher(CheckInteger), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000502
503 int64_t getValue() const { return Value; }
504
Chris Lattner9a515172010-02-25 02:04:40 +0000505 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000506 return N->getKind() == CheckInteger;
507 }
508
Chris Lattnerf4950d02010-02-27 06:22:57 +0000509 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
510
Chris Lattner136ab782010-02-25 06:49:58 +0000511private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000512 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000513 virtual bool isEqualImpl(const Matcher *M) const {
514 return cast<CheckIntegerMatcher>(M)->Value == Value;
515 }
516 virtual unsigned getHashImpl() const { return Value; }
Chris Lattner086af322010-02-27 08:11:15 +0000517 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000518};
519
Chris Lattner9a515172010-02-25 02:04:40 +0000520/// CheckCondCodeMatcher - This checks to see if the current node is a
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000521/// CondCodeSDNode with the specified condition, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000522class CheckCondCodeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000523 StringRef CondCodeName;
524public:
Chris Lattner9a515172010-02-25 02:04:40 +0000525 CheckCondCodeMatcher(StringRef condcodename)
526 : Matcher(CheckCondCode), CondCodeName(condcodename) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000527
528 StringRef getCondCodeName() const { return CondCodeName; }
529
Chris Lattner9a515172010-02-25 02:04:40 +0000530 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000531 return N->getKind() == CheckCondCode;
532 }
533
Chris Lattnerf4950d02010-02-27 06:22:57 +0000534 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
535
Chris Lattner136ab782010-02-25 06:49:58 +0000536private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000537 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000538 virtual bool isEqualImpl(const Matcher *M) const {
539 return cast<CheckCondCodeMatcher>(M)->CondCodeName == CondCodeName;
540 }
541 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000542};
543
Chris Lattner9a515172010-02-25 02:04:40 +0000544/// CheckValueTypeMatcher - This checks to see if the current node is a
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000545/// VTSDNode with the specified type, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000546class CheckValueTypeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000547 StringRef TypeName;
548public:
Chris Lattner9a515172010-02-25 02:04:40 +0000549 CheckValueTypeMatcher(StringRef type_name)
550 : Matcher(CheckValueType), TypeName(type_name) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000551
552 StringRef getTypeName() const { return TypeName; }
553
Chris Lattner9a515172010-02-25 02:04:40 +0000554 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000555 return N->getKind() == CheckValueType;
556 }
557
Chris Lattnerf4950d02010-02-27 06:22:57 +0000558 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
559
Chris Lattner136ab782010-02-25 06:49:58 +0000560private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000561 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000562 virtual bool isEqualImpl(const Matcher *M) const {
563 return cast<CheckValueTypeMatcher>(M)->TypeName == TypeName;
564 }
565 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000566};
567
568
569
Chris Lattner9a515172010-02-25 02:04:40 +0000570/// CheckComplexPatMatcher - This node runs the specified ComplexPattern on
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000571/// the current node.
Chris Lattner9a515172010-02-25 02:04:40 +0000572class CheckComplexPatMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000573 const ComplexPattern &Pattern;
574public:
Chris Lattner9a515172010-02-25 02:04:40 +0000575 CheckComplexPatMatcher(const ComplexPattern &pattern)
576 : Matcher(CheckComplexPat), Pattern(pattern) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000577
Chris Lattnerdc429fd2010-02-17 00:31:50 +0000578 const ComplexPattern &getPattern() const { return Pattern; }
579
Chris Lattner9a515172010-02-25 02:04:40 +0000580 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000581 return N->getKind() == CheckComplexPat;
582 }
583
Chris Lattnerf4950d02010-02-27 06:22:57 +0000584 // Not safe to move a pattern predicate past a complex pattern.
585 virtual bool isSafeToReorderWithPatternPredicate() const { return false; }
586
Chris Lattner136ab782010-02-25 06:49:58 +0000587private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000588 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000589 virtual bool isEqualImpl(const Matcher *M) const {
590 return &cast<CheckComplexPatMatcher>(M)->Pattern == &Pattern;
591 }
592 virtual unsigned getHashImpl() const {
593 return (unsigned)(intptr_t)&Pattern;
594 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000595};
596
Chris Lattner9a515172010-02-25 02:04:40 +0000597/// CheckAndImmMatcher - This checks to see if the current node is an 'and'
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000598/// with something equivalent to the specified immediate.
Chris Lattner9a515172010-02-25 02:04:40 +0000599class CheckAndImmMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000600 int64_t Value;
601public:
Chris Lattner9a515172010-02-25 02:04:40 +0000602 CheckAndImmMatcher(int64_t value)
603 : Matcher(CheckAndImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000604
605 int64_t getValue() const { return Value; }
606
Chris Lattner9a515172010-02-25 02:04:40 +0000607 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000608 return N->getKind() == CheckAndImm;
609 }
610
Chris Lattnerf4950d02010-02-27 06:22:57 +0000611 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
612
Chris Lattner136ab782010-02-25 06:49:58 +0000613private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000614 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000615 virtual bool isEqualImpl(const Matcher *M) const {
616 return cast<CheckAndImmMatcher>(M)->Value == Value;
617 }
618 virtual unsigned getHashImpl() const { return Value; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000619};
620
Chris Lattner9a515172010-02-25 02:04:40 +0000621/// CheckOrImmMatcher - This checks to see if the current node is an 'and'
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000622/// with something equivalent to the specified immediate.
Chris Lattner9a515172010-02-25 02:04:40 +0000623class CheckOrImmMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000624 int64_t Value;
625public:
Chris Lattner9a515172010-02-25 02:04:40 +0000626 CheckOrImmMatcher(int64_t value)
627 : Matcher(CheckOrImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000628
629 int64_t getValue() const { return Value; }
630
Chris Lattner9a515172010-02-25 02:04:40 +0000631 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000632 return N->getKind() == CheckOrImm;
633 }
634
Chris Lattnerf4950d02010-02-27 06:22:57 +0000635 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
636
Chris Lattner136ab782010-02-25 06:49:58 +0000637private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000638 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000639 virtual bool isEqualImpl(const Matcher *M) const {
640 return cast<CheckOrImmMatcher>(M)->Value == Value;
641 }
642 virtual unsigned getHashImpl() const { return Value; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000643};
Chris Lattner9de39482010-02-16 06:10:58 +0000644
Chris Lattner9a515172010-02-25 02:04:40 +0000645/// CheckFoldableChainNodeMatcher - This checks to see if the current node
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000646/// (which defines a chain operand) is safe to fold into a larger pattern.
Chris Lattner9a515172010-02-25 02:04:40 +0000647class CheckFoldableChainNodeMatcher : public Matcher {
Chris Lattner9de39482010-02-16 06:10:58 +0000648public:
Chris Lattner9a515172010-02-25 02:04:40 +0000649 CheckFoldableChainNodeMatcher()
650 : Matcher(CheckFoldableChainNode) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000651
Chris Lattner9a515172010-02-25 02:04:40 +0000652 static inline bool classof(const Matcher *N) {
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000653 return N->getKind() == CheckFoldableChainNode;
Chris Lattner9de39482010-02-16 06:10:58 +0000654 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000655
Chris Lattnerf4950d02010-02-27 06:22:57 +0000656 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
657
Chris Lattner136ab782010-02-25 06:49:58 +0000658private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000659 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000660 virtual bool isEqualImpl(const Matcher *M) const { return true; }
661 virtual unsigned getHashImpl() const { return 0; }
Chris Lattner9de39482010-02-16 06:10:58 +0000662};
663
Chris Lattner9a515172010-02-25 02:04:40 +0000664/// CheckChainCompatibleMatcher - Verify that the current node's chain
Chris Lattner283adcb2010-02-17 06:23:39 +0000665/// operand is 'compatible' with the specified recorded node's.
Chris Lattner9a515172010-02-25 02:04:40 +0000666class CheckChainCompatibleMatcher : public Matcher {
Chris Lattner283adcb2010-02-17 06:23:39 +0000667 unsigned PreviousOp;
668public:
Chris Lattner9a515172010-02-25 02:04:40 +0000669 CheckChainCompatibleMatcher(unsigned previousop)
670 : Matcher(CheckChainCompatible), PreviousOp(previousop) {}
Chris Lattner283adcb2010-02-17 06:23:39 +0000671
672 unsigned getPreviousOp() const { return PreviousOp; }
673
Chris Lattner9a515172010-02-25 02:04:40 +0000674 static inline bool classof(const Matcher *N) {
Chris Lattner283adcb2010-02-17 06:23:39 +0000675 return N->getKind() == CheckChainCompatible;
676 }
677
Chris Lattnerf4950d02010-02-27 06:22:57 +0000678 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
679
Chris Lattner136ab782010-02-25 06:49:58 +0000680private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000681 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000682 virtual bool isEqualImpl(const Matcher *M) const {
Chris Lattner50c0b362010-02-26 08:06:02 +0000683 return cast<CheckChainCompatibleMatcher>(M)->PreviousOp == PreviousOp;
Chris Lattner136ab782010-02-25 06:49:58 +0000684 }
685 virtual unsigned getHashImpl() const { return PreviousOp; }
Chris Lattner283adcb2010-02-17 06:23:39 +0000686};
687
Chris Lattner9a515172010-02-25 02:04:40 +0000688/// EmitIntegerMatcher - This creates a new TargetConstant.
689class EmitIntegerMatcher : public Matcher {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000690 int64_t Val;
691 MVT::SimpleValueType VT;
692public:
Chris Lattner9a515172010-02-25 02:04:40 +0000693 EmitIntegerMatcher(int64_t val, MVT::SimpleValueType vt)
694 : Matcher(EmitInteger), Val(val), VT(vt) {}
Chris Lattner283adcb2010-02-17 06:23:39 +0000695
Chris Lattner7043e0a2010-02-19 07:49:56 +0000696 int64_t getValue() const { return Val; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000697 MVT::SimpleValueType getVT() const { return VT; }
698
Chris Lattner9a515172010-02-25 02:04:40 +0000699 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000700 return N->getKind() == EmitInteger;
701 }
702
Chris Lattner136ab782010-02-25 06:49:58 +0000703private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000704 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000705 virtual bool isEqualImpl(const Matcher *M) const {
706 return cast<EmitIntegerMatcher>(M)->Val == Val &&
707 cast<EmitIntegerMatcher>(M)->VT == VT;
708 }
709 virtual unsigned getHashImpl() const { return (Val << 4) | VT; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000710};
Chris Lattner3163ca52010-02-21 03:22:59 +0000711
Chris Lattner9a515172010-02-25 02:04:40 +0000712/// EmitStringIntegerMatcher - A target constant whose value is represented
Chris Lattner3163ca52010-02-21 03:22:59 +0000713/// by a string.
Chris Lattner9a515172010-02-25 02:04:40 +0000714class EmitStringIntegerMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000715 std::string Val;
716 MVT::SimpleValueType VT;
717public:
Chris Lattner9a515172010-02-25 02:04:40 +0000718 EmitStringIntegerMatcher(const std::string &val, MVT::SimpleValueType vt)
719 : Matcher(EmitStringInteger), Val(val), VT(vt) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000720
721 const std::string &getValue() const { return Val; }
722 MVT::SimpleValueType getVT() const { return VT; }
723
Chris Lattner9a515172010-02-25 02:04:40 +0000724 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000725 return N->getKind() == EmitStringInteger;
726 }
727
Chris Lattner136ab782010-02-25 06:49:58 +0000728private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000729 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000730 virtual bool isEqualImpl(const Matcher *M) const {
731 return cast<EmitStringIntegerMatcher>(M)->Val == Val &&
732 cast<EmitStringIntegerMatcher>(M)->VT == VT;
733 }
734 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +0000735};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000736
Chris Lattner9a515172010-02-25 02:04:40 +0000737/// EmitRegisterMatcher - This creates a new TargetConstant.
738class EmitRegisterMatcher : public Matcher {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000739 /// Reg - The def for the register that we're emitting. If this is null, then
740 /// this is a reference to zero_reg.
741 Record *Reg;
742 MVT::SimpleValueType VT;
743public:
Chris Lattner9a515172010-02-25 02:04:40 +0000744 EmitRegisterMatcher(Record *reg, MVT::SimpleValueType vt)
745 : Matcher(EmitRegister), Reg(reg), VT(vt) {}
Chris Lattnerddfb5222010-02-18 22:03:03 +0000746
747 Record *getReg() const { return Reg; }
748 MVT::SimpleValueType getVT() const { return VT; }
749
Chris Lattner9a515172010-02-25 02:04:40 +0000750 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000751 return N->getKind() == EmitRegister;
752 }
753
Chris Lattner136ab782010-02-25 06:49:58 +0000754private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000755 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000756 virtual bool isEqualImpl(const Matcher *M) const {
757 return cast<EmitRegisterMatcher>(M)->Reg == Reg &&
758 cast<EmitRegisterMatcher>(M)->VT == VT;
759 }
760 virtual unsigned getHashImpl() const {
761 return ((unsigned)(intptr_t)Reg) << 4 | VT;
762 }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000763};
Chris Lattner3163ca52010-02-21 03:22:59 +0000764
Chris Lattner9a515172010-02-25 02:04:40 +0000765/// EmitConvertToTargetMatcher - Emit an operation that reads a specified
Chris Lattner3163ca52010-02-21 03:22:59 +0000766/// recorded node and converts it from being a ISD::Constant to
767/// ISD::TargetConstant, likewise for ConstantFP.
Chris Lattner9a515172010-02-25 02:04:40 +0000768class EmitConvertToTargetMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000769 unsigned Slot;
770public:
Chris Lattner9a515172010-02-25 02:04:40 +0000771 EmitConvertToTargetMatcher(unsigned slot)
772 : Matcher(EmitConvertToTarget), Slot(slot) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000773
774 unsigned getSlot() const { return Slot; }
775
Chris Lattner9a515172010-02-25 02:04:40 +0000776 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000777 return N->getKind() == EmitConvertToTarget;
778 }
779
Chris Lattner136ab782010-02-25 06:49:58 +0000780private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000781 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000782 virtual bool isEqualImpl(const Matcher *M) const {
783 return cast<EmitConvertToTargetMatcher>(M)->Slot == Slot;
784 }
785 virtual unsigned getHashImpl() const { return Slot; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000786};
787
Chris Lattner9a515172010-02-25 02:04:40 +0000788/// EmitMergeInputChainsMatcher - Emit a node that merges a list of input
Chris Lattner3163ca52010-02-21 03:22:59 +0000789/// chains together with a token factor. The list of nodes are the nodes in the
790/// matched pattern that have chain input/outputs. This node adds all input
791/// chains of these nodes if they are not themselves a node in the pattern.
Chris Lattner9a515172010-02-25 02:04:40 +0000792class EmitMergeInputChainsMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000793 SmallVector<unsigned, 3> ChainNodes;
794public:
Chris Lattner9a515172010-02-25 02:04:40 +0000795 EmitMergeInputChainsMatcher(const unsigned *nodes, unsigned NumNodes)
796 : Matcher(EmitMergeInputChains), ChainNodes(nodes, nodes+NumNodes) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000797
798 unsigned getNumNodes() const { return ChainNodes.size(); }
799
800 unsigned getNode(unsigned i) const {
801 assert(i < ChainNodes.size());
802 return ChainNodes[i];
803 }
804
Chris Lattner9a515172010-02-25 02:04:40 +0000805 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000806 return N->getKind() == EmitMergeInputChains;
807 }
808
Chris Lattner136ab782010-02-25 06:49:58 +0000809private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000810 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000811 virtual bool isEqualImpl(const Matcher *M) const {
812 return cast<EmitMergeInputChainsMatcher>(M)->ChainNodes == ChainNodes;
813 }
814 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +0000815};
816
Chris Lattner9a515172010-02-25 02:04:40 +0000817/// EmitCopyToRegMatcher - Emit a CopyToReg node from a value to a physreg,
Chris Lattner3163ca52010-02-21 03:22:59 +0000818/// pushing the chain and flag results.
819///
Chris Lattner9a515172010-02-25 02:04:40 +0000820class EmitCopyToRegMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000821 unsigned SrcSlot; // Value to copy into the physreg.
822 Record *DestPhysReg;
823public:
Chris Lattner9a515172010-02-25 02:04:40 +0000824 EmitCopyToRegMatcher(unsigned srcSlot, Record *destPhysReg)
825 : Matcher(EmitCopyToReg), SrcSlot(srcSlot), DestPhysReg(destPhysReg) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000826
827 unsigned getSrcSlot() const { return SrcSlot; }
828 Record *getDestPhysReg() const { return DestPhysReg; }
829
Chris Lattner9a515172010-02-25 02:04:40 +0000830 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000831 return N->getKind() == EmitCopyToReg;
832 }
833
Chris Lattner136ab782010-02-25 06:49:58 +0000834private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000835 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000836 virtual bool isEqualImpl(const Matcher *M) const {
837 return cast<EmitCopyToRegMatcher>(M)->SrcSlot == SrcSlot &&
838 cast<EmitCopyToRegMatcher>(M)->DestPhysReg == DestPhysReg;
839 }
840 virtual unsigned getHashImpl() const {
841 return SrcSlot ^ ((unsigned)(intptr_t)DestPhysReg << 4);
842 }
Chris Lattner3163ca52010-02-21 03:22:59 +0000843};
844
845
846
Chris Lattner9a515172010-02-25 02:04:40 +0000847/// EmitNodeXFormMatcher - Emit an operation that runs an SDNodeXForm on a
Chris Lattner3163ca52010-02-21 03:22:59 +0000848/// recorded node and records the result.
Chris Lattner9a515172010-02-25 02:04:40 +0000849class EmitNodeXFormMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000850 unsigned Slot;
851 Record *NodeXForm;
852public:
Chris Lattner9a515172010-02-25 02:04:40 +0000853 EmitNodeXFormMatcher(unsigned slot, Record *nodeXForm)
854 : Matcher(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000855
856 unsigned getSlot() const { return Slot; }
857 Record *getNodeXForm() const { return NodeXForm; }
858
Chris Lattner9a515172010-02-25 02:04:40 +0000859 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000860 return N->getKind() == EmitNodeXForm;
861 }
862
Chris Lattner136ab782010-02-25 06:49:58 +0000863private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000864 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000865 virtual bool isEqualImpl(const Matcher *M) const {
866 return cast<EmitNodeXFormMatcher>(M)->Slot == Slot &&
867 cast<EmitNodeXFormMatcher>(M)->NodeXForm == NodeXForm;
868 }
869 virtual unsigned getHashImpl() const {
870 return Slot ^ ((unsigned)(intptr_t)NodeXForm << 4);
871 }
Chris Lattner3163ca52010-02-21 03:22:59 +0000872};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000873
Chris Lattner7a1dab42010-02-28 02:31:26 +0000874/// EmitNodeMatcherCommon - Common class shared between EmitNode and
Chris Lattner7dae4af2010-02-28 20:55:18 +0000875/// MorphNodeTo.
Chris Lattner7a1dab42010-02-28 02:31:26 +0000876class EmitNodeMatcherCommon : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000877 std::string OpcodeName;
878 const SmallVector<MVT::SimpleValueType, 3> VTs;
879 const SmallVector<unsigned, 6> Operands;
Chris Lattner414bac82010-02-28 21:53:42 +0000880 bool HasChain, HasInFlag, HasOutFlag, HasMemRefs;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000881
Chris Lattner3163ca52010-02-21 03:22:59 +0000882 /// NumFixedArityOperands - If this is a fixed arity node, this is set to -1.
883 /// If this is a varidic node, this is set to the number of fixed arity
884 /// operands in the root of the pattern. The rest are appended to this node.
885 int NumFixedArityOperands;
886public:
Chris Lattner7a1dab42010-02-28 02:31:26 +0000887 EmitNodeMatcherCommon(const std::string &opcodeName,
888 const MVT::SimpleValueType *vts, unsigned numvts,
889 const unsigned *operands, unsigned numops,
Chris Lattner414bac82010-02-28 21:53:42 +0000890 bool hasChain, bool hasInFlag, bool hasOutFlag,
891 bool hasmemrefs,
Chris Lattner7dae4af2010-02-28 20:55:18 +0000892 int numfixedarityoperands, bool isMorphNodeTo)
893 : Matcher(isMorphNodeTo ? MorphNodeTo : EmitNode), OpcodeName(opcodeName),
Chris Lattner3163ca52010-02-21 03:22:59 +0000894 VTs(vts, vts+numvts), Operands(operands, operands+numops),
Chris Lattner414bac82010-02-28 21:53:42 +0000895 HasChain(hasChain), HasInFlag(hasInFlag), HasOutFlag(hasOutFlag),
896 HasMemRefs(hasmemrefs), NumFixedArityOperands(numfixedarityoperands) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000897
898 const std::string &getOpcodeName() const { return OpcodeName; }
899
900 unsigned getNumVTs() const { return VTs.size(); }
901 MVT::SimpleValueType getVT(unsigned i) const {
902 assert(i < VTs.size());
903 return VTs[i];
904 }
Chris Lattner5cc7a832010-02-28 20:49:53 +0000905
Chris Lattner3163ca52010-02-21 03:22:59 +0000906 unsigned getNumOperands() const { return Operands.size(); }
907 unsigned getOperand(unsigned i) const {
908 assert(i < Operands.size());
909 return Operands[i];
Chris Lattner5cc7a832010-02-28 20:49:53 +0000910 }
911
912 const SmallVectorImpl<MVT::SimpleValueType> &getVTList() const { return VTs; }
913 const SmallVectorImpl<unsigned> &getOperandList() const { return Operands; }
914
Chris Lattner3163ca52010-02-21 03:22:59 +0000915
916 bool hasChain() const { return HasChain; }
Chris Lattner414bac82010-02-28 21:53:42 +0000917 bool hasInFlag() const { return HasInFlag; }
918 bool hasOutFlag() const { return HasOutFlag; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000919 bool hasMemRefs() const { return HasMemRefs; }
920 int getNumFixedArityOperands() const { return NumFixedArityOperands; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000921
Chris Lattner9a515172010-02-25 02:04:40 +0000922 static inline bool classof(const Matcher *N) {
Chris Lattner7dae4af2010-02-28 20:55:18 +0000923 return N->getKind() == EmitNode || N->getKind() == MorphNodeTo;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000924 }
925
Chris Lattner136ab782010-02-25 06:49:58 +0000926private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000927 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000928 virtual bool isEqualImpl(const Matcher *M) const;
929 virtual unsigned getHashImpl() const;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000930};
Chris Lattnerb085ea12010-02-21 06:03:07 +0000931
Chris Lattner7a1dab42010-02-28 02:31:26 +0000932/// EmitNodeMatcher - This signals a successful match and generates a node.
933class EmitNodeMatcher : public EmitNodeMatcherCommon {
Chris Lattner19a1fbe2010-02-28 02:41:25 +0000934 unsigned FirstResultSlot;
Chris Lattner7a1dab42010-02-28 02:31:26 +0000935public:
936 EmitNodeMatcher(const std::string &opcodeName,
937 const MVT::SimpleValueType *vts, unsigned numvts,
938 const unsigned *operands, unsigned numops,
Chris Lattner414bac82010-02-28 21:53:42 +0000939 bool hasChain, bool hasInFlag, bool hasOutFlag,
940 bool hasmemrefs,
Chris Lattner19a1fbe2010-02-28 02:41:25 +0000941 int numfixedarityoperands, unsigned firstresultslot)
Chris Lattner7a1dab42010-02-28 02:31:26 +0000942 : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
Chris Lattner414bac82010-02-28 21:53:42 +0000943 hasInFlag, hasOutFlag, hasmemrefs,
944 numfixedarityoperands, false),
Chris Lattner19a1fbe2010-02-28 02:41:25 +0000945 FirstResultSlot(firstresultslot) {}
946
947 unsigned getFirstResultSlot() const { return FirstResultSlot; }
Chris Lattner7a1dab42010-02-28 02:31:26 +0000948
949 static inline bool classof(const Matcher *N) {
950 return N->getKind() == EmitNode;
951 }
952
953};
954
Chris Lattner7dae4af2010-02-28 20:55:18 +0000955class MorphNodeToMatcher : public EmitNodeMatcherCommon {
Chris Lattner7a1dab42010-02-28 02:31:26 +0000956 const PatternToMatch &Pattern;
957public:
Chris Lattner7dae4af2010-02-28 20:55:18 +0000958 MorphNodeToMatcher(const std::string &opcodeName,
959 const MVT::SimpleValueType *vts, unsigned numvts,
960 const unsigned *operands, unsigned numops,
Chris Lattner414bac82010-02-28 21:53:42 +0000961 bool hasChain, bool hasInFlag, bool hasOutFlag,
962 bool hasmemrefs,
Chris Lattner7dae4af2010-02-28 20:55:18 +0000963 int numfixedarityoperands, const PatternToMatch &pattern)
Chris Lattner7a1dab42010-02-28 02:31:26 +0000964 : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
Chris Lattner414bac82010-02-28 21:53:42 +0000965 hasInFlag, hasOutFlag, hasmemrefs,
966 numfixedarityoperands, true),
Chris Lattner7a1dab42010-02-28 02:31:26 +0000967 Pattern(pattern) {
968 }
969
970 const PatternToMatch &getPattern() const { return Pattern; }
971
972 static inline bool classof(const Matcher *N) {
Chris Lattner7dae4af2010-02-28 20:55:18 +0000973 return N->getKind() == MorphNodeTo;
Chris Lattner7a1dab42010-02-28 02:31:26 +0000974 }
975};
976
Chris Lattner9a515172010-02-25 02:04:40 +0000977/// MarkFlagResultsMatcher - This node indicates which non-root nodes in the
978/// pattern produce flags. This allows CompleteMatchMatcher to update them
Chris Lattner69f60c82010-02-24 05:33:42 +0000979/// with the output flag of the resultant code.
Chris Lattner9a515172010-02-25 02:04:40 +0000980class MarkFlagResultsMatcher : public Matcher {
Chris Lattner69f60c82010-02-24 05:33:42 +0000981 SmallVector<unsigned, 3> FlagResultNodes;
982public:
Chris Lattner9a515172010-02-25 02:04:40 +0000983 MarkFlagResultsMatcher(const unsigned *nodes, unsigned NumNodes)
984 : Matcher(MarkFlagResults), FlagResultNodes(nodes, nodes+NumNodes) {}
Chris Lattner69f60c82010-02-24 05:33:42 +0000985
986 unsigned getNumNodes() const { return FlagResultNodes.size(); }
987
988 unsigned getNode(unsigned i) const {
989 assert(i < FlagResultNodes.size());
990 return FlagResultNodes[i];
991 }
992
Chris Lattner9a515172010-02-25 02:04:40 +0000993 static inline bool classof(const Matcher *N) {
Chris Lattner69f60c82010-02-24 05:33:42 +0000994 return N->getKind() == MarkFlagResults;
995 }
996
Chris Lattner136ab782010-02-25 06:49:58 +0000997private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000998 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000999 virtual bool isEqualImpl(const Matcher *M) const {
1000 return cast<MarkFlagResultsMatcher>(M)->FlagResultNodes == FlagResultNodes;
1001 }
1002 virtual unsigned getHashImpl() const;
Chris Lattner69f60c82010-02-24 05:33:42 +00001003};
1004
Chris Lattner9a515172010-02-25 02:04:40 +00001005/// CompleteMatchMatcher - Complete a match by replacing the results of the
Chris Lattnerb085ea12010-02-21 06:03:07 +00001006/// pattern with the newly generated nodes. This also prints a comment
1007/// indicating the source and dest patterns.
Chris Lattner9a515172010-02-25 02:04:40 +00001008class CompleteMatchMatcher : public Matcher {
Chris Lattnerb085ea12010-02-21 06:03:07 +00001009 SmallVector<unsigned, 2> Results;
Chris Lattner3163ca52010-02-21 03:22:59 +00001010 const PatternToMatch &Pattern;
1011public:
Chris Lattner9a515172010-02-25 02:04:40 +00001012 CompleteMatchMatcher(const unsigned *results, unsigned numresults,
Chris Lattner5cc7a832010-02-28 20:49:53 +00001013 const PatternToMatch &pattern)
Chris Lattner9a515172010-02-25 02:04:40 +00001014 : Matcher(CompleteMatch), Results(results, results+numresults),
Chris Lattnerb085ea12010-02-21 06:03:07 +00001015 Pattern(pattern) {}
1016
1017 unsigned getNumResults() const { return Results.size(); }
1018 unsigned getResult(unsigned R) const { return Results[R]; }
Chris Lattner3163ca52010-02-21 03:22:59 +00001019 const PatternToMatch &getPattern() const { return Pattern; }
1020
Chris Lattner9a515172010-02-25 02:04:40 +00001021 static inline bool classof(const Matcher *N) {
Chris Lattnerb085ea12010-02-21 06:03:07 +00001022 return N->getKind() == CompleteMatch;
Chris Lattner3163ca52010-02-21 03:22:59 +00001023 }
1024
Chris Lattner136ab782010-02-25 06:49:58 +00001025private:
Chris Lattner392b1bf2010-02-25 06:53:39 +00001026 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +00001027 virtual bool isEqualImpl(const Matcher *M) const {
1028 return cast<CompleteMatchMatcher>(M)->Results == Results &&
1029 &cast<CompleteMatchMatcher>(M)->Pattern == &Pattern;
1030 }
1031 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +00001032};
Chris Lattner7a1dab42010-02-28 02:31:26 +00001033
Chris Lattnere7d6e3c2010-02-15 08:04:42 +00001034} // end namespace llvm
1035
1036#endif