blob: 7955c7e2630d2661ab85547bc60db9b47a06d3d7 [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 Lattnerc4188ac2010-03-03 06:28:15 +000059 SwitchType, // Dispatch based on type.
Chris Lattner3c664b32010-02-24 20:15:25 +000060 CheckChildType, // Fail if child has wrong type.
Chris Lattner3163ca52010-02-21 03:22:59 +000061 CheckInteger, // Fail if wrong val.
62 CheckCondCode, // Fail if not condcode.
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000063 CheckValueType,
64 CheckComplexPat,
65 CheckAndImm,
Chris Lattner9de39482010-02-16 06:10:58 +000066 CheckOrImm,
Chris Lattner283adcb2010-02-17 06:23:39 +000067 CheckFoldableChainNode,
Chris Lattnerddfb5222010-02-18 22:03:03 +000068
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 Lattner2e9e6842010-03-01 06:59:22 +0000419 virtual bool isEqualImpl(const Matcher *M) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000420 virtual unsigned getHashImpl() const;
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000421 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000422};
Chris Lattner2e9e6842010-03-01 06:59:22 +0000423
424/// SwitchOpcodeMatcher - Switch based on the current node's opcode, dispatching
425/// to one matcher per opcode. If the opcode doesn't match any of the cases,
426/// then the match fails. This is semantically equivalent to a Scope node where
427/// every child does a CheckOpcode, but is much faster.
428class SwitchOpcodeMatcher : public Matcher {
429 SmallVector<std::pair<const SDNodeInfo*, Matcher*>, 8> Cases;
430public:
431 SwitchOpcodeMatcher(const std::pair<const SDNodeInfo*, Matcher*> *cases,
432 unsigned numcases)
433 : Matcher(SwitchOpcode), Cases(cases, cases+numcases) {}
434
435 static inline bool classof(const Matcher *N) {
436 return N->getKind() == SwitchOpcode;
437 }
438
439 unsigned getNumCases() const { return Cases.size(); }
440
441 const SDNodeInfo &getCaseOpcode(unsigned i) const { return *Cases[i].first; }
442 Matcher *getCaseMatcher(unsigned i) { return Cases[i].second; }
443 const Matcher *getCaseMatcher(unsigned i) const { return Cases[i].second; }
444
445private:
446 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
447 virtual bool isEqualImpl(const Matcher *M) const { return false; }
448 virtual unsigned getHashImpl() const { return 4123; }
449};
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000450
Chris Lattner9a515172010-02-25 02:04:40 +0000451/// CheckTypeMatcher - This checks to see if the current node has the
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000452/// specified type, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000453class CheckTypeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000454 MVT::SimpleValueType Type;
455public:
Chris Lattner9a515172010-02-25 02:04:40 +0000456 CheckTypeMatcher(MVT::SimpleValueType type)
457 : Matcher(CheckType), Type(type) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000458
459 MVT::SimpleValueType getType() const { return Type; }
460
Chris Lattner9a515172010-02-25 02:04:40 +0000461 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000462 return N->getKind() == CheckType;
463 }
464
Chris Lattnerf4950d02010-02-27 06:22:57 +0000465 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
466
Chris Lattner136ab782010-02-25 06:49:58 +0000467private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000468 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000469 virtual bool isEqualImpl(const Matcher *M) const {
Chris Lattner2d0e0792010-02-26 08:05:36 +0000470 return cast<CheckTypeMatcher>(M)->Type == Type;
Chris Lattner136ab782010-02-25 06:49:58 +0000471 }
472 virtual unsigned getHashImpl() const { return Type; }
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000473 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000474};
Chris Lattner3c664b32010-02-24 20:15:25 +0000475
Chris Lattnerc4188ac2010-03-03 06:28:15 +0000476/// SwitchTypeMatcher - Switch based on the current node's type, dispatching
477/// to one matcher per case. If the type doesn't match any of the cases,
478/// then the match fails. This is semantically equivalent to a Scope node where
479/// every child does a CheckType, but is much faster.
480class SwitchTypeMatcher : public Matcher {
481 SmallVector<std::pair<MVT::SimpleValueType, Matcher*>, 8> Cases;
482public:
483 SwitchTypeMatcher(const std::pair<MVT::SimpleValueType, Matcher*> *cases,
484 unsigned numcases)
485 : Matcher(SwitchType), Cases(cases, cases+numcases) {}
486
487 static inline bool classof(const Matcher *N) {
488 return N->getKind() == SwitchType;
489 }
490
491 unsigned getNumCases() const { return Cases.size(); }
492
493 MVT::SimpleValueType getCaseType(unsigned i) const { return Cases[i].first; }
494 Matcher *getCaseMatcher(unsigned i) { return Cases[i].second; }
495 const Matcher *getCaseMatcher(unsigned i) const { return Cases[i].second; }
496
497private:
498 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
499 virtual bool isEqualImpl(const Matcher *M) const { return false; }
500 virtual unsigned getHashImpl() const { return 4123; }
501};
502
503
Chris Lattner9a515172010-02-25 02:04:40 +0000504/// CheckChildTypeMatcher - This checks to see if a child node has the
Chris Lattner3c664b32010-02-24 20:15:25 +0000505/// specified type, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000506class CheckChildTypeMatcher : public Matcher {
Chris Lattner3c664b32010-02-24 20:15:25 +0000507 unsigned ChildNo;
508 MVT::SimpleValueType Type;
509public:
Chris Lattner9a515172010-02-25 02:04:40 +0000510 CheckChildTypeMatcher(unsigned childno, MVT::SimpleValueType type)
511 : Matcher(CheckChildType), ChildNo(childno), Type(type) {}
Chris Lattner3c664b32010-02-24 20:15:25 +0000512
513 unsigned getChildNo() const { return ChildNo; }
514 MVT::SimpleValueType getType() const { return Type; }
515
Chris Lattner9a515172010-02-25 02:04:40 +0000516 static inline bool classof(const Matcher *N) {
Chris Lattner3c664b32010-02-24 20:15:25 +0000517 return N->getKind() == CheckChildType;
518 }
519
Chris Lattnerf4950d02010-02-27 06:22:57 +0000520 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
521
Chris Lattner136ab782010-02-25 06:49:58 +0000522private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000523 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000524 virtual bool isEqualImpl(const Matcher *M) const {
525 return cast<CheckChildTypeMatcher>(M)->ChildNo == ChildNo &&
526 cast<CheckChildTypeMatcher>(M)->Type == Type;
527 }
528 virtual unsigned getHashImpl() const { return (Type << 3) | ChildNo; }
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000529 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattner3c664b32010-02-24 20:15:25 +0000530};
531
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000532
Chris Lattner9a515172010-02-25 02:04:40 +0000533/// CheckIntegerMatcher - This checks to see if the current node is a
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000534/// ConstantSDNode with the specified integer value, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000535class CheckIntegerMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000536 int64_t Value;
537public:
Chris Lattner9a515172010-02-25 02:04:40 +0000538 CheckIntegerMatcher(int64_t value)
539 : Matcher(CheckInteger), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000540
541 int64_t getValue() const { return Value; }
542
Chris Lattner9a515172010-02-25 02:04:40 +0000543 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000544 return N->getKind() == CheckInteger;
545 }
546
Chris Lattnerf4950d02010-02-27 06:22:57 +0000547 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
548
Chris Lattner136ab782010-02-25 06:49:58 +0000549private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000550 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000551 virtual bool isEqualImpl(const Matcher *M) const {
552 return cast<CheckIntegerMatcher>(M)->Value == Value;
553 }
554 virtual unsigned getHashImpl() const { return Value; }
Chris Lattner086af322010-02-27 08:11:15 +0000555 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000556};
557
Chris Lattner9a515172010-02-25 02:04:40 +0000558/// CheckCondCodeMatcher - This checks to see if the current node is a
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000559/// CondCodeSDNode with the specified condition, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000560class CheckCondCodeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000561 StringRef CondCodeName;
562public:
Chris Lattner9a515172010-02-25 02:04:40 +0000563 CheckCondCodeMatcher(StringRef condcodename)
564 : Matcher(CheckCondCode), CondCodeName(condcodename) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000565
566 StringRef getCondCodeName() const { return CondCodeName; }
567
Chris Lattner9a515172010-02-25 02:04:40 +0000568 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000569 return N->getKind() == CheckCondCode;
570 }
571
Chris Lattnerf4950d02010-02-27 06:22:57 +0000572 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
573
Chris Lattner136ab782010-02-25 06:49:58 +0000574private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000575 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000576 virtual bool isEqualImpl(const Matcher *M) const {
577 return cast<CheckCondCodeMatcher>(M)->CondCodeName == CondCodeName;
578 }
579 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000580};
581
Chris Lattner9a515172010-02-25 02:04:40 +0000582/// CheckValueTypeMatcher - This checks to see if the current node is a
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000583/// VTSDNode with the specified type, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000584class CheckValueTypeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000585 StringRef TypeName;
586public:
Chris Lattner9a515172010-02-25 02:04:40 +0000587 CheckValueTypeMatcher(StringRef type_name)
588 : Matcher(CheckValueType), TypeName(type_name) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000589
590 StringRef getTypeName() const { return TypeName; }
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() == CheckValueType;
594 }
595
Chris Lattnerf4950d02010-02-27 06:22:57 +0000596 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
597
Chris Lattner136ab782010-02-25 06:49:58 +0000598private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000599 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000600 virtual bool isEqualImpl(const Matcher *M) const {
601 return cast<CheckValueTypeMatcher>(M)->TypeName == TypeName;
602 }
603 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000604};
605
606
607
Chris Lattner9a515172010-02-25 02:04:40 +0000608/// CheckComplexPatMatcher - This node runs the specified ComplexPattern on
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000609/// the current node.
Chris Lattner9a515172010-02-25 02:04:40 +0000610class CheckComplexPatMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000611 const ComplexPattern &Pattern;
Chris Lattner609472b2010-03-04 01:23:08 +0000612
613 /// MatchNumber - This is the recorded nodes slot that contains the node we want to
614 /// match against.
615 unsigned MatchNumber;
616
617 /// Name - The name of the node we're matching, for comment emission.
618 std::string Name;
619
Chris Lattnerdc48d142010-03-04 00:28:05 +0000620 /// FirstResult - This is the first slot in the RecordedNodes list that the
621 /// result of the match populates.
622 unsigned FirstResult;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000623public:
Chris Lattner609472b2010-03-04 01:23:08 +0000624 CheckComplexPatMatcher(const ComplexPattern &pattern, unsigned matchnumber,
625 const std::string &name, unsigned firstresult)
626 : Matcher(CheckComplexPat), Pattern(pattern), MatchNumber(matchnumber),
627 Name(name), FirstResult(firstresult) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000628
Chris Lattnerdc429fd2010-02-17 00:31:50 +0000629 const ComplexPattern &getPattern() const { return Pattern; }
Chris Lattner609472b2010-03-04 01:23:08 +0000630 unsigned getMatchNumber() const { return MatchNumber; }
631
632 const std::string getName() const { return Name; }
Chris Lattnerdc48d142010-03-04 00:28:05 +0000633 unsigned getFirstResult() const { return FirstResult; }
Chris Lattnerdc429fd2010-02-17 00:31:50 +0000634
Chris Lattner9a515172010-02-25 02:04:40 +0000635 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000636 return N->getKind() == CheckComplexPat;
637 }
638
Chris Lattnerf4950d02010-02-27 06:22:57 +0000639 // Not safe to move a pattern predicate past a complex pattern.
640 virtual bool isSafeToReorderWithPatternPredicate() const { return false; }
641
Chris Lattner136ab782010-02-25 06:49:58 +0000642private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000643 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000644 virtual bool isEqualImpl(const Matcher *M) const {
Chris Lattner609472b2010-03-04 01:23:08 +0000645 return &cast<CheckComplexPatMatcher>(M)->Pattern == &Pattern &&
646 cast<CheckComplexPatMatcher>(M)->MatchNumber == MatchNumber;
Chris Lattner136ab782010-02-25 06:49:58 +0000647 }
648 virtual unsigned getHashImpl() const {
Chris Lattner609472b2010-03-04 01:23:08 +0000649 return (unsigned)(intptr_t)&Pattern ^ MatchNumber;
Chris Lattner136ab782010-02-25 06:49:58 +0000650 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000651};
652
Chris Lattner9a515172010-02-25 02:04:40 +0000653/// CheckAndImmMatcher - This checks to see if the current node is an 'and'
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000654/// with something equivalent to the specified immediate.
Chris Lattner9a515172010-02-25 02:04:40 +0000655class CheckAndImmMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000656 int64_t Value;
657public:
Chris Lattner9a515172010-02-25 02:04:40 +0000658 CheckAndImmMatcher(int64_t value)
659 : Matcher(CheckAndImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000660
661 int64_t getValue() const { return Value; }
662
Chris Lattner9a515172010-02-25 02:04:40 +0000663 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000664 return N->getKind() == CheckAndImm;
665 }
666
Chris Lattnerf4950d02010-02-27 06:22:57 +0000667 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
668
Chris Lattner136ab782010-02-25 06:49:58 +0000669private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000670 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000671 virtual bool isEqualImpl(const Matcher *M) const {
672 return cast<CheckAndImmMatcher>(M)->Value == Value;
673 }
674 virtual unsigned getHashImpl() const { return Value; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000675};
676
Chris Lattner9a515172010-02-25 02:04:40 +0000677/// CheckOrImmMatcher - This checks to see if the current node is an 'and'
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000678/// with something equivalent to the specified immediate.
Chris Lattner9a515172010-02-25 02:04:40 +0000679class CheckOrImmMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000680 int64_t Value;
681public:
Chris Lattner9a515172010-02-25 02:04:40 +0000682 CheckOrImmMatcher(int64_t value)
683 : Matcher(CheckOrImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000684
685 int64_t getValue() const { return Value; }
686
Chris Lattner9a515172010-02-25 02:04:40 +0000687 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000688 return N->getKind() == CheckOrImm;
689 }
690
Chris Lattnerf4950d02010-02-27 06:22:57 +0000691 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
692
Chris Lattner136ab782010-02-25 06:49:58 +0000693private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000694 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000695 virtual bool isEqualImpl(const Matcher *M) const {
696 return cast<CheckOrImmMatcher>(M)->Value == Value;
697 }
698 virtual unsigned getHashImpl() const { return Value; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000699};
Chris Lattner9de39482010-02-16 06:10:58 +0000700
Chris Lattner9a515172010-02-25 02:04:40 +0000701/// CheckFoldableChainNodeMatcher - This checks to see if the current node
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000702/// (which defines a chain operand) is safe to fold into a larger pattern.
Chris Lattner9a515172010-02-25 02:04:40 +0000703class CheckFoldableChainNodeMatcher : public Matcher {
Chris Lattner9de39482010-02-16 06:10:58 +0000704public:
Chris Lattner9a515172010-02-25 02:04:40 +0000705 CheckFoldableChainNodeMatcher()
706 : Matcher(CheckFoldableChainNode) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000707
Chris Lattner9a515172010-02-25 02:04:40 +0000708 static inline bool classof(const Matcher *N) {
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000709 return N->getKind() == CheckFoldableChainNode;
Chris Lattner9de39482010-02-16 06:10:58 +0000710 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000711
Chris Lattnerf4950d02010-02-27 06:22:57 +0000712 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
713
Chris Lattner136ab782010-02-25 06:49:58 +0000714private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000715 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000716 virtual bool isEqualImpl(const Matcher *M) const { return true; }
717 virtual unsigned getHashImpl() const { return 0; }
Chris Lattner9de39482010-02-16 06:10:58 +0000718};
719
Chris Lattner9a515172010-02-25 02:04:40 +0000720/// EmitIntegerMatcher - This creates a new TargetConstant.
721class EmitIntegerMatcher : public Matcher {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000722 int64_t Val;
723 MVT::SimpleValueType VT;
724public:
Chris Lattner9a515172010-02-25 02:04:40 +0000725 EmitIntegerMatcher(int64_t val, MVT::SimpleValueType vt)
726 : Matcher(EmitInteger), Val(val), VT(vt) {}
Chris Lattner283adcb2010-02-17 06:23:39 +0000727
Chris Lattner7043e0a2010-02-19 07:49:56 +0000728 int64_t getValue() const { return Val; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000729 MVT::SimpleValueType getVT() const { return VT; }
730
Chris Lattner9a515172010-02-25 02:04:40 +0000731 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000732 return N->getKind() == EmitInteger;
733 }
734
Chris Lattner136ab782010-02-25 06:49:58 +0000735private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000736 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000737 virtual bool isEqualImpl(const Matcher *M) const {
738 return cast<EmitIntegerMatcher>(M)->Val == Val &&
739 cast<EmitIntegerMatcher>(M)->VT == VT;
740 }
741 virtual unsigned getHashImpl() const { return (Val << 4) | VT; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000742};
Chris Lattner3163ca52010-02-21 03:22:59 +0000743
Chris Lattner9a515172010-02-25 02:04:40 +0000744/// EmitStringIntegerMatcher - A target constant whose value is represented
Chris Lattner3163ca52010-02-21 03:22:59 +0000745/// by a string.
Chris Lattner9a515172010-02-25 02:04:40 +0000746class EmitStringIntegerMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000747 std::string Val;
748 MVT::SimpleValueType VT;
749public:
Chris Lattner9a515172010-02-25 02:04:40 +0000750 EmitStringIntegerMatcher(const std::string &val, MVT::SimpleValueType vt)
751 : Matcher(EmitStringInteger), Val(val), VT(vt) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000752
753 const std::string &getValue() const { return Val; }
754 MVT::SimpleValueType getVT() const { return VT; }
755
Chris Lattner9a515172010-02-25 02:04:40 +0000756 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000757 return N->getKind() == EmitStringInteger;
758 }
759
Chris Lattner136ab782010-02-25 06:49:58 +0000760private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000761 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000762 virtual bool isEqualImpl(const Matcher *M) const {
763 return cast<EmitStringIntegerMatcher>(M)->Val == Val &&
764 cast<EmitStringIntegerMatcher>(M)->VT == VT;
765 }
766 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +0000767};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000768
Chris Lattner9a515172010-02-25 02:04:40 +0000769/// EmitRegisterMatcher - This creates a new TargetConstant.
770class EmitRegisterMatcher : public Matcher {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000771 /// Reg - The def for the register that we're emitting. If this is null, then
772 /// this is a reference to zero_reg.
773 Record *Reg;
774 MVT::SimpleValueType VT;
775public:
Chris Lattner9a515172010-02-25 02:04:40 +0000776 EmitRegisterMatcher(Record *reg, MVT::SimpleValueType vt)
777 : Matcher(EmitRegister), Reg(reg), VT(vt) {}
Chris Lattnerddfb5222010-02-18 22:03:03 +0000778
779 Record *getReg() const { return Reg; }
780 MVT::SimpleValueType getVT() const { return VT; }
781
Chris Lattner9a515172010-02-25 02:04:40 +0000782 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000783 return N->getKind() == EmitRegister;
784 }
785
Chris Lattner136ab782010-02-25 06:49:58 +0000786private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000787 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000788 virtual bool isEqualImpl(const Matcher *M) const {
789 return cast<EmitRegisterMatcher>(M)->Reg == Reg &&
790 cast<EmitRegisterMatcher>(M)->VT == VT;
791 }
792 virtual unsigned getHashImpl() const {
793 return ((unsigned)(intptr_t)Reg) << 4 | VT;
794 }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000795};
Chris Lattner3163ca52010-02-21 03:22:59 +0000796
Chris Lattner9a515172010-02-25 02:04:40 +0000797/// EmitConvertToTargetMatcher - Emit an operation that reads a specified
Chris Lattner3163ca52010-02-21 03:22:59 +0000798/// recorded node and converts it from being a ISD::Constant to
799/// ISD::TargetConstant, likewise for ConstantFP.
Chris Lattner9a515172010-02-25 02:04:40 +0000800class EmitConvertToTargetMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000801 unsigned Slot;
802public:
Chris Lattner9a515172010-02-25 02:04:40 +0000803 EmitConvertToTargetMatcher(unsigned slot)
804 : Matcher(EmitConvertToTarget), Slot(slot) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000805
806 unsigned getSlot() const { return Slot; }
807
Chris Lattner9a515172010-02-25 02:04:40 +0000808 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000809 return N->getKind() == EmitConvertToTarget;
810 }
811
Chris Lattner136ab782010-02-25 06:49:58 +0000812private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000813 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000814 virtual bool isEqualImpl(const Matcher *M) const {
815 return cast<EmitConvertToTargetMatcher>(M)->Slot == Slot;
816 }
817 virtual unsigned getHashImpl() const { return Slot; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000818};
819
Chris Lattner9a515172010-02-25 02:04:40 +0000820/// EmitMergeInputChainsMatcher - Emit a node that merges a list of input
Chris Lattner3163ca52010-02-21 03:22:59 +0000821/// chains together with a token factor. The list of nodes are the nodes in the
822/// matched pattern that have chain input/outputs. This node adds all input
823/// chains of these nodes if they are not themselves a node in the pattern.
Chris Lattner9a515172010-02-25 02:04:40 +0000824class EmitMergeInputChainsMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000825 SmallVector<unsigned, 3> ChainNodes;
826public:
Chris Lattner9a515172010-02-25 02:04:40 +0000827 EmitMergeInputChainsMatcher(const unsigned *nodes, unsigned NumNodes)
828 : Matcher(EmitMergeInputChains), ChainNodes(nodes, nodes+NumNodes) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000829
830 unsigned getNumNodes() const { return ChainNodes.size(); }
831
832 unsigned getNode(unsigned i) const {
833 assert(i < ChainNodes.size());
834 return ChainNodes[i];
835 }
836
Chris Lattner9a515172010-02-25 02:04:40 +0000837 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000838 return N->getKind() == EmitMergeInputChains;
839 }
840
Chris Lattner136ab782010-02-25 06:49:58 +0000841private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000842 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000843 virtual bool isEqualImpl(const Matcher *M) const {
844 return cast<EmitMergeInputChainsMatcher>(M)->ChainNodes == ChainNodes;
845 }
846 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +0000847};
848
Chris Lattner9a515172010-02-25 02:04:40 +0000849/// EmitCopyToRegMatcher - Emit a CopyToReg node from a value to a physreg,
Chris Lattner3163ca52010-02-21 03:22:59 +0000850/// pushing the chain and flag results.
851///
Chris Lattner9a515172010-02-25 02:04:40 +0000852class EmitCopyToRegMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000853 unsigned SrcSlot; // Value to copy into the physreg.
854 Record *DestPhysReg;
855public:
Chris Lattner9a515172010-02-25 02:04:40 +0000856 EmitCopyToRegMatcher(unsigned srcSlot, Record *destPhysReg)
857 : Matcher(EmitCopyToReg), SrcSlot(srcSlot), DestPhysReg(destPhysReg) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000858
859 unsigned getSrcSlot() const { return SrcSlot; }
860 Record *getDestPhysReg() const { return DestPhysReg; }
861
Chris Lattner9a515172010-02-25 02:04:40 +0000862 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000863 return N->getKind() == EmitCopyToReg;
864 }
865
Chris Lattner136ab782010-02-25 06:49:58 +0000866private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000867 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000868 virtual bool isEqualImpl(const Matcher *M) const {
869 return cast<EmitCopyToRegMatcher>(M)->SrcSlot == SrcSlot &&
870 cast<EmitCopyToRegMatcher>(M)->DestPhysReg == DestPhysReg;
871 }
872 virtual unsigned getHashImpl() const {
873 return SrcSlot ^ ((unsigned)(intptr_t)DestPhysReg << 4);
874 }
Chris Lattner3163ca52010-02-21 03:22:59 +0000875};
876
877
878
Chris Lattner9a515172010-02-25 02:04:40 +0000879/// EmitNodeXFormMatcher - Emit an operation that runs an SDNodeXForm on a
Chris Lattner3163ca52010-02-21 03:22:59 +0000880/// recorded node and records the result.
Chris Lattner9a515172010-02-25 02:04:40 +0000881class EmitNodeXFormMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000882 unsigned Slot;
883 Record *NodeXForm;
884public:
Chris Lattner9a515172010-02-25 02:04:40 +0000885 EmitNodeXFormMatcher(unsigned slot, Record *nodeXForm)
886 : Matcher(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000887
888 unsigned getSlot() const { return Slot; }
889 Record *getNodeXForm() const { return NodeXForm; }
890
Chris Lattner9a515172010-02-25 02:04:40 +0000891 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000892 return N->getKind() == EmitNodeXForm;
893 }
894
Chris Lattner136ab782010-02-25 06:49:58 +0000895private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000896 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000897 virtual bool isEqualImpl(const Matcher *M) const {
898 return cast<EmitNodeXFormMatcher>(M)->Slot == Slot &&
899 cast<EmitNodeXFormMatcher>(M)->NodeXForm == NodeXForm;
900 }
901 virtual unsigned getHashImpl() const {
902 return Slot ^ ((unsigned)(intptr_t)NodeXForm << 4);
903 }
Chris Lattner3163ca52010-02-21 03:22:59 +0000904};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000905
Chris Lattner7a1dab42010-02-28 02:31:26 +0000906/// EmitNodeMatcherCommon - Common class shared between EmitNode and
Chris Lattner7dae4af2010-02-28 20:55:18 +0000907/// MorphNodeTo.
Chris Lattner7a1dab42010-02-28 02:31:26 +0000908class EmitNodeMatcherCommon : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000909 std::string OpcodeName;
910 const SmallVector<MVT::SimpleValueType, 3> VTs;
911 const SmallVector<unsigned, 6> Operands;
Chris Lattner414bac82010-02-28 21:53:42 +0000912 bool HasChain, HasInFlag, HasOutFlag, HasMemRefs;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000913
Chris Lattner3163ca52010-02-21 03:22:59 +0000914 /// NumFixedArityOperands - If this is a fixed arity node, this is set to -1.
915 /// If this is a varidic node, this is set to the number of fixed arity
916 /// operands in the root of the pattern. The rest are appended to this node.
917 int NumFixedArityOperands;
918public:
Chris Lattner7a1dab42010-02-28 02:31:26 +0000919 EmitNodeMatcherCommon(const std::string &opcodeName,
920 const MVT::SimpleValueType *vts, unsigned numvts,
921 const unsigned *operands, unsigned numops,
Chris Lattner414bac82010-02-28 21:53:42 +0000922 bool hasChain, bool hasInFlag, bool hasOutFlag,
923 bool hasmemrefs,
Chris Lattner7dae4af2010-02-28 20:55:18 +0000924 int numfixedarityoperands, bool isMorphNodeTo)
925 : Matcher(isMorphNodeTo ? MorphNodeTo : EmitNode), OpcodeName(opcodeName),
Chris Lattner3163ca52010-02-21 03:22:59 +0000926 VTs(vts, vts+numvts), Operands(operands, operands+numops),
Chris Lattner414bac82010-02-28 21:53:42 +0000927 HasChain(hasChain), HasInFlag(hasInFlag), HasOutFlag(hasOutFlag),
928 HasMemRefs(hasmemrefs), NumFixedArityOperands(numfixedarityoperands) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000929
930 const std::string &getOpcodeName() const { return OpcodeName; }
931
932 unsigned getNumVTs() const { return VTs.size(); }
933 MVT::SimpleValueType getVT(unsigned i) const {
934 assert(i < VTs.size());
935 return VTs[i];
936 }
Chris Lattner5cc7a832010-02-28 20:49:53 +0000937
Chris Lattner3163ca52010-02-21 03:22:59 +0000938 unsigned getNumOperands() const { return Operands.size(); }
939 unsigned getOperand(unsigned i) const {
940 assert(i < Operands.size());
941 return Operands[i];
Chris Lattner5cc7a832010-02-28 20:49:53 +0000942 }
943
944 const SmallVectorImpl<MVT::SimpleValueType> &getVTList() const { return VTs; }
945 const SmallVectorImpl<unsigned> &getOperandList() const { return Operands; }
946
Chris Lattner3163ca52010-02-21 03:22:59 +0000947
948 bool hasChain() const { return HasChain; }
Chris Lattner414bac82010-02-28 21:53:42 +0000949 bool hasInFlag() const { return HasInFlag; }
950 bool hasOutFlag() const { return HasOutFlag; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000951 bool hasMemRefs() const { return HasMemRefs; }
952 int getNumFixedArityOperands() const { return NumFixedArityOperands; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000953
Chris Lattner9a515172010-02-25 02:04:40 +0000954 static inline bool classof(const Matcher *N) {
Chris Lattner7dae4af2010-02-28 20:55:18 +0000955 return N->getKind() == EmitNode || N->getKind() == MorphNodeTo;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000956 }
957
Chris Lattner136ab782010-02-25 06:49:58 +0000958private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000959 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000960 virtual bool isEqualImpl(const Matcher *M) const;
961 virtual unsigned getHashImpl() const;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000962};
Chris Lattnerb085ea12010-02-21 06:03:07 +0000963
Chris Lattner7a1dab42010-02-28 02:31:26 +0000964/// EmitNodeMatcher - This signals a successful match and generates a node.
965class EmitNodeMatcher : public EmitNodeMatcherCommon {
Chris Lattner19a1fbe2010-02-28 02:41:25 +0000966 unsigned FirstResultSlot;
Chris Lattner7a1dab42010-02-28 02:31:26 +0000967public:
968 EmitNodeMatcher(const std::string &opcodeName,
969 const MVT::SimpleValueType *vts, unsigned numvts,
970 const unsigned *operands, unsigned numops,
Chris Lattner414bac82010-02-28 21:53:42 +0000971 bool hasChain, bool hasInFlag, bool hasOutFlag,
972 bool hasmemrefs,
Chris Lattner19a1fbe2010-02-28 02:41:25 +0000973 int numfixedarityoperands, unsigned firstresultslot)
Chris Lattner7a1dab42010-02-28 02:31:26 +0000974 : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
Chris Lattner414bac82010-02-28 21:53:42 +0000975 hasInFlag, hasOutFlag, hasmemrefs,
976 numfixedarityoperands, false),
Chris Lattner19a1fbe2010-02-28 02:41:25 +0000977 FirstResultSlot(firstresultslot) {}
978
979 unsigned getFirstResultSlot() const { return FirstResultSlot; }
Chris Lattner7a1dab42010-02-28 02:31:26 +0000980
981 static inline bool classof(const Matcher *N) {
982 return N->getKind() == EmitNode;
983 }
984
985};
986
Chris Lattner7dae4af2010-02-28 20:55:18 +0000987class MorphNodeToMatcher : public EmitNodeMatcherCommon {
Chris Lattner7a1dab42010-02-28 02:31:26 +0000988 const PatternToMatch &Pattern;
989public:
Chris Lattner7dae4af2010-02-28 20:55:18 +0000990 MorphNodeToMatcher(const std::string &opcodeName,
991 const MVT::SimpleValueType *vts, unsigned numvts,
992 const unsigned *operands, unsigned numops,
Chris Lattner414bac82010-02-28 21:53:42 +0000993 bool hasChain, bool hasInFlag, bool hasOutFlag,
994 bool hasmemrefs,
Chris Lattner7dae4af2010-02-28 20:55:18 +0000995 int numfixedarityoperands, const PatternToMatch &pattern)
Chris Lattner7a1dab42010-02-28 02:31:26 +0000996 : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
Chris Lattner414bac82010-02-28 21:53:42 +0000997 hasInFlag, hasOutFlag, hasmemrefs,
998 numfixedarityoperands, true),
Chris Lattner7a1dab42010-02-28 02:31:26 +0000999 Pattern(pattern) {
1000 }
1001
1002 const PatternToMatch &getPattern() const { return Pattern; }
1003
1004 static inline bool classof(const Matcher *N) {
Chris Lattner7dae4af2010-02-28 20:55:18 +00001005 return N->getKind() == MorphNodeTo;
Chris Lattner7a1dab42010-02-28 02:31:26 +00001006 }
1007};
1008
Chris Lattner9a515172010-02-25 02:04:40 +00001009/// MarkFlagResultsMatcher - This node indicates which non-root nodes in the
1010/// pattern produce flags. This allows CompleteMatchMatcher to update them
Chris Lattner69f60c82010-02-24 05:33:42 +00001011/// with the output flag of the resultant code.
Chris Lattner9a515172010-02-25 02:04:40 +00001012class MarkFlagResultsMatcher : public Matcher {
Chris Lattner69f60c82010-02-24 05:33:42 +00001013 SmallVector<unsigned, 3> FlagResultNodes;
1014public:
Chris Lattner9a515172010-02-25 02:04:40 +00001015 MarkFlagResultsMatcher(const unsigned *nodes, unsigned NumNodes)
1016 : Matcher(MarkFlagResults), FlagResultNodes(nodes, nodes+NumNodes) {}
Chris Lattner69f60c82010-02-24 05:33:42 +00001017
1018 unsigned getNumNodes() const { return FlagResultNodes.size(); }
1019
1020 unsigned getNode(unsigned i) const {
1021 assert(i < FlagResultNodes.size());
1022 return FlagResultNodes[i];
1023 }
1024
Chris Lattner9a515172010-02-25 02:04:40 +00001025 static inline bool classof(const Matcher *N) {
Chris Lattner69f60c82010-02-24 05:33:42 +00001026 return N->getKind() == MarkFlagResults;
1027 }
1028
Chris Lattner136ab782010-02-25 06:49:58 +00001029private:
Chris Lattner392b1bf2010-02-25 06:53:39 +00001030 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +00001031 virtual bool isEqualImpl(const Matcher *M) const {
1032 return cast<MarkFlagResultsMatcher>(M)->FlagResultNodes == FlagResultNodes;
1033 }
1034 virtual unsigned getHashImpl() const;
Chris Lattner69f60c82010-02-24 05:33:42 +00001035};
1036
Chris Lattner9a515172010-02-25 02:04:40 +00001037/// CompleteMatchMatcher - Complete a match by replacing the results of the
Chris Lattnerb085ea12010-02-21 06:03:07 +00001038/// pattern with the newly generated nodes. This also prints a comment
1039/// indicating the source and dest patterns.
Chris Lattner9a515172010-02-25 02:04:40 +00001040class CompleteMatchMatcher : public Matcher {
Chris Lattnerb085ea12010-02-21 06:03:07 +00001041 SmallVector<unsigned, 2> Results;
Chris Lattner3163ca52010-02-21 03:22:59 +00001042 const PatternToMatch &Pattern;
1043public:
Chris Lattner9a515172010-02-25 02:04:40 +00001044 CompleteMatchMatcher(const unsigned *results, unsigned numresults,
Chris Lattner5cc7a832010-02-28 20:49:53 +00001045 const PatternToMatch &pattern)
Chris Lattner9a515172010-02-25 02:04:40 +00001046 : Matcher(CompleteMatch), Results(results, results+numresults),
Chris Lattnerb085ea12010-02-21 06:03:07 +00001047 Pattern(pattern) {}
1048
1049 unsigned getNumResults() const { return Results.size(); }
1050 unsigned getResult(unsigned R) const { return Results[R]; }
Chris Lattner3163ca52010-02-21 03:22:59 +00001051 const PatternToMatch &getPattern() const { return Pattern; }
1052
Chris Lattner9a515172010-02-25 02:04:40 +00001053 static inline bool classof(const Matcher *N) {
Chris Lattnerb085ea12010-02-21 06:03:07 +00001054 return N->getKind() == CompleteMatch;
Chris Lattner3163ca52010-02-21 03:22:59 +00001055 }
1056
Chris Lattner136ab782010-02-25 06:49:58 +00001057private:
Chris Lattner392b1bf2010-02-25 06:53:39 +00001058 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +00001059 virtual bool isEqualImpl(const Matcher *M) const {
1060 return cast<CompleteMatchMatcher>(M)->Results == Results &&
1061 &cast<CompleteMatchMatcher>(M)->Pattern == &Pattern;
1062 }
1063 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +00001064};
Chris Lattner7a1dab42010-02-28 02:31:26 +00001065
Chris Lattnere7d6e3c2010-02-15 08:04:42 +00001066} // end namespace llvm
1067
1068#endif