blob: 8498d60b5d1a7a419f6fbe458bdd8752fe3dec16 [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 Lattnerdc48d142010-03-04 00:28:05 +0000612 /// FirstResult - This is the first slot in the RecordedNodes list that the
613 /// result of the match populates.
614 unsigned FirstResult;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000615public:
Chris Lattnerdc48d142010-03-04 00:28:05 +0000616 CheckComplexPatMatcher(const ComplexPattern &pattern, unsigned firstresult)
617 : Matcher(CheckComplexPat), Pattern(pattern), FirstResult(firstresult) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000618
Chris Lattnerdc429fd2010-02-17 00:31:50 +0000619 const ComplexPattern &getPattern() const { return Pattern; }
Chris Lattnerdc48d142010-03-04 00:28:05 +0000620 unsigned getFirstResult() const { return FirstResult; }
Chris Lattnerdc429fd2010-02-17 00:31:50 +0000621
Chris Lattner9a515172010-02-25 02:04:40 +0000622 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000623 return N->getKind() == CheckComplexPat;
624 }
625
Chris Lattnerf4950d02010-02-27 06:22:57 +0000626 // Not safe to move a pattern predicate past a complex pattern.
627 virtual bool isSafeToReorderWithPatternPredicate() const { return false; }
628
Chris Lattner136ab782010-02-25 06:49:58 +0000629private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000630 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000631 virtual bool isEqualImpl(const Matcher *M) const {
632 return &cast<CheckComplexPatMatcher>(M)->Pattern == &Pattern;
633 }
634 virtual unsigned getHashImpl() const {
635 return (unsigned)(intptr_t)&Pattern;
636 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000637};
638
Chris Lattner9a515172010-02-25 02:04:40 +0000639/// CheckAndImmMatcher - This checks to see if the current node is an 'and'
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000640/// with something equivalent to the specified immediate.
Chris Lattner9a515172010-02-25 02:04:40 +0000641class CheckAndImmMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000642 int64_t Value;
643public:
Chris Lattner9a515172010-02-25 02:04:40 +0000644 CheckAndImmMatcher(int64_t value)
645 : Matcher(CheckAndImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000646
647 int64_t getValue() const { return Value; }
648
Chris Lattner9a515172010-02-25 02:04:40 +0000649 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000650 return N->getKind() == CheckAndImm;
651 }
652
Chris Lattnerf4950d02010-02-27 06:22:57 +0000653 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
654
Chris Lattner136ab782010-02-25 06:49:58 +0000655private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000656 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000657 virtual bool isEqualImpl(const Matcher *M) const {
658 return cast<CheckAndImmMatcher>(M)->Value == Value;
659 }
660 virtual unsigned getHashImpl() const { return Value; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000661};
662
Chris Lattner9a515172010-02-25 02:04:40 +0000663/// CheckOrImmMatcher - This checks to see if the current node is an 'and'
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000664/// with something equivalent to the specified immediate.
Chris Lattner9a515172010-02-25 02:04:40 +0000665class CheckOrImmMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000666 int64_t Value;
667public:
Chris Lattner9a515172010-02-25 02:04:40 +0000668 CheckOrImmMatcher(int64_t value)
669 : Matcher(CheckOrImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000670
671 int64_t getValue() const { return Value; }
672
Chris Lattner9a515172010-02-25 02:04:40 +0000673 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000674 return N->getKind() == CheckOrImm;
675 }
676
Chris Lattnerf4950d02010-02-27 06:22:57 +0000677 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
678
Chris Lattner136ab782010-02-25 06:49:58 +0000679private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000680 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000681 virtual bool isEqualImpl(const Matcher *M) const {
682 return cast<CheckOrImmMatcher>(M)->Value == Value;
683 }
684 virtual unsigned getHashImpl() const { return Value; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000685};
Chris Lattner9de39482010-02-16 06:10:58 +0000686
Chris Lattner9a515172010-02-25 02:04:40 +0000687/// CheckFoldableChainNodeMatcher - This checks to see if the current node
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000688/// (which defines a chain operand) is safe to fold into a larger pattern.
Chris Lattner9a515172010-02-25 02:04:40 +0000689class CheckFoldableChainNodeMatcher : public Matcher {
Chris Lattner9de39482010-02-16 06:10:58 +0000690public:
Chris Lattner9a515172010-02-25 02:04:40 +0000691 CheckFoldableChainNodeMatcher()
692 : Matcher(CheckFoldableChainNode) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000693
Chris Lattner9a515172010-02-25 02:04:40 +0000694 static inline bool classof(const Matcher *N) {
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000695 return N->getKind() == CheckFoldableChainNode;
Chris Lattner9de39482010-02-16 06:10:58 +0000696 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000697
Chris Lattnerf4950d02010-02-27 06:22:57 +0000698 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
699
Chris Lattner136ab782010-02-25 06:49:58 +0000700private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000701 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000702 virtual bool isEqualImpl(const Matcher *M) const { return true; }
703 virtual unsigned getHashImpl() const { return 0; }
Chris Lattner9de39482010-02-16 06:10:58 +0000704};
705
Chris Lattner9a515172010-02-25 02:04:40 +0000706/// EmitIntegerMatcher - This creates a new TargetConstant.
707class EmitIntegerMatcher : public Matcher {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000708 int64_t Val;
709 MVT::SimpleValueType VT;
710public:
Chris Lattner9a515172010-02-25 02:04:40 +0000711 EmitIntegerMatcher(int64_t val, MVT::SimpleValueType vt)
712 : Matcher(EmitInteger), Val(val), VT(vt) {}
Chris Lattner283adcb2010-02-17 06:23:39 +0000713
Chris Lattner7043e0a2010-02-19 07:49:56 +0000714 int64_t getValue() const { return Val; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000715 MVT::SimpleValueType getVT() const { return VT; }
716
Chris Lattner9a515172010-02-25 02:04:40 +0000717 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000718 return N->getKind() == EmitInteger;
719 }
720
Chris Lattner136ab782010-02-25 06:49:58 +0000721private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000722 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000723 virtual bool isEqualImpl(const Matcher *M) const {
724 return cast<EmitIntegerMatcher>(M)->Val == Val &&
725 cast<EmitIntegerMatcher>(M)->VT == VT;
726 }
727 virtual unsigned getHashImpl() const { return (Val << 4) | VT; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000728};
Chris Lattner3163ca52010-02-21 03:22:59 +0000729
Chris Lattner9a515172010-02-25 02:04:40 +0000730/// EmitStringIntegerMatcher - A target constant whose value is represented
Chris Lattner3163ca52010-02-21 03:22:59 +0000731/// by a string.
Chris Lattner9a515172010-02-25 02:04:40 +0000732class EmitStringIntegerMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000733 std::string Val;
734 MVT::SimpleValueType VT;
735public:
Chris Lattner9a515172010-02-25 02:04:40 +0000736 EmitStringIntegerMatcher(const std::string &val, MVT::SimpleValueType vt)
737 : Matcher(EmitStringInteger), Val(val), VT(vt) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000738
739 const std::string &getValue() const { return Val; }
740 MVT::SimpleValueType getVT() const { return VT; }
741
Chris Lattner9a515172010-02-25 02:04:40 +0000742 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000743 return N->getKind() == EmitStringInteger;
744 }
745
Chris Lattner136ab782010-02-25 06:49:58 +0000746private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000747 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000748 virtual bool isEqualImpl(const Matcher *M) const {
749 return cast<EmitStringIntegerMatcher>(M)->Val == Val &&
750 cast<EmitStringIntegerMatcher>(M)->VT == VT;
751 }
752 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +0000753};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000754
Chris Lattner9a515172010-02-25 02:04:40 +0000755/// EmitRegisterMatcher - This creates a new TargetConstant.
756class EmitRegisterMatcher : public Matcher {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000757 /// Reg - The def for the register that we're emitting. If this is null, then
758 /// this is a reference to zero_reg.
759 Record *Reg;
760 MVT::SimpleValueType VT;
761public:
Chris Lattner9a515172010-02-25 02:04:40 +0000762 EmitRegisterMatcher(Record *reg, MVT::SimpleValueType vt)
763 : Matcher(EmitRegister), Reg(reg), VT(vt) {}
Chris Lattnerddfb5222010-02-18 22:03:03 +0000764
765 Record *getReg() const { return Reg; }
766 MVT::SimpleValueType getVT() const { return VT; }
767
Chris Lattner9a515172010-02-25 02:04:40 +0000768 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000769 return N->getKind() == EmitRegister;
770 }
771
Chris Lattner136ab782010-02-25 06:49:58 +0000772private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000773 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000774 virtual bool isEqualImpl(const Matcher *M) const {
775 return cast<EmitRegisterMatcher>(M)->Reg == Reg &&
776 cast<EmitRegisterMatcher>(M)->VT == VT;
777 }
778 virtual unsigned getHashImpl() const {
779 return ((unsigned)(intptr_t)Reg) << 4 | VT;
780 }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000781};
Chris Lattner3163ca52010-02-21 03:22:59 +0000782
Chris Lattner9a515172010-02-25 02:04:40 +0000783/// EmitConvertToTargetMatcher - Emit an operation that reads a specified
Chris Lattner3163ca52010-02-21 03:22:59 +0000784/// recorded node and converts it from being a ISD::Constant to
785/// ISD::TargetConstant, likewise for ConstantFP.
Chris Lattner9a515172010-02-25 02:04:40 +0000786class EmitConvertToTargetMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000787 unsigned Slot;
788public:
Chris Lattner9a515172010-02-25 02:04:40 +0000789 EmitConvertToTargetMatcher(unsigned slot)
790 : Matcher(EmitConvertToTarget), Slot(slot) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000791
792 unsigned getSlot() const { return Slot; }
793
Chris Lattner9a515172010-02-25 02:04:40 +0000794 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000795 return N->getKind() == EmitConvertToTarget;
796 }
797
Chris Lattner136ab782010-02-25 06:49:58 +0000798private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000799 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000800 virtual bool isEqualImpl(const Matcher *M) const {
801 return cast<EmitConvertToTargetMatcher>(M)->Slot == Slot;
802 }
803 virtual unsigned getHashImpl() const { return Slot; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000804};
805
Chris Lattner9a515172010-02-25 02:04:40 +0000806/// EmitMergeInputChainsMatcher - Emit a node that merges a list of input
Chris Lattner3163ca52010-02-21 03:22:59 +0000807/// chains together with a token factor. The list of nodes are the nodes in the
808/// matched pattern that have chain input/outputs. This node adds all input
809/// chains of these nodes if they are not themselves a node in the pattern.
Chris Lattner9a515172010-02-25 02:04:40 +0000810class EmitMergeInputChainsMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000811 SmallVector<unsigned, 3> ChainNodes;
812public:
Chris Lattner9a515172010-02-25 02:04:40 +0000813 EmitMergeInputChainsMatcher(const unsigned *nodes, unsigned NumNodes)
814 : Matcher(EmitMergeInputChains), ChainNodes(nodes, nodes+NumNodes) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000815
816 unsigned getNumNodes() const { return ChainNodes.size(); }
817
818 unsigned getNode(unsigned i) const {
819 assert(i < ChainNodes.size());
820 return ChainNodes[i];
821 }
822
Chris Lattner9a515172010-02-25 02:04:40 +0000823 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000824 return N->getKind() == EmitMergeInputChains;
825 }
826
Chris Lattner136ab782010-02-25 06:49:58 +0000827private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000828 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000829 virtual bool isEqualImpl(const Matcher *M) const {
830 return cast<EmitMergeInputChainsMatcher>(M)->ChainNodes == ChainNodes;
831 }
832 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +0000833};
834
Chris Lattner9a515172010-02-25 02:04:40 +0000835/// EmitCopyToRegMatcher - Emit a CopyToReg node from a value to a physreg,
Chris Lattner3163ca52010-02-21 03:22:59 +0000836/// pushing the chain and flag results.
837///
Chris Lattner9a515172010-02-25 02:04:40 +0000838class EmitCopyToRegMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000839 unsigned SrcSlot; // Value to copy into the physreg.
840 Record *DestPhysReg;
841public:
Chris Lattner9a515172010-02-25 02:04:40 +0000842 EmitCopyToRegMatcher(unsigned srcSlot, Record *destPhysReg)
843 : Matcher(EmitCopyToReg), SrcSlot(srcSlot), DestPhysReg(destPhysReg) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000844
845 unsigned getSrcSlot() const { return SrcSlot; }
846 Record *getDestPhysReg() const { return DestPhysReg; }
847
Chris Lattner9a515172010-02-25 02:04:40 +0000848 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000849 return N->getKind() == EmitCopyToReg;
850 }
851
Chris Lattner136ab782010-02-25 06:49:58 +0000852private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000853 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000854 virtual bool isEqualImpl(const Matcher *M) const {
855 return cast<EmitCopyToRegMatcher>(M)->SrcSlot == SrcSlot &&
856 cast<EmitCopyToRegMatcher>(M)->DestPhysReg == DestPhysReg;
857 }
858 virtual unsigned getHashImpl() const {
859 return SrcSlot ^ ((unsigned)(intptr_t)DestPhysReg << 4);
860 }
Chris Lattner3163ca52010-02-21 03:22:59 +0000861};
862
863
864
Chris Lattner9a515172010-02-25 02:04:40 +0000865/// EmitNodeXFormMatcher - Emit an operation that runs an SDNodeXForm on a
Chris Lattner3163ca52010-02-21 03:22:59 +0000866/// recorded node and records the result.
Chris Lattner9a515172010-02-25 02:04:40 +0000867class EmitNodeXFormMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000868 unsigned Slot;
869 Record *NodeXForm;
870public:
Chris Lattner9a515172010-02-25 02:04:40 +0000871 EmitNodeXFormMatcher(unsigned slot, Record *nodeXForm)
872 : Matcher(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000873
874 unsigned getSlot() const { return Slot; }
875 Record *getNodeXForm() const { return NodeXForm; }
876
Chris Lattner9a515172010-02-25 02:04:40 +0000877 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000878 return N->getKind() == EmitNodeXForm;
879 }
880
Chris Lattner136ab782010-02-25 06:49:58 +0000881private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000882 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000883 virtual bool isEqualImpl(const Matcher *M) const {
884 return cast<EmitNodeXFormMatcher>(M)->Slot == Slot &&
885 cast<EmitNodeXFormMatcher>(M)->NodeXForm == NodeXForm;
886 }
887 virtual unsigned getHashImpl() const {
888 return Slot ^ ((unsigned)(intptr_t)NodeXForm << 4);
889 }
Chris Lattner3163ca52010-02-21 03:22:59 +0000890};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000891
Chris Lattner7a1dab42010-02-28 02:31:26 +0000892/// EmitNodeMatcherCommon - Common class shared between EmitNode and
Chris Lattner7dae4af2010-02-28 20:55:18 +0000893/// MorphNodeTo.
Chris Lattner7a1dab42010-02-28 02:31:26 +0000894class EmitNodeMatcherCommon : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000895 std::string OpcodeName;
896 const SmallVector<MVT::SimpleValueType, 3> VTs;
897 const SmallVector<unsigned, 6> Operands;
Chris Lattner414bac82010-02-28 21:53:42 +0000898 bool HasChain, HasInFlag, HasOutFlag, HasMemRefs;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000899
Chris Lattner3163ca52010-02-21 03:22:59 +0000900 /// NumFixedArityOperands - If this is a fixed arity node, this is set to -1.
901 /// If this is a varidic node, this is set to the number of fixed arity
902 /// operands in the root of the pattern. The rest are appended to this node.
903 int NumFixedArityOperands;
904public:
Chris Lattner7a1dab42010-02-28 02:31:26 +0000905 EmitNodeMatcherCommon(const std::string &opcodeName,
906 const MVT::SimpleValueType *vts, unsigned numvts,
907 const unsigned *operands, unsigned numops,
Chris Lattner414bac82010-02-28 21:53:42 +0000908 bool hasChain, bool hasInFlag, bool hasOutFlag,
909 bool hasmemrefs,
Chris Lattner7dae4af2010-02-28 20:55:18 +0000910 int numfixedarityoperands, bool isMorphNodeTo)
911 : Matcher(isMorphNodeTo ? MorphNodeTo : EmitNode), OpcodeName(opcodeName),
Chris Lattner3163ca52010-02-21 03:22:59 +0000912 VTs(vts, vts+numvts), Operands(operands, operands+numops),
Chris Lattner414bac82010-02-28 21:53:42 +0000913 HasChain(hasChain), HasInFlag(hasInFlag), HasOutFlag(hasOutFlag),
914 HasMemRefs(hasmemrefs), NumFixedArityOperands(numfixedarityoperands) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000915
916 const std::string &getOpcodeName() const { return OpcodeName; }
917
918 unsigned getNumVTs() const { return VTs.size(); }
919 MVT::SimpleValueType getVT(unsigned i) const {
920 assert(i < VTs.size());
921 return VTs[i];
922 }
Chris Lattner5cc7a832010-02-28 20:49:53 +0000923
Chris Lattner3163ca52010-02-21 03:22:59 +0000924 unsigned getNumOperands() const { return Operands.size(); }
925 unsigned getOperand(unsigned i) const {
926 assert(i < Operands.size());
927 return Operands[i];
Chris Lattner5cc7a832010-02-28 20:49:53 +0000928 }
929
930 const SmallVectorImpl<MVT::SimpleValueType> &getVTList() const { return VTs; }
931 const SmallVectorImpl<unsigned> &getOperandList() const { return Operands; }
932
Chris Lattner3163ca52010-02-21 03:22:59 +0000933
934 bool hasChain() const { return HasChain; }
Chris Lattner414bac82010-02-28 21:53:42 +0000935 bool hasInFlag() const { return HasInFlag; }
936 bool hasOutFlag() const { return HasOutFlag; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000937 bool hasMemRefs() const { return HasMemRefs; }
938 int getNumFixedArityOperands() const { return NumFixedArityOperands; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000939
Chris Lattner9a515172010-02-25 02:04:40 +0000940 static inline bool classof(const Matcher *N) {
Chris Lattner7dae4af2010-02-28 20:55:18 +0000941 return N->getKind() == EmitNode || N->getKind() == MorphNodeTo;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000942 }
943
Chris Lattner136ab782010-02-25 06:49:58 +0000944private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000945 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000946 virtual bool isEqualImpl(const Matcher *M) const;
947 virtual unsigned getHashImpl() const;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000948};
Chris Lattnerb085ea12010-02-21 06:03:07 +0000949
Chris Lattner7a1dab42010-02-28 02:31:26 +0000950/// EmitNodeMatcher - This signals a successful match and generates a node.
951class EmitNodeMatcher : public EmitNodeMatcherCommon {
Chris Lattner19a1fbe2010-02-28 02:41:25 +0000952 unsigned FirstResultSlot;
Chris Lattner7a1dab42010-02-28 02:31:26 +0000953public:
954 EmitNodeMatcher(const std::string &opcodeName,
955 const MVT::SimpleValueType *vts, unsigned numvts,
956 const unsigned *operands, unsigned numops,
Chris Lattner414bac82010-02-28 21:53:42 +0000957 bool hasChain, bool hasInFlag, bool hasOutFlag,
958 bool hasmemrefs,
Chris Lattner19a1fbe2010-02-28 02:41:25 +0000959 int numfixedarityoperands, unsigned firstresultslot)
Chris Lattner7a1dab42010-02-28 02:31:26 +0000960 : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
Chris Lattner414bac82010-02-28 21:53:42 +0000961 hasInFlag, hasOutFlag, hasmemrefs,
962 numfixedarityoperands, false),
Chris Lattner19a1fbe2010-02-28 02:41:25 +0000963 FirstResultSlot(firstresultslot) {}
964
965 unsigned getFirstResultSlot() const { return FirstResultSlot; }
Chris Lattner7a1dab42010-02-28 02:31:26 +0000966
967 static inline bool classof(const Matcher *N) {
968 return N->getKind() == EmitNode;
969 }
970
971};
972
Chris Lattner7dae4af2010-02-28 20:55:18 +0000973class MorphNodeToMatcher : public EmitNodeMatcherCommon {
Chris Lattner7a1dab42010-02-28 02:31:26 +0000974 const PatternToMatch &Pattern;
975public:
Chris Lattner7dae4af2010-02-28 20:55:18 +0000976 MorphNodeToMatcher(const std::string &opcodeName,
977 const MVT::SimpleValueType *vts, unsigned numvts,
978 const unsigned *operands, unsigned numops,
Chris Lattner414bac82010-02-28 21:53:42 +0000979 bool hasChain, bool hasInFlag, bool hasOutFlag,
980 bool hasmemrefs,
Chris Lattner7dae4af2010-02-28 20:55:18 +0000981 int numfixedarityoperands, const PatternToMatch &pattern)
Chris Lattner7a1dab42010-02-28 02:31:26 +0000982 : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
Chris Lattner414bac82010-02-28 21:53:42 +0000983 hasInFlag, hasOutFlag, hasmemrefs,
984 numfixedarityoperands, true),
Chris Lattner7a1dab42010-02-28 02:31:26 +0000985 Pattern(pattern) {
986 }
987
988 const PatternToMatch &getPattern() const { return Pattern; }
989
990 static inline bool classof(const Matcher *N) {
Chris Lattner7dae4af2010-02-28 20:55:18 +0000991 return N->getKind() == MorphNodeTo;
Chris Lattner7a1dab42010-02-28 02:31:26 +0000992 }
993};
994
Chris Lattner9a515172010-02-25 02:04:40 +0000995/// MarkFlagResultsMatcher - This node indicates which non-root nodes in the
996/// pattern produce flags. This allows CompleteMatchMatcher to update them
Chris Lattner69f60c82010-02-24 05:33:42 +0000997/// with the output flag of the resultant code.
Chris Lattner9a515172010-02-25 02:04:40 +0000998class MarkFlagResultsMatcher : public Matcher {
Chris Lattner69f60c82010-02-24 05:33:42 +0000999 SmallVector<unsigned, 3> FlagResultNodes;
1000public:
Chris Lattner9a515172010-02-25 02:04:40 +00001001 MarkFlagResultsMatcher(const unsigned *nodes, unsigned NumNodes)
1002 : Matcher(MarkFlagResults), FlagResultNodes(nodes, nodes+NumNodes) {}
Chris Lattner69f60c82010-02-24 05:33:42 +00001003
1004 unsigned getNumNodes() const { return FlagResultNodes.size(); }
1005
1006 unsigned getNode(unsigned i) const {
1007 assert(i < FlagResultNodes.size());
1008 return FlagResultNodes[i];
1009 }
1010
Chris Lattner9a515172010-02-25 02:04:40 +00001011 static inline bool classof(const Matcher *N) {
Chris Lattner69f60c82010-02-24 05:33:42 +00001012 return N->getKind() == MarkFlagResults;
1013 }
1014
Chris Lattner136ab782010-02-25 06:49:58 +00001015private:
Chris Lattner392b1bf2010-02-25 06:53:39 +00001016 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +00001017 virtual bool isEqualImpl(const Matcher *M) const {
1018 return cast<MarkFlagResultsMatcher>(M)->FlagResultNodes == FlagResultNodes;
1019 }
1020 virtual unsigned getHashImpl() const;
Chris Lattner69f60c82010-02-24 05:33:42 +00001021};
1022
Chris Lattner9a515172010-02-25 02:04:40 +00001023/// CompleteMatchMatcher - Complete a match by replacing the results of the
Chris Lattnerb085ea12010-02-21 06:03:07 +00001024/// pattern with the newly generated nodes. This also prints a comment
1025/// indicating the source and dest patterns.
Chris Lattner9a515172010-02-25 02:04:40 +00001026class CompleteMatchMatcher : public Matcher {
Chris Lattnerb085ea12010-02-21 06:03:07 +00001027 SmallVector<unsigned, 2> Results;
Chris Lattner3163ca52010-02-21 03:22:59 +00001028 const PatternToMatch &Pattern;
1029public:
Chris Lattner9a515172010-02-25 02:04:40 +00001030 CompleteMatchMatcher(const unsigned *results, unsigned numresults,
Chris Lattner5cc7a832010-02-28 20:49:53 +00001031 const PatternToMatch &pattern)
Chris Lattner9a515172010-02-25 02:04:40 +00001032 : Matcher(CompleteMatch), Results(results, results+numresults),
Chris Lattnerb085ea12010-02-21 06:03:07 +00001033 Pattern(pattern) {}
1034
1035 unsigned getNumResults() const { return Results.size(); }
1036 unsigned getResult(unsigned R) const { return Results[R]; }
Chris Lattner3163ca52010-02-21 03:22:59 +00001037 const PatternToMatch &getPattern() const { return Pattern; }
1038
Chris Lattner9a515172010-02-25 02:04:40 +00001039 static inline bool classof(const Matcher *N) {
Chris Lattnerb085ea12010-02-21 06:03:07 +00001040 return N->getKind() == CompleteMatch;
Chris Lattner3163ca52010-02-21 03:22:59 +00001041 }
1042
Chris Lattner136ab782010-02-25 06:49:58 +00001043private:
Chris Lattner392b1bf2010-02-25 06:53:39 +00001044 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +00001045 virtual bool isEqualImpl(const Matcher *M) const {
1046 return cast<CompleteMatchMatcher>(M)->Results == Results &&
1047 &cast<CompleteMatchMatcher>(M)->Pattern == &Pattern;
1048 }
1049 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +00001050};
Chris Lattner7a1dab42010-02-28 02:31:26 +00001051
Chris Lattnere7d6e3c2010-02-15 08:04:42 +00001052} // end namespace llvm
1053
1054#endif