blob: 3eb6755674adfc72d6f5c4b03b7b6bdcee262de4 [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 Lattner220b9682010-03-01 07:17:40 +000028Matcher *ConvertPatternToMatcher(const PatternToMatch &Pattern,unsigned Variant,
Chris Lattner9a515172010-02-25 02:04:40 +000029 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 Lattner2e9e6842010-03-01 06:59:22 +000057 SwitchOpcode, // Dispatch based on opcode.
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
68 // Node creation/emisssion.
Chris Lattner3163ca52010-02-21 03:22:59 +000069 EmitInteger, // Create a TargetConstant
70 EmitStringInteger, // Create a TargetConstant from a string.
71 EmitRegister, // Create a register.
72 EmitConvertToTarget, // Convert a imm/fpimm to target imm/fpimm
73 EmitMergeInputChains, // Merge together a chains for an input.
74 EmitCopyToReg, // Emit a copytoreg into a physreg.
75 EmitNode, // Create a DAG node
76 EmitNodeXForm, // Run a SDNodeXForm
Chris Lattner69f60c82010-02-24 05:33:42 +000077 MarkFlagResults, // Indicate which interior nodes have flag results.
Chris Lattner7a1dab42010-02-28 02:31:26 +000078 CompleteMatch, // Finish a match and update the results.
Chris Lattner7dae4af2010-02-28 20:55:18 +000079 MorphNodeTo // Build a node, finish a match and update results.
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000080 };
81 const KindTy Kind;
Chris Lattner3b31c982010-02-18 02:49:24 +000082
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000083protected:
Chris Lattner9a515172010-02-25 02:04:40 +000084 Matcher(KindTy K) : Kind(K) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000085public:
Chris Lattner9a515172010-02-25 02:04:40 +000086 virtual ~Matcher() {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000087
88 KindTy getKind() const { return Kind; }
Chris Lattner3b31c982010-02-18 02:49:24 +000089
Chris Lattner9a515172010-02-25 02:04:40 +000090 Matcher *getNext() { return Next.get(); }
91 const Matcher *getNext() const { return Next.get(); }
92 void setNext(Matcher *C) { Next.reset(C); }
93 Matcher *takeNext() { return Next.take(); }
Chris Lattner3ee1bc42010-02-24 07:31:45 +000094
Chris Lattner9a515172010-02-25 02:04:40 +000095 OwningPtr<Matcher> &getNextPtr() { return Next; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000096
Chris Lattner9a515172010-02-25 02:04:40 +000097 static inline bool classof(const Matcher *) { return true; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000098
Chris Lattner136ab782010-02-25 06:49:58 +000099 bool isEqual(const Matcher *M) const {
100 if (getKind() != M->getKind()) return false;
101 return isEqualImpl(M);
102 }
103
104 unsigned getHash() const {
Chris Lattner54ee7362010-02-26 07:35:27 +0000105 // Clear the high bit so we don't conflict with tombstones etc.
106 return ((getHashImpl() << 4) ^ getKind()) & (~0U>>1);
Chris Lattner136ab782010-02-25 06:49:58 +0000107 }
108
Chris Lattnerf4950d02010-02-27 06:22:57 +0000109 /// isSafeToReorderWithPatternPredicate - Return true if it is safe to sink a
110 /// PatternPredicate node past this one.
111 virtual bool isSafeToReorderWithPatternPredicate() const {
112 return false;
113 }
114
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000115 /// isContradictory - Return true of these two matchers could never match on
116 /// the same node.
117 bool isContradictory(const Matcher *Other) const {
118 // Since this predicate is reflexive, we canonicalize the ordering so that
119 // we always match a node against nodes with kinds that are greater or equal
120 // to them. For example, we'll pass in a CheckType node as an argument to
121 // the CheckOpcode method, not the other way around.
122 if (getKind() < Other->getKind())
123 return isContradictoryImpl(Other);
124 return Other->isContradictoryImpl(this);
125 }
126
Chris Lattner392b1bf2010-02-25 06:53:39 +0000127 void print(raw_ostream &OS, unsigned indent = 0) const;
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000128 void printOne(raw_ostream &OS) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000129 void dump() const;
Chris Lattner3b31c982010-02-18 02:49:24 +0000130protected:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000131 virtual void printImpl(raw_ostream &OS, unsigned indent) const = 0;
Chris Lattner136ab782010-02-25 06:49:58 +0000132 virtual bool isEqualImpl(const Matcher *M) const = 0;
133 virtual unsigned getHashImpl() const = 0;
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000134 virtual bool isContradictoryImpl(const Matcher *M) const { return false; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000135};
136
Chris Lattner42363662010-02-25 19:00:39 +0000137/// ScopeMatcher - This attempts to match each of its children to find the first
138/// one that successfully matches. If one child fails, it tries the next child.
139/// If none of the children match then this check fails. It never has a 'next'.
Chris Lattner9a515172010-02-25 02:04:40 +0000140class ScopeMatcher : public Matcher {
Chris Lattner42363662010-02-25 19:00:39 +0000141 SmallVector<Matcher*, 4> Children;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000142public:
Chris Lattner42363662010-02-25 19:00:39 +0000143 ScopeMatcher(Matcher *const *children, unsigned numchildren)
144 : Matcher(Scope), Children(children, children+numchildren) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000145 }
Chris Lattner42363662010-02-25 19:00:39 +0000146 virtual ~ScopeMatcher();
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000147
Chris Lattner42363662010-02-25 19:00:39 +0000148 unsigned getNumChildren() const { return Children.size(); }
149
150 Matcher *getChild(unsigned i) { return Children[i]; }
151 const Matcher *getChild(unsigned i) const { return Children[i]; }
152
153 void resetChild(unsigned i, Matcher *N) {
154 delete Children[i];
155 Children[i] = N;
156 }
157
158 Matcher *takeChild(unsigned i) {
159 Matcher *Res = Children[i];
160 Children[i] = 0;
161 return Res;
162 }
Chris Lattner54ee7362010-02-26 07:35:27 +0000163
164 void setNumChildren(unsigned NC) {
165 if (NC < Children.size()) {
166 // delete any children we're about to lose pointers to.
167 for (unsigned i = NC, e = Children.size(); i != e; ++i)
168 delete Children[i];
169 }
170 Children.resize(NC);
171 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000172
Chris Lattner9a515172010-02-25 02:04:40 +0000173 static inline bool classof(const Matcher *N) {
Chris Lattnerac10e4f2010-02-25 01:56:48 +0000174 return N->getKind() == Scope;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000175 }
176
Chris Lattner136ab782010-02-25 06:49:58 +0000177private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000178 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000179 virtual bool isEqualImpl(const Matcher *M) const { return false; }
Chris Lattner42363662010-02-25 19:00:39 +0000180 virtual unsigned getHashImpl() const { return 12312; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000181};
182
Chris Lattner9a515172010-02-25 02:04:40 +0000183/// RecordMatcher - Save the current node in the operand list.
184class RecordMatcher : public Matcher {
Chris Lattner56cf88d2010-02-17 01:03:09 +0000185 /// WhatFor - This is a string indicating why we're recording this. This
186 /// should only be used for comment generation not anything semantic.
187 std::string WhatFor;
Chris Lattner5377f912010-03-01 02:24:17 +0000188
189 /// ResultNo - The slot number in the RecordedNodes vector that this will be,
190 /// just printed as a comment.
191 unsigned ResultNo;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000192public:
Chris Lattner5377f912010-03-01 02:24:17 +0000193 RecordMatcher(const std::string &whatfor, unsigned resultNo)
194 : Matcher(RecordNode), WhatFor(whatfor), ResultNo(resultNo) {}
Chris Lattner56cf88d2010-02-17 01:03:09 +0000195
Chris Lattner086ca522010-02-17 01:27:29 +0000196 const std::string &getWhatFor() const { return WhatFor; }
Chris Lattner5377f912010-03-01 02:24:17 +0000197 unsigned getResultNo() const { return ResultNo; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000198
Chris Lattner9a515172010-02-25 02:04:40 +0000199 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000200 return N->getKind() == RecordNode;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000201 }
202
Chris Lattnerf4950d02010-02-27 06:22:57 +0000203 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
Chris Lattner136ab782010-02-25 06:49:58 +0000204private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000205 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000206 virtual bool isEqualImpl(const Matcher *M) const { return true; }
207 virtual unsigned getHashImpl() const { return 0; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000208};
209
Chris Lattner9a515172010-02-25 02:04:40 +0000210/// RecordChildMatcher - Save a numbered child of the current node, or fail
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000211/// the match if it doesn't exist. This is logically equivalent to:
212/// MoveChild N + RecordNode + MoveParent.
Chris Lattner9a515172010-02-25 02:04:40 +0000213class RecordChildMatcher : public Matcher {
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000214 unsigned ChildNo;
215
216 /// WhatFor - This is a string indicating why we're recording this. This
217 /// should only be used for comment generation not anything semantic.
218 std::string WhatFor;
Chris Lattner5377f912010-03-01 02:24:17 +0000219
220 /// ResultNo - The slot number in the RecordedNodes vector that this will be,
221 /// just printed as a comment.
222 unsigned ResultNo;
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000223public:
Chris Lattner5377f912010-03-01 02:24:17 +0000224 RecordChildMatcher(unsigned childno, const std::string &whatfor,
225 unsigned resultNo)
226 : Matcher(RecordChild), ChildNo(childno), WhatFor(whatfor),
227 ResultNo(resultNo) {}
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000228
229 unsigned getChildNo() const { return ChildNo; }
230 const std::string &getWhatFor() const { return WhatFor; }
Chris Lattner5377f912010-03-01 02:24:17 +0000231 unsigned getResultNo() const { return ResultNo; }
232
Chris Lattner9a515172010-02-25 02:04:40 +0000233 static inline bool classof(const Matcher *N) {
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000234 return N->getKind() == RecordChild;
235 }
236
Chris Lattnerf4950d02010-02-27 06:22:57 +0000237 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
238
Chris Lattner136ab782010-02-25 06:49:58 +0000239private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000240 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000241 virtual bool isEqualImpl(const Matcher *M) const {
242 return cast<RecordChildMatcher>(M)->getChildNo() == getChildNo();
243 }
244 virtual unsigned getHashImpl() const { return getChildNo(); }
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000245};
246
Chris Lattner9a515172010-02-25 02:04:40 +0000247/// RecordMemRefMatcher - Save the current node's memref.
248class RecordMemRefMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000249public:
Chris Lattner9a515172010-02-25 02:04:40 +0000250 RecordMemRefMatcher() : Matcher(RecordMemRef) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000251
Chris Lattner9a515172010-02-25 02:04:40 +0000252 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000253 return N->getKind() == RecordMemRef;
254 }
255
Chris Lattnerf4950d02010-02-27 06:22:57 +0000256 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
257
Chris Lattner136ab782010-02-25 06:49:58 +0000258private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000259 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000260 virtual bool isEqualImpl(const Matcher *M) const { return true; }
261 virtual unsigned getHashImpl() const { return 0; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000262};
263
264
Chris Lattner9a515172010-02-25 02:04:40 +0000265/// CaptureFlagInputMatcher - If the current record has a flag input, record
Chris Lattner3163ca52010-02-21 03:22:59 +0000266/// it so that it is used as an input to the generated code.
Chris Lattner9a515172010-02-25 02:04:40 +0000267class CaptureFlagInputMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000268public:
Chris Lattner9a515172010-02-25 02:04:40 +0000269 CaptureFlagInputMatcher() : Matcher(CaptureFlagInput) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000270
Chris Lattner9a515172010-02-25 02:04:40 +0000271 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000272 return N->getKind() == CaptureFlagInput;
273 }
274
Chris Lattnerf4950d02010-02-27 06:22:57 +0000275 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
276
Chris Lattner136ab782010-02-25 06:49:58 +0000277private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000278 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000279 virtual bool isEqualImpl(const Matcher *M) const { return true; }
280 virtual unsigned getHashImpl() const { return 0; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000281};
282
Chris Lattner9a515172010-02-25 02:04:40 +0000283/// MoveChildMatcher - This tells the interpreter to move into the
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000284/// specified child node.
Chris Lattner9a515172010-02-25 02:04:40 +0000285class MoveChildMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000286 unsigned ChildNo;
287public:
Chris Lattner9a515172010-02-25 02:04:40 +0000288 MoveChildMatcher(unsigned childNo) : Matcher(MoveChild), ChildNo(childNo) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000289
290 unsigned getChildNo() const { return ChildNo; }
291
Chris Lattner9a515172010-02-25 02:04:40 +0000292 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000293 return N->getKind() == MoveChild;
294 }
295
Chris Lattnerf4950d02010-02-27 06:22:57 +0000296 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
297
Chris Lattner136ab782010-02-25 06:49:58 +0000298private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000299 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000300 virtual bool isEqualImpl(const Matcher *M) const {
301 return cast<MoveChildMatcher>(M)->getChildNo() == getChildNo();
302 }
303 virtual unsigned getHashImpl() const { return getChildNo(); }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000304};
305
Chris Lattner9a515172010-02-25 02:04:40 +0000306/// MoveParentMatcher - This tells the interpreter to move to the parent
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000307/// of the current node.
Chris Lattner9a515172010-02-25 02:04:40 +0000308class MoveParentMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000309public:
Chris Lattner9a515172010-02-25 02:04:40 +0000310 MoveParentMatcher() : Matcher(MoveParent) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000311
Chris Lattner9a515172010-02-25 02:04:40 +0000312 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000313 return N->getKind() == MoveParent;
314 }
315
Chris Lattnerf4950d02010-02-27 06:22:57 +0000316 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
317
Chris Lattner136ab782010-02-25 06:49:58 +0000318private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000319 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000320 virtual bool isEqualImpl(const Matcher *M) const { return true; }
321 virtual unsigned getHashImpl() const { return 0; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000322};
323
Chris Lattner9a515172010-02-25 02:04:40 +0000324/// CheckSameMatcher - This checks to see if this node is exactly the same
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000325/// node as the specified match that was recorded with 'Record'. This is used
326/// when patterns have the same name in them, like '(mul GPR:$in, GPR:$in)'.
Chris Lattner9a515172010-02-25 02:04:40 +0000327class CheckSameMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000328 unsigned MatchNumber;
329public:
Chris Lattner9a515172010-02-25 02:04:40 +0000330 CheckSameMatcher(unsigned matchnumber)
Chris Lattner136ab782010-02-25 06:49:58 +0000331 : Matcher(CheckSame), MatchNumber(matchnumber) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000332
333 unsigned getMatchNumber() const { return MatchNumber; }
334
Chris Lattner9a515172010-02-25 02:04:40 +0000335 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000336 return N->getKind() == CheckSame;
337 }
338
Chris Lattnerf4950d02010-02-27 06:22:57 +0000339 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
340
Chris Lattner136ab782010-02-25 06:49:58 +0000341private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000342 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000343 virtual bool isEqualImpl(const Matcher *M) const {
344 return cast<CheckSameMatcher>(M)->getMatchNumber() == getMatchNumber();
345 }
346 virtual unsigned getHashImpl() const { return getMatchNumber(); }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000347};
348
Chris Lattner9a515172010-02-25 02:04:40 +0000349/// CheckPatternPredicateMatcher - This checks the target-specific predicate
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000350/// to see if the entire pattern is capable of matching. This predicate does
351/// not take a node as input. This is used for subtarget feature checks etc.
Chris Lattner9a515172010-02-25 02:04:40 +0000352class CheckPatternPredicateMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000353 std::string Predicate;
354public:
Chris Lattner9a515172010-02-25 02:04:40 +0000355 CheckPatternPredicateMatcher(StringRef predicate)
Chris Lattner136ab782010-02-25 06:49:58 +0000356 : Matcher(CheckPatternPredicate), Predicate(predicate) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000357
358 StringRef getPredicate() const { return Predicate; }
359
Chris Lattner9a515172010-02-25 02:04:40 +0000360 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000361 return N->getKind() == CheckPatternPredicate;
362 }
363
Chris Lattnerf4950d02010-02-27 06:22:57 +0000364 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
365
Chris Lattner136ab782010-02-25 06:49:58 +0000366private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000367 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000368 virtual bool isEqualImpl(const Matcher *M) const {
369 return cast<CheckPatternPredicateMatcher>(M)->getPredicate() == Predicate;
370 }
371 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000372};
373
Chris Lattner9a515172010-02-25 02:04:40 +0000374/// CheckPredicateMatcher - This checks the target-specific predicate to
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000375/// see if the node is acceptable.
Chris Lattner9a515172010-02-25 02:04:40 +0000376class CheckPredicateMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000377 StringRef PredName;
378public:
Chris Lattner9a515172010-02-25 02:04:40 +0000379 CheckPredicateMatcher(StringRef predname)
380 : Matcher(CheckPredicate), PredName(predname) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000381
382 StringRef getPredicateName() const { return PredName; }
383
Chris Lattner9a515172010-02-25 02:04:40 +0000384 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000385 return N->getKind() == CheckPredicate;
386 }
387
Chris Lattnerf4950d02010-02-27 06:22:57 +0000388 // TODO: Ok?
389 //virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
390
Chris Lattner136ab782010-02-25 06:49:58 +0000391private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000392 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000393 virtual bool isEqualImpl(const Matcher *M) const {
394 return cast<CheckPredicateMatcher>(M)->PredName == PredName;
395 }
396 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000397};
398
399
Chris Lattner9a515172010-02-25 02:04:40 +0000400/// CheckOpcodeMatcher - This checks to see if the current node has the
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000401/// specified opcode, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000402class CheckOpcodeMatcher : public Matcher {
Chris Lattnere9f720b2010-02-27 21:48:43 +0000403 const SDNodeInfo &Opcode;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000404public:
Chris Lattnere9f720b2010-02-27 21:48:43 +0000405 CheckOpcodeMatcher(const SDNodeInfo &opcode)
406 : Matcher(CheckOpcode), Opcode(opcode) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000407
Chris Lattnere9f720b2010-02-27 21:48:43 +0000408 const SDNodeInfo &getOpcode() const { return Opcode; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000409
Chris Lattner9a515172010-02-25 02:04:40 +0000410 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000411 return N->getKind() == CheckOpcode;
412 }
413
Chris Lattnerf4950d02010-02-27 06:22:57 +0000414 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
415
Chris Lattner136ab782010-02-25 06:49:58 +0000416private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000417 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner2e9e6842010-03-01 06:59:22 +0000418 virtual bool isEqualImpl(const Matcher *M) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000419 virtual unsigned getHashImpl() const;
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000420 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000421};
Chris Lattner2e9e6842010-03-01 06:59:22 +0000422
423/// SwitchOpcodeMatcher - Switch based on the current node's opcode, dispatching
424/// to one matcher per opcode. If the opcode doesn't match any of the cases,
425/// then the match fails. This is semantically equivalent to a Scope node where
426/// every child does a CheckOpcode, but is much faster.
427class SwitchOpcodeMatcher : public Matcher {
428 SmallVector<std::pair<const SDNodeInfo*, Matcher*>, 8> Cases;
429public:
430 SwitchOpcodeMatcher(const std::pair<const SDNodeInfo*, Matcher*> *cases,
431 unsigned numcases)
432 : Matcher(SwitchOpcode), Cases(cases, cases+numcases) {}
433
434 static inline bool classof(const Matcher *N) {
435 return N->getKind() == SwitchOpcode;
436 }
437
438 unsigned getNumCases() const { return Cases.size(); }
439
440 const SDNodeInfo &getCaseOpcode(unsigned i) const { return *Cases[i].first; }
441 Matcher *getCaseMatcher(unsigned i) { return Cases[i].second; }
442 const Matcher *getCaseMatcher(unsigned i) const { return Cases[i].second; }
443
444private:
445 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
446 virtual bool isEqualImpl(const Matcher *M) const { return false; }
447 virtual unsigned getHashImpl() const { return 4123; }
448};
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000449
Chris Lattner9a515172010-02-25 02:04:40 +0000450/// CheckTypeMatcher - This checks to see if the current node has the
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000451/// specified type, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000452class CheckTypeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000453 MVT::SimpleValueType Type;
454public:
Chris Lattner9a515172010-02-25 02:04:40 +0000455 CheckTypeMatcher(MVT::SimpleValueType type)
456 : Matcher(CheckType), Type(type) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000457
458 MVT::SimpleValueType getType() const { return Type; }
459
Chris Lattner9a515172010-02-25 02:04:40 +0000460 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000461 return N->getKind() == CheckType;
462 }
463
Chris Lattnerf4950d02010-02-27 06:22:57 +0000464 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
465
Chris Lattner136ab782010-02-25 06:49:58 +0000466private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000467 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000468 virtual bool isEqualImpl(const Matcher *M) const {
Chris Lattner2d0e0792010-02-26 08:05:36 +0000469 return cast<CheckTypeMatcher>(M)->Type == Type;
Chris Lattner136ab782010-02-25 06:49:58 +0000470 }
471 virtual unsigned getHashImpl() const { return Type; }
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000472 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000473};
Chris Lattner3c664b32010-02-24 20:15:25 +0000474
Chris Lattner9a515172010-02-25 02:04:40 +0000475/// CheckChildTypeMatcher - This checks to see if a child node has the
Chris Lattner3c664b32010-02-24 20:15:25 +0000476/// specified type, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000477class CheckChildTypeMatcher : public Matcher {
Chris Lattner3c664b32010-02-24 20:15:25 +0000478 unsigned ChildNo;
479 MVT::SimpleValueType Type;
480public:
Chris Lattner9a515172010-02-25 02:04:40 +0000481 CheckChildTypeMatcher(unsigned childno, MVT::SimpleValueType type)
482 : Matcher(CheckChildType), ChildNo(childno), Type(type) {}
Chris Lattner3c664b32010-02-24 20:15:25 +0000483
484 unsigned getChildNo() const { return ChildNo; }
485 MVT::SimpleValueType getType() const { return Type; }
486
Chris Lattner9a515172010-02-25 02:04:40 +0000487 static inline bool classof(const Matcher *N) {
Chris Lattner3c664b32010-02-24 20:15:25 +0000488 return N->getKind() == CheckChildType;
489 }
490
Chris Lattnerf4950d02010-02-27 06:22:57 +0000491 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
492
Chris Lattner136ab782010-02-25 06:49:58 +0000493private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000494 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000495 virtual bool isEqualImpl(const Matcher *M) const {
496 return cast<CheckChildTypeMatcher>(M)->ChildNo == ChildNo &&
497 cast<CheckChildTypeMatcher>(M)->Type == Type;
498 }
499 virtual unsigned getHashImpl() const { return (Type << 3) | ChildNo; }
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000500 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattner3c664b32010-02-24 20:15:25 +0000501};
502
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000503
Chris Lattner9a515172010-02-25 02:04:40 +0000504/// CheckIntegerMatcher - This checks to see if the current node is a
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000505/// ConstantSDNode with the specified integer value, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000506class CheckIntegerMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000507 int64_t Value;
508public:
Chris Lattner9a515172010-02-25 02:04:40 +0000509 CheckIntegerMatcher(int64_t value)
510 : Matcher(CheckInteger), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000511
512 int64_t getValue() const { return Value; }
513
Chris Lattner9a515172010-02-25 02:04:40 +0000514 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000515 return N->getKind() == CheckInteger;
516 }
517
Chris Lattnerf4950d02010-02-27 06:22:57 +0000518 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
519
Chris Lattner136ab782010-02-25 06:49:58 +0000520private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000521 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000522 virtual bool isEqualImpl(const Matcher *M) const {
523 return cast<CheckIntegerMatcher>(M)->Value == Value;
524 }
525 virtual unsigned getHashImpl() const { return Value; }
Chris Lattner086af322010-02-27 08:11:15 +0000526 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000527};
528
Chris Lattner9a515172010-02-25 02:04:40 +0000529/// CheckCondCodeMatcher - This checks to see if the current node is a
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000530/// CondCodeSDNode with the specified condition, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000531class CheckCondCodeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000532 StringRef CondCodeName;
533public:
Chris Lattner9a515172010-02-25 02:04:40 +0000534 CheckCondCodeMatcher(StringRef condcodename)
535 : Matcher(CheckCondCode), CondCodeName(condcodename) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000536
537 StringRef getCondCodeName() const { return CondCodeName; }
538
Chris Lattner9a515172010-02-25 02:04:40 +0000539 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000540 return N->getKind() == CheckCondCode;
541 }
542
Chris Lattnerf4950d02010-02-27 06:22:57 +0000543 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
544
Chris Lattner136ab782010-02-25 06:49:58 +0000545private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000546 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000547 virtual bool isEqualImpl(const Matcher *M) const {
548 return cast<CheckCondCodeMatcher>(M)->CondCodeName == CondCodeName;
549 }
550 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000551};
552
Chris Lattner9a515172010-02-25 02:04:40 +0000553/// CheckValueTypeMatcher - This checks to see if the current node is a
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000554/// VTSDNode with the specified type, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000555class CheckValueTypeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000556 StringRef TypeName;
557public:
Chris Lattner9a515172010-02-25 02:04:40 +0000558 CheckValueTypeMatcher(StringRef type_name)
559 : Matcher(CheckValueType), TypeName(type_name) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000560
561 StringRef getTypeName() const { return TypeName; }
562
Chris Lattner9a515172010-02-25 02:04:40 +0000563 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000564 return N->getKind() == CheckValueType;
565 }
566
Chris Lattnerf4950d02010-02-27 06:22:57 +0000567 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
568
Chris Lattner136ab782010-02-25 06:49:58 +0000569private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000570 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000571 virtual bool isEqualImpl(const Matcher *M) const {
572 return cast<CheckValueTypeMatcher>(M)->TypeName == TypeName;
573 }
574 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000575};
576
577
578
Chris Lattner9a515172010-02-25 02:04:40 +0000579/// CheckComplexPatMatcher - This node runs the specified ComplexPattern on
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000580/// the current node.
Chris Lattner9a515172010-02-25 02:04:40 +0000581class CheckComplexPatMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000582 const ComplexPattern &Pattern;
583public:
Chris Lattner9a515172010-02-25 02:04:40 +0000584 CheckComplexPatMatcher(const ComplexPattern &pattern)
585 : Matcher(CheckComplexPat), Pattern(pattern) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000586
Chris Lattnerdc429fd2010-02-17 00:31:50 +0000587 const ComplexPattern &getPattern() const { return Pattern; }
588
Chris Lattner9a515172010-02-25 02:04:40 +0000589 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000590 return N->getKind() == CheckComplexPat;
591 }
592
Chris Lattnerf4950d02010-02-27 06:22:57 +0000593 // Not safe to move a pattern predicate past a complex pattern.
594 virtual bool isSafeToReorderWithPatternPredicate() const { return false; }
595
Chris Lattner136ab782010-02-25 06:49:58 +0000596private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000597 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000598 virtual bool isEqualImpl(const Matcher *M) const {
599 return &cast<CheckComplexPatMatcher>(M)->Pattern == &Pattern;
600 }
601 virtual unsigned getHashImpl() const {
602 return (unsigned)(intptr_t)&Pattern;
603 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000604};
605
Chris Lattner9a515172010-02-25 02:04:40 +0000606/// CheckAndImmMatcher - This checks to see if the current node is an 'and'
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000607/// with something equivalent to the specified immediate.
Chris Lattner9a515172010-02-25 02:04:40 +0000608class CheckAndImmMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000609 int64_t Value;
610public:
Chris Lattner9a515172010-02-25 02:04:40 +0000611 CheckAndImmMatcher(int64_t value)
612 : Matcher(CheckAndImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000613
614 int64_t getValue() const { return Value; }
615
Chris Lattner9a515172010-02-25 02:04:40 +0000616 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000617 return N->getKind() == CheckAndImm;
618 }
619
Chris Lattnerf4950d02010-02-27 06:22:57 +0000620 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
621
Chris Lattner136ab782010-02-25 06:49:58 +0000622private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000623 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000624 virtual bool isEqualImpl(const Matcher *M) const {
625 return cast<CheckAndImmMatcher>(M)->Value == Value;
626 }
627 virtual unsigned getHashImpl() const { return Value; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000628};
629
Chris Lattner9a515172010-02-25 02:04:40 +0000630/// CheckOrImmMatcher - This checks to see if the current node is an 'and'
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000631/// with something equivalent to the specified immediate.
Chris Lattner9a515172010-02-25 02:04:40 +0000632class CheckOrImmMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000633 int64_t Value;
634public:
Chris Lattner9a515172010-02-25 02:04:40 +0000635 CheckOrImmMatcher(int64_t value)
636 : Matcher(CheckOrImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000637
638 int64_t getValue() const { return Value; }
639
Chris Lattner9a515172010-02-25 02:04:40 +0000640 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000641 return N->getKind() == CheckOrImm;
642 }
643
Chris Lattnerf4950d02010-02-27 06:22:57 +0000644 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
645
Chris Lattner136ab782010-02-25 06:49:58 +0000646private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000647 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000648 virtual bool isEqualImpl(const Matcher *M) const {
649 return cast<CheckOrImmMatcher>(M)->Value == Value;
650 }
651 virtual unsigned getHashImpl() const { return Value; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000652};
Chris Lattner9de39482010-02-16 06:10:58 +0000653
Chris Lattner9a515172010-02-25 02:04:40 +0000654/// CheckFoldableChainNodeMatcher - This checks to see if the current node
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000655/// (which defines a chain operand) is safe to fold into a larger pattern.
Chris Lattner9a515172010-02-25 02:04:40 +0000656class CheckFoldableChainNodeMatcher : public Matcher {
Chris Lattner9de39482010-02-16 06:10:58 +0000657public:
Chris Lattner9a515172010-02-25 02:04:40 +0000658 CheckFoldableChainNodeMatcher()
659 : Matcher(CheckFoldableChainNode) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000660
Chris Lattner9a515172010-02-25 02:04:40 +0000661 static inline bool classof(const Matcher *N) {
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000662 return N->getKind() == CheckFoldableChainNode;
Chris Lattner9de39482010-02-16 06:10:58 +0000663 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000664
Chris Lattnerf4950d02010-02-27 06:22:57 +0000665 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
666
Chris Lattner136ab782010-02-25 06:49:58 +0000667private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000668 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000669 virtual bool isEqualImpl(const Matcher *M) const { return true; }
670 virtual unsigned getHashImpl() const { return 0; }
Chris Lattner9de39482010-02-16 06:10:58 +0000671};
672
Chris Lattner9a515172010-02-25 02:04:40 +0000673/// EmitIntegerMatcher - This creates a new TargetConstant.
674class EmitIntegerMatcher : public Matcher {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000675 int64_t Val;
676 MVT::SimpleValueType VT;
677public:
Chris Lattner9a515172010-02-25 02:04:40 +0000678 EmitIntegerMatcher(int64_t val, MVT::SimpleValueType vt)
679 : Matcher(EmitInteger), Val(val), VT(vt) {}
Chris Lattner283adcb2010-02-17 06:23:39 +0000680
Chris Lattner7043e0a2010-02-19 07:49:56 +0000681 int64_t getValue() const { return Val; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000682 MVT::SimpleValueType getVT() const { return VT; }
683
Chris Lattner9a515172010-02-25 02:04:40 +0000684 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000685 return N->getKind() == EmitInteger;
686 }
687
Chris Lattner136ab782010-02-25 06:49:58 +0000688private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000689 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000690 virtual bool isEqualImpl(const Matcher *M) const {
691 return cast<EmitIntegerMatcher>(M)->Val == Val &&
692 cast<EmitIntegerMatcher>(M)->VT == VT;
693 }
694 virtual unsigned getHashImpl() const { return (Val << 4) | VT; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000695};
Chris Lattner3163ca52010-02-21 03:22:59 +0000696
Chris Lattner9a515172010-02-25 02:04:40 +0000697/// EmitStringIntegerMatcher - A target constant whose value is represented
Chris Lattner3163ca52010-02-21 03:22:59 +0000698/// by a string.
Chris Lattner9a515172010-02-25 02:04:40 +0000699class EmitStringIntegerMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000700 std::string Val;
701 MVT::SimpleValueType VT;
702public:
Chris Lattner9a515172010-02-25 02:04:40 +0000703 EmitStringIntegerMatcher(const std::string &val, MVT::SimpleValueType vt)
704 : Matcher(EmitStringInteger), Val(val), VT(vt) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000705
706 const std::string &getValue() const { return Val; }
707 MVT::SimpleValueType getVT() const { return VT; }
708
Chris Lattner9a515172010-02-25 02:04:40 +0000709 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000710 return N->getKind() == EmitStringInteger;
711 }
712
Chris Lattner136ab782010-02-25 06:49:58 +0000713private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000714 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000715 virtual bool isEqualImpl(const Matcher *M) const {
716 return cast<EmitStringIntegerMatcher>(M)->Val == Val &&
717 cast<EmitStringIntegerMatcher>(M)->VT == VT;
718 }
719 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +0000720};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000721
Chris Lattner9a515172010-02-25 02:04:40 +0000722/// EmitRegisterMatcher - This creates a new TargetConstant.
723class EmitRegisterMatcher : public Matcher {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000724 /// Reg - The def for the register that we're emitting. If this is null, then
725 /// this is a reference to zero_reg.
726 Record *Reg;
727 MVT::SimpleValueType VT;
728public:
Chris Lattner9a515172010-02-25 02:04:40 +0000729 EmitRegisterMatcher(Record *reg, MVT::SimpleValueType vt)
730 : Matcher(EmitRegister), Reg(reg), VT(vt) {}
Chris Lattnerddfb5222010-02-18 22:03:03 +0000731
732 Record *getReg() const { return Reg; }
733 MVT::SimpleValueType getVT() const { return VT; }
734
Chris Lattner9a515172010-02-25 02:04:40 +0000735 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000736 return N->getKind() == EmitRegister;
737 }
738
Chris Lattner136ab782010-02-25 06:49:58 +0000739private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000740 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000741 virtual bool isEqualImpl(const Matcher *M) const {
742 return cast<EmitRegisterMatcher>(M)->Reg == Reg &&
743 cast<EmitRegisterMatcher>(M)->VT == VT;
744 }
745 virtual unsigned getHashImpl() const {
746 return ((unsigned)(intptr_t)Reg) << 4 | VT;
747 }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000748};
Chris Lattner3163ca52010-02-21 03:22:59 +0000749
Chris Lattner9a515172010-02-25 02:04:40 +0000750/// EmitConvertToTargetMatcher - Emit an operation that reads a specified
Chris Lattner3163ca52010-02-21 03:22:59 +0000751/// recorded node and converts it from being a ISD::Constant to
752/// ISD::TargetConstant, likewise for ConstantFP.
Chris Lattner9a515172010-02-25 02:04:40 +0000753class EmitConvertToTargetMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000754 unsigned Slot;
755public:
Chris Lattner9a515172010-02-25 02:04:40 +0000756 EmitConvertToTargetMatcher(unsigned slot)
757 : Matcher(EmitConvertToTarget), Slot(slot) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000758
759 unsigned getSlot() const { return Slot; }
760
Chris Lattner9a515172010-02-25 02:04:40 +0000761 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000762 return N->getKind() == EmitConvertToTarget;
763 }
764
Chris Lattner136ab782010-02-25 06:49:58 +0000765private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000766 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000767 virtual bool isEqualImpl(const Matcher *M) const {
768 return cast<EmitConvertToTargetMatcher>(M)->Slot == Slot;
769 }
770 virtual unsigned getHashImpl() const { return Slot; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000771};
772
Chris Lattner9a515172010-02-25 02:04:40 +0000773/// EmitMergeInputChainsMatcher - Emit a node that merges a list of input
Chris Lattner3163ca52010-02-21 03:22:59 +0000774/// chains together with a token factor. The list of nodes are the nodes in the
775/// matched pattern that have chain input/outputs. This node adds all input
776/// chains of these nodes if they are not themselves a node in the pattern.
Chris Lattner9a515172010-02-25 02:04:40 +0000777class EmitMergeInputChainsMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000778 SmallVector<unsigned, 3> ChainNodes;
779public:
Chris Lattner9a515172010-02-25 02:04:40 +0000780 EmitMergeInputChainsMatcher(const unsigned *nodes, unsigned NumNodes)
781 : Matcher(EmitMergeInputChains), ChainNodes(nodes, nodes+NumNodes) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000782
783 unsigned getNumNodes() const { return ChainNodes.size(); }
784
785 unsigned getNode(unsigned i) const {
786 assert(i < ChainNodes.size());
787 return ChainNodes[i];
788 }
789
Chris Lattner9a515172010-02-25 02:04:40 +0000790 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000791 return N->getKind() == EmitMergeInputChains;
792 }
793
Chris Lattner136ab782010-02-25 06:49:58 +0000794private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000795 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000796 virtual bool isEqualImpl(const Matcher *M) const {
797 return cast<EmitMergeInputChainsMatcher>(M)->ChainNodes == ChainNodes;
798 }
799 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +0000800};
801
Chris Lattner9a515172010-02-25 02:04:40 +0000802/// EmitCopyToRegMatcher - Emit a CopyToReg node from a value to a physreg,
Chris Lattner3163ca52010-02-21 03:22:59 +0000803/// pushing the chain and flag results.
804///
Chris Lattner9a515172010-02-25 02:04:40 +0000805class EmitCopyToRegMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000806 unsigned SrcSlot; // Value to copy into the physreg.
807 Record *DestPhysReg;
808public:
Chris Lattner9a515172010-02-25 02:04:40 +0000809 EmitCopyToRegMatcher(unsigned srcSlot, Record *destPhysReg)
810 : Matcher(EmitCopyToReg), SrcSlot(srcSlot), DestPhysReg(destPhysReg) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000811
812 unsigned getSrcSlot() const { return SrcSlot; }
813 Record *getDestPhysReg() const { return DestPhysReg; }
814
Chris Lattner9a515172010-02-25 02:04:40 +0000815 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000816 return N->getKind() == EmitCopyToReg;
817 }
818
Chris Lattner136ab782010-02-25 06:49:58 +0000819private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000820 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000821 virtual bool isEqualImpl(const Matcher *M) const {
822 return cast<EmitCopyToRegMatcher>(M)->SrcSlot == SrcSlot &&
823 cast<EmitCopyToRegMatcher>(M)->DestPhysReg == DestPhysReg;
824 }
825 virtual unsigned getHashImpl() const {
826 return SrcSlot ^ ((unsigned)(intptr_t)DestPhysReg << 4);
827 }
Chris Lattner3163ca52010-02-21 03:22:59 +0000828};
829
830
831
Chris Lattner9a515172010-02-25 02:04:40 +0000832/// EmitNodeXFormMatcher - Emit an operation that runs an SDNodeXForm on a
Chris Lattner3163ca52010-02-21 03:22:59 +0000833/// recorded node and records the result.
Chris Lattner9a515172010-02-25 02:04:40 +0000834class EmitNodeXFormMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000835 unsigned Slot;
836 Record *NodeXForm;
837public:
Chris Lattner9a515172010-02-25 02:04:40 +0000838 EmitNodeXFormMatcher(unsigned slot, Record *nodeXForm)
839 : Matcher(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000840
841 unsigned getSlot() const { return Slot; }
842 Record *getNodeXForm() const { return NodeXForm; }
843
Chris Lattner9a515172010-02-25 02:04:40 +0000844 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000845 return N->getKind() == EmitNodeXForm;
846 }
847
Chris Lattner136ab782010-02-25 06:49:58 +0000848private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000849 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000850 virtual bool isEqualImpl(const Matcher *M) const {
851 return cast<EmitNodeXFormMatcher>(M)->Slot == Slot &&
852 cast<EmitNodeXFormMatcher>(M)->NodeXForm == NodeXForm;
853 }
854 virtual unsigned getHashImpl() const {
855 return Slot ^ ((unsigned)(intptr_t)NodeXForm << 4);
856 }
Chris Lattner3163ca52010-02-21 03:22:59 +0000857};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000858
Chris Lattner7a1dab42010-02-28 02:31:26 +0000859/// EmitNodeMatcherCommon - Common class shared between EmitNode and
Chris Lattner7dae4af2010-02-28 20:55:18 +0000860/// MorphNodeTo.
Chris Lattner7a1dab42010-02-28 02:31:26 +0000861class EmitNodeMatcherCommon : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000862 std::string OpcodeName;
863 const SmallVector<MVT::SimpleValueType, 3> VTs;
864 const SmallVector<unsigned, 6> Operands;
Chris Lattner414bac82010-02-28 21:53:42 +0000865 bool HasChain, HasInFlag, HasOutFlag, HasMemRefs;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000866
Chris Lattner3163ca52010-02-21 03:22:59 +0000867 /// NumFixedArityOperands - If this is a fixed arity node, this is set to -1.
868 /// If this is a varidic node, this is set to the number of fixed arity
869 /// operands in the root of the pattern. The rest are appended to this node.
870 int NumFixedArityOperands;
871public:
Chris Lattner7a1dab42010-02-28 02:31:26 +0000872 EmitNodeMatcherCommon(const std::string &opcodeName,
873 const MVT::SimpleValueType *vts, unsigned numvts,
874 const unsigned *operands, unsigned numops,
Chris Lattner414bac82010-02-28 21:53:42 +0000875 bool hasChain, bool hasInFlag, bool hasOutFlag,
876 bool hasmemrefs,
Chris Lattner7dae4af2010-02-28 20:55:18 +0000877 int numfixedarityoperands, bool isMorphNodeTo)
878 : Matcher(isMorphNodeTo ? MorphNodeTo : EmitNode), OpcodeName(opcodeName),
Chris Lattner3163ca52010-02-21 03:22:59 +0000879 VTs(vts, vts+numvts), Operands(operands, operands+numops),
Chris Lattner414bac82010-02-28 21:53:42 +0000880 HasChain(hasChain), HasInFlag(hasInFlag), HasOutFlag(hasOutFlag),
881 HasMemRefs(hasmemrefs), NumFixedArityOperands(numfixedarityoperands) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000882
883 const std::string &getOpcodeName() const { return OpcodeName; }
884
885 unsigned getNumVTs() const { return VTs.size(); }
886 MVT::SimpleValueType getVT(unsigned i) const {
887 assert(i < VTs.size());
888 return VTs[i];
889 }
Chris Lattner5cc7a832010-02-28 20:49:53 +0000890
Chris Lattner3163ca52010-02-21 03:22:59 +0000891 unsigned getNumOperands() const { return Operands.size(); }
892 unsigned getOperand(unsigned i) const {
893 assert(i < Operands.size());
894 return Operands[i];
Chris Lattner5cc7a832010-02-28 20:49:53 +0000895 }
896
897 const SmallVectorImpl<MVT::SimpleValueType> &getVTList() const { return VTs; }
898 const SmallVectorImpl<unsigned> &getOperandList() const { return Operands; }
899
Chris Lattner3163ca52010-02-21 03:22:59 +0000900
901 bool hasChain() const { return HasChain; }
Chris Lattner414bac82010-02-28 21:53:42 +0000902 bool hasInFlag() const { return HasInFlag; }
903 bool hasOutFlag() const { return HasOutFlag; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000904 bool hasMemRefs() const { return HasMemRefs; }
905 int getNumFixedArityOperands() const { return NumFixedArityOperands; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000906
Chris Lattner9a515172010-02-25 02:04:40 +0000907 static inline bool classof(const Matcher *N) {
Chris Lattner7dae4af2010-02-28 20:55:18 +0000908 return N->getKind() == EmitNode || N->getKind() == MorphNodeTo;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000909 }
910
Chris Lattner136ab782010-02-25 06:49:58 +0000911private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000912 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000913 virtual bool isEqualImpl(const Matcher *M) const;
914 virtual unsigned getHashImpl() const;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000915};
Chris Lattnerb085ea12010-02-21 06:03:07 +0000916
Chris Lattner7a1dab42010-02-28 02:31:26 +0000917/// EmitNodeMatcher - This signals a successful match and generates a node.
918class EmitNodeMatcher : public EmitNodeMatcherCommon {
Chris Lattner19a1fbe2010-02-28 02:41:25 +0000919 unsigned FirstResultSlot;
Chris Lattner7a1dab42010-02-28 02:31:26 +0000920public:
921 EmitNodeMatcher(const std::string &opcodeName,
922 const MVT::SimpleValueType *vts, unsigned numvts,
923 const unsigned *operands, unsigned numops,
Chris Lattner414bac82010-02-28 21:53:42 +0000924 bool hasChain, bool hasInFlag, bool hasOutFlag,
925 bool hasmemrefs,
Chris Lattner19a1fbe2010-02-28 02:41:25 +0000926 int numfixedarityoperands, unsigned firstresultslot)
Chris Lattner7a1dab42010-02-28 02:31:26 +0000927 : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
Chris Lattner414bac82010-02-28 21:53:42 +0000928 hasInFlag, hasOutFlag, hasmemrefs,
929 numfixedarityoperands, false),
Chris Lattner19a1fbe2010-02-28 02:41:25 +0000930 FirstResultSlot(firstresultslot) {}
931
932 unsigned getFirstResultSlot() const { return FirstResultSlot; }
Chris Lattner7a1dab42010-02-28 02:31:26 +0000933
934 static inline bool classof(const Matcher *N) {
935 return N->getKind() == EmitNode;
936 }
937
938};
939
Chris Lattner7dae4af2010-02-28 20:55:18 +0000940class MorphNodeToMatcher : public EmitNodeMatcherCommon {
Chris Lattner7a1dab42010-02-28 02:31:26 +0000941 const PatternToMatch &Pattern;
942public:
Chris Lattner7dae4af2010-02-28 20:55:18 +0000943 MorphNodeToMatcher(const std::string &opcodeName,
944 const MVT::SimpleValueType *vts, unsigned numvts,
945 const unsigned *operands, unsigned numops,
Chris Lattner414bac82010-02-28 21:53:42 +0000946 bool hasChain, bool hasInFlag, bool hasOutFlag,
947 bool hasmemrefs,
Chris Lattner7dae4af2010-02-28 20:55:18 +0000948 int numfixedarityoperands, const PatternToMatch &pattern)
Chris Lattner7a1dab42010-02-28 02:31:26 +0000949 : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
Chris Lattner414bac82010-02-28 21:53:42 +0000950 hasInFlag, hasOutFlag, hasmemrefs,
951 numfixedarityoperands, true),
Chris Lattner7a1dab42010-02-28 02:31:26 +0000952 Pattern(pattern) {
953 }
954
955 const PatternToMatch &getPattern() const { return Pattern; }
956
957 static inline bool classof(const Matcher *N) {
Chris Lattner7dae4af2010-02-28 20:55:18 +0000958 return N->getKind() == MorphNodeTo;
Chris Lattner7a1dab42010-02-28 02:31:26 +0000959 }
960};
961
Chris Lattner9a515172010-02-25 02:04:40 +0000962/// MarkFlagResultsMatcher - This node indicates which non-root nodes in the
963/// pattern produce flags. This allows CompleteMatchMatcher to update them
Chris Lattner69f60c82010-02-24 05:33:42 +0000964/// with the output flag of the resultant code.
Chris Lattner9a515172010-02-25 02:04:40 +0000965class MarkFlagResultsMatcher : public Matcher {
Chris Lattner69f60c82010-02-24 05:33:42 +0000966 SmallVector<unsigned, 3> FlagResultNodes;
967public:
Chris Lattner9a515172010-02-25 02:04:40 +0000968 MarkFlagResultsMatcher(const unsigned *nodes, unsigned NumNodes)
969 : Matcher(MarkFlagResults), FlagResultNodes(nodes, nodes+NumNodes) {}
Chris Lattner69f60c82010-02-24 05:33:42 +0000970
971 unsigned getNumNodes() const { return FlagResultNodes.size(); }
972
973 unsigned getNode(unsigned i) const {
974 assert(i < FlagResultNodes.size());
975 return FlagResultNodes[i];
976 }
977
Chris Lattner9a515172010-02-25 02:04:40 +0000978 static inline bool classof(const Matcher *N) {
Chris Lattner69f60c82010-02-24 05:33:42 +0000979 return N->getKind() == MarkFlagResults;
980 }
981
Chris Lattner136ab782010-02-25 06:49:58 +0000982private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000983 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000984 virtual bool isEqualImpl(const Matcher *M) const {
985 return cast<MarkFlagResultsMatcher>(M)->FlagResultNodes == FlagResultNodes;
986 }
987 virtual unsigned getHashImpl() const;
Chris Lattner69f60c82010-02-24 05:33:42 +0000988};
989
Chris Lattner9a515172010-02-25 02:04:40 +0000990/// CompleteMatchMatcher - Complete a match by replacing the results of the
Chris Lattnerb085ea12010-02-21 06:03:07 +0000991/// pattern with the newly generated nodes. This also prints a comment
992/// indicating the source and dest patterns.
Chris Lattner9a515172010-02-25 02:04:40 +0000993class CompleteMatchMatcher : public Matcher {
Chris Lattnerb085ea12010-02-21 06:03:07 +0000994 SmallVector<unsigned, 2> Results;
Chris Lattner3163ca52010-02-21 03:22:59 +0000995 const PatternToMatch &Pattern;
996public:
Chris Lattner9a515172010-02-25 02:04:40 +0000997 CompleteMatchMatcher(const unsigned *results, unsigned numresults,
Chris Lattner5cc7a832010-02-28 20:49:53 +0000998 const PatternToMatch &pattern)
Chris Lattner9a515172010-02-25 02:04:40 +0000999 : Matcher(CompleteMatch), Results(results, results+numresults),
Chris Lattnerb085ea12010-02-21 06:03:07 +00001000 Pattern(pattern) {}
1001
1002 unsigned getNumResults() const { return Results.size(); }
1003 unsigned getResult(unsigned R) const { return Results[R]; }
Chris Lattner3163ca52010-02-21 03:22:59 +00001004 const PatternToMatch &getPattern() const { return Pattern; }
1005
Chris Lattner9a515172010-02-25 02:04:40 +00001006 static inline bool classof(const Matcher *N) {
Chris Lattnerb085ea12010-02-21 06:03:07 +00001007 return N->getKind() == CompleteMatch;
Chris Lattner3163ca52010-02-21 03:22:59 +00001008 }
1009
Chris Lattner136ab782010-02-25 06:49:58 +00001010private:
Chris Lattner392b1bf2010-02-25 06:53:39 +00001011 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +00001012 virtual bool isEqualImpl(const Matcher *M) const {
1013 return cast<CompleteMatchMatcher>(M)->Results == Results &&
1014 &cast<CompleteMatchMatcher>(M)->Pattern == &Pattern;
1015 }
1016 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +00001017};
Chris Lattner7a1dab42010-02-28 02:31:26 +00001018
Chris Lattnere7d6e3c2010-02-15 08:04:42 +00001019} // end namespace llvm
1020
1021#endif