blob: 657c41e5e11c55270fcb0721fbcf96006108136b [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 Lattner5377f912010-03-01 02:24:17 +0000189
190 /// ResultNo - The slot number in the RecordedNodes vector that this will be,
191 /// just printed as a comment.
192 unsigned ResultNo;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000193public:
Chris Lattner5377f912010-03-01 02:24:17 +0000194 RecordMatcher(const std::string &whatfor, unsigned resultNo)
195 : Matcher(RecordNode), WhatFor(whatfor), ResultNo(resultNo) {}
Chris Lattner56cf88d2010-02-17 01:03:09 +0000196
Chris Lattner086ca522010-02-17 01:27:29 +0000197 const std::string &getWhatFor() const { return WhatFor; }
Chris Lattner5377f912010-03-01 02:24:17 +0000198 unsigned getResultNo() const { return ResultNo; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000199
Chris Lattner9a515172010-02-25 02:04:40 +0000200 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000201 return N->getKind() == RecordNode;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000202 }
203
Chris Lattnerf4950d02010-02-27 06:22:57 +0000204 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
Chris Lattner136ab782010-02-25 06:49:58 +0000205private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000206 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000207 virtual bool isEqualImpl(const Matcher *M) const { return true; }
208 virtual unsigned getHashImpl() const { return 0; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000209};
210
Chris Lattner9a515172010-02-25 02:04:40 +0000211/// RecordChildMatcher - Save a numbered child of the current node, or fail
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000212/// the match if it doesn't exist. This is logically equivalent to:
213/// MoveChild N + RecordNode + MoveParent.
Chris Lattner9a515172010-02-25 02:04:40 +0000214class RecordChildMatcher : public Matcher {
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000215 unsigned ChildNo;
216
217 /// WhatFor - This is a string indicating why we're recording this. This
218 /// should only be used for comment generation not anything semantic.
219 std::string WhatFor;
Chris Lattner5377f912010-03-01 02:24:17 +0000220
221 /// ResultNo - The slot number in the RecordedNodes vector that this will be,
222 /// just printed as a comment.
223 unsigned ResultNo;
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000224public:
Chris Lattner5377f912010-03-01 02:24:17 +0000225 RecordChildMatcher(unsigned childno, const std::string &whatfor,
226 unsigned resultNo)
227 : Matcher(RecordChild), ChildNo(childno), WhatFor(whatfor),
228 ResultNo(resultNo) {}
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000229
230 unsigned getChildNo() const { return ChildNo; }
231 const std::string &getWhatFor() const { return WhatFor; }
Chris Lattner5377f912010-03-01 02:24:17 +0000232 unsigned getResultNo() const { return ResultNo; }
233
Chris Lattner9a515172010-02-25 02:04:40 +0000234 static inline bool classof(const Matcher *N) {
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000235 return N->getKind() == RecordChild;
236 }
237
Chris Lattnerf4950d02010-02-27 06:22:57 +0000238 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
239
Chris Lattner136ab782010-02-25 06:49:58 +0000240private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000241 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000242 virtual bool isEqualImpl(const Matcher *M) const {
243 return cast<RecordChildMatcher>(M)->getChildNo() == getChildNo();
244 }
245 virtual unsigned getHashImpl() const { return getChildNo(); }
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000246};
247
Chris Lattner9a515172010-02-25 02:04:40 +0000248/// RecordMemRefMatcher - Save the current node's memref.
249class RecordMemRefMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000250public:
Chris Lattner9a515172010-02-25 02:04:40 +0000251 RecordMemRefMatcher() : Matcher(RecordMemRef) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000252
Chris Lattner9a515172010-02-25 02:04:40 +0000253 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000254 return N->getKind() == RecordMemRef;
255 }
256
Chris Lattnerf4950d02010-02-27 06:22:57 +0000257 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
258
Chris Lattner136ab782010-02-25 06:49:58 +0000259private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000260 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000261 virtual bool isEqualImpl(const Matcher *M) const { return true; }
262 virtual unsigned getHashImpl() const { return 0; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000263};
264
265
Chris Lattner9a515172010-02-25 02:04:40 +0000266/// CaptureFlagInputMatcher - If the current record has a flag input, record
Chris Lattner3163ca52010-02-21 03:22:59 +0000267/// it so that it is used as an input to the generated code.
Chris Lattner9a515172010-02-25 02:04:40 +0000268class CaptureFlagInputMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000269public:
Chris Lattner9a515172010-02-25 02:04:40 +0000270 CaptureFlagInputMatcher() : Matcher(CaptureFlagInput) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000271
Chris Lattner9a515172010-02-25 02:04:40 +0000272 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000273 return N->getKind() == CaptureFlagInput;
274 }
275
Chris Lattnerf4950d02010-02-27 06:22:57 +0000276 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
277
Chris Lattner136ab782010-02-25 06:49:58 +0000278private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000279 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000280 virtual bool isEqualImpl(const Matcher *M) const { return true; }
281 virtual unsigned getHashImpl() const { return 0; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000282};
283
Chris Lattner9a515172010-02-25 02:04:40 +0000284/// MoveChildMatcher - This tells the interpreter to move into the
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000285/// specified child node.
Chris Lattner9a515172010-02-25 02:04:40 +0000286class MoveChildMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000287 unsigned ChildNo;
288public:
Chris Lattner9a515172010-02-25 02:04:40 +0000289 MoveChildMatcher(unsigned childNo) : Matcher(MoveChild), ChildNo(childNo) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000290
291 unsigned getChildNo() const { return ChildNo; }
292
Chris Lattner9a515172010-02-25 02:04:40 +0000293 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000294 return N->getKind() == MoveChild;
295 }
296
Chris Lattnerf4950d02010-02-27 06:22:57 +0000297 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
298
Chris Lattner136ab782010-02-25 06:49:58 +0000299private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000300 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000301 virtual bool isEqualImpl(const Matcher *M) const {
302 return cast<MoveChildMatcher>(M)->getChildNo() == getChildNo();
303 }
304 virtual unsigned getHashImpl() const { return getChildNo(); }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000305};
306
Chris Lattner9a515172010-02-25 02:04:40 +0000307/// MoveParentMatcher - This tells the interpreter to move to the parent
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000308/// of the current node.
Chris Lattner9a515172010-02-25 02:04:40 +0000309class MoveParentMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000310public:
Chris Lattner9a515172010-02-25 02:04:40 +0000311 MoveParentMatcher() : Matcher(MoveParent) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000312
Chris Lattner9a515172010-02-25 02:04:40 +0000313 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000314 return N->getKind() == MoveParent;
315 }
316
Chris Lattnerf4950d02010-02-27 06:22:57 +0000317 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
318
Chris Lattner136ab782010-02-25 06:49:58 +0000319private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000320 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000321 virtual bool isEqualImpl(const Matcher *M) const { return true; }
322 virtual unsigned getHashImpl() const { return 0; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000323};
324
Chris Lattner9a515172010-02-25 02:04:40 +0000325/// CheckSameMatcher - This checks to see if this node is exactly the same
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000326/// node as the specified match that was recorded with 'Record'. This is used
327/// when patterns have the same name in them, like '(mul GPR:$in, GPR:$in)'.
Chris Lattner9a515172010-02-25 02:04:40 +0000328class CheckSameMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000329 unsigned MatchNumber;
330public:
Chris Lattner9a515172010-02-25 02:04:40 +0000331 CheckSameMatcher(unsigned matchnumber)
Chris Lattner136ab782010-02-25 06:49:58 +0000332 : Matcher(CheckSame), MatchNumber(matchnumber) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000333
334 unsigned getMatchNumber() const { return MatchNumber; }
335
Chris Lattner9a515172010-02-25 02:04:40 +0000336 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000337 return N->getKind() == CheckSame;
338 }
339
Chris Lattnerf4950d02010-02-27 06:22:57 +0000340 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
341
Chris Lattner136ab782010-02-25 06:49:58 +0000342private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000343 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000344 virtual bool isEqualImpl(const Matcher *M) const {
345 return cast<CheckSameMatcher>(M)->getMatchNumber() == getMatchNumber();
346 }
347 virtual unsigned getHashImpl() const { return getMatchNumber(); }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000348};
349
Chris Lattner9a515172010-02-25 02:04:40 +0000350/// CheckPatternPredicateMatcher - This checks the target-specific predicate
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000351/// to see if the entire pattern is capable of matching. This predicate does
352/// not take a node as input. This is used for subtarget feature checks etc.
Chris Lattner9a515172010-02-25 02:04:40 +0000353class CheckPatternPredicateMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000354 std::string Predicate;
355public:
Chris Lattner9a515172010-02-25 02:04:40 +0000356 CheckPatternPredicateMatcher(StringRef predicate)
Chris Lattner136ab782010-02-25 06:49:58 +0000357 : Matcher(CheckPatternPredicate), Predicate(predicate) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000358
359 StringRef getPredicate() const { return Predicate; }
360
Chris Lattner9a515172010-02-25 02:04:40 +0000361 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000362 return N->getKind() == CheckPatternPredicate;
363 }
364
Chris Lattnerf4950d02010-02-27 06:22:57 +0000365 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
366
Chris Lattner136ab782010-02-25 06:49:58 +0000367private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000368 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000369 virtual bool isEqualImpl(const Matcher *M) const {
370 return cast<CheckPatternPredicateMatcher>(M)->getPredicate() == Predicate;
371 }
372 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000373};
374
Chris Lattner9a515172010-02-25 02:04:40 +0000375/// CheckPredicateMatcher - This checks the target-specific predicate to
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000376/// see if the node is acceptable.
Chris Lattner9a515172010-02-25 02:04:40 +0000377class CheckPredicateMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000378 StringRef PredName;
379public:
Chris Lattner9a515172010-02-25 02:04:40 +0000380 CheckPredicateMatcher(StringRef predname)
381 : Matcher(CheckPredicate), PredName(predname) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000382
383 StringRef getPredicateName() const { return PredName; }
384
Chris Lattner9a515172010-02-25 02:04:40 +0000385 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000386 return N->getKind() == CheckPredicate;
387 }
388
Chris Lattnerf4950d02010-02-27 06:22:57 +0000389 // TODO: Ok?
390 //virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
391
Chris Lattner136ab782010-02-25 06:49:58 +0000392private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000393 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000394 virtual bool isEqualImpl(const Matcher *M) const {
395 return cast<CheckPredicateMatcher>(M)->PredName == PredName;
396 }
397 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000398};
399
400
Chris Lattner9a515172010-02-25 02:04:40 +0000401/// CheckOpcodeMatcher - This checks to see if the current node has the
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000402/// specified opcode, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000403class CheckOpcodeMatcher : public Matcher {
Chris Lattnere9f720b2010-02-27 21:48:43 +0000404 const SDNodeInfo &Opcode;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000405public:
Chris Lattnere9f720b2010-02-27 21:48:43 +0000406 CheckOpcodeMatcher(const SDNodeInfo &opcode)
407 : Matcher(CheckOpcode), Opcode(opcode) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000408
Chris Lattnere9f720b2010-02-27 21:48:43 +0000409 const SDNodeInfo &getOpcode() const { return Opcode; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000410
Chris Lattner9a515172010-02-25 02:04:40 +0000411 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000412 return N->getKind() == CheckOpcode;
413 }
414
Chris Lattnerf4950d02010-02-27 06:22:57 +0000415 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
416
Chris Lattner136ab782010-02-25 06:49:58 +0000417private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000418 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000419 virtual bool isEqualImpl(const Matcher *M) const {
Chris Lattnere9f720b2010-02-27 21:48:43 +0000420 return &cast<CheckOpcodeMatcher>(M)->Opcode == &Opcode;
Chris Lattner136ab782010-02-25 06:49:58 +0000421 }
422 virtual unsigned getHashImpl() const;
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000423 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000424};
425
Chris Lattner9a515172010-02-25 02:04:40 +0000426/// CheckMultiOpcodeMatcher - This checks to see if the current node has one
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000427/// of the specified opcode, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000428class CheckMultiOpcodeMatcher : public Matcher {
Chris Lattnere9f720b2010-02-27 21:48:43 +0000429 SmallVector<const SDNodeInfo*, 4> Opcodes;
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000430public:
Chris Lattnere9f720b2010-02-27 21:48:43 +0000431 CheckMultiOpcodeMatcher(const SDNodeInfo * const *opcodes, unsigned numops)
432 : Matcher(CheckMultiOpcode), Opcodes(opcodes, opcodes+numops) {}
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000433
Chris Lattnere9f720b2010-02-27 21:48:43 +0000434 unsigned getNumOpcodes() const { return Opcodes.size(); }
435 const SDNodeInfo &getOpcode(unsigned i) const { return *Opcodes[i]; }
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000436
Chris Lattner9a515172010-02-25 02:04:40 +0000437 static inline bool classof(const Matcher *N) {
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000438 return N->getKind() == CheckMultiOpcode;
439 }
440
Chris Lattnerf4950d02010-02-27 06:22:57 +0000441 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
442
Chris Lattner136ab782010-02-25 06:49:58 +0000443private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000444 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000445 virtual bool isEqualImpl(const Matcher *M) const {
Chris Lattnere9f720b2010-02-27 21:48:43 +0000446 return cast<CheckMultiOpcodeMatcher>(M)->Opcodes == Opcodes;
Chris Lattner136ab782010-02-25 06:49:58 +0000447 }
448 virtual unsigned getHashImpl() const;
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000449};
450
451
452
Chris Lattner9a515172010-02-25 02:04:40 +0000453/// CheckTypeMatcher - This checks to see if the current node has the
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000454/// specified type, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000455class CheckTypeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000456 MVT::SimpleValueType Type;
457public:
Chris Lattner9a515172010-02-25 02:04:40 +0000458 CheckTypeMatcher(MVT::SimpleValueType type)
459 : Matcher(CheckType), Type(type) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000460
461 MVT::SimpleValueType getType() const { return Type; }
462
Chris Lattner9a515172010-02-25 02:04:40 +0000463 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000464 return N->getKind() == CheckType;
465 }
466
Chris Lattnerf4950d02010-02-27 06:22:57 +0000467 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
468
Chris Lattner136ab782010-02-25 06:49:58 +0000469private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000470 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000471 virtual bool isEqualImpl(const Matcher *M) const {
Chris Lattner2d0e0792010-02-26 08:05:36 +0000472 return cast<CheckTypeMatcher>(M)->Type == Type;
Chris Lattner136ab782010-02-25 06:49:58 +0000473 }
474 virtual unsigned getHashImpl() const { return Type; }
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000475 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000476};
Chris Lattner3c664b32010-02-24 20:15:25 +0000477
Chris Lattner9a515172010-02-25 02:04:40 +0000478/// CheckChildTypeMatcher - This checks to see if a child node has the
Chris Lattner3c664b32010-02-24 20:15:25 +0000479/// specified type, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000480class CheckChildTypeMatcher : public Matcher {
Chris Lattner3c664b32010-02-24 20:15:25 +0000481 unsigned ChildNo;
482 MVT::SimpleValueType Type;
483public:
Chris Lattner9a515172010-02-25 02:04:40 +0000484 CheckChildTypeMatcher(unsigned childno, MVT::SimpleValueType type)
485 : Matcher(CheckChildType), ChildNo(childno), Type(type) {}
Chris Lattner3c664b32010-02-24 20:15:25 +0000486
487 unsigned getChildNo() const { return ChildNo; }
488 MVT::SimpleValueType getType() const { return Type; }
489
Chris Lattner9a515172010-02-25 02:04:40 +0000490 static inline bool classof(const Matcher *N) {
Chris Lattner3c664b32010-02-24 20:15:25 +0000491 return N->getKind() == CheckChildType;
492 }
493
Chris Lattnerf4950d02010-02-27 06:22:57 +0000494 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
495
Chris Lattner136ab782010-02-25 06:49:58 +0000496private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000497 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000498 virtual bool isEqualImpl(const Matcher *M) const {
499 return cast<CheckChildTypeMatcher>(M)->ChildNo == ChildNo &&
500 cast<CheckChildTypeMatcher>(M)->Type == Type;
501 }
502 virtual unsigned getHashImpl() const { return (Type << 3) | ChildNo; }
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000503 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattner3c664b32010-02-24 20:15:25 +0000504};
505
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000506
Chris Lattner9a515172010-02-25 02:04:40 +0000507/// CheckIntegerMatcher - This checks to see if the current node is a
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000508/// ConstantSDNode with the specified integer value, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000509class CheckIntegerMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000510 int64_t Value;
511public:
Chris Lattner9a515172010-02-25 02:04:40 +0000512 CheckIntegerMatcher(int64_t value)
513 : Matcher(CheckInteger), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000514
515 int64_t getValue() const { return Value; }
516
Chris Lattner9a515172010-02-25 02:04:40 +0000517 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000518 return N->getKind() == CheckInteger;
519 }
520
Chris Lattnerf4950d02010-02-27 06:22:57 +0000521 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
522
Chris Lattner136ab782010-02-25 06:49:58 +0000523private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000524 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000525 virtual bool isEqualImpl(const Matcher *M) const {
526 return cast<CheckIntegerMatcher>(M)->Value == Value;
527 }
528 virtual unsigned getHashImpl() const { return Value; }
Chris Lattner086af322010-02-27 08:11:15 +0000529 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000530};
531
Chris Lattner9a515172010-02-25 02:04:40 +0000532/// CheckCondCodeMatcher - This checks to see if the current node is a
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000533/// CondCodeSDNode with the specified condition, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000534class CheckCondCodeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000535 StringRef CondCodeName;
536public:
Chris Lattner9a515172010-02-25 02:04:40 +0000537 CheckCondCodeMatcher(StringRef condcodename)
538 : Matcher(CheckCondCode), CondCodeName(condcodename) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000539
540 StringRef getCondCodeName() const { return CondCodeName; }
541
Chris Lattner9a515172010-02-25 02:04:40 +0000542 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000543 return N->getKind() == CheckCondCode;
544 }
545
Chris Lattnerf4950d02010-02-27 06:22:57 +0000546 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
547
Chris Lattner136ab782010-02-25 06:49:58 +0000548private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000549 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000550 virtual bool isEqualImpl(const Matcher *M) const {
551 return cast<CheckCondCodeMatcher>(M)->CondCodeName == CondCodeName;
552 }
553 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000554};
555
Chris Lattner9a515172010-02-25 02:04:40 +0000556/// CheckValueTypeMatcher - This checks to see if the current node is a
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000557/// VTSDNode with the specified type, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000558class CheckValueTypeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000559 StringRef TypeName;
560public:
Chris Lattner9a515172010-02-25 02:04:40 +0000561 CheckValueTypeMatcher(StringRef type_name)
562 : Matcher(CheckValueType), TypeName(type_name) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000563
564 StringRef getTypeName() const { return TypeName; }
565
Chris Lattner9a515172010-02-25 02:04:40 +0000566 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000567 return N->getKind() == CheckValueType;
568 }
569
Chris Lattnerf4950d02010-02-27 06:22:57 +0000570 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
571
Chris Lattner136ab782010-02-25 06:49:58 +0000572private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000573 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000574 virtual bool isEqualImpl(const Matcher *M) const {
575 return cast<CheckValueTypeMatcher>(M)->TypeName == TypeName;
576 }
577 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000578};
579
580
581
Chris Lattner9a515172010-02-25 02:04:40 +0000582/// CheckComplexPatMatcher - This node runs the specified ComplexPattern on
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000583/// the current node.
Chris Lattner9a515172010-02-25 02:04:40 +0000584class CheckComplexPatMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000585 const ComplexPattern &Pattern;
586public:
Chris Lattner9a515172010-02-25 02:04:40 +0000587 CheckComplexPatMatcher(const ComplexPattern &pattern)
588 : Matcher(CheckComplexPat), Pattern(pattern) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000589
Chris Lattnerdc429fd2010-02-17 00:31:50 +0000590 const ComplexPattern &getPattern() const { return Pattern; }
591
Chris Lattner9a515172010-02-25 02:04:40 +0000592 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000593 return N->getKind() == CheckComplexPat;
594 }
595
Chris Lattnerf4950d02010-02-27 06:22:57 +0000596 // Not safe to move a pattern predicate past a complex pattern.
597 virtual bool isSafeToReorderWithPatternPredicate() const { return false; }
598
Chris Lattner136ab782010-02-25 06:49:58 +0000599private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000600 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000601 virtual bool isEqualImpl(const Matcher *M) const {
602 return &cast<CheckComplexPatMatcher>(M)->Pattern == &Pattern;
603 }
604 virtual unsigned getHashImpl() const {
605 return (unsigned)(intptr_t)&Pattern;
606 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000607};
608
Chris Lattner9a515172010-02-25 02:04:40 +0000609/// CheckAndImmMatcher - This checks to see if the current node is an 'and'
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000610/// with something equivalent to the specified immediate.
Chris Lattner9a515172010-02-25 02:04:40 +0000611class CheckAndImmMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000612 int64_t Value;
613public:
Chris Lattner9a515172010-02-25 02:04:40 +0000614 CheckAndImmMatcher(int64_t value)
615 : Matcher(CheckAndImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000616
617 int64_t getValue() const { return Value; }
618
Chris Lattner9a515172010-02-25 02:04:40 +0000619 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000620 return N->getKind() == CheckAndImm;
621 }
622
Chris Lattnerf4950d02010-02-27 06:22:57 +0000623 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
624
Chris Lattner136ab782010-02-25 06:49:58 +0000625private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000626 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000627 virtual bool isEqualImpl(const Matcher *M) const {
628 return cast<CheckAndImmMatcher>(M)->Value == Value;
629 }
630 virtual unsigned getHashImpl() const { return Value; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000631};
632
Chris Lattner9a515172010-02-25 02:04:40 +0000633/// CheckOrImmMatcher - This checks to see if the current node is an 'and'
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000634/// with something equivalent to the specified immediate.
Chris Lattner9a515172010-02-25 02:04:40 +0000635class CheckOrImmMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000636 int64_t Value;
637public:
Chris Lattner9a515172010-02-25 02:04:40 +0000638 CheckOrImmMatcher(int64_t value)
639 : Matcher(CheckOrImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000640
641 int64_t getValue() const { return Value; }
642
Chris Lattner9a515172010-02-25 02:04:40 +0000643 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000644 return N->getKind() == CheckOrImm;
645 }
646
Chris Lattnerf4950d02010-02-27 06:22:57 +0000647 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
648
Chris Lattner136ab782010-02-25 06:49:58 +0000649private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000650 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000651 virtual bool isEqualImpl(const Matcher *M) const {
652 return cast<CheckOrImmMatcher>(M)->Value == Value;
653 }
654 virtual unsigned getHashImpl() const { return Value; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000655};
Chris Lattner9de39482010-02-16 06:10:58 +0000656
Chris Lattner9a515172010-02-25 02:04:40 +0000657/// CheckFoldableChainNodeMatcher - This checks to see if the current node
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000658/// (which defines a chain operand) is safe to fold into a larger pattern.
Chris Lattner9a515172010-02-25 02:04:40 +0000659class CheckFoldableChainNodeMatcher : public Matcher {
Chris Lattner9de39482010-02-16 06:10:58 +0000660public:
Chris Lattner9a515172010-02-25 02:04:40 +0000661 CheckFoldableChainNodeMatcher()
662 : Matcher(CheckFoldableChainNode) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000663
Chris Lattner9a515172010-02-25 02:04:40 +0000664 static inline bool classof(const Matcher *N) {
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000665 return N->getKind() == CheckFoldableChainNode;
Chris Lattner9de39482010-02-16 06:10:58 +0000666 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000667
Chris Lattnerf4950d02010-02-27 06:22:57 +0000668 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
669
Chris Lattner136ab782010-02-25 06:49:58 +0000670private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000671 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000672 virtual bool isEqualImpl(const Matcher *M) const { return true; }
673 virtual unsigned getHashImpl() const { return 0; }
Chris Lattner9de39482010-02-16 06:10:58 +0000674};
675
Chris Lattner9a515172010-02-25 02:04:40 +0000676/// CheckChainCompatibleMatcher - Verify that the current node's chain
Chris Lattner283adcb2010-02-17 06:23:39 +0000677/// operand is 'compatible' with the specified recorded node's.
Chris Lattner9a515172010-02-25 02:04:40 +0000678class CheckChainCompatibleMatcher : public Matcher {
Chris Lattner283adcb2010-02-17 06:23:39 +0000679 unsigned PreviousOp;
680public:
Chris Lattner9a515172010-02-25 02:04:40 +0000681 CheckChainCompatibleMatcher(unsigned previousop)
682 : Matcher(CheckChainCompatible), PreviousOp(previousop) {}
Chris Lattner283adcb2010-02-17 06:23:39 +0000683
684 unsigned getPreviousOp() const { return PreviousOp; }
685
Chris Lattner9a515172010-02-25 02:04:40 +0000686 static inline bool classof(const Matcher *N) {
Chris Lattner283adcb2010-02-17 06:23:39 +0000687 return N->getKind() == CheckChainCompatible;
688 }
689
Chris Lattnerf4950d02010-02-27 06:22:57 +0000690 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
691
Chris Lattner136ab782010-02-25 06:49:58 +0000692private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000693 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000694 virtual bool isEqualImpl(const Matcher *M) const {
Chris Lattner50c0b362010-02-26 08:06:02 +0000695 return cast<CheckChainCompatibleMatcher>(M)->PreviousOp == PreviousOp;
Chris Lattner136ab782010-02-25 06:49:58 +0000696 }
697 virtual unsigned getHashImpl() const { return PreviousOp; }
Chris Lattner283adcb2010-02-17 06:23:39 +0000698};
699
Chris Lattner9a515172010-02-25 02:04:40 +0000700/// EmitIntegerMatcher - This creates a new TargetConstant.
701class EmitIntegerMatcher : public Matcher {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000702 int64_t Val;
703 MVT::SimpleValueType VT;
704public:
Chris Lattner9a515172010-02-25 02:04:40 +0000705 EmitIntegerMatcher(int64_t val, MVT::SimpleValueType vt)
706 : Matcher(EmitInteger), Val(val), VT(vt) {}
Chris Lattner283adcb2010-02-17 06:23:39 +0000707
Chris Lattner7043e0a2010-02-19 07:49:56 +0000708 int64_t getValue() const { return Val; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000709 MVT::SimpleValueType getVT() const { return VT; }
710
Chris Lattner9a515172010-02-25 02:04:40 +0000711 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000712 return N->getKind() == EmitInteger;
713 }
714
Chris Lattner136ab782010-02-25 06:49:58 +0000715private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000716 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000717 virtual bool isEqualImpl(const Matcher *M) const {
718 return cast<EmitIntegerMatcher>(M)->Val == Val &&
719 cast<EmitIntegerMatcher>(M)->VT == VT;
720 }
721 virtual unsigned getHashImpl() const { return (Val << 4) | VT; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000722};
Chris Lattner3163ca52010-02-21 03:22:59 +0000723
Chris Lattner9a515172010-02-25 02:04:40 +0000724/// EmitStringIntegerMatcher - A target constant whose value is represented
Chris Lattner3163ca52010-02-21 03:22:59 +0000725/// by a string.
Chris Lattner9a515172010-02-25 02:04:40 +0000726class EmitStringIntegerMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000727 std::string Val;
728 MVT::SimpleValueType VT;
729public:
Chris Lattner9a515172010-02-25 02:04:40 +0000730 EmitStringIntegerMatcher(const std::string &val, MVT::SimpleValueType vt)
731 : Matcher(EmitStringInteger), Val(val), VT(vt) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000732
733 const std::string &getValue() const { return Val; }
734 MVT::SimpleValueType getVT() const { return VT; }
735
Chris Lattner9a515172010-02-25 02:04:40 +0000736 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000737 return N->getKind() == EmitStringInteger;
738 }
739
Chris Lattner136ab782010-02-25 06:49:58 +0000740private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000741 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000742 virtual bool isEqualImpl(const Matcher *M) const {
743 return cast<EmitStringIntegerMatcher>(M)->Val == Val &&
744 cast<EmitStringIntegerMatcher>(M)->VT == VT;
745 }
746 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +0000747};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000748
Chris Lattner9a515172010-02-25 02:04:40 +0000749/// EmitRegisterMatcher - This creates a new TargetConstant.
750class EmitRegisterMatcher : public Matcher {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000751 /// Reg - The def for the register that we're emitting. If this is null, then
752 /// this is a reference to zero_reg.
753 Record *Reg;
754 MVT::SimpleValueType VT;
755public:
Chris Lattner9a515172010-02-25 02:04:40 +0000756 EmitRegisterMatcher(Record *reg, MVT::SimpleValueType vt)
757 : Matcher(EmitRegister), Reg(reg), VT(vt) {}
Chris Lattnerddfb5222010-02-18 22:03:03 +0000758
759 Record *getReg() const { return Reg; }
760 MVT::SimpleValueType getVT() const { return VT; }
761
Chris Lattner9a515172010-02-25 02:04:40 +0000762 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000763 return N->getKind() == EmitRegister;
764 }
765
Chris Lattner136ab782010-02-25 06:49:58 +0000766private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000767 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000768 virtual bool isEqualImpl(const Matcher *M) const {
769 return cast<EmitRegisterMatcher>(M)->Reg == Reg &&
770 cast<EmitRegisterMatcher>(M)->VT == VT;
771 }
772 virtual unsigned getHashImpl() const {
773 return ((unsigned)(intptr_t)Reg) << 4 | VT;
774 }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000775};
Chris Lattner3163ca52010-02-21 03:22:59 +0000776
Chris Lattner9a515172010-02-25 02:04:40 +0000777/// EmitConvertToTargetMatcher - Emit an operation that reads a specified
Chris Lattner3163ca52010-02-21 03:22:59 +0000778/// recorded node and converts it from being a ISD::Constant to
779/// ISD::TargetConstant, likewise for ConstantFP.
Chris Lattner9a515172010-02-25 02:04:40 +0000780class EmitConvertToTargetMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000781 unsigned Slot;
782public:
Chris Lattner9a515172010-02-25 02:04:40 +0000783 EmitConvertToTargetMatcher(unsigned slot)
784 : Matcher(EmitConvertToTarget), Slot(slot) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000785
786 unsigned getSlot() const { return Slot; }
787
Chris Lattner9a515172010-02-25 02:04:40 +0000788 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000789 return N->getKind() == EmitConvertToTarget;
790 }
791
Chris Lattner136ab782010-02-25 06:49:58 +0000792private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000793 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000794 virtual bool isEqualImpl(const Matcher *M) const {
795 return cast<EmitConvertToTargetMatcher>(M)->Slot == Slot;
796 }
797 virtual unsigned getHashImpl() const { return Slot; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000798};
799
Chris Lattner9a515172010-02-25 02:04:40 +0000800/// EmitMergeInputChainsMatcher - Emit a node that merges a list of input
Chris Lattner3163ca52010-02-21 03:22:59 +0000801/// chains together with a token factor. The list of nodes are the nodes in the
802/// matched pattern that have chain input/outputs. This node adds all input
803/// chains of these nodes if they are not themselves a node in the pattern.
Chris Lattner9a515172010-02-25 02:04:40 +0000804class EmitMergeInputChainsMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000805 SmallVector<unsigned, 3> ChainNodes;
806public:
Chris Lattner9a515172010-02-25 02:04:40 +0000807 EmitMergeInputChainsMatcher(const unsigned *nodes, unsigned NumNodes)
808 : Matcher(EmitMergeInputChains), ChainNodes(nodes, nodes+NumNodes) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000809
810 unsigned getNumNodes() const { return ChainNodes.size(); }
811
812 unsigned getNode(unsigned i) const {
813 assert(i < ChainNodes.size());
814 return ChainNodes[i];
815 }
816
Chris Lattner9a515172010-02-25 02:04:40 +0000817 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000818 return N->getKind() == EmitMergeInputChains;
819 }
820
Chris Lattner136ab782010-02-25 06:49:58 +0000821private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000822 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000823 virtual bool isEqualImpl(const Matcher *M) const {
824 return cast<EmitMergeInputChainsMatcher>(M)->ChainNodes == ChainNodes;
825 }
826 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +0000827};
828
Chris Lattner9a515172010-02-25 02:04:40 +0000829/// EmitCopyToRegMatcher - Emit a CopyToReg node from a value to a physreg,
Chris Lattner3163ca52010-02-21 03:22:59 +0000830/// pushing the chain and flag results.
831///
Chris Lattner9a515172010-02-25 02:04:40 +0000832class EmitCopyToRegMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000833 unsigned SrcSlot; // Value to copy into the physreg.
834 Record *DestPhysReg;
835public:
Chris Lattner9a515172010-02-25 02:04:40 +0000836 EmitCopyToRegMatcher(unsigned srcSlot, Record *destPhysReg)
837 : Matcher(EmitCopyToReg), SrcSlot(srcSlot), DestPhysReg(destPhysReg) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000838
839 unsigned getSrcSlot() const { return SrcSlot; }
840 Record *getDestPhysReg() const { return DestPhysReg; }
841
Chris Lattner9a515172010-02-25 02:04:40 +0000842 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000843 return N->getKind() == EmitCopyToReg;
844 }
845
Chris Lattner136ab782010-02-25 06:49:58 +0000846private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000847 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000848 virtual bool isEqualImpl(const Matcher *M) const {
849 return cast<EmitCopyToRegMatcher>(M)->SrcSlot == SrcSlot &&
850 cast<EmitCopyToRegMatcher>(M)->DestPhysReg == DestPhysReg;
851 }
852 virtual unsigned getHashImpl() const {
853 return SrcSlot ^ ((unsigned)(intptr_t)DestPhysReg << 4);
854 }
Chris Lattner3163ca52010-02-21 03:22:59 +0000855};
856
857
858
Chris Lattner9a515172010-02-25 02:04:40 +0000859/// EmitNodeXFormMatcher - Emit an operation that runs an SDNodeXForm on a
Chris Lattner3163ca52010-02-21 03:22:59 +0000860/// recorded node and records the result.
Chris Lattner9a515172010-02-25 02:04:40 +0000861class EmitNodeXFormMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000862 unsigned Slot;
863 Record *NodeXForm;
864public:
Chris Lattner9a515172010-02-25 02:04:40 +0000865 EmitNodeXFormMatcher(unsigned slot, Record *nodeXForm)
866 : Matcher(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000867
868 unsigned getSlot() const { return Slot; }
869 Record *getNodeXForm() const { return NodeXForm; }
870
Chris Lattner9a515172010-02-25 02:04:40 +0000871 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000872 return N->getKind() == EmitNodeXForm;
873 }
874
Chris Lattner136ab782010-02-25 06:49:58 +0000875private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000876 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000877 virtual bool isEqualImpl(const Matcher *M) const {
878 return cast<EmitNodeXFormMatcher>(M)->Slot == Slot &&
879 cast<EmitNodeXFormMatcher>(M)->NodeXForm == NodeXForm;
880 }
881 virtual unsigned getHashImpl() const {
882 return Slot ^ ((unsigned)(intptr_t)NodeXForm << 4);
883 }
Chris Lattner3163ca52010-02-21 03:22:59 +0000884};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000885
Chris Lattner7a1dab42010-02-28 02:31:26 +0000886/// EmitNodeMatcherCommon - Common class shared between EmitNode and
Chris Lattner7dae4af2010-02-28 20:55:18 +0000887/// MorphNodeTo.
Chris Lattner7a1dab42010-02-28 02:31:26 +0000888class EmitNodeMatcherCommon : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000889 std::string OpcodeName;
890 const SmallVector<MVT::SimpleValueType, 3> VTs;
891 const SmallVector<unsigned, 6> Operands;
Chris Lattner414bac82010-02-28 21:53:42 +0000892 bool HasChain, HasInFlag, HasOutFlag, HasMemRefs;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000893
Chris Lattner3163ca52010-02-21 03:22:59 +0000894 /// NumFixedArityOperands - If this is a fixed arity node, this is set to -1.
895 /// If this is a varidic node, this is set to the number of fixed arity
896 /// operands in the root of the pattern. The rest are appended to this node.
897 int NumFixedArityOperands;
898public:
Chris Lattner7a1dab42010-02-28 02:31:26 +0000899 EmitNodeMatcherCommon(const std::string &opcodeName,
900 const MVT::SimpleValueType *vts, unsigned numvts,
901 const unsigned *operands, unsigned numops,
Chris Lattner414bac82010-02-28 21:53:42 +0000902 bool hasChain, bool hasInFlag, bool hasOutFlag,
903 bool hasmemrefs,
Chris Lattner7dae4af2010-02-28 20:55:18 +0000904 int numfixedarityoperands, bool isMorphNodeTo)
905 : Matcher(isMorphNodeTo ? MorphNodeTo : EmitNode), OpcodeName(opcodeName),
Chris Lattner3163ca52010-02-21 03:22:59 +0000906 VTs(vts, vts+numvts), Operands(operands, operands+numops),
Chris Lattner414bac82010-02-28 21:53:42 +0000907 HasChain(hasChain), HasInFlag(hasInFlag), HasOutFlag(hasOutFlag),
908 HasMemRefs(hasmemrefs), NumFixedArityOperands(numfixedarityoperands) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000909
910 const std::string &getOpcodeName() const { return OpcodeName; }
911
912 unsigned getNumVTs() const { return VTs.size(); }
913 MVT::SimpleValueType getVT(unsigned i) const {
914 assert(i < VTs.size());
915 return VTs[i];
916 }
Chris Lattner5cc7a832010-02-28 20:49:53 +0000917
Chris Lattner3163ca52010-02-21 03:22:59 +0000918 unsigned getNumOperands() const { return Operands.size(); }
919 unsigned getOperand(unsigned i) const {
920 assert(i < Operands.size());
921 return Operands[i];
Chris Lattner5cc7a832010-02-28 20:49:53 +0000922 }
923
924 const SmallVectorImpl<MVT::SimpleValueType> &getVTList() const { return VTs; }
925 const SmallVectorImpl<unsigned> &getOperandList() const { return Operands; }
926
Chris Lattner3163ca52010-02-21 03:22:59 +0000927
928 bool hasChain() const { return HasChain; }
Chris Lattner414bac82010-02-28 21:53:42 +0000929 bool hasInFlag() const { return HasInFlag; }
930 bool hasOutFlag() const { return HasOutFlag; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000931 bool hasMemRefs() const { return HasMemRefs; }
932 int getNumFixedArityOperands() const { return NumFixedArityOperands; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000933
Chris Lattner9a515172010-02-25 02:04:40 +0000934 static inline bool classof(const Matcher *N) {
Chris Lattner7dae4af2010-02-28 20:55:18 +0000935 return N->getKind() == EmitNode || N->getKind() == MorphNodeTo;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000936 }
937
Chris Lattner136ab782010-02-25 06:49:58 +0000938private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000939 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000940 virtual bool isEqualImpl(const Matcher *M) const;
941 virtual unsigned getHashImpl() const;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000942};
Chris Lattnerb085ea12010-02-21 06:03:07 +0000943
Chris Lattner7a1dab42010-02-28 02:31:26 +0000944/// EmitNodeMatcher - This signals a successful match and generates a node.
945class EmitNodeMatcher : public EmitNodeMatcherCommon {
Chris Lattner19a1fbe2010-02-28 02:41:25 +0000946 unsigned FirstResultSlot;
Chris Lattner7a1dab42010-02-28 02:31:26 +0000947public:
948 EmitNodeMatcher(const std::string &opcodeName,
949 const MVT::SimpleValueType *vts, unsigned numvts,
950 const unsigned *operands, unsigned numops,
Chris Lattner414bac82010-02-28 21:53:42 +0000951 bool hasChain, bool hasInFlag, bool hasOutFlag,
952 bool hasmemrefs,
Chris Lattner19a1fbe2010-02-28 02:41:25 +0000953 int numfixedarityoperands, unsigned firstresultslot)
Chris Lattner7a1dab42010-02-28 02:31:26 +0000954 : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
Chris Lattner414bac82010-02-28 21:53:42 +0000955 hasInFlag, hasOutFlag, hasmemrefs,
956 numfixedarityoperands, false),
Chris Lattner19a1fbe2010-02-28 02:41:25 +0000957 FirstResultSlot(firstresultslot) {}
958
959 unsigned getFirstResultSlot() const { return FirstResultSlot; }
Chris Lattner7a1dab42010-02-28 02:31:26 +0000960
961 static inline bool classof(const Matcher *N) {
962 return N->getKind() == EmitNode;
963 }
964
965};
966
Chris Lattner7dae4af2010-02-28 20:55:18 +0000967class MorphNodeToMatcher : public EmitNodeMatcherCommon {
Chris Lattner7a1dab42010-02-28 02:31:26 +0000968 const PatternToMatch &Pattern;
969public:
Chris Lattner7dae4af2010-02-28 20:55:18 +0000970 MorphNodeToMatcher(const std::string &opcodeName,
971 const MVT::SimpleValueType *vts, unsigned numvts,
972 const unsigned *operands, unsigned numops,
Chris Lattner414bac82010-02-28 21:53:42 +0000973 bool hasChain, bool hasInFlag, bool hasOutFlag,
974 bool hasmemrefs,
Chris Lattner7dae4af2010-02-28 20:55:18 +0000975 int numfixedarityoperands, const PatternToMatch &pattern)
Chris Lattner7a1dab42010-02-28 02:31:26 +0000976 : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
Chris Lattner414bac82010-02-28 21:53:42 +0000977 hasInFlag, hasOutFlag, hasmemrefs,
978 numfixedarityoperands, true),
Chris Lattner7a1dab42010-02-28 02:31:26 +0000979 Pattern(pattern) {
980 }
981
982 const PatternToMatch &getPattern() const { return Pattern; }
983
984 static inline bool classof(const Matcher *N) {
Chris Lattner7dae4af2010-02-28 20:55:18 +0000985 return N->getKind() == MorphNodeTo;
Chris Lattner7a1dab42010-02-28 02:31:26 +0000986 }
987};
988
Chris Lattner9a515172010-02-25 02:04:40 +0000989/// MarkFlagResultsMatcher - This node indicates which non-root nodes in the
990/// pattern produce flags. This allows CompleteMatchMatcher to update them
Chris Lattner69f60c82010-02-24 05:33:42 +0000991/// with the output flag of the resultant code.
Chris Lattner9a515172010-02-25 02:04:40 +0000992class MarkFlagResultsMatcher : public Matcher {
Chris Lattner69f60c82010-02-24 05:33:42 +0000993 SmallVector<unsigned, 3> FlagResultNodes;
994public:
Chris Lattner9a515172010-02-25 02:04:40 +0000995 MarkFlagResultsMatcher(const unsigned *nodes, unsigned NumNodes)
996 : Matcher(MarkFlagResults), FlagResultNodes(nodes, nodes+NumNodes) {}
Chris Lattner69f60c82010-02-24 05:33:42 +0000997
998 unsigned getNumNodes() const { return FlagResultNodes.size(); }
999
1000 unsigned getNode(unsigned i) const {
1001 assert(i < FlagResultNodes.size());
1002 return FlagResultNodes[i];
1003 }
1004
Chris Lattner9a515172010-02-25 02:04:40 +00001005 static inline bool classof(const Matcher *N) {
Chris Lattner69f60c82010-02-24 05:33:42 +00001006 return N->getKind() == MarkFlagResults;
1007 }
1008
Chris Lattner136ab782010-02-25 06:49:58 +00001009private:
Chris Lattner392b1bf2010-02-25 06:53:39 +00001010 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +00001011 virtual bool isEqualImpl(const Matcher *M) const {
1012 return cast<MarkFlagResultsMatcher>(M)->FlagResultNodes == FlagResultNodes;
1013 }
1014 virtual unsigned getHashImpl() const;
Chris Lattner69f60c82010-02-24 05:33:42 +00001015};
1016
Chris Lattner9a515172010-02-25 02:04:40 +00001017/// CompleteMatchMatcher - Complete a match by replacing the results of the
Chris Lattnerb085ea12010-02-21 06:03:07 +00001018/// pattern with the newly generated nodes. This also prints a comment
1019/// indicating the source and dest patterns.
Chris Lattner9a515172010-02-25 02:04:40 +00001020class CompleteMatchMatcher : public Matcher {
Chris Lattnerb085ea12010-02-21 06:03:07 +00001021 SmallVector<unsigned, 2> Results;
Chris Lattner3163ca52010-02-21 03:22:59 +00001022 const PatternToMatch &Pattern;
1023public:
Chris Lattner9a515172010-02-25 02:04:40 +00001024 CompleteMatchMatcher(const unsigned *results, unsigned numresults,
Chris Lattner5cc7a832010-02-28 20:49:53 +00001025 const PatternToMatch &pattern)
Chris Lattner9a515172010-02-25 02:04:40 +00001026 : Matcher(CompleteMatch), Results(results, results+numresults),
Chris Lattnerb085ea12010-02-21 06:03:07 +00001027 Pattern(pattern) {}
1028
1029 unsigned getNumResults() const { return Results.size(); }
1030 unsigned getResult(unsigned R) const { return Results[R]; }
Chris Lattner3163ca52010-02-21 03:22:59 +00001031 const PatternToMatch &getPattern() const { return Pattern; }
1032
Chris Lattner9a515172010-02-25 02:04:40 +00001033 static inline bool classof(const Matcher *N) {
Chris Lattnerb085ea12010-02-21 06:03:07 +00001034 return N->getKind() == CompleteMatch;
Chris Lattner3163ca52010-02-21 03:22:59 +00001035 }
1036
Chris Lattner136ab782010-02-25 06:49:58 +00001037private:
Chris Lattner392b1bf2010-02-25 06:53:39 +00001038 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +00001039 virtual bool isEqualImpl(const Matcher *M) const {
1040 return cast<CompleteMatchMatcher>(M)->Results == Results &&
1041 &cast<CompleteMatchMatcher>(M)->Pattern == &Pattern;
1042 }
1043 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +00001044};
Chris Lattner7a1dab42010-02-28 02:31:26 +00001045
Chris Lattnere7d6e3c2010-02-15 08:04:42 +00001046} // end namespace llvm
1047
1048#endif