blob: 8b6b32291429899381441e6a70b6b0929ca18b15 [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 Lattnerf58c08e2010-02-22 22:30:37 +000058 CheckMultiOpcode, // Fail if not in opcode list.
Chris Lattner3163ca52010-02-21 03:22:59 +000059 CheckType, // Fail if not correct 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 CheckChainCompatible,
69
70 // Node creation/emisssion.
Chris Lattner3163ca52010-02-21 03:22:59 +000071 EmitInteger, // Create a TargetConstant
72 EmitStringInteger, // Create a TargetConstant from a string.
73 EmitRegister, // Create a register.
74 EmitConvertToTarget, // Convert a imm/fpimm to target imm/fpimm
75 EmitMergeInputChains, // Merge together a chains for an input.
76 EmitCopyToReg, // Emit a copytoreg into a physreg.
77 EmitNode, // Create a DAG node
78 EmitNodeXForm, // Run a SDNodeXForm
Chris Lattner69f60c82010-02-24 05:33:42 +000079 MarkFlagResults, // Indicate which interior nodes have flag results.
Chris Lattner7a1dab42010-02-28 02:31:26 +000080 CompleteMatch, // Finish a match and update the results.
Chris Lattner7dae4af2010-02-28 20:55:18 +000081 MorphNodeTo // Build a node, finish a match and update results.
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000082 };
83 const KindTy Kind;
Chris Lattner3b31c982010-02-18 02:49:24 +000084
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000085protected:
Chris Lattner9a515172010-02-25 02:04:40 +000086 Matcher(KindTy K) : Kind(K) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000087public:
Chris Lattner9a515172010-02-25 02:04:40 +000088 virtual ~Matcher() {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000089
90 KindTy getKind() const { return Kind; }
Chris Lattner3b31c982010-02-18 02:49:24 +000091
Chris Lattner9a515172010-02-25 02:04:40 +000092 Matcher *getNext() { return Next.get(); }
93 const Matcher *getNext() const { return Next.get(); }
94 void setNext(Matcher *C) { Next.reset(C); }
95 Matcher *takeNext() { return Next.take(); }
Chris Lattner3ee1bc42010-02-24 07:31:45 +000096
Chris Lattner9a515172010-02-25 02:04:40 +000097 OwningPtr<Matcher> &getNextPtr() { return Next; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000098
Chris Lattner9a515172010-02-25 02:04:40 +000099 static inline bool classof(const Matcher *) { return true; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000100
Chris Lattner136ab782010-02-25 06:49:58 +0000101 bool isEqual(const Matcher *M) const {
102 if (getKind() != M->getKind()) return false;
103 return isEqualImpl(M);
104 }
105
106 unsigned getHash() const {
Chris Lattner54ee7362010-02-26 07:35:27 +0000107 // Clear the high bit so we don't conflict with tombstones etc.
108 return ((getHashImpl() << 4) ^ getKind()) & (~0U>>1);
Chris Lattner136ab782010-02-25 06:49:58 +0000109 }
110
Chris Lattnerf4950d02010-02-27 06:22:57 +0000111 /// isSafeToReorderWithPatternPredicate - Return true if it is safe to sink a
112 /// PatternPredicate node past this one.
113 virtual bool isSafeToReorderWithPatternPredicate() const {
114 return false;
115 }
116
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000117 /// isContradictory - Return true of these two matchers could never match on
118 /// the same node.
119 bool isContradictory(const Matcher *Other) const {
120 // Since this predicate is reflexive, we canonicalize the ordering so that
121 // we always match a node against nodes with kinds that are greater or equal
122 // to them. For example, we'll pass in a CheckType node as an argument to
123 // the CheckOpcode method, not the other way around.
124 if (getKind() < Other->getKind())
125 return isContradictoryImpl(Other);
126 return Other->isContradictoryImpl(this);
127 }
128
Chris Lattner392b1bf2010-02-25 06:53:39 +0000129 void print(raw_ostream &OS, unsigned indent = 0) const;
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000130 void printOne(raw_ostream &OS) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000131 void dump() const;
Chris Lattner3b31c982010-02-18 02:49:24 +0000132protected:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000133 virtual void printImpl(raw_ostream &OS, unsigned indent) const = 0;
Chris Lattner136ab782010-02-25 06:49:58 +0000134 virtual bool isEqualImpl(const Matcher *M) const = 0;
135 virtual unsigned getHashImpl() const = 0;
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000136 virtual bool isContradictoryImpl(const Matcher *M) const { return false; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000137};
138
Chris Lattner42363662010-02-25 19:00:39 +0000139/// ScopeMatcher - This attempts to match each of its children to find the first
140/// one that successfully matches. If one child fails, it tries the next child.
141/// If none of the children match then this check fails. It never has a 'next'.
Chris Lattner9a515172010-02-25 02:04:40 +0000142class ScopeMatcher : public Matcher {
Chris Lattner42363662010-02-25 19:00:39 +0000143 SmallVector<Matcher*, 4> Children;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000144public:
Chris Lattner42363662010-02-25 19:00:39 +0000145 ScopeMatcher(Matcher *const *children, unsigned numchildren)
146 : Matcher(Scope), Children(children, children+numchildren) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000147 }
Chris Lattner42363662010-02-25 19:00:39 +0000148 virtual ~ScopeMatcher();
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000149
Chris Lattner42363662010-02-25 19:00:39 +0000150 unsigned getNumChildren() const { return Children.size(); }
151
152 Matcher *getChild(unsigned i) { return Children[i]; }
153 const Matcher *getChild(unsigned i) const { return Children[i]; }
154
155 void resetChild(unsigned i, Matcher *N) {
156 delete Children[i];
157 Children[i] = N;
158 }
159
160 Matcher *takeChild(unsigned i) {
161 Matcher *Res = Children[i];
162 Children[i] = 0;
163 return Res;
164 }
Chris Lattner54ee7362010-02-26 07:35:27 +0000165
166 void setNumChildren(unsigned NC) {
167 if (NC < Children.size()) {
168 // delete any children we're about to lose pointers to.
169 for (unsigned i = NC, e = Children.size(); i != e; ++i)
170 delete Children[i];
171 }
172 Children.resize(NC);
173 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000174
Chris Lattner9a515172010-02-25 02:04:40 +0000175 static inline bool classof(const Matcher *N) {
Chris Lattnerac10e4f2010-02-25 01:56:48 +0000176 return N->getKind() == Scope;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000177 }
178
Chris Lattner136ab782010-02-25 06:49:58 +0000179private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000180 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000181 virtual bool isEqualImpl(const Matcher *M) const { return false; }
Chris Lattner42363662010-02-25 19:00:39 +0000182 virtual unsigned getHashImpl() const { return 12312; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000183};
184
Chris Lattner9a515172010-02-25 02:04:40 +0000185/// RecordMatcher - Save the current node in the operand list.
186class RecordMatcher : public Matcher {
Chris Lattner56cf88d2010-02-17 01:03:09 +0000187 /// WhatFor - This is a string indicating why we're recording this. This
188 /// should only be used for comment generation not anything semantic.
189 std::string WhatFor;
Chris Lattner5377f912010-03-01 02:24:17 +0000190
191 /// ResultNo - The slot number in the RecordedNodes vector that this will be,
192 /// just printed as a comment.
193 unsigned ResultNo;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000194public:
Chris Lattner5377f912010-03-01 02:24:17 +0000195 RecordMatcher(const std::string &whatfor, unsigned resultNo)
196 : Matcher(RecordNode), WhatFor(whatfor), ResultNo(resultNo) {}
Chris Lattner56cf88d2010-02-17 01:03:09 +0000197
Chris Lattner086ca522010-02-17 01:27:29 +0000198 const std::string &getWhatFor() const { return WhatFor; }
Chris Lattner5377f912010-03-01 02:24:17 +0000199 unsigned getResultNo() const { return ResultNo; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000200
Chris Lattner9a515172010-02-25 02:04:40 +0000201 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000202 return N->getKind() == RecordNode;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000203 }
204
Chris Lattnerf4950d02010-02-27 06:22:57 +0000205 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
Chris Lattner136ab782010-02-25 06:49:58 +0000206private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000207 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000208 virtual bool isEqualImpl(const Matcher *M) const { return true; }
209 virtual unsigned getHashImpl() const { return 0; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000210};
211
Chris Lattner9a515172010-02-25 02:04:40 +0000212/// RecordChildMatcher - Save a numbered child of the current node, or fail
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000213/// the match if it doesn't exist. This is logically equivalent to:
214/// MoveChild N + RecordNode + MoveParent.
Chris Lattner9a515172010-02-25 02:04:40 +0000215class RecordChildMatcher : public Matcher {
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000216 unsigned ChildNo;
217
218 /// WhatFor - This is a string indicating why we're recording this. This
219 /// should only be used for comment generation not anything semantic.
220 std::string WhatFor;
Chris Lattner5377f912010-03-01 02:24:17 +0000221
222 /// ResultNo - The slot number in the RecordedNodes vector that this will be,
223 /// just printed as a comment.
224 unsigned ResultNo;
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000225public:
Chris Lattner5377f912010-03-01 02:24:17 +0000226 RecordChildMatcher(unsigned childno, const std::string &whatfor,
227 unsigned resultNo)
228 : Matcher(RecordChild), ChildNo(childno), WhatFor(whatfor),
229 ResultNo(resultNo) {}
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000230
231 unsigned getChildNo() const { return ChildNo; }
232 const std::string &getWhatFor() const { return WhatFor; }
Chris Lattner5377f912010-03-01 02:24:17 +0000233 unsigned getResultNo() const { return ResultNo; }
234
Chris Lattner9a515172010-02-25 02:04:40 +0000235 static inline bool classof(const Matcher *N) {
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000236 return N->getKind() == RecordChild;
237 }
238
Chris Lattnerf4950d02010-02-27 06:22:57 +0000239 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
240
Chris Lattner136ab782010-02-25 06:49:58 +0000241private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000242 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000243 virtual bool isEqualImpl(const Matcher *M) const {
244 return cast<RecordChildMatcher>(M)->getChildNo() == getChildNo();
245 }
246 virtual unsigned getHashImpl() const { return getChildNo(); }
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000247};
248
Chris Lattner9a515172010-02-25 02:04:40 +0000249/// RecordMemRefMatcher - Save the current node's memref.
250class RecordMemRefMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000251public:
Chris Lattner9a515172010-02-25 02:04:40 +0000252 RecordMemRefMatcher() : Matcher(RecordMemRef) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000253
Chris Lattner9a515172010-02-25 02:04:40 +0000254 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000255 return N->getKind() == RecordMemRef;
256 }
257
Chris Lattnerf4950d02010-02-27 06:22:57 +0000258 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
259
Chris Lattner136ab782010-02-25 06:49:58 +0000260private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000261 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000262 virtual bool isEqualImpl(const Matcher *M) const { return true; }
263 virtual unsigned getHashImpl() const { return 0; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000264};
265
266
Chris Lattner9a515172010-02-25 02:04:40 +0000267/// CaptureFlagInputMatcher - If the current record has a flag input, record
Chris Lattner3163ca52010-02-21 03:22:59 +0000268/// it so that it is used as an input to the generated code.
Chris Lattner9a515172010-02-25 02:04:40 +0000269class CaptureFlagInputMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000270public:
Chris Lattner9a515172010-02-25 02:04:40 +0000271 CaptureFlagInputMatcher() : Matcher(CaptureFlagInput) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000272
Chris Lattner9a515172010-02-25 02:04:40 +0000273 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000274 return N->getKind() == CaptureFlagInput;
275 }
276
Chris Lattnerf4950d02010-02-27 06:22:57 +0000277 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
278
Chris Lattner136ab782010-02-25 06:49:58 +0000279private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000280 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000281 virtual bool isEqualImpl(const Matcher *M) const { return true; }
282 virtual unsigned getHashImpl() const { return 0; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000283};
284
Chris Lattner9a515172010-02-25 02:04:40 +0000285/// MoveChildMatcher - This tells the interpreter to move into the
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000286/// specified child node.
Chris Lattner9a515172010-02-25 02:04:40 +0000287class MoveChildMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000288 unsigned ChildNo;
289public:
Chris Lattner9a515172010-02-25 02:04:40 +0000290 MoveChildMatcher(unsigned childNo) : Matcher(MoveChild), ChildNo(childNo) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000291
292 unsigned getChildNo() const { return ChildNo; }
293
Chris Lattner9a515172010-02-25 02:04:40 +0000294 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000295 return N->getKind() == MoveChild;
296 }
297
Chris Lattnerf4950d02010-02-27 06:22:57 +0000298 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
299
Chris Lattner136ab782010-02-25 06:49:58 +0000300private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000301 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000302 virtual bool isEqualImpl(const Matcher *M) const {
303 return cast<MoveChildMatcher>(M)->getChildNo() == getChildNo();
304 }
305 virtual unsigned getHashImpl() const { return getChildNo(); }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000306};
307
Chris Lattner9a515172010-02-25 02:04:40 +0000308/// MoveParentMatcher - This tells the interpreter to move to the parent
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000309/// of the current node.
Chris Lattner9a515172010-02-25 02:04:40 +0000310class MoveParentMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000311public:
Chris Lattner9a515172010-02-25 02:04:40 +0000312 MoveParentMatcher() : Matcher(MoveParent) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000313
Chris Lattner9a515172010-02-25 02:04:40 +0000314 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000315 return N->getKind() == MoveParent;
316 }
317
Chris Lattnerf4950d02010-02-27 06:22:57 +0000318 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
319
Chris Lattner136ab782010-02-25 06:49:58 +0000320private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000321 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000322 virtual bool isEqualImpl(const Matcher *M) const { return true; }
323 virtual unsigned getHashImpl() const { return 0; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000324};
325
Chris Lattner9a515172010-02-25 02:04:40 +0000326/// CheckSameMatcher - This checks to see if this node is exactly the same
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000327/// node as the specified match that was recorded with 'Record'. This is used
328/// when patterns have the same name in them, like '(mul GPR:$in, GPR:$in)'.
Chris Lattner9a515172010-02-25 02:04:40 +0000329class CheckSameMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000330 unsigned MatchNumber;
331public:
Chris Lattner9a515172010-02-25 02:04:40 +0000332 CheckSameMatcher(unsigned matchnumber)
Chris Lattner136ab782010-02-25 06:49:58 +0000333 : Matcher(CheckSame), MatchNumber(matchnumber) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000334
335 unsigned getMatchNumber() const { return MatchNumber; }
336
Chris Lattner9a515172010-02-25 02:04:40 +0000337 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000338 return N->getKind() == CheckSame;
339 }
340
Chris Lattnerf4950d02010-02-27 06:22:57 +0000341 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
342
Chris Lattner136ab782010-02-25 06:49:58 +0000343private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000344 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000345 virtual bool isEqualImpl(const Matcher *M) const {
346 return cast<CheckSameMatcher>(M)->getMatchNumber() == getMatchNumber();
347 }
348 virtual unsigned getHashImpl() const { return getMatchNumber(); }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000349};
350
Chris Lattner9a515172010-02-25 02:04:40 +0000351/// CheckPatternPredicateMatcher - This checks the target-specific predicate
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000352/// to see if the entire pattern is capable of matching. This predicate does
353/// not take a node as input. This is used for subtarget feature checks etc.
Chris Lattner9a515172010-02-25 02:04:40 +0000354class CheckPatternPredicateMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000355 std::string Predicate;
356public:
Chris Lattner9a515172010-02-25 02:04:40 +0000357 CheckPatternPredicateMatcher(StringRef predicate)
Chris Lattner136ab782010-02-25 06:49:58 +0000358 : Matcher(CheckPatternPredicate), Predicate(predicate) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000359
360 StringRef getPredicate() const { return Predicate; }
361
Chris Lattner9a515172010-02-25 02:04:40 +0000362 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000363 return N->getKind() == CheckPatternPredicate;
364 }
365
Chris Lattnerf4950d02010-02-27 06:22:57 +0000366 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
367
Chris Lattner136ab782010-02-25 06:49:58 +0000368private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000369 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000370 virtual bool isEqualImpl(const Matcher *M) const {
371 return cast<CheckPatternPredicateMatcher>(M)->getPredicate() == Predicate;
372 }
373 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000374};
375
Chris Lattner9a515172010-02-25 02:04:40 +0000376/// CheckPredicateMatcher - This checks the target-specific predicate to
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000377/// see if the node is acceptable.
Chris Lattner9a515172010-02-25 02:04:40 +0000378class CheckPredicateMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000379 StringRef PredName;
380public:
Chris Lattner9a515172010-02-25 02:04:40 +0000381 CheckPredicateMatcher(StringRef predname)
382 : Matcher(CheckPredicate), PredName(predname) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000383
384 StringRef getPredicateName() const { return PredName; }
385
Chris Lattner9a515172010-02-25 02:04:40 +0000386 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000387 return N->getKind() == CheckPredicate;
388 }
389
Chris Lattnerf4950d02010-02-27 06:22:57 +0000390 // TODO: Ok?
391 //virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
392
Chris Lattner136ab782010-02-25 06:49:58 +0000393private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000394 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000395 virtual bool isEqualImpl(const Matcher *M) const {
396 return cast<CheckPredicateMatcher>(M)->PredName == PredName;
397 }
398 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000399};
400
401
Chris Lattner9a515172010-02-25 02:04:40 +0000402/// CheckOpcodeMatcher - This checks to see if the current node has the
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000403/// specified opcode, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000404class CheckOpcodeMatcher : public Matcher {
Chris Lattnere9f720b2010-02-27 21:48:43 +0000405 const SDNodeInfo &Opcode;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000406public:
Chris Lattnere9f720b2010-02-27 21:48:43 +0000407 CheckOpcodeMatcher(const SDNodeInfo &opcode)
408 : Matcher(CheckOpcode), Opcode(opcode) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000409
Chris Lattnere9f720b2010-02-27 21:48:43 +0000410 const SDNodeInfo &getOpcode() const { return Opcode; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000411
Chris Lattner9a515172010-02-25 02:04:40 +0000412 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000413 return N->getKind() == CheckOpcode;
414 }
415
Chris Lattnerf4950d02010-02-27 06:22:57 +0000416 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
417
Chris Lattner136ab782010-02-25 06:49:58 +0000418private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000419 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner2e9e6842010-03-01 06:59:22 +0000420 virtual bool isEqualImpl(const Matcher *M) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000421 virtual unsigned getHashImpl() const;
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000422 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000423};
Chris Lattner2e9e6842010-03-01 06:59:22 +0000424
425/// SwitchOpcodeMatcher - Switch based on the current node's opcode, dispatching
426/// to one matcher per opcode. If the opcode doesn't match any of the cases,
427/// then the match fails. This is semantically equivalent to a Scope node where
428/// every child does a CheckOpcode, but is much faster.
429class SwitchOpcodeMatcher : public Matcher {
430 SmallVector<std::pair<const SDNodeInfo*, Matcher*>, 8> Cases;
431public:
432 SwitchOpcodeMatcher(const std::pair<const SDNodeInfo*, Matcher*> *cases,
433 unsigned numcases)
434 : Matcher(SwitchOpcode), Cases(cases, cases+numcases) {}
435
436 static inline bool classof(const Matcher *N) {
437 return N->getKind() == SwitchOpcode;
438 }
439
440 unsigned getNumCases() const { return Cases.size(); }
441
442 const SDNodeInfo &getCaseOpcode(unsigned i) const { return *Cases[i].first; }
443 Matcher *getCaseMatcher(unsigned i) { return Cases[i].second; }
444 const Matcher *getCaseMatcher(unsigned i) const { return Cases[i].second; }
445
446private:
447 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
448 virtual bool isEqualImpl(const Matcher *M) const { return false; }
449 virtual unsigned getHashImpl() const { return 4123; }
450};
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000451
Chris Lattner9a515172010-02-25 02:04:40 +0000452/// CheckTypeMatcher - This checks to see if the current node has the
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000453/// specified type, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000454class CheckTypeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000455 MVT::SimpleValueType Type;
456public:
Chris Lattner9a515172010-02-25 02:04:40 +0000457 CheckTypeMatcher(MVT::SimpleValueType type)
458 : Matcher(CheckType), Type(type) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000459
460 MVT::SimpleValueType getType() const { return Type; }
461
Chris Lattner9a515172010-02-25 02:04:40 +0000462 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000463 return N->getKind() == CheckType;
464 }
465
Chris Lattnerf4950d02010-02-27 06:22:57 +0000466 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
467
Chris Lattner136ab782010-02-25 06:49:58 +0000468private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000469 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000470 virtual bool isEqualImpl(const Matcher *M) const {
Chris Lattner2d0e0792010-02-26 08:05:36 +0000471 return cast<CheckTypeMatcher>(M)->Type == Type;
Chris Lattner136ab782010-02-25 06:49:58 +0000472 }
473 virtual unsigned getHashImpl() const { return Type; }
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000474 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000475};
Chris Lattner3c664b32010-02-24 20:15:25 +0000476
Chris Lattner9a515172010-02-25 02:04:40 +0000477/// CheckChildTypeMatcher - This checks to see if a child node has the
Chris Lattner3c664b32010-02-24 20:15:25 +0000478/// specified type, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000479class CheckChildTypeMatcher : public Matcher {
Chris Lattner3c664b32010-02-24 20:15:25 +0000480 unsigned ChildNo;
481 MVT::SimpleValueType Type;
482public:
Chris Lattner9a515172010-02-25 02:04:40 +0000483 CheckChildTypeMatcher(unsigned childno, MVT::SimpleValueType type)
484 : Matcher(CheckChildType), ChildNo(childno), Type(type) {}
Chris Lattner3c664b32010-02-24 20:15:25 +0000485
486 unsigned getChildNo() const { return ChildNo; }
487 MVT::SimpleValueType getType() const { return Type; }
488
Chris Lattner9a515172010-02-25 02:04:40 +0000489 static inline bool classof(const Matcher *N) {
Chris Lattner3c664b32010-02-24 20:15:25 +0000490 return N->getKind() == CheckChildType;
491 }
492
Chris Lattnerf4950d02010-02-27 06:22:57 +0000493 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
494
Chris Lattner136ab782010-02-25 06:49:58 +0000495private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000496 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000497 virtual bool isEqualImpl(const Matcher *M) const {
498 return cast<CheckChildTypeMatcher>(M)->ChildNo == ChildNo &&
499 cast<CheckChildTypeMatcher>(M)->Type == Type;
500 }
501 virtual unsigned getHashImpl() const { return (Type << 3) | ChildNo; }
Chris Lattnerddfd5ab2010-02-27 07:49:13 +0000502 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattner3c664b32010-02-24 20:15:25 +0000503};
504
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000505
Chris Lattner9a515172010-02-25 02:04:40 +0000506/// CheckIntegerMatcher - This checks to see if the current node is a
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000507/// ConstantSDNode with the specified integer value, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000508class CheckIntegerMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000509 int64_t Value;
510public:
Chris Lattner9a515172010-02-25 02:04:40 +0000511 CheckIntegerMatcher(int64_t value)
512 : Matcher(CheckInteger), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000513
514 int64_t getValue() const { return Value; }
515
Chris Lattner9a515172010-02-25 02:04:40 +0000516 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000517 return N->getKind() == CheckInteger;
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<CheckIntegerMatcher>(M)->Value == Value;
526 }
527 virtual unsigned getHashImpl() const { return Value; }
Chris Lattner086af322010-02-27 08:11:15 +0000528 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000529};
530
Chris Lattner9a515172010-02-25 02:04:40 +0000531/// CheckCondCodeMatcher - This checks to see if the current node is a
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000532/// CondCodeSDNode with the specified condition, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000533class CheckCondCodeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000534 StringRef CondCodeName;
535public:
Chris Lattner9a515172010-02-25 02:04:40 +0000536 CheckCondCodeMatcher(StringRef condcodename)
537 : Matcher(CheckCondCode), CondCodeName(condcodename) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000538
539 StringRef getCondCodeName() const { return CondCodeName; }
540
Chris Lattner9a515172010-02-25 02:04:40 +0000541 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000542 return N->getKind() == CheckCondCode;
543 }
544
Chris Lattnerf4950d02010-02-27 06:22:57 +0000545 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
546
Chris Lattner136ab782010-02-25 06:49:58 +0000547private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000548 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000549 virtual bool isEqualImpl(const Matcher *M) const {
550 return cast<CheckCondCodeMatcher>(M)->CondCodeName == CondCodeName;
551 }
552 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000553};
554
Chris Lattner9a515172010-02-25 02:04:40 +0000555/// CheckValueTypeMatcher - This checks to see if the current node is a
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000556/// VTSDNode with the specified type, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000557class CheckValueTypeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000558 StringRef TypeName;
559public:
Chris Lattner9a515172010-02-25 02:04:40 +0000560 CheckValueTypeMatcher(StringRef type_name)
561 : Matcher(CheckValueType), TypeName(type_name) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000562
563 StringRef getTypeName() const { return TypeName; }
564
Chris Lattner9a515172010-02-25 02:04:40 +0000565 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000566 return N->getKind() == CheckValueType;
567 }
568
Chris Lattnerf4950d02010-02-27 06:22:57 +0000569 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
570
Chris Lattner136ab782010-02-25 06:49:58 +0000571private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000572 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000573 virtual bool isEqualImpl(const Matcher *M) const {
574 return cast<CheckValueTypeMatcher>(M)->TypeName == TypeName;
575 }
576 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000577};
578
579
580
Chris Lattner9a515172010-02-25 02:04:40 +0000581/// CheckComplexPatMatcher - This node runs the specified ComplexPattern on
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000582/// the current node.
Chris Lattner9a515172010-02-25 02:04:40 +0000583class CheckComplexPatMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000584 const ComplexPattern &Pattern;
585public:
Chris Lattner9a515172010-02-25 02:04:40 +0000586 CheckComplexPatMatcher(const ComplexPattern &pattern)
587 : Matcher(CheckComplexPat), Pattern(pattern) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000588
Chris Lattnerdc429fd2010-02-17 00:31:50 +0000589 const ComplexPattern &getPattern() const { return Pattern; }
590
Chris Lattner9a515172010-02-25 02:04:40 +0000591 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000592 return N->getKind() == CheckComplexPat;
593 }
594
Chris Lattnerf4950d02010-02-27 06:22:57 +0000595 // Not safe to move a pattern predicate past a complex pattern.
596 virtual bool isSafeToReorderWithPatternPredicate() const { return false; }
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<CheckComplexPatMatcher>(M)->Pattern == &Pattern;
602 }
603 virtual unsigned getHashImpl() const {
604 return (unsigned)(intptr_t)&Pattern;
605 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000606};
607
Chris Lattner9a515172010-02-25 02:04:40 +0000608/// CheckAndImmMatcher - This checks to see if the current node is an 'and'
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000609/// with something equivalent to the specified immediate.
Chris Lattner9a515172010-02-25 02:04:40 +0000610class CheckAndImmMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000611 int64_t Value;
612public:
Chris Lattner9a515172010-02-25 02:04:40 +0000613 CheckAndImmMatcher(int64_t value)
614 : Matcher(CheckAndImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000615
616 int64_t getValue() const { return Value; }
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() == CheckAndImm;
620 }
621
Chris Lattnerf4950d02010-02-27 06:22:57 +0000622 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
623
Chris Lattner136ab782010-02-25 06:49:58 +0000624private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000625 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000626 virtual bool isEqualImpl(const Matcher *M) const {
627 return cast<CheckAndImmMatcher>(M)->Value == Value;
628 }
629 virtual unsigned getHashImpl() const { return Value; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000630};
631
Chris Lattner9a515172010-02-25 02:04:40 +0000632/// CheckOrImmMatcher - This checks to see if the current node is an 'and'
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000633/// with something equivalent to the specified immediate.
Chris Lattner9a515172010-02-25 02:04:40 +0000634class CheckOrImmMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000635 int64_t Value;
636public:
Chris Lattner9a515172010-02-25 02:04:40 +0000637 CheckOrImmMatcher(int64_t value)
638 : Matcher(CheckOrImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000639
640 int64_t getValue() const { return Value; }
641
Chris Lattner9a515172010-02-25 02:04:40 +0000642 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000643 return N->getKind() == CheckOrImm;
644 }
645
Chris Lattnerf4950d02010-02-27 06:22:57 +0000646 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
647
Chris Lattner136ab782010-02-25 06:49:58 +0000648private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000649 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000650 virtual bool isEqualImpl(const Matcher *M) const {
651 return cast<CheckOrImmMatcher>(M)->Value == Value;
652 }
653 virtual unsigned getHashImpl() const { return Value; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000654};
Chris Lattner9de39482010-02-16 06:10:58 +0000655
Chris Lattner9a515172010-02-25 02:04:40 +0000656/// CheckFoldableChainNodeMatcher - This checks to see if the current node
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000657/// (which defines a chain operand) is safe to fold into a larger pattern.
Chris Lattner9a515172010-02-25 02:04:40 +0000658class CheckFoldableChainNodeMatcher : public Matcher {
Chris Lattner9de39482010-02-16 06:10:58 +0000659public:
Chris Lattner9a515172010-02-25 02:04:40 +0000660 CheckFoldableChainNodeMatcher()
661 : Matcher(CheckFoldableChainNode) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000662
Chris Lattner9a515172010-02-25 02:04:40 +0000663 static inline bool classof(const Matcher *N) {
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000664 return N->getKind() == CheckFoldableChainNode;
Chris Lattner9de39482010-02-16 06:10:58 +0000665 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000666
Chris Lattnerf4950d02010-02-27 06:22:57 +0000667 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
668
Chris Lattner136ab782010-02-25 06:49:58 +0000669private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000670 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000671 virtual bool isEqualImpl(const Matcher *M) const { return true; }
672 virtual unsigned getHashImpl() const { return 0; }
Chris Lattner9de39482010-02-16 06:10:58 +0000673};
674
Chris Lattner9a515172010-02-25 02:04:40 +0000675/// CheckChainCompatibleMatcher - Verify that the current node's chain
Chris Lattner283adcb2010-02-17 06:23:39 +0000676/// operand is 'compatible' with the specified recorded node's.
Chris Lattner9a515172010-02-25 02:04:40 +0000677class CheckChainCompatibleMatcher : public Matcher {
Chris Lattner283adcb2010-02-17 06:23:39 +0000678 unsigned PreviousOp;
679public:
Chris Lattner9a515172010-02-25 02:04:40 +0000680 CheckChainCompatibleMatcher(unsigned previousop)
681 : Matcher(CheckChainCompatible), PreviousOp(previousop) {}
Chris Lattner283adcb2010-02-17 06:23:39 +0000682
683 unsigned getPreviousOp() const { return PreviousOp; }
684
Chris Lattner9a515172010-02-25 02:04:40 +0000685 static inline bool classof(const Matcher *N) {
Chris Lattner283adcb2010-02-17 06:23:39 +0000686 return N->getKind() == CheckChainCompatible;
687 }
688
Chris Lattnerf4950d02010-02-27 06:22:57 +0000689 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
690
Chris Lattner136ab782010-02-25 06:49:58 +0000691private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000692 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000693 virtual bool isEqualImpl(const Matcher *M) const {
Chris Lattner50c0b362010-02-26 08:06:02 +0000694 return cast<CheckChainCompatibleMatcher>(M)->PreviousOp == PreviousOp;
Chris Lattner136ab782010-02-25 06:49:58 +0000695 }
696 virtual unsigned getHashImpl() const { return PreviousOp; }
Chris Lattner283adcb2010-02-17 06:23:39 +0000697};
698
Chris Lattner9a515172010-02-25 02:04:40 +0000699/// EmitIntegerMatcher - This creates a new TargetConstant.
700class EmitIntegerMatcher : public Matcher {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000701 int64_t Val;
702 MVT::SimpleValueType VT;
703public:
Chris Lattner9a515172010-02-25 02:04:40 +0000704 EmitIntegerMatcher(int64_t val, MVT::SimpleValueType vt)
705 : Matcher(EmitInteger), Val(val), VT(vt) {}
Chris Lattner283adcb2010-02-17 06:23:39 +0000706
Chris Lattner7043e0a2010-02-19 07:49:56 +0000707 int64_t getValue() const { return Val; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000708 MVT::SimpleValueType getVT() const { return VT; }
709
Chris Lattner9a515172010-02-25 02:04:40 +0000710 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000711 return N->getKind() == EmitInteger;
712 }
713
Chris Lattner136ab782010-02-25 06:49:58 +0000714private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000715 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000716 virtual bool isEqualImpl(const Matcher *M) const {
717 return cast<EmitIntegerMatcher>(M)->Val == Val &&
718 cast<EmitIntegerMatcher>(M)->VT == VT;
719 }
720 virtual unsigned getHashImpl() const { return (Val << 4) | VT; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000721};
Chris Lattner3163ca52010-02-21 03:22:59 +0000722
Chris Lattner9a515172010-02-25 02:04:40 +0000723/// EmitStringIntegerMatcher - A target constant whose value is represented
Chris Lattner3163ca52010-02-21 03:22:59 +0000724/// by a string.
Chris Lattner9a515172010-02-25 02:04:40 +0000725class EmitStringIntegerMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000726 std::string Val;
727 MVT::SimpleValueType VT;
728public:
Chris Lattner9a515172010-02-25 02:04:40 +0000729 EmitStringIntegerMatcher(const std::string &val, MVT::SimpleValueType vt)
730 : Matcher(EmitStringInteger), Val(val), VT(vt) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000731
732 const std::string &getValue() const { return Val; }
733 MVT::SimpleValueType getVT() const { return VT; }
734
Chris Lattner9a515172010-02-25 02:04:40 +0000735 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000736 return N->getKind() == EmitStringInteger;
737 }
738
Chris Lattner136ab782010-02-25 06:49:58 +0000739private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000740 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000741 virtual bool isEqualImpl(const Matcher *M) const {
742 return cast<EmitStringIntegerMatcher>(M)->Val == Val &&
743 cast<EmitStringIntegerMatcher>(M)->VT == VT;
744 }
745 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +0000746};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000747
Chris Lattner9a515172010-02-25 02:04:40 +0000748/// EmitRegisterMatcher - This creates a new TargetConstant.
749class EmitRegisterMatcher : public Matcher {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000750 /// Reg - The def for the register that we're emitting. If this is null, then
751 /// this is a reference to zero_reg.
752 Record *Reg;
753 MVT::SimpleValueType VT;
754public:
Chris Lattner9a515172010-02-25 02:04:40 +0000755 EmitRegisterMatcher(Record *reg, MVT::SimpleValueType vt)
756 : Matcher(EmitRegister), Reg(reg), VT(vt) {}
Chris Lattnerddfb5222010-02-18 22:03:03 +0000757
758 Record *getReg() const { return Reg; }
759 MVT::SimpleValueType getVT() const { return VT; }
760
Chris Lattner9a515172010-02-25 02:04:40 +0000761 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000762 return N->getKind() == EmitRegister;
763 }
764
Chris Lattner136ab782010-02-25 06:49:58 +0000765private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000766 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000767 virtual bool isEqualImpl(const Matcher *M) const {
768 return cast<EmitRegisterMatcher>(M)->Reg == Reg &&
769 cast<EmitRegisterMatcher>(M)->VT == VT;
770 }
771 virtual unsigned getHashImpl() const {
772 return ((unsigned)(intptr_t)Reg) << 4 | VT;
773 }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000774};
Chris Lattner3163ca52010-02-21 03:22:59 +0000775
Chris Lattner9a515172010-02-25 02:04:40 +0000776/// EmitConvertToTargetMatcher - Emit an operation that reads a specified
Chris Lattner3163ca52010-02-21 03:22:59 +0000777/// recorded node and converts it from being a ISD::Constant to
778/// ISD::TargetConstant, likewise for ConstantFP.
Chris Lattner9a515172010-02-25 02:04:40 +0000779class EmitConvertToTargetMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000780 unsigned Slot;
781public:
Chris Lattner9a515172010-02-25 02:04:40 +0000782 EmitConvertToTargetMatcher(unsigned slot)
783 : Matcher(EmitConvertToTarget), Slot(slot) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000784
785 unsigned getSlot() const { return Slot; }
786
Chris Lattner9a515172010-02-25 02:04:40 +0000787 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000788 return N->getKind() == EmitConvertToTarget;
789 }
790
Chris Lattner136ab782010-02-25 06:49:58 +0000791private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000792 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000793 virtual bool isEqualImpl(const Matcher *M) const {
794 return cast<EmitConvertToTargetMatcher>(M)->Slot == Slot;
795 }
796 virtual unsigned getHashImpl() const { return Slot; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000797};
798
Chris Lattner9a515172010-02-25 02:04:40 +0000799/// EmitMergeInputChainsMatcher - Emit a node that merges a list of input
Chris Lattner3163ca52010-02-21 03:22:59 +0000800/// chains together with a token factor. The list of nodes are the nodes in the
801/// matched pattern that have chain input/outputs. This node adds all input
802/// chains of these nodes if they are not themselves a node in the pattern.
Chris Lattner9a515172010-02-25 02:04:40 +0000803class EmitMergeInputChainsMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000804 SmallVector<unsigned, 3> ChainNodes;
805public:
Chris Lattner9a515172010-02-25 02:04:40 +0000806 EmitMergeInputChainsMatcher(const unsigned *nodes, unsigned NumNodes)
807 : Matcher(EmitMergeInputChains), ChainNodes(nodes, nodes+NumNodes) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000808
809 unsigned getNumNodes() const { return ChainNodes.size(); }
810
811 unsigned getNode(unsigned i) const {
812 assert(i < ChainNodes.size());
813 return ChainNodes[i];
814 }
815
Chris Lattner9a515172010-02-25 02:04:40 +0000816 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000817 return N->getKind() == EmitMergeInputChains;
818 }
819
Chris Lattner136ab782010-02-25 06:49:58 +0000820private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000821 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000822 virtual bool isEqualImpl(const Matcher *M) const {
823 return cast<EmitMergeInputChainsMatcher>(M)->ChainNodes == ChainNodes;
824 }
825 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +0000826};
827
Chris Lattner9a515172010-02-25 02:04:40 +0000828/// EmitCopyToRegMatcher - Emit a CopyToReg node from a value to a physreg,
Chris Lattner3163ca52010-02-21 03:22:59 +0000829/// pushing the chain and flag results.
830///
Chris Lattner9a515172010-02-25 02:04:40 +0000831class EmitCopyToRegMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000832 unsigned SrcSlot; // Value to copy into the physreg.
833 Record *DestPhysReg;
834public:
Chris Lattner9a515172010-02-25 02:04:40 +0000835 EmitCopyToRegMatcher(unsigned srcSlot, Record *destPhysReg)
836 : Matcher(EmitCopyToReg), SrcSlot(srcSlot), DestPhysReg(destPhysReg) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000837
838 unsigned getSrcSlot() const { return SrcSlot; }
839 Record *getDestPhysReg() const { return DestPhysReg; }
840
Chris Lattner9a515172010-02-25 02:04:40 +0000841 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000842 return N->getKind() == EmitCopyToReg;
843 }
844
Chris Lattner136ab782010-02-25 06:49:58 +0000845private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000846 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000847 virtual bool isEqualImpl(const Matcher *M) const {
848 return cast<EmitCopyToRegMatcher>(M)->SrcSlot == SrcSlot &&
849 cast<EmitCopyToRegMatcher>(M)->DestPhysReg == DestPhysReg;
850 }
851 virtual unsigned getHashImpl() const {
852 return SrcSlot ^ ((unsigned)(intptr_t)DestPhysReg << 4);
853 }
Chris Lattner3163ca52010-02-21 03:22:59 +0000854};
855
856
857
Chris Lattner9a515172010-02-25 02:04:40 +0000858/// EmitNodeXFormMatcher - Emit an operation that runs an SDNodeXForm on a
Chris Lattner3163ca52010-02-21 03:22:59 +0000859/// recorded node and records the result.
Chris Lattner9a515172010-02-25 02:04:40 +0000860class EmitNodeXFormMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000861 unsigned Slot;
862 Record *NodeXForm;
863public:
Chris Lattner9a515172010-02-25 02:04:40 +0000864 EmitNodeXFormMatcher(unsigned slot, Record *nodeXForm)
865 : Matcher(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000866
867 unsigned getSlot() const { return Slot; }
868 Record *getNodeXForm() const { return NodeXForm; }
869
Chris Lattner9a515172010-02-25 02:04:40 +0000870 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000871 return N->getKind() == EmitNodeXForm;
872 }
873
Chris Lattner136ab782010-02-25 06:49:58 +0000874private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000875 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000876 virtual bool isEqualImpl(const Matcher *M) const {
877 return cast<EmitNodeXFormMatcher>(M)->Slot == Slot &&
878 cast<EmitNodeXFormMatcher>(M)->NodeXForm == NodeXForm;
879 }
880 virtual unsigned getHashImpl() const {
881 return Slot ^ ((unsigned)(intptr_t)NodeXForm << 4);
882 }
Chris Lattner3163ca52010-02-21 03:22:59 +0000883};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000884
Chris Lattner7a1dab42010-02-28 02:31:26 +0000885/// EmitNodeMatcherCommon - Common class shared between EmitNode and
Chris Lattner7dae4af2010-02-28 20:55:18 +0000886/// MorphNodeTo.
Chris Lattner7a1dab42010-02-28 02:31:26 +0000887class EmitNodeMatcherCommon : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000888 std::string OpcodeName;
889 const SmallVector<MVT::SimpleValueType, 3> VTs;
890 const SmallVector<unsigned, 6> Operands;
Chris Lattner414bac82010-02-28 21:53:42 +0000891 bool HasChain, HasInFlag, HasOutFlag, HasMemRefs;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000892
Chris Lattner3163ca52010-02-21 03:22:59 +0000893 /// NumFixedArityOperands - If this is a fixed arity node, this is set to -1.
894 /// If this is a varidic node, this is set to the number of fixed arity
895 /// operands in the root of the pattern. The rest are appended to this node.
896 int NumFixedArityOperands;
897public:
Chris Lattner7a1dab42010-02-28 02:31:26 +0000898 EmitNodeMatcherCommon(const std::string &opcodeName,
899 const MVT::SimpleValueType *vts, unsigned numvts,
900 const unsigned *operands, unsigned numops,
Chris Lattner414bac82010-02-28 21:53:42 +0000901 bool hasChain, bool hasInFlag, bool hasOutFlag,
902 bool hasmemrefs,
Chris Lattner7dae4af2010-02-28 20:55:18 +0000903 int numfixedarityoperands, bool isMorphNodeTo)
904 : Matcher(isMorphNodeTo ? MorphNodeTo : EmitNode), OpcodeName(opcodeName),
Chris Lattner3163ca52010-02-21 03:22:59 +0000905 VTs(vts, vts+numvts), Operands(operands, operands+numops),
Chris Lattner414bac82010-02-28 21:53:42 +0000906 HasChain(hasChain), HasInFlag(hasInFlag), HasOutFlag(hasOutFlag),
907 HasMemRefs(hasmemrefs), NumFixedArityOperands(numfixedarityoperands) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000908
909 const std::string &getOpcodeName() const { return OpcodeName; }
910
911 unsigned getNumVTs() const { return VTs.size(); }
912 MVT::SimpleValueType getVT(unsigned i) const {
913 assert(i < VTs.size());
914 return VTs[i];
915 }
Chris Lattner5cc7a832010-02-28 20:49:53 +0000916
Chris Lattner3163ca52010-02-21 03:22:59 +0000917 unsigned getNumOperands() const { return Operands.size(); }
918 unsigned getOperand(unsigned i) const {
919 assert(i < Operands.size());
920 return Operands[i];
Chris Lattner5cc7a832010-02-28 20:49:53 +0000921 }
922
923 const SmallVectorImpl<MVT::SimpleValueType> &getVTList() const { return VTs; }
924 const SmallVectorImpl<unsigned> &getOperandList() const { return Operands; }
925
Chris Lattner3163ca52010-02-21 03:22:59 +0000926
927 bool hasChain() const { return HasChain; }
Chris Lattner414bac82010-02-28 21:53:42 +0000928 bool hasInFlag() const { return HasInFlag; }
929 bool hasOutFlag() const { return HasOutFlag; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000930 bool hasMemRefs() const { return HasMemRefs; }
931 int getNumFixedArityOperands() const { return NumFixedArityOperands; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000932
Chris Lattner9a515172010-02-25 02:04:40 +0000933 static inline bool classof(const Matcher *N) {
Chris Lattner7dae4af2010-02-28 20:55:18 +0000934 return N->getKind() == EmitNode || N->getKind() == MorphNodeTo;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000935 }
936
Chris Lattner136ab782010-02-25 06:49:58 +0000937private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000938 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000939 virtual bool isEqualImpl(const Matcher *M) const;
940 virtual unsigned getHashImpl() const;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000941};
Chris Lattnerb085ea12010-02-21 06:03:07 +0000942
Chris Lattner7a1dab42010-02-28 02:31:26 +0000943/// EmitNodeMatcher - This signals a successful match and generates a node.
944class EmitNodeMatcher : public EmitNodeMatcherCommon {
Chris Lattner19a1fbe2010-02-28 02:41:25 +0000945 unsigned FirstResultSlot;
Chris Lattner7a1dab42010-02-28 02:31:26 +0000946public:
947 EmitNodeMatcher(const std::string &opcodeName,
948 const MVT::SimpleValueType *vts, unsigned numvts,
949 const unsigned *operands, unsigned numops,
Chris Lattner414bac82010-02-28 21:53:42 +0000950 bool hasChain, bool hasInFlag, bool hasOutFlag,
951 bool hasmemrefs,
Chris Lattner19a1fbe2010-02-28 02:41:25 +0000952 int numfixedarityoperands, unsigned firstresultslot)
Chris Lattner7a1dab42010-02-28 02:31:26 +0000953 : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
Chris Lattner414bac82010-02-28 21:53:42 +0000954 hasInFlag, hasOutFlag, hasmemrefs,
955 numfixedarityoperands, false),
Chris Lattner19a1fbe2010-02-28 02:41:25 +0000956 FirstResultSlot(firstresultslot) {}
957
958 unsigned getFirstResultSlot() const { return FirstResultSlot; }
Chris Lattner7a1dab42010-02-28 02:31:26 +0000959
960 static inline bool classof(const Matcher *N) {
961 return N->getKind() == EmitNode;
962 }
963
964};
965
Chris Lattner7dae4af2010-02-28 20:55:18 +0000966class MorphNodeToMatcher : public EmitNodeMatcherCommon {
Chris Lattner7a1dab42010-02-28 02:31:26 +0000967 const PatternToMatch &Pattern;
968public:
Chris Lattner7dae4af2010-02-28 20:55:18 +0000969 MorphNodeToMatcher(const std::string &opcodeName,
970 const MVT::SimpleValueType *vts, unsigned numvts,
971 const unsigned *operands, unsigned numops,
Chris Lattner414bac82010-02-28 21:53:42 +0000972 bool hasChain, bool hasInFlag, bool hasOutFlag,
973 bool hasmemrefs,
Chris Lattner7dae4af2010-02-28 20:55:18 +0000974 int numfixedarityoperands, const PatternToMatch &pattern)
Chris Lattner7a1dab42010-02-28 02:31:26 +0000975 : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
Chris Lattner414bac82010-02-28 21:53:42 +0000976 hasInFlag, hasOutFlag, hasmemrefs,
977 numfixedarityoperands, true),
Chris Lattner7a1dab42010-02-28 02:31:26 +0000978 Pattern(pattern) {
979 }
980
981 const PatternToMatch &getPattern() const { return Pattern; }
982
983 static inline bool classof(const Matcher *N) {
Chris Lattner7dae4af2010-02-28 20:55:18 +0000984 return N->getKind() == MorphNodeTo;
Chris Lattner7a1dab42010-02-28 02:31:26 +0000985 }
986};
987
Chris Lattner9a515172010-02-25 02:04:40 +0000988/// MarkFlagResultsMatcher - This node indicates which non-root nodes in the
989/// pattern produce flags. This allows CompleteMatchMatcher to update them
Chris Lattner69f60c82010-02-24 05:33:42 +0000990/// with the output flag of the resultant code.
Chris Lattner9a515172010-02-25 02:04:40 +0000991class MarkFlagResultsMatcher : public Matcher {
Chris Lattner69f60c82010-02-24 05:33:42 +0000992 SmallVector<unsigned, 3> FlagResultNodes;
993public:
Chris Lattner9a515172010-02-25 02:04:40 +0000994 MarkFlagResultsMatcher(const unsigned *nodes, unsigned NumNodes)
995 : Matcher(MarkFlagResults), FlagResultNodes(nodes, nodes+NumNodes) {}
Chris Lattner69f60c82010-02-24 05:33:42 +0000996
997 unsigned getNumNodes() const { return FlagResultNodes.size(); }
998
999 unsigned getNode(unsigned i) const {
1000 assert(i < FlagResultNodes.size());
1001 return FlagResultNodes[i];
1002 }
1003
Chris Lattner9a515172010-02-25 02:04:40 +00001004 static inline bool classof(const Matcher *N) {
Chris Lattner69f60c82010-02-24 05:33:42 +00001005 return N->getKind() == MarkFlagResults;
1006 }
1007
Chris Lattner136ab782010-02-25 06:49:58 +00001008private:
Chris Lattner392b1bf2010-02-25 06:53:39 +00001009 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +00001010 virtual bool isEqualImpl(const Matcher *M) const {
1011 return cast<MarkFlagResultsMatcher>(M)->FlagResultNodes == FlagResultNodes;
1012 }
1013 virtual unsigned getHashImpl() const;
Chris Lattner69f60c82010-02-24 05:33:42 +00001014};
1015
Chris Lattner9a515172010-02-25 02:04:40 +00001016/// CompleteMatchMatcher - Complete a match by replacing the results of the
Chris Lattnerb085ea12010-02-21 06:03:07 +00001017/// pattern with the newly generated nodes. This also prints a comment
1018/// indicating the source and dest patterns.
Chris Lattner9a515172010-02-25 02:04:40 +00001019class CompleteMatchMatcher : public Matcher {
Chris Lattnerb085ea12010-02-21 06:03:07 +00001020 SmallVector<unsigned, 2> Results;
Chris Lattner3163ca52010-02-21 03:22:59 +00001021 const PatternToMatch &Pattern;
1022public:
Chris Lattner9a515172010-02-25 02:04:40 +00001023 CompleteMatchMatcher(const unsigned *results, unsigned numresults,
Chris Lattner5cc7a832010-02-28 20:49:53 +00001024 const PatternToMatch &pattern)
Chris Lattner9a515172010-02-25 02:04:40 +00001025 : Matcher(CompleteMatch), Results(results, results+numresults),
Chris Lattnerb085ea12010-02-21 06:03:07 +00001026 Pattern(pattern) {}
1027
1028 unsigned getNumResults() const { return Results.size(); }
1029 unsigned getResult(unsigned R) const { return Results[R]; }
Chris Lattner3163ca52010-02-21 03:22:59 +00001030 const PatternToMatch &getPattern() const { return Pattern; }
1031
Chris Lattner9a515172010-02-25 02:04:40 +00001032 static inline bool classof(const Matcher *N) {
Chris Lattnerb085ea12010-02-21 06:03:07 +00001033 return N->getKind() == CompleteMatch;
Chris Lattner3163ca52010-02-21 03:22:59 +00001034 }
1035
Chris Lattner136ab782010-02-25 06:49:58 +00001036private:
Chris Lattner392b1bf2010-02-25 06:53:39 +00001037 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +00001038 virtual bool isEqualImpl(const Matcher *M) const {
1039 return cast<CompleteMatchMatcher>(M)->Results == Results &&
1040 &cast<CompleteMatchMatcher>(M)->Pattern == &Pattern;
1041 }
1042 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +00001043};
Chris Lattner7a1dab42010-02-28 02:31:26 +00001044
Chris Lattnere7d6e3c2010-02-15 08:04:42 +00001045} // end namespace llvm
1046
1047#endif