blob: c2e81711e085d45601a10ea53411c1bbb714e5a4 [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;
612public:
Chris Lattner9a515172010-02-25 02:04:40 +0000613 CheckComplexPatMatcher(const ComplexPattern &pattern)
614 : Matcher(CheckComplexPat), Pattern(pattern) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000615
Chris Lattnerdc429fd2010-02-17 00:31:50 +0000616 const ComplexPattern &getPattern() const { return Pattern; }
617
Chris Lattner9a515172010-02-25 02:04:40 +0000618 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000619 return N->getKind() == CheckComplexPat;
620 }
621
Chris Lattnerf4950d02010-02-27 06:22:57 +0000622 // Not safe to move a pattern predicate past a complex pattern.
623 virtual bool isSafeToReorderWithPatternPredicate() const { return false; }
624
Chris Lattner136ab782010-02-25 06:49:58 +0000625private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000626 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000627 virtual bool isEqualImpl(const Matcher *M) const {
628 return &cast<CheckComplexPatMatcher>(M)->Pattern == &Pattern;
629 }
630 virtual unsigned getHashImpl() const {
631 return (unsigned)(intptr_t)&Pattern;
632 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000633};
634
Chris Lattner9a515172010-02-25 02:04:40 +0000635/// CheckAndImmMatcher - This checks to see if the current node is an 'and'
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000636/// with something equivalent to the specified immediate.
Chris Lattner9a515172010-02-25 02:04:40 +0000637class CheckAndImmMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000638 int64_t Value;
639public:
Chris Lattner9a515172010-02-25 02:04:40 +0000640 CheckAndImmMatcher(int64_t value)
641 : Matcher(CheckAndImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000642
643 int64_t getValue() const { return Value; }
644
Chris Lattner9a515172010-02-25 02:04:40 +0000645 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000646 return N->getKind() == CheckAndImm;
647 }
648
Chris Lattnerf4950d02010-02-27 06:22:57 +0000649 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
650
Chris Lattner136ab782010-02-25 06:49:58 +0000651private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000652 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000653 virtual bool isEqualImpl(const Matcher *M) const {
654 return cast<CheckAndImmMatcher>(M)->Value == Value;
655 }
656 virtual unsigned getHashImpl() const { return Value; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000657};
658
Chris Lattner9a515172010-02-25 02:04:40 +0000659/// CheckOrImmMatcher - This checks to see if the current node is an 'and'
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000660/// with something equivalent to the specified immediate.
Chris Lattner9a515172010-02-25 02:04:40 +0000661class CheckOrImmMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000662 int64_t Value;
663public:
Chris Lattner9a515172010-02-25 02:04:40 +0000664 CheckOrImmMatcher(int64_t value)
665 : Matcher(CheckOrImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000666
667 int64_t getValue() const { return Value; }
668
Chris Lattner9a515172010-02-25 02:04:40 +0000669 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000670 return N->getKind() == CheckOrImm;
671 }
672
Chris Lattnerf4950d02010-02-27 06:22:57 +0000673 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
674
Chris Lattner136ab782010-02-25 06:49:58 +0000675private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000676 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000677 virtual bool isEqualImpl(const Matcher *M) const {
678 return cast<CheckOrImmMatcher>(M)->Value == Value;
679 }
680 virtual unsigned getHashImpl() const { return Value; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000681};
Chris Lattner9de39482010-02-16 06:10:58 +0000682
Chris Lattner9a515172010-02-25 02:04:40 +0000683/// CheckFoldableChainNodeMatcher - This checks to see if the current node
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000684/// (which defines a chain operand) is safe to fold into a larger pattern.
Chris Lattner9a515172010-02-25 02:04:40 +0000685class CheckFoldableChainNodeMatcher : public Matcher {
Chris Lattner9de39482010-02-16 06:10:58 +0000686public:
Chris Lattner9a515172010-02-25 02:04:40 +0000687 CheckFoldableChainNodeMatcher()
688 : Matcher(CheckFoldableChainNode) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000689
Chris Lattner9a515172010-02-25 02:04:40 +0000690 static inline bool classof(const Matcher *N) {
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000691 return N->getKind() == CheckFoldableChainNode;
Chris Lattner9de39482010-02-16 06:10:58 +0000692 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000693
Chris Lattnerf4950d02010-02-27 06:22:57 +0000694 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
695
Chris Lattner136ab782010-02-25 06:49:58 +0000696private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000697 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000698 virtual bool isEqualImpl(const Matcher *M) const { return true; }
699 virtual unsigned getHashImpl() const { return 0; }
Chris Lattner9de39482010-02-16 06:10:58 +0000700};
701
Chris Lattner9a515172010-02-25 02:04:40 +0000702/// EmitIntegerMatcher - This creates a new TargetConstant.
703class EmitIntegerMatcher : public Matcher {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000704 int64_t Val;
705 MVT::SimpleValueType VT;
706public:
Chris Lattner9a515172010-02-25 02:04:40 +0000707 EmitIntegerMatcher(int64_t val, MVT::SimpleValueType vt)
708 : Matcher(EmitInteger), Val(val), VT(vt) {}
Chris Lattner283adcb2010-02-17 06:23:39 +0000709
Chris Lattner7043e0a2010-02-19 07:49:56 +0000710 int64_t getValue() const { return Val; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000711 MVT::SimpleValueType getVT() const { return VT; }
712
Chris Lattner9a515172010-02-25 02:04:40 +0000713 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000714 return N->getKind() == EmitInteger;
715 }
716
Chris Lattner136ab782010-02-25 06:49:58 +0000717private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000718 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000719 virtual bool isEqualImpl(const Matcher *M) const {
720 return cast<EmitIntegerMatcher>(M)->Val == Val &&
721 cast<EmitIntegerMatcher>(M)->VT == VT;
722 }
723 virtual unsigned getHashImpl() const { return (Val << 4) | VT; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000724};
Chris Lattner3163ca52010-02-21 03:22:59 +0000725
Chris Lattner9a515172010-02-25 02:04:40 +0000726/// EmitStringIntegerMatcher - A target constant whose value is represented
Chris Lattner3163ca52010-02-21 03:22:59 +0000727/// by a string.
Chris Lattner9a515172010-02-25 02:04:40 +0000728class EmitStringIntegerMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000729 std::string Val;
730 MVT::SimpleValueType VT;
731public:
Chris Lattner9a515172010-02-25 02:04:40 +0000732 EmitStringIntegerMatcher(const std::string &val, MVT::SimpleValueType vt)
733 : Matcher(EmitStringInteger), Val(val), VT(vt) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000734
735 const std::string &getValue() const { return Val; }
736 MVT::SimpleValueType getVT() const { return VT; }
737
Chris Lattner9a515172010-02-25 02:04:40 +0000738 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000739 return N->getKind() == EmitStringInteger;
740 }
741
Chris Lattner136ab782010-02-25 06:49:58 +0000742private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000743 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000744 virtual bool isEqualImpl(const Matcher *M) const {
745 return cast<EmitStringIntegerMatcher>(M)->Val == Val &&
746 cast<EmitStringIntegerMatcher>(M)->VT == VT;
747 }
748 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +0000749};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000750
Chris Lattner9a515172010-02-25 02:04:40 +0000751/// EmitRegisterMatcher - This creates a new TargetConstant.
752class EmitRegisterMatcher : public Matcher {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000753 /// Reg - The def for the register that we're emitting. If this is null, then
754 /// this is a reference to zero_reg.
755 Record *Reg;
756 MVT::SimpleValueType VT;
757public:
Chris Lattner9a515172010-02-25 02:04:40 +0000758 EmitRegisterMatcher(Record *reg, MVT::SimpleValueType vt)
759 : Matcher(EmitRegister), Reg(reg), VT(vt) {}
Chris Lattnerddfb5222010-02-18 22:03:03 +0000760
761 Record *getReg() const { return Reg; }
762 MVT::SimpleValueType getVT() const { return VT; }
763
Chris Lattner9a515172010-02-25 02:04:40 +0000764 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000765 return N->getKind() == EmitRegister;
766 }
767
Chris Lattner136ab782010-02-25 06:49:58 +0000768private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000769 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000770 virtual bool isEqualImpl(const Matcher *M) const {
771 return cast<EmitRegisterMatcher>(M)->Reg == Reg &&
772 cast<EmitRegisterMatcher>(M)->VT == VT;
773 }
774 virtual unsigned getHashImpl() const {
775 return ((unsigned)(intptr_t)Reg) << 4 | VT;
776 }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000777};
Chris Lattner3163ca52010-02-21 03:22:59 +0000778
Chris Lattner9a515172010-02-25 02:04:40 +0000779/// EmitConvertToTargetMatcher - Emit an operation that reads a specified
Chris Lattner3163ca52010-02-21 03:22:59 +0000780/// recorded node and converts it from being a ISD::Constant to
781/// ISD::TargetConstant, likewise for ConstantFP.
Chris Lattner9a515172010-02-25 02:04:40 +0000782class EmitConvertToTargetMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000783 unsigned Slot;
784public:
Chris Lattner9a515172010-02-25 02:04:40 +0000785 EmitConvertToTargetMatcher(unsigned slot)
786 : Matcher(EmitConvertToTarget), Slot(slot) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000787
788 unsigned getSlot() const { return Slot; }
789
Chris Lattner9a515172010-02-25 02:04:40 +0000790 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000791 return N->getKind() == EmitConvertToTarget;
792 }
793
Chris Lattner136ab782010-02-25 06:49:58 +0000794private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000795 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000796 virtual bool isEqualImpl(const Matcher *M) const {
797 return cast<EmitConvertToTargetMatcher>(M)->Slot == Slot;
798 }
799 virtual unsigned getHashImpl() const { return Slot; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000800};
801
Chris Lattner9a515172010-02-25 02:04:40 +0000802/// EmitMergeInputChainsMatcher - Emit a node that merges a list of input
Chris Lattner3163ca52010-02-21 03:22:59 +0000803/// chains together with a token factor. The list of nodes are the nodes in the
804/// matched pattern that have chain input/outputs. This node adds all input
805/// chains of these nodes if they are not themselves a node in the pattern.
Chris Lattner9a515172010-02-25 02:04:40 +0000806class EmitMergeInputChainsMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000807 SmallVector<unsigned, 3> ChainNodes;
808public:
Chris Lattner9a515172010-02-25 02:04:40 +0000809 EmitMergeInputChainsMatcher(const unsigned *nodes, unsigned NumNodes)
810 : Matcher(EmitMergeInputChains), ChainNodes(nodes, nodes+NumNodes) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000811
812 unsigned getNumNodes() const { return ChainNodes.size(); }
813
814 unsigned getNode(unsigned i) const {
815 assert(i < ChainNodes.size());
816 return ChainNodes[i];
817 }
818
Chris Lattner9a515172010-02-25 02:04:40 +0000819 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000820 return N->getKind() == EmitMergeInputChains;
821 }
822
Chris Lattner136ab782010-02-25 06:49:58 +0000823private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000824 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000825 virtual bool isEqualImpl(const Matcher *M) const {
826 return cast<EmitMergeInputChainsMatcher>(M)->ChainNodes == ChainNodes;
827 }
828 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +0000829};
830
Chris Lattner9a515172010-02-25 02:04:40 +0000831/// EmitCopyToRegMatcher - Emit a CopyToReg node from a value to a physreg,
Chris Lattner3163ca52010-02-21 03:22:59 +0000832/// pushing the chain and flag results.
833///
Chris Lattner9a515172010-02-25 02:04:40 +0000834class EmitCopyToRegMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000835 unsigned SrcSlot; // Value to copy into the physreg.
836 Record *DestPhysReg;
837public:
Chris Lattner9a515172010-02-25 02:04:40 +0000838 EmitCopyToRegMatcher(unsigned srcSlot, Record *destPhysReg)
839 : Matcher(EmitCopyToReg), SrcSlot(srcSlot), DestPhysReg(destPhysReg) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000840
841 unsigned getSrcSlot() const { return SrcSlot; }
842 Record *getDestPhysReg() const { return DestPhysReg; }
843
Chris Lattner9a515172010-02-25 02:04:40 +0000844 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000845 return N->getKind() == EmitCopyToReg;
846 }
847
Chris Lattner136ab782010-02-25 06:49:58 +0000848private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000849 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000850 virtual bool isEqualImpl(const Matcher *M) const {
851 return cast<EmitCopyToRegMatcher>(M)->SrcSlot == SrcSlot &&
852 cast<EmitCopyToRegMatcher>(M)->DestPhysReg == DestPhysReg;
853 }
854 virtual unsigned getHashImpl() const {
855 return SrcSlot ^ ((unsigned)(intptr_t)DestPhysReg << 4);
856 }
Chris Lattner3163ca52010-02-21 03:22:59 +0000857};
858
859
860
Chris Lattner9a515172010-02-25 02:04:40 +0000861/// EmitNodeXFormMatcher - Emit an operation that runs an SDNodeXForm on a
Chris Lattner3163ca52010-02-21 03:22:59 +0000862/// recorded node and records the result.
Chris Lattner9a515172010-02-25 02:04:40 +0000863class EmitNodeXFormMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000864 unsigned Slot;
865 Record *NodeXForm;
866public:
Chris Lattner9a515172010-02-25 02:04:40 +0000867 EmitNodeXFormMatcher(unsigned slot, Record *nodeXForm)
868 : Matcher(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000869
870 unsigned getSlot() const { return Slot; }
871 Record *getNodeXForm() const { return NodeXForm; }
872
Chris Lattner9a515172010-02-25 02:04:40 +0000873 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000874 return N->getKind() == EmitNodeXForm;
875 }
876
Chris Lattner136ab782010-02-25 06:49:58 +0000877private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000878 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000879 virtual bool isEqualImpl(const Matcher *M) const {
880 return cast<EmitNodeXFormMatcher>(M)->Slot == Slot &&
881 cast<EmitNodeXFormMatcher>(M)->NodeXForm == NodeXForm;
882 }
883 virtual unsigned getHashImpl() const {
884 return Slot ^ ((unsigned)(intptr_t)NodeXForm << 4);
885 }
Chris Lattner3163ca52010-02-21 03:22:59 +0000886};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000887
Chris Lattner7a1dab42010-02-28 02:31:26 +0000888/// EmitNodeMatcherCommon - Common class shared between EmitNode and
Chris Lattner7dae4af2010-02-28 20:55:18 +0000889/// MorphNodeTo.
Chris Lattner7a1dab42010-02-28 02:31:26 +0000890class EmitNodeMatcherCommon : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000891 std::string OpcodeName;
892 const SmallVector<MVT::SimpleValueType, 3> VTs;
893 const SmallVector<unsigned, 6> Operands;
Chris Lattner414bac82010-02-28 21:53:42 +0000894 bool HasChain, HasInFlag, HasOutFlag, HasMemRefs;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000895
Chris Lattner3163ca52010-02-21 03:22:59 +0000896 /// NumFixedArityOperands - If this is a fixed arity node, this is set to -1.
897 /// If this is a varidic node, this is set to the number of fixed arity
898 /// operands in the root of the pattern. The rest are appended to this node.
899 int NumFixedArityOperands;
900public:
Chris Lattner7a1dab42010-02-28 02:31:26 +0000901 EmitNodeMatcherCommon(const std::string &opcodeName,
902 const MVT::SimpleValueType *vts, unsigned numvts,
903 const unsigned *operands, unsigned numops,
Chris Lattner414bac82010-02-28 21:53:42 +0000904 bool hasChain, bool hasInFlag, bool hasOutFlag,
905 bool hasmemrefs,
Chris Lattner7dae4af2010-02-28 20:55:18 +0000906 int numfixedarityoperands, bool isMorphNodeTo)
907 : Matcher(isMorphNodeTo ? MorphNodeTo : EmitNode), OpcodeName(opcodeName),
Chris Lattner3163ca52010-02-21 03:22:59 +0000908 VTs(vts, vts+numvts), Operands(operands, operands+numops),
Chris Lattner414bac82010-02-28 21:53:42 +0000909 HasChain(hasChain), HasInFlag(hasInFlag), HasOutFlag(hasOutFlag),
910 HasMemRefs(hasmemrefs), NumFixedArityOperands(numfixedarityoperands) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000911
912 const std::string &getOpcodeName() const { return OpcodeName; }
913
914 unsigned getNumVTs() const { return VTs.size(); }
915 MVT::SimpleValueType getVT(unsigned i) const {
916 assert(i < VTs.size());
917 return VTs[i];
918 }
Chris Lattner5cc7a832010-02-28 20:49:53 +0000919
Chris Lattner3163ca52010-02-21 03:22:59 +0000920 unsigned getNumOperands() const { return Operands.size(); }
921 unsigned getOperand(unsigned i) const {
922 assert(i < Operands.size());
923 return Operands[i];
Chris Lattner5cc7a832010-02-28 20:49:53 +0000924 }
925
926 const SmallVectorImpl<MVT::SimpleValueType> &getVTList() const { return VTs; }
927 const SmallVectorImpl<unsigned> &getOperandList() const { return Operands; }
928
Chris Lattner3163ca52010-02-21 03:22:59 +0000929
930 bool hasChain() const { return HasChain; }
Chris Lattner414bac82010-02-28 21:53:42 +0000931 bool hasInFlag() const { return HasInFlag; }
932 bool hasOutFlag() const { return HasOutFlag; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000933 bool hasMemRefs() const { return HasMemRefs; }
934 int getNumFixedArityOperands() const { return NumFixedArityOperands; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000935
Chris Lattner9a515172010-02-25 02:04:40 +0000936 static inline bool classof(const Matcher *N) {
Chris Lattner7dae4af2010-02-28 20:55:18 +0000937 return N->getKind() == EmitNode || N->getKind() == MorphNodeTo;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000938 }
939
Chris Lattner136ab782010-02-25 06:49:58 +0000940private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000941 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000942 virtual bool isEqualImpl(const Matcher *M) const;
943 virtual unsigned getHashImpl() const;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000944};
Chris Lattnerb085ea12010-02-21 06:03:07 +0000945
Chris Lattner7a1dab42010-02-28 02:31:26 +0000946/// EmitNodeMatcher - This signals a successful match and generates a node.
947class EmitNodeMatcher : public EmitNodeMatcherCommon {
Chris Lattner19a1fbe2010-02-28 02:41:25 +0000948 unsigned FirstResultSlot;
Chris Lattner7a1dab42010-02-28 02:31:26 +0000949public:
950 EmitNodeMatcher(const std::string &opcodeName,
951 const MVT::SimpleValueType *vts, unsigned numvts,
952 const unsigned *operands, unsigned numops,
Chris Lattner414bac82010-02-28 21:53:42 +0000953 bool hasChain, bool hasInFlag, bool hasOutFlag,
954 bool hasmemrefs,
Chris Lattner19a1fbe2010-02-28 02:41:25 +0000955 int numfixedarityoperands, unsigned firstresultslot)
Chris Lattner7a1dab42010-02-28 02:31:26 +0000956 : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
Chris Lattner414bac82010-02-28 21:53:42 +0000957 hasInFlag, hasOutFlag, hasmemrefs,
958 numfixedarityoperands, false),
Chris Lattner19a1fbe2010-02-28 02:41:25 +0000959 FirstResultSlot(firstresultslot) {}
960
961 unsigned getFirstResultSlot() const { return FirstResultSlot; }
Chris Lattner7a1dab42010-02-28 02:31:26 +0000962
963 static inline bool classof(const Matcher *N) {
964 return N->getKind() == EmitNode;
965 }
966
967};
968
Chris Lattner7dae4af2010-02-28 20:55:18 +0000969class MorphNodeToMatcher : public EmitNodeMatcherCommon {
Chris Lattner7a1dab42010-02-28 02:31:26 +0000970 const PatternToMatch &Pattern;
971public:
Chris Lattner7dae4af2010-02-28 20:55:18 +0000972 MorphNodeToMatcher(const std::string &opcodeName,
973 const MVT::SimpleValueType *vts, unsigned numvts,
974 const unsigned *operands, unsigned numops,
Chris Lattner414bac82010-02-28 21:53:42 +0000975 bool hasChain, bool hasInFlag, bool hasOutFlag,
976 bool hasmemrefs,
Chris Lattner7dae4af2010-02-28 20:55:18 +0000977 int numfixedarityoperands, const PatternToMatch &pattern)
Chris Lattner7a1dab42010-02-28 02:31:26 +0000978 : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
Chris Lattner414bac82010-02-28 21:53:42 +0000979 hasInFlag, hasOutFlag, hasmemrefs,
980 numfixedarityoperands, true),
Chris Lattner7a1dab42010-02-28 02:31:26 +0000981 Pattern(pattern) {
982 }
983
984 const PatternToMatch &getPattern() const { return Pattern; }
985
986 static inline bool classof(const Matcher *N) {
Chris Lattner7dae4af2010-02-28 20:55:18 +0000987 return N->getKind() == MorphNodeTo;
Chris Lattner7a1dab42010-02-28 02:31:26 +0000988 }
989};
990
Chris Lattner9a515172010-02-25 02:04:40 +0000991/// MarkFlagResultsMatcher - This node indicates which non-root nodes in the
992/// pattern produce flags. This allows CompleteMatchMatcher to update them
Chris Lattner69f60c82010-02-24 05:33:42 +0000993/// with the output flag of the resultant code.
Chris Lattner9a515172010-02-25 02:04:40 +0000994class MarkFlagResultsMatcher : public Matcher {
Chris Lattner69f60c82010-02-24 05:33:42 +0000995 SmallVector<unsigned, 3> FlagResultNodes;
996public:
Chris Lattner9a515172010-02-25 02:04:40 +0000997 MarkFlagResultsMatcher(const unsigned *nodes, unsigned NumNodes)
998 : Matcher(MarkFlagResults), FlagResultNodes(nodes, nodes+NumNodes) {}
Chris Lattner69f60c82010-02-24 05:33:42 +0000999
1000 unsigned getNumNodes() const { return FlagResultNodes.size(); }
1001
1002 unsigned getNode(unsigned i) const {
1003 assert(i < FlagResultNodes.size());
1004 return FlagResultNodes[i];
1005 }
1006
Chris Lattner9a515172010-02-25 02:04:40 +00001007 static inline bool classof(const Matcher *N) {
Chris Lattner69f60c82010-02-24 05:33:42 +00001008 return N->getKind() == MarkFlagResults;
1009 }
1010
Chris Lattner136ab782010-02-25 06:49:58 +00001011private:
Chris Lattner392b1bf2010-02-25 06:53:39 +00001012 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +00001013 virtual bool isEqualImpl(const Matcher *M) const {
1014 return cast<MarkFlagResultsMatcher>(M)->FlagResultNodes == FlagResultNodes;
1015 }
1016 virtual unsigned getHashImpl() const;
Chris Lattner69f60c82010-02-24 05:33:42 +00001017};
1018
Chris Lattner9a515172010-02-25 02:04:40 +00001019/// CompleteMatchMatcher - Complete a match by replacing the results of the
Chris Lattnerb085ea12010-02-21 06:03:07 +00001020/// pattern with the newly generated nodes. This also prints a comment
1021/// indicating the source and dest patterns.
Chris Lattner9a515172010-02-25 02:04:40 +00001022class CompleteMatchMatcher : public Matcher {
Chris Lattnerb085ea12010-02-21 06:03:07 +00001023 SmallVector<unsigned, 2> Results;
Chris Lattner3163ca52010-02-21 03:22:59 +00001024 const PatternToMatch &Pattern;
1025public:
Chris Lattner9a515172010-02-25 02:04:40 +00001026 CompleteMatchMatcher(const unsigned *results, unsigned numresults,
Chris Lattner5cc7a832010-02-28 20:49:53 +00001027 const PatternToMatch &pattern)
Chris Lattner9a515172010-02-25 02:04:40 +00001028 : Matcher(CompleteMatch), Results(results, results+numresults),
Chris Lattnerb085ea12010-02-21 06:03:07 +00001029 Pattern(pattern) {}
1030
1031 unsigned getNumResults() const { return Results.size(); }
1032 unsigned getResult(unsigned R) const { return Results[R]; }
Chris Lattner3163ca52010-02-21 03:22:59 +00001033 const PatternToMatch &getPattern() const { return Pattern; }
1034
Chris Lattner9a515172010-02-25 02:04:40 +00001035 static inline bool classof(const Matcher *N) {
Chris Lattnerb085ea12010-02-21 06:03:07 +00001036 return N->getKind() == CompleteMatch;
Chris Lattner3163ca52010-02-21 03:22:59 +00001037 }
1038
Chris Lattner136ab782010-02-25 06:49:58 +00001039private:
Chris Lattner392b1bf2010-02-25 06:53:39 +00001040 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +00001041 virtual bool isEqualImpl(const Matcher *M) const {
1042 return cast<CompleteMatchMatcher>(M)->Results == Results &&
1043 &cast<CompleteMatchMatcher>(M)->Pattern == &Pattern;
1044 }
1045 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +00001046};
Chris Lattner7a1dab42010-02-28 02:31:26 +00001047
Chris Lattnere7d6e3c2010-02-15 08:04:42 +00001048} // end namespace llvm
1049
1050#endif