blob: 99ebf98b1e4bbceb8b2c0267fff2b26ef7a84796 [file] [log] [blame]
Chris Lattnerda272d12010-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 Lattner050a03d2010-02-16 07:21:10 +000013#include "llvm/CodeGen/ValueTypes.h"
Chris Lattnerda272d12010-02-15 08:04:42 +000014#include "llvm/ADT/OwningPtr.h"
15#include "llvm/ADT/StringRef.h"
Chris Lattner8e946be2010-02-21 03:22:59 +000016#include "llvm/ADT/SmallVector.h"
Chris Lattner050a03d2010-02-16 07:21:10 +000017#include "llvm/Support/Casting.h"
Chris Lattnerda272d12010-02-15 08:04:42 +000018
19namespace llvm {
Jim Grosbach4a6d7352011-03-11 02:19:02 +000020 struct CodeGenRegister;
Chris Lattnerda272d12010-02-15 08:04:42 +000021 class CodeGenDAGPatterns;
Chris Lattnerb21ba712010-02-25 02:04:40 +000022 class Matcher;
Chris Lattnerda272d12010-02-15 08:04:42 +000023 class PatternToMatch;
24 class raw_ostream;
25 class ComplexPattern;
Chris Lattner845c0422010-02-18 22:03:03 +000026 class Record;
Chris Lattnera230f962010-02-27 21:48:43 +000027 class SDNodeInfo;
Chris Lattner54379062011-04-17 21:38:24 +000028 class TreePredicateFn;
29 class TreePattern;
Chris Lattnerda272d12010-02-15 08:04:42 +000030
Chris Lattnerfa342fa2010-03-01 07:17:40 +000031Matcher *ConvertPatternToMatcher(const PatternToMatch &Pattern,unsigned Variant,
Chris Lattnerb21ba712010-02-25 02:04:40 +000032 const CodeGenDAGPatterns &CGP);
Chris Lattnerc78f2a32010-02-28 20:49:53 +000033Matcher *OptimizeMatcher(Matcher *Matcher, const CodeGenDAGPatterns &CGP);
Chris Lattner4d0c9312010-03-01 01:54:19 +000034void EmitMatcherTable(const Matcher *Matcher, const CodeGenDAGPatterns &CGP,
Jim Grosbach4a6d7352011-03-11 02:19:02 +000035 raw_ostream &OS);
Chris Lattnerda272d12010-02-15 08:04:42 +000036
Jim Grosbachfbadcd02010-12-21 16:16:00 +000037
Chris Lattnerb21ba712010-02-25 02:04:40 +000038/// Matcher - Base class for all the the DAG ISel Matcher representation
Chris Lattnerda272d12010-02-15 08:04:42 +000039/// nodes.
Chris Lattnerb21ba712010-02-25 02:04:40 +000040class Matcher {
Chris Lattnerbd8227f2010-02-18 02:53:41 +000041 // The next matcher node that is executed after this one. Null if this is the
42 // last stage of a match.
Chris Lattnerb21ba712010-02-25 02:04:40 +000043 OwningPtr<Matcher> Next;
David Blaikie2d24e2a2011-12-20 02:50:00 +000044 virtual void anchor();
Chris Lattnerda272d12010-02-15 08:04:42 +000045public:
46 enum KindTy {
Chris Lattner8e946be2010-02-21 03:22:59 +000047 // Matcher state manipulation.
Chris Lattner60df53e2010-02-25 01:56:48 +000048 Scope, // Push a checking scope.
Chris Lattner8e946be2010-02-21 03:22:59 +000049 RecordNode, // Record the current node.
Chris Lattner19b5a752010-02-24 07:31:45 +000050 RecordChild, // Record a child of the current node.
Chris Lattner8e946be2010-02-21 03:22:59 +000051 RecordMemRef, // Record the memref in the current node.
Chris Lattner8950bca2010-12-23 17:03:20 +000052 CaptureGlueInput, // If the current node has an input glue, save it.
Chris Lattner8e946be2010-02-21 03:22:59 +000053 MoveChild, // Move current node to specified child.
54 MoveParent, // Move current node to parent.
Jim Grosbachfbadcd02010-12-21 16:16:00 +000055
Chris Lattner845c0422010-02-18 22:03:03 +000056 // Predicate checking.
Chris Lattner8e946be2010-02-21 03:22:59 +000057 CheckSame, // Fail if not same as prev match.
Chris Lattnerda272d12010-02-15 08:04:42 +000058 CheckPatternPredicate,
Chris Lattner8e946be2010-02-21 03:22:59 +000059 CheckPredicate, // Fail if node predicate fails.
60 CheckOpcode, // Fail if not opcode.
Chris Lattnereb669212010-03-01 06:59:22 +000061 SwitchOpcode, // Dispatch based on opcode.
Chris Lattner8e946be2010-02-21 03:22:59 +000062 CheckType, // Fail if not correct type.
Chris Lattnercfe2eab2010-03-03 06:28:15 +000063 SwitchType, // Dispatch based on type.
Chris Lattner23cfda72010-02-24 20:15:25 +000064 CheckChildType, // Fail if child has wrong type.
Chris Lattner8e946be2010-02-21 03:22:59 +000065 CheckInteger, // Fail if wrong val.
66 CheckCondCode, // Fail if not condcode.
Chris Lattnerda272d12010-02-15 08:04:42 +000067 CheckValueType,
68 CheckComplexPat,
69 CheckAndImm,
Chris Lattnere39650a2010-02-16 06:10:58 +000070 CheckOrImm,
Chris Lattner9a747f12010-02-17 06:23:39 +000071 CheckFoldableChainNode,
Jim Grosbachfbadcd02010-12-21 16:16:00 +000072
Chris Lattner845c0422010-02-18 22:03:03 +000073 // Node creation/emisssion.
Chris Lattner8e946be2010-02-21 03:22:59 +000074 EmitInteger, // Create a TargetConstant
75 EmitStringInteger, // Create a TargetConstant from a string.
76 EmitRegister, // Create a register.
77 EmitConvertToTarget, // Convert a imm/fpimm to target imm/fpimm
78 EmitMergeInputChains, // Merge together a chains for an input.
79 EmitCopyToReg, // Emit a copytoreg into a physreg.
80 EmitNode, // Create a DAG node
81 EmitNodeXForm, // Run a SDNodeXForm
Chris Lattner8950bca2010-12-23 17:03:20 +000082 MarkGlueResults, // Indicate which interior nodes have glue results.
Chris Lattnere86097a2010-02-28 02:31:26 +000083 CompleteMatch, // Finish a match and update the results.
Chris Lattner9a215002010-02-28 20:55:18 +000084 MorphNodeTo // Build a node, finish a match and update results.
Chris Lattnerda272d12010-02-15 08:04:42 +000085 };
86 const KindTy Kind;
Chris Lattner8ef9c792010-02-18 02:49:24 +000087
Chris Lattnerda272d12010-02-15 08:04:42 +000088protected:
Chris Lattnerb21ba712010-02-25 02:04:40 +000089 Matcher(KindTy K) : Kind(K) {}
Chris Lattnerda272d12010-02-15 08:04:42 +000090public:
Chris Lattnerb21ba712010-02-25 02:04:40 +000091 virtual ~Matcher() {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +000092
Chris Lattnerda272d12010-02-15 08:04:42 +000093 KindTy getKind() const { return Kind; }
Chris Lattner8ef9c792010-02-18 02:49:24 +000094
Chris Lattnerb21ba712010-02-25 02:04:40 +000095 Matcher *getNext() { return Next.get(); }
96 const Matcher *getNext() const { return Next.get(); }
97 void setNext(Matcher *C) { Next.reset(C); }
98 Matcher *takeNext() { return Next.take(); }
Chris Lattner19b5a752010-02-24 07:31:45 +000099
Chris Lattnerb21ba712010-02-25 02:04:40 +0000100 OwningPtr<Matcher> &getNextPtr() { return Next; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000101
Chris Lattnerb21ba712010-02-25 02:04:40 +0000102 static inline bool classof(const Matcher *) { return true; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000103
Chris Lattner58aa8342010-02-25 06:49:58 +0000104 bool isEqual(const Matcher *M) const {
105 if (getKind() != M->getKind()) return false;
106 return isEqualImpl(M);
107 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000108
Chris Lattner58aa8342010-02-25 06:49:58 +0000109 unsigned getHash() const {
Chris Lattnerca56fea2010-02-26 07:35:27 +0000110 // Clear the high bit so we don't conflict with tombstones etc.
111 return ((getHashImpl() << 4) ^ getKind()) & (~0U>>1);
Chris Lattner58aa8342010-02-25 06:49:58 +0000112 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000113
Chris Lattnerd323fd42010-02-27 06:22:57 +0000114 /// isSafeToReorderWithPatternPredicate - Return true if it is safe to sink a
115 /// PatternPredicate node past this one.
116 virtual bool isSafeToReorderWithPatternPredicate() const {
117 return false;
118 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000119
Chris Lattner48aa5752010-03-07 06:29:26 +0000120 /// isSimplePredicateNode - Return true if this is a simple predicate that
121 /// operates on the node or its children without potential side effects or a
122 /// change of the current node.
123 bool isSimplePredicateNode() const {
124 switch (getKind()) {
125 default: return false;
126 case CheckSame:
127 case CheckPatternPredicate:
128 case CheckPredicate:
129 case CheckOpcode:
130 case CheckType:
131 case CheckChildType:
132 case CheckInteger:
133 case CheckCondCode:
134 case CheckValueType:
135 case CheckAndImm:
136 case CheckOrImm:
137 case CheckFoldableChainNode:
138 return true;
139 }
140 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000141
Chris Lattner48aa5752010-03-07 06:29:26 +0000142 /// isSimplePredicateOrRecordNode - Return true if this is a record node or
143 /// a simple predicate.
144 bool isSimplePredicateOrRecordNode() const {
145 return isSimplePredicateNode() ||
146 getKind() == RecordNode || getKind() == RecordChild;
147 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000148
Chris Lattner48aa5752010-03-07 06:29:26 +0000149 /// unlinkNode - Unlink the specified node from this chain. If Other == this,
150 /// we unlink the next pointer and return it. Otherwise we unlink Other from
151 /// the list and return this.
152 Matcher *unlinkNode(Matcher *Other);
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000153
Chris Lattner48aa5752010-03-07 06:29:26 +0000154 /// canMoveBefore - Return true if this matcher is the same as Other, or if
155 /// we can move this matcher past all of the nodes in-between Other and this
156 /// node. Other must be equal to or before this.
157 bool canMoveBefore(const Matcher *Other) const;
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000158
Chris Lattner48aa5752010-03-07 06:29:26 +0000159 /// canMoveBefore - Return true if it is safe to move the current matcher
160 /// across the specified one.
161 bool canMoveBeforeNode(const Matcher *Other) const;
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000162
Chris Lattner82781b92010-02-27 07:49:13 +0000163 /// isContradictory - Return true of these two matchers could never match on
164 /// the same node.
165 bool isContradictory(const Matcher *Other) const {
166 // Since this predicate is reflexive, we canonicalize the ordering so that
167 // we always match a node against nodes with kinds that are greater or equal
168 // to them. For example, we'll pass in a CheckType node as an argument to
169 // the CheckOpcode method, not the other way around.
170 if (getKind() < Other->getKind())
171 return isContradictoryImpl(Other);
172 return Other->isContradictoryImpl(this);
173 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000174
Chris Lattnera5028a62010-02-25 06:53:39 +0000175 void print(raw_ostream &OS, unsigned indent = 0) const;
Chris Lattner82781b92010-02-27 07:49:13 +0000176 void printOne(raw_ostream &OS) const;
Chris Lattnerda272d12010-02-15 08:04:42 +0000177 void dump() const;
Chris Lattner8ef9c792010-02-18 02:49:24 +0000178protected:
Chris Lattnera5028a62010-02-25 06:53:39 +0000179 virtual void printImpl(raw_ostream &OS, unsigned indent) const = 0;
Chris Lattner58aa8342010-02-25 06:49:58 +0000180 virtual bool isEqualImpl(const Matcher *M) const = 0;
181 virtual unsigned getHashImpl() const = 0;
Chris Lattner82781b92010-02-27 07:49:13 +0000182 virtual bool isContradictoryImpl(const Matcher *M) const { return false; }
Chris Lattnerda272d12010-02-15 08:04:42 +0000183};
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000184
Chris Lattnerd6c84722010-02-25 19:00:39 +0000185/// ScopeMatcher - This attempts to match each of its children to find the first
186/// one that successfully matches. If one child fails, it tries the next child.
187/// If none of the children match then this check fails. It never has a 'next'.
Chris Lattnerb21ba712010-02-25 02:04:40 +0000188class ScopeMatcher : public Matcher {
Chris Lattnerd6c84722010-02-25 19:00:39 +0000189 SmallVector<Matcher*, 4> Children;
Chris Lattnerda272d12010-02-15 08:04:42 +0000190public:
Chris Lattnerd6c84722010-02-25 19:00:39 +0000191 ScopeMatcher(Matcher *const *children, unsigned numchildren)
192 : Matcher(Scope), Children(children, children+numchildren) {
Chris Lattnerda272d12010-02-15 08:04:42 +0000193 }
Chris Lattnerd6c84722010-02-25 19:00:39 +0000194 virtual ~ScopeMatcher();
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000195
Chris Lattnerd6c84722010-02-25 19:00:39 +0000196 unsigned getNumChildren() const { return Children.size(); }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000197
Chris Lattnerd6c84722010-02-25 19:00:39 +0000198 Matcher *getChild(unsigned i) { return Children[i]; }
199 const Matcher *getChild(unsigned i) const { return Children[i]; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000200
Chris Lattnerd6c84722010-02-25 19:00:39 +0000201 void resetChild(unsigned i, Matcher *N) {
202 delete Children[i];
203 Children[i] = N;
204 }
205
206 Matcher *takeChild(unsigned i) {
207 Matcher *Res = Children[i];
208 Children[i] = 0;
209 return Res;
210 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000211
Chris Lattnerca56fea2010-02-26 07:35:27 +0000212 void setNumChildren(unsigned NC) {
213 if (NC < Children.size()) {
214 // delete any children we're about to lose pointers to.
215 for (unsigned i = NC, e = Children.size(); i != e; ++i)
216 delete Children[i];
217 }
218 Children.resize(NC);
219 }
Chris Lattnerda272d12010-02-15 08:04:42 +0000220
Chris Lattnerb21ba712010-02-25 02:04:40 +0000221 static inline bool classof(const Matcher *N) {
Chris Lattner60df53e2010-02-25 01:56:48 +0000222 return N->getKind() == Scope;
Chris Lattnerda272d12010-02-15 08:04:42 +0000223 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000224
Chris Lattner58aa8342010-02-25 06:49:58 +0000225private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000226 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000227 virtual bool isEqualImpl(const Matcher *M) const { return false; }
Chris Lattnerd6c84722010-02-25 19:00:39 +0000228 virtual unsigned getHashImpl() const { return 12312; }
Chris Lattnerda272d12010-02-15 08:04:42 +0000229};
230
Chris Lattnerb21ba712010-02-25 02:04:40 +0000231/// RecordMatcher - Save the current node in the operand list.
232class RecordMatcher : public Matcher {
Chris Lattnerc96087b2010-02-17 01:03:09 +0000233 /// WhatFor - This is a string indicating why we're recording this. This
234 /// should only be used for comment generation not anything semantic.
235 std::string WhatFor;
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000236
Chris Lattner0cebe612010-03-01 02:24:17 +0000237 /// ResultNo - The slot number in the RecordedNodes vector that this will be,
238 /// just printed as a comment.
239 unsigned ResultNo;
Chris Lattnerda272d12010-02-15 08:04:42 +0000240public:
Chris Lattner0cebe612010-03-01 02:24:17 +0000241 RecordMatcher(const std::string &whatfor, unsigned resultNo)
242 : Matcher(RecordNode), WhatFor(whatfor), ResultNo(resultNo) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000243
Chris Lattnerc642b842010-02-17 01:27:29 +0000244 const std::string &getWhatFor() const { return WhatFor; }
Chris Lattner0cebe612010-03-01 02:24:17 +0000245 unsigned getResultNo() const { return ResultNo; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000246
Chris Lattnerb21ba712010-02-25 02:04:40 +0000247 static inline bool classof(const Matcher *N) {
Chris Lattner845c0422010-02-18 22:03:03 +0000248 return N->getKind() == RecordNode;
Chris Lattnerda272d12010-02-15 08:04:42 +0000249 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000250
Chris Lattnerd323fd42010-02-27 06:22:57 +0000251 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
Chris Lattner58aa8342010-02-25 06:49:58 +0000252private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000253 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000254 virtual bool isEqualImpl(const Matcher *M) const { return true; }
255 virtual unsigned getHashImpl() const { return 0; }
Chris Lattnerda272d12010-02-15 08:04:42 +0000256};
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000257
Chris Lattnerb21ba712010-02-25 02:04:40 +0000258/// RecordChildMatcher - Save a numbered child of the current node, or fail
Chris Lattner19b5a752010-02-24 07:31:45 +0000259/// the match if it doesn't exist. This is logically equivalent to:
260/// MoveChild N + RecordNode + MoveParent.
Chris Lattnerb21ba712010-02-25 02:04:40 +0000261class RecordChildMatcher : public Matcher {
Chris Lattner19b5a752010-02-24 07:31:45 +0000262 unsigned ChildNo;
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000263
Chris Lattner19b5a752010-02-24 07:31:45 +0000264 /// WhatFor - This is a string indicating why we're recording this. This
265 /// should only be used for comment generation not anything semantic.
266 std::string WhatFor;
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000267
Chris Lattner0cebe612010-03-01 02:24:17 +0000268 /// ResultNo - The slot number in the RecordedNodes vector that this will be,
269 /// just printed as a comment.
270 unsigned ResultNo;
Chris Lattner19b5a752010-02-24 07:31:45 +0000271public:
Chris Lattner0cebe612010-03-01 02:24:17 +0000272 RecordChildMatcher(unsigned childno, const std::string &whatfor,
273 unsigned resultNo)
274 : Matcher(RecordChild), ChildNo(childno), WhatFor(whatfor),
275 ResultNo(resultNo) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000276
Chris Lattner19b5a752010-02-24 07:31:45 +0000277 unsigned getChildNo() const { return ChildNo; }
278 const std::string &getWhatFor() const { return WhatFor; }
Chris Lattner0cebe612010-03-01 02:24:17 +0000279 unsigned getResultNo() const { return ResultNo; }
280
Chris Lattnerb21ba712010-02-25 02:04:40 +0000281 static inline bool classof(const Matcher *N) {
Chris Lattner19b5a752010-02-24 07:31:45 +0000282 return N->getKind() == RecordChild;
283 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000284
Chris Lattnerd323fd42010-02-27 06:22:57 +0000285 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
286
Chris Lattner58aa8342010-02-25 06:49:58 +0000287private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000288 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000289 virtual bool isEqualImpl(const Matcher *M) const {
290 return cast<RecordChildMatcher>(M)->getChildNo() == getChildNo();
291 }
292 virtual unsigned getHashImpl() const { return getChildNo(); }
Chris Lattner19b5a752010-02-24 07:31:45 +0000293};
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000294
Chris Lattnerb21ba712010-02-25 02:04:40 +0000295/// RecordMemRefMatcher - Save the current node's memref.
296class RecordMemRefMatcher : public Matcher {
Chris Lattner8e946be2010-02-21 03:22:59 +0000297public:
Chris Lattnerb21ba712010-02-25 02:04:40 +0000298 RecordMemRefMatcher() : Matcher(RecordMemRef) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000299
Chris Lattnerb21ba712010-02-25 02:04:40 +0000300 static inline bool classof(const Matcher *N) {
Chris Lattner8e946be2010-02-21 03:22:59 +0000301 return N->getKind() == RecordMemRef;
302 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000303
Chris Lattnerd323fd42010-02-27 06:22:57 +0000304 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
305
Chris Lattner58aa8342010-02-25 06:49:58 +0000306private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000307 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000308 virtual bool isEqualImpl(const Matcher *M) const { return true; }
309 virtual unsigned getHashImpl() const { return 0; }
Chris Lattner8e946be2010-02-21 03:22:59 +0000310};
311
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000312
Chris Lattner8950bca2010-12-23 17:03:20 +0000313/// CaptureGlueInputMatcher - If the current record has a glue input, record
Chris Lattner8e946be2010-02-21 03:22:59 +0000314/// it so that it is used as an input to the generated code.
Chris Lattner8950bca2010-12-23 17:03:20 +0000315class CaptureGlueInputMatcher : public Matcher {
Chris Lattner8e946be2010-02-21 03:22:59 +0000316public:
Chris Lattner8950bca2010-12-23 17:03:20 +0000317 CaptureGlueInputMatcher() : Matcher(CaptureGlueInput) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000318
Chris Lattnerb21ba712010-02-25 02:04:40 +0000319 static inline bool classof(const Matcher *N) {
Chris Lattner8950bca2010-12-23 17:03:20 +0000320 return N->getKind() == CaptureGlueInput;
Chris Lattner8e946be2010-02-21 03:22:59 +0000321 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000322
Chris Lattnerd323fd42010-02-27 06:22:57 +0000323 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
324
Chris Lattner58aa8342010-02-25 06:49:58 +0000325private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000326 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000327 virtual bool isEqualImpl(const Matcher *M) const { return true; }
328 virtual unsigned getHashImpl() const { return 0; }
Chris Lattner8e946be2010-02-21 03:22:59 +0000329};
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000330
Chris Lattnerb21ba712010-02-25 02:04:40 +0000331/// MoveChildMatcher - This tells the interpreter to move into the
Chris Lattnerda272d12010-02-15 08:04:42 +0000332/// specified child node.
Chris Lattnerb21ba712010-02-25 02:04:40 +0000333class MoveChildMatcher : public Matcher {
Chris Lattnerda272d12010-02-15 08:04:42 +0000334 unsigned ChildNo;
335public:
Chris Lattnerb21ba712010-02-25 02:04:40 +0000336 MoveChildMatcher(unsigned childNo) : Matcher(MoveChild), ChildNo(childNo) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000337
Chris Lattnerda272d12010-02-15 08:04:42 +0000338 unsigned getChildNo() const { return ChildNo; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000339
Chris Lattnerb21ba712010-02-25 02:04:40 +0000340 static inline bool classof(const Matcher *N) {
Chris Lattnerda272d12010-02-15 08:04:42 +0000341 return N->getKind() == MoveChild;
342 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000343
Chris Lattnerd323fd42010-02-27 06:22:57 +0000344 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
345
Chris Lattner58aa8342010-02-25 06:49:58 +0000346private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000347 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000348 virtual bool isEqualImpl(const Matcher *M) const {
349 return cast<MoveChildMatcher>(M)->getChildNo() == getChildNo();
350 }
351 virtual unsigned getHashImpl() const { return getChildNo(); }
Chris Lattnerda272d12010-02-15 08:04:42 +0000352};
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000353
Chris Lattnerb21ba712010-02-25 02:04:40 +0000354/// MoveParentMatcher - This tells the interpreter to move to the parent
Chris Lattnerda272d12010-02-15 08:04:42 +0000355/// of the current node.
Chris Lattnerb21ba712010-02-25 02:04:40 +0000356class MoveParentMatcher : public Matcher {
Chris Lattnerda272d12010-02-15 08:04:42 +0000357public:
Chris Lattnerb21ba712010-02-25 02:04:40 +0000358 MoveParentMatcher() : Matcher(MoveParent) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000359
Chris Lattnerb21ba712010-02-25 02:04:40 +0000360 static inline bool classof(const Matcher *N) {
Chris Lattnerda272d12010-02-15 08:04:42 +0000361 return N->getKind() == MoveParent;
362 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000363
Chris Lattnerd323fd42010-02-27 06:22:57 +0000364 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
365
Chris Lattner58aa8342010-02-25 06:49:58 +0000366private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000367 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000368 virtual bool isEqualImpl(const Matcher *M) const { return true; }
369 virtual unsigned getHashImpl() const { return 0; }
Chris Lattnerda272d12010-02-15 08:04:42 +0000370};
371
Chris Lattnerb21ba712010-02-25 02:04:40 +0000372/// CheckSameMatcher - This checks to see if this node is exactly the same
Chris Lattnerda272d12010-02-15 08:04:42 +0000373/// node as the specified match that was recorded with 'Record'. This is used
374/// when patterns have the same name in them, like '(mul GPR:$in, GPR:$in)'.
Chris Lattnerb21ba712010-02-25 02:04:40 +0000375class CheckSameMatcher : public Matcher {
Chris Lattnerda272d12010-02-15 08:04:42 +0000376 unsigned MatchNumber;
377public:
Chris Lattnerb21ba712010-02-25 02:04:40 +0000378 CheckSameMatcher(unsigned matchnumber)
Chris Lattner58aa8342010-02-25 06:49:58 +0000379 : Matcher(CheckSame), MatchNumber(matchnumber) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000380
Chris Lattnerda272d12010-02-15 08:04:42 +0000381 unsigned getMatchNumber() const { return MatchNumber; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000382
Chris Lattnerb21ba712010-02-25 02:04:40 +0000383 static inline bool classof(const Matcher *N) {
Chris Lattnerda272d12010-02-15 08:04:42 +0000384 return N->getKind() == CheckSame;
385 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000386
Chris Lattnerd323fd42010-02-27 06:22:57 +0000387 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
388
Chris Lattner58aa8342010-02-25 06:49:58 +0000389private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000390 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000391 virtual bool isEqualImpl(const Matcher *M) const {
392 return cast<CheckSameMatcher>(M)->getMatchNumber() == getMatchNumber();
393 }
394 virtual unsigned getHashImpl() const { return getMatchNumber(); }
Chris Lattnerda272d12010-02-15 08:04:42 +0000395};
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000396
Chris Lattnerb21ba712010-02-25 02:04:40 +0000397/// CheckPatternPredicateMatcher - This checks the target-specific predicate
Chris Lattnerda272d12010-02-15 08:04:42 +0000398/// to see if the entire pattern is capable of matching. This predicate does
399/// not take a node as input. This is used for subtarget feature checks etc.
Chris Lattnerb21ba712010-02-25 02:04:40 +0000400class CheckPatternPredicateMatcher : public Matcher {
Chris Lattnerda272d12010-02-15 08:04:42 +0000401 std::string Predicate;
402public:
Chris Lattnerb21ba712010-02-25 02:04:40 +0000403 CheckPatternPredicateMatcher(StringRef predicate)
Chris Lattner58aa8342010-02-25 06:49:58 +0000404 : Matcher(CheckPatternPredicate), Predicate(predicate) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000405
Chris Lattnerda272d12010-02-15 08:04:42 +0000406 StringRef getPredicate() const { return Predicate; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000407
Chris Lattnerb21ba712010-02-25 02:04:40 +0000408 static inline bool classof(const Matcher *N) {
Chris Lattnerda272d12010-02-15 08:04:42 +0000409 return N->getKind() == CheckPatternPredicate;
410 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000411
Chris Lattnerd323fd42010-02-27 06:22:57 +0000412 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
413
Chris Lattner58aa8342010-02-25 06:49:58 +0000414private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000415 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000416 virtual bool isEqualImpl(const Matcher *M) const {
417 return cast<CheckPatternPredicateMatcher>(M)->getPredicate() == Predicate;
418 }
419 virtual unsigned getHashImpl() const;
Chris Lattnerda272d12010-02-15 08:04:42 +0000420};
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000421
Chris Lattnerb21ba712010-02-25 02:04:40 +0000422/// CheckPredicateMatcher - This checks the target-specific predicate to
Chris Lattnerda272d12010-02-15 08:04:42 +0000423/// see if the node is acceptable.
Chris Lattnerb21ba712010-02-25 02:04:40 +0000424class CheckPredicateMatcher : public Matcher {
Chris Lattner54379062011-04-17 21:38:24 +0000425 TreePattern *Pred;
Chris Lattnerda272d12010-02-15 08:04:42 +0000426public:
Chris Lattner54379062011-04-17 21:38:24 +0000427 CheckPredicateMatcher(const TreePredicateFn &pred);
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000428
Chris Lattner54379062011-04-17 21:38:24 +0000429 TreePredicateFn getPredicate() const;
Chris Lattnerda272d12010-02-15 08:04:42 +0000430
Chris Lattnerb21ba712010-02-25 02:04:40 +0000431 static inline bool classof(const Matcher *N) {
Chris Lattnerda272d12010-02-15 08:04:42 +0000432 return N->getKind() == CheckPredicate;
433 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000434
Chris Lattnerd323fd42010-02-27 06:22:57 +0000435 // TODO: Ok?
436 //virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
437
Chris Lattner58aa8342010-02-25 06:49:58 +0000438private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000439 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000440 virtual bool isEqualImpl(const Matcher *M) const {
Chris Lattner54379062011-04-17 21:38:24 +0000441 return cast<CheckPredicateMatcher>(M)->Pred == Pred;
Chris Lattner58aa8342010-02-25 06:49:58 +0000442 }
443 virtual unsigned getHashImpl() const;
Chris Lattnerda272d12010-02-15 08:04:42 +0000444};
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000445
446
Chris Lattnerb21ba712010-02-25 02:04:40 +0000447/// CheckOpcodeMatcher - This checks to see if the current node has the
Chris Lattnerda272d12010-02-15 08:04:42 +0000448/// specified opcode, if not it fails to match.
Chris Lattnerb21ba712010-02-25 02:04:40 +0000449class CheckOpcodeMatcher : public Matcher {
Chris Lattnera230f962010-02-27 21:48:43 +0000450 const SDNodeInfo &Opcode;
Chris Lattnerda272d12010-02-15 08:04:42 +0000451public:
Chris Lattnera230f962010-02-27 21:48:43 +0000452 CheckOpcodeMatcher(const SDNodeInfo &opcode)
453 : Matcher(CheckOpcode), Opcode(opcode) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000454
Chris Lattnera230f962010-02-27 21:48:43 +0000455 const SDNodeInfo &getOpcode() const { return Opcode; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000456
Chris Lattnerb21ba712010-02-25 02:04:40 +0000457 static inline bool classof(const Matcher *N) {
Chris Lattnerda272d12010-02-15 08:04:42 +0000458 return N->getKind() == CheckOpcode;
459 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000460
Chris Lattnerd323fd42010-02-27 06:22:57 +0000461 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
462
Chris Lattner58aa8342010-02-25 06:49:58 +0000463private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000464 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattnereb669212010-03-01 06:59:22 +0000465 virtual bool isEqualImpl(const Matcher *M) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000466 virtual unsigned getHashImpl() const;
Chris Lattner82781b92010-02-27 07:49:13 +0000467 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattnerda272d12010-02-15 08:04:42 +0000468};
Chris Lattnereb669212010-03-01 06:59:22 +0000469
470/// SwitchOpcodeMatcher - Switch based on the current node's opcode, dispatching
471/// to one matcher per opcode. If the opcode doesn't match any of the cases,
472/// then the match fails. This is semantically equivalent to a Scope node where
473/// every child does a CheckOpcode, but is much faster.
474class SwitchOpcodeMatcher : public Matcher {
475 SmallVector<std::pair<const SDNodeInfo*, Matcher*>, 8> Cases;
476public:
477 SwitchOpcodeMatcher(const std::pair<const SDNodeInfo*, Matcher*> *cases,
478 unsigned numcases)
479 : Matcher(SwitchOpcode), Cases(cases, cases+numcases) {}
480
481 static inline bool classof(const Matcher *N) {
482 return N->getKind() == SwitchOpcode;
483 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000484
Chris Lattnereb669212010-03-01 06:59:22 +0000485 unsigned getNumCases() const { return Cases.size(); }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000486
Chris Lattnereb669212010-03-01 06:59:22 +0000487 const SDNodeInfo &getCaseOpcode(unsigned i) const { return *Cases[i].first; }
488 Matcher *getCaseMatcher(unsigned i) { return Cases[i].second; }
489 const Matcher *getCaseMatcher(unsigned i) const { return Cases[i].second; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000490
Chris Lattnereb669212010-03-01 06:59:22 +0000491private:
492 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
493 virtual bool isEqualImpl(const Matcher *M) const { return false; }
494 virtual unsigned getHashImpl() const { return 4123; }
495};
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000496
Chris Lattnerb21ba712010-02-25 02:04:40 +0000497/// CheckTypeMatcher - This checks to see if the current node has the
Chris Lattner084df622010-03-24 00:41:19 +0000498/// specified type at the specified result, if not it fails to match.
Chris Lattnerb21ba712010-02-25 02:04:40 +0000499class CheckTypeMatcher : public Matcher {
Chris Lattnerda272d12010-02-15 08:04:42 +0000500 MVT::SimpleValueType Type;
Chris Lattner084df622010-03-24 00:41:19 +0000501 unsigned ResNo;
Chris Lattnerda272d12010-02-15 08:04:42 +0000502public:
Chris Lattner084df622010-03-24 00:41:19 +0000503 CheckTypeMatcher(MVT::SimpleValueType type, unsigned resno)
504 : Matcher(CheckType), Type(type), ResNo(resno) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000505
Chris Lattnerda272d12010-02-15 08:04:42 +0000506 MVT::SimpleValueType getType() const { return Type; }
Chris Lattner084df622010-03-24 00:41:19 +0000507 unsigned getResNo() const { return ResNo; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000508
Chris Lattnerb21ba712010-02-25 02:04:40 +0000509 static inline bool classof(const Matcher *N) {
Chris Lattnerda272d12010-02-15 08:04:42 +0000510 return N->getKind() == CheckType;
511 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000512
Chris Lattnerd323fd42010-02-27 06:22:57 +0000513 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
514
Chris Lattner58aa8342010-02-25 06:49:58 +0000515private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000516 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000517 virtual bool isEqualImpl(const Matcher *M) const {
Chris Lattner38717f62010-02-26 08:05:36 +0000518 return cast<CheckTypeMatcher>(M)->Type == Type;
Chris Lattner58aa8342010-02-25 06:49:58 +0000519 }
520 virtual unsigned getHashImpl() const { return Type; }
Chris Lattner82781b92010-02-27 07:49:13 +0000521 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattnerda272d12010-02-15 08:04:42 +0000522};
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000523
Chris Lattnercfe2eab2010-03-03 06:28:15 +0000524/// SwitchTypeMatcher - Switch based on the current node's type, dispatching
525/// to one matcher per case. If the type doesn't match any of the cases,
526/// then the match fails. This is semantically equivalent to a Scope node where
527/// every child does a CheckType, but is much faster.
528class SwitchTypeMatcher : public Matcher {
529 SmallVector<std::pair<MVT::SimpleValueType, Matcher*>, 8> Cases;
530public:
531 SwitchTypeMatcher(const std::pair<MVT::SimpleValueType, Matcher*> *cases,
532 unsigned numcases)
533 : Matcher(SwitchType), Cases(cases, cases+numcases) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000534
Chris Lattnercfe2eab2010-03-03 06:28:15 +0000535 static inline bool classof(const Matcher *N) {
536 return N->getKind() == SwitchType;
537 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000538
Chris Lattnercfe2eab2010-03-03 06:28:15 +0000539 unsigned getNumCases() const { return Cases.size(); }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000540
Chris Lattnercfe2eab2010-03-03 06:28:15 +0000541 MVT::SimpleValueType getCaseType(unsigned i) const { return Cases[i].first; }
542 Matcher *getCaseMatcher(unsigned i) { return Cases[i].second; }
543 const Matcher *getCaseMatcher(unsigned i) const { return Cases[i].second; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000544
Chris Lattnercfe2eab2010-03-03 06:28:15 +0000545private:
546 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
547 virtual bool isEqualImpl(const Matcher *M) const { return false; }
548 virtual unsigned getHashImpl() const { return 4123; }
549};
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000550
551
Chris Lattnerb21ba712010-02-25 02:04:40 +0000552/// CheckChildTypeMatcher - This checks to see if a child node has the
Chris Lattner23cfda72010-02-24 20:15:25 +0000553/// specified type, if not it fails to match.
Chris Lattnerb21ba712010-02-25 02:04:40 +0000554class CheckChildTypeMatcher : public Matcher {
Chris Lattner23cfda72010-02-24 20:15:25 +0000555 unsigned ChildNo;
556 MVT::SimpleValueType Type;
557public:
Chris Lattnerb21ba712010-02-25 02:04:40 +0000558 CheckChildTypeMatcher(unsigned childno, MVT::SimpleValueType type)
559 : Matcher(CheckChildType), ChildNo(childno), Type(type) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000560
Chris Lattner23cfda72010-02-24 20:15:25 +0000561 unsigned getChildNo() const { return ChildNo; }
562 MVT::SimpleValueType getType() const { return Type; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000563
Chris Lattnerb21ba712010-02-25 02:04:40 +0000564 static inline bool classof(const Matcher *N) {
Chris Lattner23cfda72010-02-24 20:15:25 +0000565 return N->getKind() == CheckChildType;
566 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000567
Chris Lattnerd323fd42010-02-27 06:22:57 +0000568 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
569
Chris Lattner58aa8342010-02-25 06:49:58 +0000570private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000571 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000572 virtual bool isEqualImpl(const Matcher *M) const {
573 return cast<CheckChildTypeMatcher>(M)->ChildNo == ChildNo &&
574 cast<CheckChildTypeMatcher>(M)->Type == Type;
575 }
576 virtual unsigned getHashImpl() const { return (Type << 3) | ChildNo; }
Chris Lattner82781b92010-02-27 07:49:13 +0000577 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattner23cfda72010-02-24 20:15:25 +0000578};
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000579
Chris Lattnerda272d12010-02-15 08:04:42 +0000580
Chris Lattnerb21ba712010-02-25 02:04:40 +0000581/// CheckIntegerMatcher - This checks to see if the current node is a
Chris Lattnerda272d12010-02-15 08:04:42 +0000582/// ConstantSDNode with the specified integer value, if not it fails to match.
Chris Lattnerb21ba712010-02-25 02:04:40 +0000583class CheckIntegerMatcher : public Matcher {
Chris Lattnerda272d12010-02-15 08:04:42 +0000584 int64_t Value;
585public:
Chris Lattnerb21ba712010-02-25 02:04:40 +0000586 CheckIntegerMatcher(int64_t value)
587 : Matcher(CheckInteger), Value(value) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000588
Chris Lattnerda272d12010-02-15 08:04:42 +0000589 int64_t getValue() const { return Value; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000590
Chris Lattnerb21ba712010-02-25 02:04:40 +0000591 static inline bool classof(const Matcher *N) {
Chris Lattnerda272d12010-02-15 08:04:42 +0000592 return N->getKind() == CheckInteger;
593 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000594
Chris Lattnerd323fd42010-02-27 06:22:57 +0000595 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
596
Chris Lattner58aa8342010-02-25 06:49:58 +0000597private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000598 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000599 virtual bool isEqualImpl(const Matcher *M) const {
600 return cast<CheckIntegerMatcher>(M)->Value == Value;
601 }
602 virtual unsigned getHashImpl() const { return Value; }
Chris Lattner24789622010-02-27 08:11:15 +0000603 virtual bool isContradictoryImpl(const Matcher *M) const;
Chris Lattnerda272d12010-02-15 08:04:42 +0000604};
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000605
Chris Lattnerb21ba712010-02-25 02:04:40 +0000606/// CheckCondCodeMatcher - This checks to see if the current node is a
Chris Lattnerda272d12010-02-15 08:04:42 +0000607/// CondCodeSDNode with the specified condition, if not it fails to match.
Chris Lattnerb21ba712010-02-25 02:04:40 +0000608class CheckCondCodeMatcher : public Matcher {
Chris Lattnerda272d12010-02-15 08:04:42 +0000609 StringRef CondCodeName;
610public:
Chris Lattnerb21ba712010-02-25 02:04:40 +0000611 CheckCondCodeMatcher(StringRef condcodename)
612 : Matcher(CheckCondCode), CondCodeName(condcodename) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000613
Chris Lattnerda272d12010-02-15 08:04:42 +0000614 StringRef getCondCodeName() const { return CondCodeName; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000615
Chris Lattnerb21ba712010-02-25 02:04:40 +0000616 static inline bool classof(const Matcher *N) {
Chris Lattnerda272d12010-02-15 08:04:42 +0000617 return N->getKind() == CheckCondCode;
618 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000619
Chris Lattnerd323fd42010-02-27 06:22:57 +0000620 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
621
Chris Lattner58aa8342010-02-25 06:49:58 +0000622private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000623 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000624 virtual bool isEqualImpl(const Matcher *M) const {
625 return cast<CheckCondCodeMatcher>(M)->CondCodeName == CondCodeName;
626 }
627 virtual unsigned getHashImpl() const;
Chris Lattnerda272d12010-02-15 08:04:42 +0000628};
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000629
Chris Lattnerb21ba712010-02-25 02:04:40 +0000630/// CheckValueTypeMatcher - This checks to see if the current node is a
Chris Lattnerda272d12010-02-15 08:04:42 +0000631/// VTSDNode with the specified type, if not it fails to match.
Chris Lattnerb21ba712010-02-25 02:04:40 +0000632class CheckValueTypeMatcher : public Matcher {
Chris Lattnerda272d12010-02-15 08:04:42 +0000633 StringRef TypeName;
634public:
Chris Lattnerb21ba712010-02-25 02:04:40 +0000635 CheckValueTypeMatcher(StringRef type_name)
636 : Matcher(CheckValueType), TypeName(type_name) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000637
Chris Lattnerda272d12010-02-15 08:04:42 +0000638 StringRef getTypeName() const { return TypeName; }
639
Chris Lattnerb21ba712010-02-25 02:04:40 +0000640 static inline bool classof(const Matcher *N) {
Chris Lattnerda272d12010-02-15 08:04:42 +0000641 return N->getKind() == CheckValueType;
642 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000643
Chris Lattnerd323fd42010-02-27 06:22:57 +0000644 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
645
Chris Lattner58aa8342010-02-25 06:49:58 +0000646private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000647 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000648 virtual bool isEqualImpl(const Matcher *M) const {
649 return cast<CheckValueTypeMatcher>(M)->TypeName == TypeName;
650 }
651 virtual unsigned getHashImpl() const;
Chris Lattner48aa5752010-03-07 06:29:26 +0000652 bool isContradictoryImpl(const Matcher *M) const;
Chris Lattnerda272d12010-02-15 08:04:42 +0000653};
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000654
655
656
Chris Lattnerb21ba712010-02-25 02:04:40 +0000657/// CheckComplexPatMatcher - This node runs the specified ComplexPattern on
Chris Lattnerda272d12010-02-15 08:04:42 +0000658/// the current node.
Chris Lattnerb21ba712010-02-25 02:04:40 +0000659class CheckComplexPatMatcher : public Matcher {
Chris Lattnerda272d12010-02-15 08:04:42 +0000660 const ComplexPattern &Pattern;
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000661
662 /// MatchNumber - This is the recorded nodes slot that contains the node we
663 /// want to match against.
Chris Lattner57bf8a42010-03-04 01:23:08 +0000664 unsigned MatchNumber;
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000665
Chris Lattner57bf8a42010-03-04 01:23:08 +0000666 /// Name - The name of the node we're matching, for comment emission.
667 std::string Name;
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000668
Chris Lattnerd1aca7c2010-03-04 00:28:05 +0000669 /// FirstResult - This is the first slot in the RecordedNodes list that the
670 /// result of the match populates.
671 unsigned FirstResult;
Chris Lattnerda272d12010-02-15 08:04:42 +0000672public:
Chris Lattner57bf8a42010-03-04 01:23:08 +0000673 CheckComplexPatMatcher(const ComplexPattern &pattern, unsigned matchnumber,
674 const std::string &name, unsigned firstresult)
675 : Matcher(CheckComplexPat), Pattern(pattern), MatchNumber(matchnumber),
676 Name(name), FirstResult(firstresult) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000677
Chris Lattnere609a512010-02-17 00:31:50 +0000678 const ComplexPattern &getPattern() const { return Pattern; }
Chris Lattner57bf8a42010-03-04 01:23:08 +0000679 unsigned getMatchNumber() const { return MatchNumber; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000680
Chris Lattner57bf8a42010-03-04 01:23:08 +0000681 const std::string getName() const { return Name; }
Chris Lattnerd1aca7c2010-03-04 00:28:05 +0000682 unsigned getFirstResult() const { return FirstResult; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000683
Chris Lattnerb21ba712010-02-25 02:04:40 +0000684 static inline bool classof(const Matcher *N) {
Chris Lattnerda272d12010-02-15 08:04:42 +0000685 return N->getKind() == CheckComplexPat;
686 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000687
Chris Lattnerd323fd42010-02-27 06:22:57 +0000688 // Not safe to move a pattern predicate past a complex pattern.
689 virtual bool isSafeToReorderWithPatternPredicate() const { return false; }
690
Chris Lattner58aa8342010-02-25 06:49:58 +0000691private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000692 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000693 virtual bool isEqualImpl(const Matcher *M) const {
Chris Lattner57bf8a42010-03-04 01:23:08 +0000694 return &cast<CheckComplexPatMatcher>(M)->Pattern == &Pattern &&
695 cast<CheckComplexPatMatcher>(M)->MatchNumber == MatchNumber;
Chris Lattner58aa8342010-02-25 06:49:58 +0000696 }
697 virtual unsigned getHashImpl() const {
Chris Lattner57bf8a42010-03-04 01:23:08 +0000698 return (unsigned)(intptr_t)&Pattern ^ MatchNumber;
Chris Lattner58aa8342010-02-25 06:49:58 +0000699 }
Chris Lattnerda272d12010-02-15 08:04:42 +0000700};
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000701
Chris Lattnerb21ba712010-02-25 02:04:40 +0000702/// CheckAndImmMatcher - This checks to see if the current node is an 'and'
Chris Lattnerda272d12010-02-15 08:04:42 +0000703/// with something equivalent to the specified immediate.
Chris Lattnerb21ba712010-02-25 02:04:40 +0000704class CheckAndImmMatcher : public Matcher {
Chris Lattnerda272d12010-02-15 08:04:42 +0000705 int64_t Value;
706public:
Chris Lattnerb21ba712010-02-25 02:04:40 +0000707 CheckAndImmMatcher(int64_t value)
708 : Matcher(CheckAndImm), Value(value) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000709
Chris Lattnerda272d12010-02-15 08:04:42 +0000710 int64_t getValue() const { return Value; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000711
Chris Lattnerb21ba712010-02-25 02:04:40 +0000712 static inline bool classof(const Matcher *N) {
Chris Lattnerda272d12010-02-15 08:04:42 +0000713 return N->getKind() == CheckAndImm;
714 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000715
Chris Lattnerd323fd42010-02-27 06:22:57 +0000716 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
717
Chris Lattner58aa8342010-02-25 06:49:58 +0000718private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000719 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000720 virtual bool isEqualImpl(const Matcher *M) const {
721 return cast<CheckAndImmMatcher>(M)->Value == Value;
722 }
723 virtual unsigned getHashImpl() const { return Value; }
Chris Lattnerda272d12010-02-15 08:04:42 +0000724};
725
Chris Lattnerb21ba712010-02-25 02:04:40 +0000726/// CheckOrImmMatcher - This checks to see if the current node is an 'and'
Chris Lattnerda272d12010-02-15 08:04:42 +0000727/// with something equivalent to the specified immediate.
Chris Lattnerb21ba712010-02-25 02:04:40 +0000728class CheckOrImmMatcher : public Matcher {
Chris Lattnerda272d12010-02-15 08:04:42 +0000729 int64_t Value;
730public:
Chris Lattnerb21ba712010-02-25 02:04:40 +0000731 CheckOrImmMatcher(int64_t value)
732 : Matcher(CheckOrImm), Value(value) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000733
Chris Lattnerda272d12010-02-15 08:04:42 +0000734 int64_t getValue() const { return Value; }
735
Chris Lattnerb21ba712010-02-25 02:04:40 +0000736 static inline bool classof(const Matcher *N) {
Chris Lattnerda272d12010-02-15 08:04:42 +0000737 return N->getKind() == CheckOrImm;
738 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000739
Chris Lattnerd323fd42010-02-27 06:22:57 +0000740 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
741
Chris Lattner58aa8342010-02-25 06:49:58 +0000742private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000743 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000744 virtual bool isEqualImpl(const Matcher *M) const {
745 return cast<CheckOrImmMatcher>(M)->Value == Value;
746 }
747 virtual unsigned getHashImpl() const { return Value; }
Chris Lattnerda272d12010-02-15 08:04:42 +0000748};
Chris Lattnere39650a2010-02-16 06:10:58 +0000749
Chris Lattnerb21ba712010-02-25 02:04:40 +0000750/// CheckFoldableChainNodeMatcher - This checks to see if the current node
Chris Lattner21390d72010-02-16 19:15:55 +0000751/// (which defines a chain operand) is safe to fold into a larger pattern.
Chris Lattnerb21ba712010-02-25 02:04:40 +0000752class CheckFoldableChainNodeMatcher : public Matcher {
Chris Lattnere39650a2010-02-16 06:10:58 +0000753public:
Chris Lattnerb21ba712010-02-25 02:04:40 +0000754 CheckFoldableChainNodeMatcher()
755 : Matcher(CheckFoldableChainNode) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000756
Chris Lattnerb21ba712010-02-25 02:04:40 +0000757 static inline bool classof(const Matcher *N) {
Chris Lattner21390d72010-02-16 19:15:55 +0000758 return N->getKind() == CheckFoldableChainNode;
Chris Lattnere39650a2010-02-16 06:10:58 +0000759 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000760
Chris Lattnerd323fd42010-02-27 06:22:57 +0000761 virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
762
Chris Lattner58aa8342010-02-25 06:49:58 +0000763private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000764 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000765 virtual bool isEqualImpl(const Matcher *M) const { return true; }
766 virtual unsigned getHashImpl() const { return 0; }
Chris Lattnere39650a2010-02-16 06:10:58 +0000767};
768
Chris Lattnerb21ba712010-02-25 02:04:40 +0000769/// EmitIntegerMatcher - This creates a new TargetConstant.
770class EmitIntegerMatcher : public Matcher {
Chris Lattner845c0422010-02-18 22:03:03 +0000771 int64_t Val;
772 MVT::SimpleValueType VT;
773public:
Chris Lattnerb21ba712010-02-25 02:04:40 +0000774 EmitIntegerMatcher(int64_t val, MVT::SimpleValueType vt)
775 : Matcher(EmitInteger), Val(val), VT(vt) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000776
Chris Lattner906b4992010-02-19 07:49:56 +0000777 int64_t getValue() const { return Val; }
Chris Lattner845c0422010-02-18 22:03:03 +0000778 MVT::SimpleValueType getVT() const { return VT; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000779
Chris Lattnerb21ba712010-02-25 02:04:40 +0000780 static inline bool classof(const Matcher *N) {
Chris Lattner845c0422010-02-18 22:03:03 +0000781 return N->getKind() == EmitInteger;
782 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000783
Chris Lattner58aa8342010-02-25 06:49:58 +0000784private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000785 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000786 virtual bool isEqualImpl(const Matcher *M) const {
787 return cast<EmitIntegerMatcher>(M)->Val == Val &&
788 cast<EmitIntegerMatcher>(M)->VT == VT;
789 }
790 virtual unsigned getHashImpl() const { return (Val << 4) | VT; }
Chris Lattner845c0422010-02-18 22:03:03 +0000791};
Chris Lattner8e946be2010-02-21 03:22:59 +0000792
Chris Lattnerb21ba712010-02-25 02:04:40 +0000793/// EmitStringIntegerMatcher - A target constant whose value is represented
Chris Lattner8e946be2010-02-21 03:22:59 +0000794/// by a string.
Chris Lattnerb21ba712010-02-25 02:04:40 +0000795class EmitStringIntegerMatcher : public Matcher {
Chris Lattner8e946be2010-02-21 03:22:59 +0000796 std::string Val;
797 MVT::SimpleValueType VT;
798public:
Chris Lattnerb21ba712010-02-25 02:04:40 +0000799 EmitStringIntegerMatcher(const std::string &val, MVT::SimpleValueType vt)
800 : Matcher(EmitStringInteger), Val(val), VT(vt) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000801
Chris Lattner8e946be2010-02-21 03:22:59 +0000802 const std::string &getValue() const { return Val; }
803 MVT::SimpleValueType getVT() const { return VT; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000804
Chris Lattnerb21ba712010-02-25 02:04:40 +0000805 static inline bool classof(const Matcher *N) {
Chris Lattner8e946be2010-02-21 03:22:59 +0000806 return N->getKind() == EmitStringInteger;
807 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000808
Chris Lattner58aa8342010-02-25 06:49:58 +0000809private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000810 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000811 virtual bool isEqualImpl(const Matcher *M) const {
812 return cast<EmitStringIntegerMatcher>(M)->Val == Val &&
813 cast<EmitStringIntegerMatcher>(M)->VT == VT;
814 }
815 virtual unsigned getHashImpl() const;
Chris Lattner8e946be2010-02-21 03:22:59 +0000816};
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000817
Chris Lattnerb21ba712010-02-25 02:04:40 +0000818/// EmitRegisterMatcher - This creates a new TargetConstant.
819class EmitRegisterMatcher : public Matcher {
Chris Lattner845c0422010-02-18 22:03:03 +0000820 /// Reg - The def for the register that we're emitting. If this is null, then
821 /// this is a reference to zero_reg.
Jim Grosbach4a6d7352011-03-11 02:19:02 +0000822 const CodeGenRegister *Reg;
Chris Lattner845c0422010-02-18 22:03:03 +0000823 MVT::SimpleValueType VT;
824public:
Jim Grosbach4a6d7352011-03-11 02:19:02 +0000825 EmitRegisterMatcher(const CodeGenRegister *reg, MVT::SimpleValueType vt)
Chris Lattnerb21ba712010-02-25 02:04:40 +0000826 : Matcher(EmitRegister), Reg(reg), VT(vt) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000827
Jim Grosbach4a6d7352011-03-11 02:19:02 +0000828 const CodeGenRegister *getReg() const { return Reg; }
Chris Lattner845c0422010-02-18 22:03:03 +0000829 MVT::SimpleValueType getVT() const { return VT; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000830
Chris Lattnerb21ba712010-02-25 02:04:40 +0000831 static inline bool classof(const Matcher *N) {
Chris Lattner845c0422010-02-18 22:03:03 +0000832 return N->getKind() == EmitRegister;
833 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000834
Chris Lattner58aa8342010-02-25 06:49:58 +0000835private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000836 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000837 virtual bool isEqualImpl(const Matcher *M) const {
838 return cast<EmitRegisterMatcher>(M)->Reg == Reg &&
839 cast<EmitRegisterMatcher>(M)->VT == VT;
840 }
841 virtual unsigned getHashImpl() const {
842 return ((unsigned)(intptr_t)Reg) << 4 | VT;
843 }
Chris Lattner845c0422010-02-18 22:03:03 +0000844};
Chris Lattner8e946be2010-02-21 03:22:59 +0000845
Chris Lattnerb21ba712010-02-25 02:04:40 +0000846/// EmitConvertToTargetMatcher - Emit an operation that reads a specified
Chris Lattner8e946be2010-02-21 03:22:59 +0000847/// recorded node and converts it from being a ISD::Constant to
848/// ISD::TargetConstant, likewise for ConstantFP.
Chris Lattnerb21ba712010-02-25 02:04:40 +0000849class EmitConvertToTargetMatcher : public Matcher {
Chris Lattner8e946be2010-02-21 03:22:59 +0000850 unsigned Slot;
851public:
Chris Lattnerb21ba712010-02-25 02:04:40 +0000852 EmitConvertToTargetMatcher(unsigned slot)
853 : Matcher(EmitConvertToTarget), Slot(slot) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000854
Chris Lattner8e946be2010-02-21 03:22:59 +0000855 unsigned getSlot() const { return Slot; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000856
Chris Lattnerb21ba712010-02-25 02:04:40 +0000857 static inline bool classof(const Matcher *N) {
Chris Lattner8e946be2010-02-21 03:22:59 +0000858 return N->getKind() == EmitConvertToTarget;
859 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000860
Chris Lattner58aa8342010-02-25 06:49:58 +0000861private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000862 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000863 virtual bool isEqualImpl(const Matcher *M) const {
864 return cast<EmitConvertToTargetMatcher>(M)->Slot == Slot;
865 }
866 virtual unsigned getHashImpl() const { return Slot; }
Chris Lattner8e946be2010-02-21 03:22:59 +0000867};
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000868
Chris Lattnerb21ba712010-02-25 02:04:40 +0000869/// EmitMergeInputChainsMatcher - Emit a node that merges a list of input
Chris Lattner8e946be2010-02-21 03:22:59 +0000870/// chains together with a token factor. The list of nodes are the nodes in the
871/// matched pattern that have chain input/outputs. This node adds all input
872/// chains of these nodes if they are not themselves a node in the pattern.
Chris Lattnerb21ba712010-02-25 02:04:40 +0000873class EmitMergeInputChainsMatcher : public Matcher {
Chris Lattner8e946be2010-02-21 03:22:59 +0000874 SmallVector<unsigned, 3> ChainNodes;
875public:
Chris Lattnerb21ba712010-02-25 02:04:40 +0000876 EmitMergeInputChainsMatcher(const unsigned *nodes, unsigned NumNodes)
877 : Matcher(EmitMergeInputChains), ChainNodes(nodes, nodes+NumNodes) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000878
Chris Lattner8e946be2010-02-21 03:22:59 +0000879 unsigned getNumNodes() const { return ChainNodes.size(); }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000880
Chris Lattner8e946be2010-02-21 03:22:59 +0000881 unsigned getNode(unsigned i) const {
882 assert(i < ChainNodes.size());
883 return ChainNodes[i];
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000884 }
885
Chris Lattnerb21ba712010-02-25 02:04:40 +0000886 static inline bool classof(const Matcher *N) {
Chris Lattner8e946be2010-02-21 03:22:59 +0000887 return N->getKind() == EmitMergeInputChains;
888 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000889
Chris Lattner58aa8342010-02-25 06:49:58 +0000890private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000891 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000892 virtual bool isEqualImpl(const Matcher *M) const {
893 return cast<EmitMergeInputChainsMatcher>(M)->ChainNodes == ChainNodes;
894 }
895 virtual unsigned getHashImpl() const;
Chris Lattner8e946be2010-02-21 03:22:59 +0000896};
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000897
Chris Lattnerb21ba712010-02-25 02:04:40 +0000898/// EmitCopyToRegMatcher - Emit a CopyToReg node from a value to a physreg,
Chris Lattner8950bca2010-12-23 17:03:20 +0000899/// pushing the chain and glue results.
Chris Lattner8e946be2010-02-21 03:22:59 +0000900///
Chris Lattnerb21ba712010-02-25 02:04:40 +0000901class EmitCopyToRegMatcher : public Matcher {
Chris Lattner8e946be2010-02-21 03:22:59 +0000902 unsigned SrcSlot; // Value to copy into the physreg.
903 Record *DestPhysReg;
904public:
Chris Lattnerb21ba712010-02-25 02:04:40 +0000905 EmitCopyToRegMatcher(unsigned srcSlot, Record *destPhysReg)
906 : Matcher(EmitCopyToReg), SrcSlot(srcSlot), DestPhysReg(destPhysReg) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000907
Chris Lattner8e946be2010-02-21 03:22:59 +0000908 unsigned getSrcSlot() const { return SrcSlot; }
909 Record *getDestPhysReg() const { return DestPhysReg; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000910
Chris Lattnerb21ba712010-02-25 02:04:40 +0000911 static inline bool classof(const Matcher *N) {
Chris Lattner8e946be2010-02-21 03:22:59 +0000912 return N->getKind() == EmitCopyToReg;
913 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000914
Chris Lattner58aa8342010-02-25 06:49:58 +0000915private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000916 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000917 virtual bool isEqualImpl(const Matcher *M) const {
918 return cast<EmitCopyToRegMatcher>(M)->SrcSlot == SrcSlot &&
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000919 cast<EmitCopyToRegMatcher>(M)->DestPhysReg == DestPhysReg;
Chris Lattner58aa8342010-02-25 06:49:58 +0000920 }
921 virtual unsigned getHashImpl() const {
922 return SrcSlot ^ ((unsigned)(intptr_t)DestPhysReg << 4);
923 }
Chris Lattner8e946be2010-02-21 03:22:59 +0000924};
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000925
926
927
Chris Lattnerb21ba712010-02-25 02:04:40 +0000928/// EmitNodeXFormMatcher - Emit an operation that runs an SDNodeXForm on a
Chris Lattner8e946be2010-02-21 03:22:59 +0000929/// recorded node and records the result.
Chris Lattnerb21ba712010-02-25 02:04:40 +0000930class EmitNodeXFormMatcher : public Matcher {
Chris Lattner8e946be2010-02-21 03:22:59 +0000931 unsigned Slot;
932 Record *NodeXForm;
933public:
Chris Lattnerb21ba712010-02-25 02:04:40 +0000934 EmitNodeXFormMatcher(unsigned slot, Record *nodeXForm)
935 : Matcher(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000936
Chris Lattner8e946be2010-02-21 03:22:59 +0000937 unsigned getSlot() const { return Slot; }
938 Record *getNodeXForm() const { return NodeXForm; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000939
Chris Lattnerb21ba712010-02-25 02:04:40 +0000940 static inline bool classof(const Matcher *N) {
Chris Lattner8e946be2010-02-21 03:22:59 +0000941 return N->getKind() == EmitNodeXForm;
942 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000943
Chris Lattner58aa8342010-02-25 06:49:58 +0000944private:
Chris Lattnera5028a62010-02-25 06:53:39 +0000945 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +0000946 virtual bool isEqualImpl(const Matcher *M) const {
947 return cast<EmitNodeXFormMatcher>(M)->Slot == Slot &&
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000948 cast<EmitNodeXFormMatcher>(M)->NodeXForm == NodeXForm;
Chris Lattner58aa8342010-02-25 06:49:58 +0000949 }
950 virtual unsigned getHashImpl() const {
951 return Slot ^ ((unsigned)(intptr_t)NodeXForm << 4);
952 }
Chris Lattner8e946be2010-02-21 03:22:59 +0000953};
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000954
Chris Lattnere86097a2010-02-28 02:31:26 +0000955/// EmitNodeMatcherCommon - Common class shared between EmitNode and
Chris Lattner9a215002010-02-28 20:55:18 +0000956/// MorphNodeTo.
Chris Lattnere86097a2010-02-28 02:31:26 +0000957class EmitNodeMatcherCommon : public Matcher {
Chris Lattner8e946be2010-02-21 03:22:59 +0000958 std::string OpcodeName;
959 const SmallVector<MVT::SimpleValueType, 3> VTs;
960 const SmallVector<unsigned, 6> Operands;
Chris Lattner036609b2010-12-23 18:28:41 +0000961 bool HasChain, HasInGlue, HasOutGlue, HasMemRefs;
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000962
Chris Lattner8e946be2010-02-21 03:22:59 +0000963 /// NumFixedArityOperands - If this is a fixed arity node, this is set to -1.
964 /// If this is a varidic node, this is set to the number of fixed arity
965 /// operands in the root of the pattern. The rest are appended to this node.
966 int NumFixedArityOperands;
967public:
Chris Lattnere86097a2010-02-28 02:31:26 +0000968 EmitNodeMatcherCommon(const std::string &opcodeName,
969 const MVT::SimpleValueType *vts, unsigned numvts,
970 const unsigned *operands, unsigned numops,
Chris Lattner8950bca2010-12-23 17:03:20 +0000971 bool hasChain, bool hasInGlue, bool hasOutGlue,
Chris Lattnerff7fb602010-02-28 21:53:42 +0000972 bool hasmemrefs,
Chris Lattner9a215002010-02-28 20:55:18 +0000973 int numfixedarityoperands, bool isMorphNodeTo)
974 : Matcher(isMorphNodeTo ? MorphNodeTo : EmitNode), OpcodeName(opcodeName),
Chris Lattner8e946be2010-02-21 03:22:59 +0000975 VTs(vts, vts+numvts), Operands(operands, operands+numops),
Chris Lattner036609b2010-12-23 18:28:41 +0000976 HasChain(hasChain), HasInGlue(hasInGlue), HasOutGlue(hasOutGlue),
Chris Lattnerff7fb602010-02-28 21:53:42 +0000977 HasMemRefs(hasmemrefs), NumFixedArityOperands(numfixedarityoperands) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000978
Chris Lattner8e946be2010-02-21 03:22:59 +0000979 const std::string &getOpcodeName() const { return OpcodeName; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000980
Chris Lattner8e946be2010-02-21 03:22:59 +0000981 unsigned getNumVTs() const { return VTs.size(); }
982 MVT::SimpleValueType getVT(unsigned i) const {
983 assert(i < VTs.size());
984 return VTs[i];
985 }
Chris Lattnerc78f2a32010-02-28 20:49:53 +0000986
Chris Lattner8e946be2010-02-21 03:22:59 +0000987 unsigned getNumOperands() const { return Operands.size(); }
988 unsigned getOperand(unsigned i) const {
989 assert(i < Operands.size());
990 return Operands[i];
Chris Lattnerc78f2a32010-02-28 20:49:53 +0000991 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000992
Chris Lattnerc78f2a32010-02-28 20:49:53 +0000993 const SmallVectorImpl<MVT::SimpleValueType> &getVTList() const { return VTs; }
994 const SmallVectorImpl<unsigned> &getOperandList() const { return Operands; }
995
Jim Grosbachfbadcd02010-12-21 16:16:00 +0000996
Chris Lattner8e946be2010-02-21 03:22:59 +0000997 bool hasChain() const { return HasChain; }
Chris Lattner036609b2010-12-23 18:28:41 +0000998 bool hasInFlag() const { return HasInGlue; }
999 bool hasOutFlag() const { return HasOutGlue; }
Chris Lattner8e946be2010-02-21 03:22:59 +00001000 bool hasMemRefs() const { return HasMemRefs; }
1001 int getNumFixedArityOperands() const { return NumFixedArityOperands; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +00001002
Chris Lattnerb21ba712010-02-25 02:04:40 +00001003 static inline bool classof(const Matcher *N) {
Chris Lattner9a215002010-02-28 20:55:18 +00001004 return N->getKind() == EmitNode || N->getKind() == MorphNodeTo;
Chris Lattner845c0422010-02-18 22:03:03 +00001005 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +00001006
Chris Lattner58aa8342010-02-25 06:49:58 +00001007private:
Chris Lattnera5028a62010-02-25 06:53:39 +00001008 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +00001009 virtual bool isEqualImpl(const Matcher *M) const;
1010 virtual unsigned getHashImpl() const;
Chris Lattner845c0422010-02-18 22:03:03 +00001011};
Jim Grosbachfbadcd02010-12-21 16:16:00 +00001012
Chris Lattnere86097a2010-02-28 02:31:26 +00001013/// EmitNodeMatcher - This signals a successful match and generates a node.
1014class EmitNodeMatcher : public EmitNodeMatcherCommon {
David Blaikie2d24e2a2011-12-20 02:50:00 +00001015 virtual void anchor();
Chris Lattner6281cda2010-02-28 02:41:25 +00001016 unsigned FirstResultSlot;
Chris Lattnere86097a2010-02-28 02:31:26 +00001017public:
1018 EmitNodeMatcher(const std::string &opcodeName,
1019 const MVT::SimpleValueType *vts, unsigned numvts,
1020 const unsigned *operands, unsigned numops,
Chris Lattnerff7fb602010-02-28 21:53:42 +00001021 bool hasChain, bool hasInFlag, bool hasOutFlag,
1022 bool hasmemrefs,
Chris Lattner6281cda2010-02-28 02:41:25 +00001023 int numfixedarityoperands, unsigned firstresultslot)
Chris Lattnere86097a2010-02-28 02:31:26 +00001024 : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
Chris Lattnerff7fb602010-02-28 21:53:42 +00001025 hasInFlag, hasOutFlag, hasmemrefs,
1026 numfixedarityoperands, false),
Chris Lattner6281cda2010-02-28 02:41:25 +00001027 FirstResultSlot(firstresultslot) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +00001028
Chris Lattner6281cda2010-02-28 02:41:25 +00001029 unsigned getFirstResultSlot() const { return FirstResultSlot; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +00001030
Chris Lattnere86097a2010-02-28 02:31:26 +00001031 static inline bool classof(const Matcher *N) {
1032 return N->getKind() == EmitNode;
1033 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +00001034
Chris Lattnere86097a2010-02-28 02:31:26 +00001035};
Jim Grosbachfbadcd02010-12-21 16:16:00 +00001036
Chris Lattner9a215002010-02-28 20:55:18 +00001037class MorphNodeToMatcher : public EmitNodeMatcherCommon {
David Blaikie2d24e2a2011-12-20 02:50:00 +00001038 virtual void anchor();
Chris Lattnere86097a2010-02-28 02:31:26 +00001039 const PatternToMatch &Pattern;
1040public:
Chris Lattner9a215002010-02-28 20:55:18 +00001041 MorphNodeToMatcher(const std::string &opcodeName,
1042 const MVT::SimpleValueType *vts, unsigned numvts,
1043 const unsigned *operands, unsigned numops,
Chris Lattnerff7fb602010-02-28 21:53:42 +00001044 bool hasChain, bool hasInFlag, bool hasOutFlag,
1045 bool hasmemrefs,
Chris Lattner9a215002010-02-28 20:55:18 +00001046 int numfixedarityoperands, const PatternToMatch &pattern)
Chris Lattnere86097a2010-02-28 02:31:26 +00001047 : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
Chris Lattnerff7fb602010-02-28 21:53:42 +00001048 hasInFlag, hasOutFlag, hasmemrefs,
1049 numfixedarityoperands, true),
Chris Lattnere86097a2010-02-28 02:31:26 +00001050 Pattern(pattern) {
1051 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +00001052
Chris Lattnere86097a2010-02-28 02:31:26 +00001053 const PatternToMatch &getPattern() const { return Pattern; }
1054
1055 static inline bool classof(const Matcher *N) {
Chris Lattner9a215002010-02-28 20:55:18 +00001056 return N->getKind() == MorphNodeTo;
Chris Lattnere86097a2010-02-28 02:31:26 +00001057 }
1058};
Jim Grosbachfbadcd02010-12-21 16:16:00 +00001059
Chris Lattner8950bca2010-12-23 17:03:20 +00001060/// MarkGlueResultsMatcher - This node indicates which non-root nodes in the
1061/// pattern produce glue. This allows CompleteMatchMatcher to update them
1062/// with the output glue of the resultant code.
1063class MarkGlueResultsMatcher : public Matcher {
1064 SmallVector<unsigned, 3> GlueResultNodes;
Chris Lattner02f73582010-02-24 05:33:42 +00001065public:
Chris Lattner8950bca2010-12-23 17:03:20 +00001066 MarkGlueResultsMatcher(const unsigned *nodes, unsigned NumNodes)
1067 : Matcher(MarkGlueResults), GlueResultNodes(nodes, nodes+NumNodes) {}
Jim Grosbachfbadcd02010-12-21 16:16:00 +00001068
Chris Lattner8950bca2010-12-23 17:03:20 +00001069 unsigned getNumNodes() const { return GlueResultNodes.size(); }
Jim Grosbachfbadcd02010-12-21 16:16:00 +00001070
Chris Lattner02f73582010-02-24 05:33:42 +00001071 unsigned getNode(unsigned i) const {
Chris Lattner8950bca2010-12-23 17:03:20 +00001072 assert(i < GlueResultNodes.size());
1073 return GlueResultNodes[i];
Jim Grosbachfbadcd02010-12-21 16:16:00 +00001074 }
1075
Chris Lattnerb21ba712010-02-25 02:04:40 +00001076 static inline bool classof(const Matcher *N) {
Chris Lattner8950bca2010-12-23 17:03:20 +00001077 return N->getKind() == MarkGlueResults;
Chris Lattner02f73582010-02-24 05:33:42 +00001078 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +00001079
Chris Lattner58aa8342010-02-25 06:49:58 +00001080private:
Chris Lattnera5028a62010-02-25 06:53:39 +00001081 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +00001082 virtual bool isEqualImpl(const Matcher *M) const {
Chris Lattner8950bca2010-12-23 17:03:20 +00001083 return cast<MarkGlueResultsMatcher>(M)->GlueResultNodes == GlueResultNodes;
Chris Lattner58aa8342010-02-25 06:49:58 +00001084 }
1085 virtual unsigned getHashImpl() const;
Chris Lattner02f73582010-02-24 05:33:42 +00001086};
1087
Chris Lattnerb21ba712010-02-25 02:04:40 +00001088/// CompleteMatchMatcher - Complete a match by replacing the results of the
Chris Lattner77f2e272010-02-21 06:03:07 +00001089/// pattern with the newly generated nodes. This also prints a comment
1090/// indicating the source and dest patterns.
Chris Lattnerb21ba712010-02-25 02:04:40 +00001091class CompleteMatchMatcher : public Matcher {
Chris Lattner77f2e272010-02-21 06:03:07 +00001092 SmallVector<unsigned, 2> Results;
Chris Lattner8e946be2010-02-21 03:22:59 +00001093 const PatternToMatch &Pattern;
1094public:
Chris Lattnerb21ba712010-02-25 02:04:40 +00001095 CompleteMatchMatcher(const unsigned *results, unsigned numresults,
Chris Lattnerc78f2a32010-02-28 20:49:53 +00001096 const PatternToMatch &pattern)
Chris Lattnerb21ba712010-02-25 02:04:40 +00001097 : Matcher(CompleteMatch), Results(results, results+numresults),
Chris Lattner77f2e272010-02-21 06:03:07 +00001098 Pattern(pattern) {}
1099
1100 unsigned getNumResults() const { return Results.size(); }
1101 unsigned getResult(unsigned R) const { return Results[R]; }
Chris Lattner8e946be2010-02-21 03:22:59 +00001102 const PatternToMatch &getPattern() const { return Pattern; }
Jim Grosbachfbadcd02010-12-21 16:16:00 +00001103
Chris Lattnerb21ba712010-02-25 02:04:40 +00001104 static inline bool classof(const Matcher *N) {
Chris Lattner77f2e272010-02-21 06:03:07 +00001105 return N->getKind() == CompleteMatch;
Chris Lattner8e946be2010-02-21 03:22:59 +00001106 }
Jim Grosbachfbadcd02010-12-21 16:16:00 +00001107
Chris Lattner58aa8342010-02-25 06:49:58 +00001108private:
Chris Lattnera5028a62010-02-25 06:53:39 +00001109 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner58aa8342010-02-25 06:49:58 +00001110 virtual bool isEqualImpl(const Matcher *M) const {
1111 return cast<CompleteMatchMatcher>(M)->Results == Results &&
1112 &cast<CompleteMatchMatcher>(M)->Pattern == &Pattern;
1113 }
1114 virtual unsigned getHashImpl() const;
Chris Lattner8e946be2010-02-21 03:22:59 +00001115};
Jim Grosbachfbadcd02010-12-21 16:16:00 +00001116
Chris Lattnerda272d12010-02-15 08:04:42 +00001117} // end namespace llvm
1118
1119#endif