blob: 9286b33dc5bef1aab9f7c2de45d3e247f12296d1 [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 Lattnere7d6e3c2010-02-15 08:04:42 +000026
Chris Lattner9a515172010-02-25 02:04:40 +000027Matcher *ConvertPatternToMatcher(const PatternToMatch &Pattern,
28 const CodeGenDAGPatterns &CGP);
29Matcher *OptimizeMatcher(Matcher *Matcher);
30void EmitMatcherTable(const Matcher *Matcher, raw_ostream &OS);
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000031
32
Chris Lattner9a515172010-02-25 02:04:40 +000033/// Matcher - Base class for all the the DAG ISel Matcher representation
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000034/// nodes.
Chris Lattner9a515172010-02-25 02:04:40 +000035class Matcher {
Chris Lattner78039ec2010-02-18 02:53:41 +000036 // The next matcher node that is executed after this one. Null if this is the
37 // last stage of a match.
Chris Lattner9a515172010-02-25 02:04:40 +000038 OwningPtr<Matcher> Next;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000039public:
40 enum KindTy {
Chris Lattner3163ca52010-02-21 03:22:59 +000041 // Matcher state manipulation.
Chris Lattnerac10e4f2010-02-25 01:56:48 +000042 Scope, // Push a checking scope.
Chris Lattner3163ca52010-02-21 03:22:59 +000043 RecordNode, // Record the current node.
Chris Lattner3ee1bc42010-02-24 07:31:45 +000044 RecordChild, // Record a child of the current node.
Chris Lattner3163ca52010-02-21 03:22:59 +000045 RecordMemRef, // Record the memref in the current node.
46 CaptureFlagInput, // If the current node has an input flag, save it.
47 MoveChild, // Move current node to specified child.
48 MoveParent, // Move current node to parent.
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000049
Chris Lattnerddfb5222010-02-18 22:03:03 +000050 // Predicate checking.
Chris Lattner3163ca52010-02-21 03:22:59 +000051 CheckSame, // Fail if not same as prev match.
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000052 CheckPatternPredicate,
Chris Lattner3163ca52010-02-21 03:22:59 +000053 CheckPredicate, // Fail if node predicate fails.
54 CheckOpcode, // Fail if not opcode.
Chris Lattnerf58c08e2010-02-22 22:30:37 +000055 CheckMultiOpcode, // Fail if not in opcode list.
Chris Lattner3163ca52010-02-21 03:22:59 +000056 CheckType, // Fail if not correct type.
Chris Lattner3c664b32010-02-24 20:15:25 +000057 CheckChildType, // Fail if child has wrong type.
Chris Lattner3163ca52010-02-21 03:22:59 +000058 CheckInteger, // Fail if wrong val.
59 CheckCondCode, // Fail if not condcode.
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000060 CheckValueType,
61 CheckComplexPat,
62 CheckAndImm,
Chris Lattner9de39482010-02-16 06:10:58 +000063 CheckOrImm,
Chris Lattner283adcb2010-02-17 06:23:39 +000064 CheckFoldableChainNode,
Chris Lattnerddfb5222010-02-18 22:03:03 +000065 CheckChainCompatible,
66
67 // Node creation/emisssion.
Chris Lattner3163ca52010-02-21 03:22:59 +000068 EmitInteger, // Create a TargetConstant
69 EmitStringInteger, // Create a TargetConstant from a string.
70 EmitRegister, // Create a register.
71 EmitConvertToTarget, // Convert a imm/fpimm to target imm/fpimm
72 EmitMergeInputChains, // Merge together a chains for an input.
73 EmitCopyToReg, // Emit a copytoreg into a physreg.
74 EmitNode, // Create a DAG node
75 EmitNodeXForm, // Run a SDNodeXForm
Chris Lattner69f60c82010-02-24 05:33:42 +000076 MarkFlagResults, // Indicate which interior nodes have flag results.
Chris Lattnerb085ea12010-02-21 06:03:07 +000077 CompleteMatch // Finish a match and update the results.
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000078 };
79 const KindTy Kind;
Chris Lattner3b31c982010-02-18 02:49:24 +000080
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000081protected:
Chris Lattner9a515172010-02-25 02:04:40 +000082 Matcher(KindTy K) : Kind(K) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000083public:
Chris Lattner9a515172010-02-25 02:04:40 +000084 virtual ~Matcher() {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000085
86 KindTy getKind() const { return Kind; }
Chris Lattner3b31c982010-02-18 02:49:24 +000087
Chris Lattner9a515172010-02-25 02:04:40 +000088 Matcher *getNext() { return Next.get(); }
89 const Matcher *getNext() const { return Next.get(); }
90 void setNext(Matcher *C) { Next.reset(C); }
91 Matcher *takeNext() { return Next.take(); }
Chris Lattner3ee1bc42010-02-24 07:31:45 +000092
Chris Lattner9a515172010-02-25 02:04:40 +000093 OwningPtr<Matcher> &getNextPtr() { return Next; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000094
Chris Lattner9a515172010-02-25 02:04:40 +000095 static inline bool classof(const Matcher *) { return true; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000096
97 virtual void print(raw_ostream &OS, unsigned indent = 0) const = 0;
98 void dump() const;
Chris Lattner3b31c982010-02-18 02:49:24 +000099protected:
Chris Lattner78039ec2010-02-18 02:53:41 +0000100 void printNext(raw_ostream &OS, unsigned indent) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000101};
102
Chris Lattner9a515172010-02-25 02:04:40 +0000103/// ScopeMatcher - This pushes a failure scope on the stack and evaluates
Chris Lattnerac10e4f2010-02-25 01:56:48 +0000104/// 'Check'. If 'Check' fails to match, it pops its scope and continues on to
105/// 'Next'.
Chris Lattner9a515172010-02-25 02:04:40 +0000106class ScopeMatcher : public Matcher {
107 OwningPtr<Matcher> Check;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000108public:
Chris Lattner9a515172010-02-25 02:04:40 +0000109 ScopeMatcher(Matcher *check = 0, Matcher *next = 0)
110 : Matcher(Scope), Check(check) {
Chris Lattner78039ec2010-02-18 02:53:41 +0000111 setNext(next);
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000112 }
113
Chris Lattner9a515172010-02-25 02:04:40 +0000114 Matcher *getCheck() { return Check.get(); }
115 const Matcher *getCheck() const { return Check.get(); }
116 void setCheck(Matcher *N) { Check.reset(N); }
117 OwningPtr<Matcher> &getCheckPtr() { return Check; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000118
Chris Lattner9a515172010-02-25 02:04:40 +0000119 static inline bool classof(const Matcher *N) {
Chris Lattnerac10e4f2010-02-25 01:56:48 +0000120 return N->getKind() == Scope;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000121 }
122
123 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
124};
125
Chris Lattner9a515172010-02-25 02:04:40 +0000126/// RecordMatcher - Save the current node in the operand list.
127class RecordMatcher : public Matcher {
Chris Lattner56cf88d2010-02-17 01:03:09 +0000128 /// WhatFor - This is a string indicating why we're recording this. This
129 /// should only be used for comment generation not anything semantic.
130 std::string WhatFor;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000131public:
Chris Lattner9a515172010-02-25 02:04:40 +0000132 RecordMatcher(const std::string &whatfor)
133 : Matcher(RecordNode), WhatFor(whatfor) {}
Chris Lattner56cf88d2010-02-17 01:03:09 +0000134
Chris Lattner086ca522010-02-17 01:27:29 +0000135 const std::string &getWhatFor() const { return WhatFor; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000136
Chris Lattner9a515172010-02-25 02:04:40 +0000137 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000138 return N->getKind() == RecordNode;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000139 }
140
141 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
142};
143
Chris Lattner9a515172010-02-25 02:04:40 +0000144/// RecordChildMatcher - Save a numbered child of the current node, or fail
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000145/// the match if it doesn't exist. This is logically equivalent to:
146/// MoveChild N + RecordNode + MoveParent.
Chris Lattner9a515172010-02-25 02:04:40 +0000147class RecordChildMatcher : public Matcher {
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000148 unsigned ChildNo;
149
150 /// WhatFor - This is a string indicating why we're recording this. This
151 /// should only be used for comment generation not anything semantic.
152 std::string WhatFor;
153public:
Chris Lattner9a515172010-02-25 02:04:40 +0000154 RecordChildMatcher(unsigned childno, const std::string &whatfor)
155 : Matcher(RecordChild), ChildNo(childno), WhatFor(whatfor) {}
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000156
157 unsigned getChildNo() const { return ChildNo; }
158 const std::string &getWhatFor() const { return WhatFor; }
159
Chris Lattner9a515172010-02-25 02:04:40 +0000160 static inline bool classof(const Matcher *N) {
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000161 return N->getKind() == RecordChild;
162 }
163
164 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
165};
166
Chris Lattner9a515172010-02-25 02:04:40 +0000167/// RecordMemRefMatcher - Save the current node's memref.
168class RecordMemRefMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000169public:
Chris Lattner9a515172010-02-25 02:04:40 +0000170 RecordMemRefMatcher() : Matcher(RecordMemRef) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000171
Chris Lattner9a515172010-02-25 02:04:40 +0000172 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000173 return N->getKind() == RecordMemRef;
174 }
175
176 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
177};
178
179
Chris Lattner9a515172010-02-25 02:04:40 +0000180/// CaptureFlagInputMatcher - If the current record has a flag input, record
Chris Lattner3163ca52010-02-21 03:22:59 +0000181/// it so that it is used as an input to the generated code.
Chris Lattner9a515172010-02-25 02:04:40 +0000182class CaptureFlagInputMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000183public:
Chris Lattner9a515172010-02-25 02:04:40 +0000184 CaptureFlagInputMatcher() : Matcher(CaptureFlagInput) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000185
Chris Lattner9a515172010-02-25 02:04:40 +0000186 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000187 return N->getKind() == CaptureFlagInput;
188 }
189
190 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
191};
192
Chris Lattner9a515172010-02-25 02:04:40 +0000193/// MoveChildMatcher - This tells the interpreter to move into the
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000194/// specified child node.
Chris Lattner9a515172010-02-25 02:04:40 +0000195class MoveChildMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000196 unsigned ChildNo;
197public:
Chris Lattner9a515172010-02-25 02:04:40 +0000198 MoveChildMatcher(unsigned childNo) : Matcher(MoveChild), ChildNo(childNo) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000199
200 unsigned getChildNo() const { return ChildNo; }
201
Chris Lattner9a515172010-02-25 02:04:40 +0000202 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000203 return N->getKind() == MoveChild;
204 }
205
206 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
207};
208
Chris Lattner9a515172010-02-25 02:04:40 +0000209/// MoveParentMatcher - This tells the interpreter to move to the parent
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000210/// of the current node.
Chris Lattner9a515172010-02-25 02:04:40 +0000211class MoveParentMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000212public:
Chris Lattner9a515172010-02-25 02:04:40 +0000213 MoveParentMatcher() : Matcher(MoveParent) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000214
Chris Lattner9a515172010-02-25 02:04:40 +0000215 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000216 return N->getKind() == MoveParent;
217 }
218
219 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
220};
221
Chris Lattner9a515172010-02-25 02:04:40 +0000222/// CheckSameMatcher - This checks to see if this node is exactly the same
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000223/// node as the specified match that was recorded with 'Record'. This is used
224/// when patterns have the same name in them, like '(mul GPR:$in, GPR:$in)'.
Chris Lattner9a515172010-02-25 02:04:40 +0000225class CheckSameMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000226 unsigned MatchNumber;
227public:
Chris Lattner9a515172010-02-25 02:04:40 +0000228 CheckSameMatcher(unsigned matchnumber)
229 : Matcher(CheckSame), MatchNumber(matchnumber) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000230
231 unsigned getMatchNumber() const { return MatchNumber; }
232
Chris Lattner9a515172010-02-25 02:04:40 +0000233 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000234 return N->getKind() == CheckSame;
235 }
236
237 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
238};
239
Chris Lattner9a515172010-02-25 02:04:40 +0000240/// CheckPatternPredicateMatcher - This checks the target-specific predicate
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000241/// to see if the entire pattern is capable of matching. This predicate does
242/// not take a node as input. This is used for subtarget feature checks etc.
Chris Lattner9a515172010-02-25 02:04:40 +0000243class CheckPatternPredicateMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000244 std::string Predicate;
245public:
Chris Lattner9a515172010-02-25 02:04:40 +0000246 CheckPatternPredicateMatcher(StringRef predicate)
247 : Matcher(CheckPatternPredicate), Predicate(predicate) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000248
249 StringRef getPredicate() const { return Predicate; }
250
Chris Lattner9a515172010-02-25 02:04:40 +0000251 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000252 return N->getKind() == CheckPatternPredicate;
253 }
254
255 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
256};
257
Chris Lattner9a515172010-02-25 02:04:40 +0000258/// CheckPredicateMatcher - This checks the target-specific predicate to
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000259/// see if the node is acceptable.
Chris Lattner9a515172010-02-25 02:04:40 +0000260class CheckPredicateMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000261 StringRef PredName;
262public:
Chris Lattner9a515172010-02-25 02:04:40 +0000263 CheckPredicateMatcher(StringRef predname)
264 : Matcher(CheckPredicate), PredName(predname) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000265
266 StringRef getPredicateName() const { return PredName; }
267
Chris Lattner9a515172010-02-25 02:04:40 +0000268 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000269 return N->getKind() == CheckPredicate;
270 }
271
272 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
273};
274
275
Chris Lattner9a515172010-02-25 02:04:40 +0000276/// CheckOpcodeMatcher - This checks to see if the current node has the
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000277/// specified opcode, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000278class CheckOpcodeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000279 StringRef OpcodeName;
280public:
Chris Lattner9a515172010-02-25 02:04:40 +0000281 CheckOpcodeMatcher(StringRef opcodename)
282 : Matcher(CheckOpcode), OpcodeName(opcodename) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000283
284 StringRef getOpcodeName() const { return OpcodeName; }
285
Chris Lattner9a515172010-02-25 02:04:40 +0000286 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000287 return N->getKind() == CheckOpcode;
288 }
289
290 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
291};
292
Chris Lattner9a515172010-02-25 02:04:40 +0000293/// CheckMultiOpcodeMatcher - This checks to see if the current node has one
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000294/// of the specified opcode, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000295class CheckMultiOpcodeMatcher : public Matcher {
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000296 SmallVector<StringRef, 4> OpcodeNames;
297public:
Chris Lattner9a515172010-02-25 02:04:40 +0000298 CheckMultiOpcodeMatcher(const StringRef *opcodes, unsigned numops)
299 : Matcher(CheckMultiOpcode), OpcodeNames(opcodes, opcodes+numops) {}
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000300
301 unsigned getNumOpcodeNames() const { return OpcodeNames.size(); }
302 StringRef getOpcodeName(unsigned i) const { return OpcodeNames[i]; }
303
Chris Lattner9a515172010-02-25 02:04:40 +0000304 static inline bool classof(const Matcher *N) {
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000305 return N->getKind() == CheckMultiOpcode;
306 }
307
308 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
309};
310
311
312
Chris Lattner9a515172010-02-25 02:04:40 +0000313/// CheckTypeMatcher - This checks to see if the current node has the
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000314/// specified type, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000315class CheckTypeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000316 MVT::SimpleValueType Type;
317public:
Chris Lattner9a515172010-02-25 02:04:40 +0000318 CheckTypeMatcher(MVT::SimpleValueType type)
319 : Matcher(CheckType), Type(type) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000320
321 MVT::SimpleValueType getType() const { return Type; }
322
Chris Lattner9a515172010-02-25 02:04:40 +0000323 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000324 return N->getKind() == CheckType;
325 }
326
327 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
328};
Chris Lattner3c664b32010-02-24 20:15:25 +0000329
Chris Lattner9a515172010-02-25 02:04:40 +0000330/// CheckChildTypeMatcher - This checks to see if a child node has the
Chris Lattner3c664b32010-02-24 20:15:25 +0000331/// specified type, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000332class CheckChildTypeMatcher : public Matcher {
Chris Lattner3c664b32010-02-24 20:15:25 +0000333 unsigned ChildNo;
334 MVT::SimpleValueType Type;
335public:
Chris Lattner9a515172010-02-25 02:04:40 +0000336 CheckChildTypeMatcher(unsigned childno, MVT::SimpleValueType type)
337 : Matcher(CheckChildType), ChildNo(childno), Type(type) {}
Chris Lattner3c664b32010-02-24 20:15:25 +0000338
339 unsigned getChildNo() const { return ChildNo; }
340 MVT::SimpleValueType getType() const { return Type; }
341
Chris Lattner9a515172010-02-25 02:04:40 +0000342 static inline bool classof(const Matcher *N) {
Chris Lattner3c664b32010-02-24 20:15:25 +0000343 return N->getKind() == CheckChildType;
344 }
345
346 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
347};
348
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000349
Chris Lattner9a515172010-02-25 02:04:40 +0000350/// CheckIntegerMatcher - This checks to see if the current node is a
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000351/// ConstantSDNode with the specified integer value, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000352class CheckIntegerMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000353 int64_t Value;
354public:
Chris Lattner9a515172010-02-25 02:04:40 +0000355 CheckIntegerMatcher(int64_t value)
356 : Matcher(CheckInteger), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000357
358 int64_t getValue() const { return Value; }
359
Chris Lattner9a515172010-02-25 02:04:40 +0000360 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000361 return N->getKind() == CheckInteger;
362 }
363
364 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
365};
366
Chris Lattner9a515172010-02-25 02:04:40 +0000367/// CheckCondCodeMatcher - This checks to see if the current node is a
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000368/// CondCodeSDNode with the specified condition, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000369class CheckCondCodeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000370 StringRef CondCodeName;
371public:
Chris Lattner9a515172010-02-25 02:04:40 +0000372 CheckCondCodeMatcher(StringRef condcodename)
373 : Matcher(CheckCondCode), CondCodeName(condcodename) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000374
375 StringRef getCondCodeName() const { return CondCodeName; }
376
Chris Lattner9a515172010-02-25 02:04:40 +0000377 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000378 return N->getKind() == CheckCondCode;
379 }
380
381 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
382};
383
Chris Lattner9a515172010-02-25 02:04:40 +0000384/// CheckValueTypeMatcher - This checks to see if the current node is a
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000385/// VTSDNode with the specified type, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000386class CheckValueTypeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000387 StringRef TypeName;
388public:
Chris Lattner9a515172010-02-25 02:04:40 +0000389 CheckValueTypeMatcher(StringRef type_name)
390 : Matcher(CheckValueType), TypeName(type_name) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000391
392 StringRef getTypeName() const { return TypeName; }
393
Chris Lattner9a515172010-02-25 02:04:40 +0000394 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000395 return N->getKind() == CheckValueType;
396 }
397
398 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
399};
400
401
402
Chris Lattner9a515172010-02-25 02:04:40 +0000403/// CheckComplexPatMatcher - This node runs the specified ComplexPattern on
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000404/// the current node.
Chris Lattner9a515172010-02-25 02:04:40 +0000405class CheckComplexPatMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000406 const ComplexPattern &Pattern;
407public:
Chris Lattner9a515172010-02-25 02:04:40 +0000408 CheckComplexPatMatcher(const ComplexPattern &pattern)
409 : Matcher(CheckComplexPat), Pattern(pattern) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000410
Chris Lattnerdc429fd2010-02-17 00:31:50 +0000411 const ComplexPattern &getPattern() const { return Pattern; }
412
Chris Lattner9a515172010-02-25 02:04:40 +0000413 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000414 return N->getKind() == CheckComplexPat;
415 }
416
417 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
418};
419
Chris Lattner9a515172010-02-25 02:04:40 +0000420/// CheckAndImmMatcher - This checks to see if the current node is an 'and'
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000421/// with something equivalent to the specified immediate.
Chris Lattner9a515172010-02-25 02:04:40 +0000422class CheckAndImmMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000423 int64_t Value;
424public:
Chris Lattner9a515172010-02-25 02:04:40 +0000425 CheckAndImmMatcher(int64_t value)
426 : Matcher(CheckAndImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000427
428 int64_t getValue() const { return Value; }
429
Chris Lattner9a515172010-02-25 02:04:40 +0000430 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000431 return N->getKind() == CheckAndImm;
432 }
433
434 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
435};
436
Chris Lattner9a515172010-02-25 02:04:40 +0000437/// CheckOrImmMatcher - This checks to see if the current node is an 'and'
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000438/// with something equivalent to the specified immediate.
Chris Lattner9a515172010-02-25 02:04:40 +0000439class CheckOrImmMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000440 int64_t Value;
441public:
Chris Lattner9a515172010-02-25 02:04:40 +0000442 CheckOrImmMatcher(int64_t value)
443 : Matcher(CheckOrImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000444
445 int64_t getValue() const { return Value; }
446
Chris Lattner9a515172010-02-25 02:04:40 +0000447 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000448 return N->getKind() == CheckOrImm;
449 }
450
451 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
452};
Chris Lattner9de39482010-02-16 06:10:58 +0000453
Chris Lattner9a515172010-02-25 02:04:40 +0000454/// CheckFoldableChainNodeMatcher - This checks to see if the current node
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000455/// (which defines a chain operand) is safe to fold into a larger pattern.
Chris Lattner9a515172010-02-25 02:04:40 +0000456class CheckFoldableChainNodeMatcher : public Matcher {
Chris Lattner9de39482010-02-16 06:10:58 +0000457public:
Chris Lattner9a515172010-02-25 02:04:40 +0000458 CheckFoldableChainNodeMatcher()
459 : Matcher(CheckFoldableChainNode) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000460
Chris Lattner9a515172010-02-25 02:04:40 +0000461 static inline bool classof(const Matcher *N) {
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000462 return N->getKind() == CheckFoldableChainNode;
Chris Lattner9de39482010-02-16 06:10:58 +0000463 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000464
Chris Lattner9de39482010-02-16 06:10:58 +0000465 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
466};
467
Chris Lattner9a515172010-02-25 02:04:40 +0000468/// CheckChainCompatibleMatcher - Verify that the current node's chain
Chris Lattner283adcb2010-02-17 06:23:39 +0000469/// operand is 'compatible' with the specified recorded node's.
Chris Lattner9a515172010-02-25 02:04:40 +0000470class CheckChainCompatibleMatcher : public Matcher {
Chris Lattner283adcb2010-02-17 06:23:39 +0000471 unsigned PreviousOp;
472public:
Chris Lattner9a515172010-02-25 02:04:40 +0000473 CheckChainCompatibleMatcher(unsigned previousop)
474 : Matcher(CheckChainCompatible), PreviousOp(previousop) {}
Chris Lattner283adcb2010-02-17 06:23:39 +0000475
476 unsigned getPreviousOp() const { return PreviousOp; }
477
Chris Lattner9a515172010-02-25 02:04:40 +0000478 static inline bool classof(const Matcher *N) {
Chris Lattner283adcb2010-02-17 06:23:39 +0000479 return N->getKind() == CheckChainCompatible;
480 }
481
482 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
483};
484
Chris Lattner9a515172010-02-25 02:04:40 +0000485/// EmitIntegerMatcher - This creates a new TargetConstant.
486class EmitIntegerMatcher : public Matcher {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000487 int64_t Val;
488 MVT::SimpleValueType VT;
489public:
Chris Lattner9a515172010-02-25 02:04:40 +0000490 EmitIntegerMatcher(int64_t val, MVT::SimpleValueType vt)
491 : Matcher(EmitInteger), Val(val), VT(vt) {}
Chris Lattner283adcb2010-02-17 06:23:39 +0000492
Chris Lattner7043e0a2010-02-19 07:49:56 +0000493 int64_t getValue() const { return Val; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000494 MVT::SimpleValueType getVT() const { return VT; }
495
Chris Lattner9a515172010-02-25 02:04:40 +0000496 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000497 return N->getKind() == EmitInteger;
498 }
499
500 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
501};
Chris Lattner3163ca52010-02-21 03:22:59 +0000502
Chris Lattner9a515172010-02-25 02:04:40 +0000503/// EmitStringIntegerMatcher - A target constant whose value is represented
Chris Lattner3163ca52010-02-21 03:22:59 +0000504/// by a string.
Chris Lattner9a515172010-02-25 02:04:40 +0000505class EmitStringIntegerMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000506 std::string Val;
507 MVT::SimpleValueType VT;
508public:
Chris Lattner9a515172010-02-25 02:04:40 +0000509 EmitStringIntegerMatcher(const std::string &val, MVT::SimpleValueType vt)
510 : Matcher(EmitStringInteger), Val(val), VT(vt) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000511
512 const std::string &getValue() const { return Val; }
513 MVT::SimpleValueType getVT() const { return VT; }
514
Chris Lattner9a515172010-02-25 02:04:40 +0000515 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000516 return N->getKind() == EmitStringInteger;
517 }
518
519 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
520};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000521
Chris Lattner9a515172010-02-25 02:04:40 +0000522/// EmitRegisterMatcher - This creates a new TargetConstant.
523class EmitRegisterMatcher : public Matcher {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000524 /// Reg - The def for the register that we're emitting. If this is null, then
525 /// this is a reference to zero_reg.
526 Record *Reg;
527 MVT::SimpleValueType VT;
528public:
Chris Lattner9a515172010-02-25 02:04:40 +0000529 EmitRegisterMatcher(Record *reg, MVT::SimpleValueType vt)
530 : Matcher(EmitRegister), Reg(reg), VT(vt) {}
Chris Lattnerddfb5222010-02-18 22:03:03 +0000531
532 Record *getReg() const { return Reg; }
533 MVT::SimpleValueType getVT() const { return VT; }
534
Chris Lattner9a515172010-02-25 02:04:40 +0000535 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000536 return N->getKind() == EmitRegister;
537 }
538
539 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
540};
Chris Lattner3163ca52010-02-21 03:22:59 +0000541
Chris Lattner9a515172010-02-25 02:04:40 +0000542/// EmitConvertToTargetMatcher - Emit an operation that reads a specified
Chris Lattner3163ca52010-02-21 03:22:59 +0000543/// recorded node and converts it from being a ISD::Constant to
544/// ISD::TargetConstant, likewise for ConstantFP.
Chris Lattner9a515172010-02-25 02:04:40 +0000545class EmitConvertToTargetMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000546 unsigned Slot;
547public:
Chris Lattner9a515172010-02-25 02:04:40 +0000548 EmitConvertToTargetMatcher(unsigned slot)
549 : Matcher(EmitConvertToTarget), Slot(slot) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000550
551 unsigned getSlot() const { return Slot; }
552
Chris Lattner9a515172010-02-25 02:04:40 +0000553 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000554 return N->getKind() == EmitConvertToTarget;
555 }
556
557 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
558};
559
Chris Lattner9a515172010-02-25 02:04:40 +0000560/// EmitMergeInputChainsMatcher - Emit a node that merges a list of input
Chris Lattner3163ca52010-02-21 03:22:59 +0000561/// chains together with a token factor. The list of nodes are the nodes in the
562/// matched pattern that have chain input/outputs. This node adds all input
563/// chains of these nodes if they are not themselves a node in the pattern.
Chris Lattner9a515172010-02-25 02:04:40 +0000564class EmitMergeInputChainsMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000565 SmallVector<unsigned, 3> ChainNodes;
566public:
Chris Lattner9a515172010-02-25 02:04:40 +0000567 EmitMergeInputChainsMatcher(const unsigned *nodes, unsigned NumNodes)
568 : Matcher(EmitMergeInputChains), ChainNodes(nodes, nodes+NumNodes) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000569
570 unsigned getNumNodes() const { return ChainNodes.size(); }
571
572 unsigned getNode(unsigned i) const {
573 assert(i < ChainNodes.size());
574 return ChainNodes[i];
575 }
576
Chris Lattner9a515172010-02-25 02:04:40 +0000577 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000578 return N->getKind() == EmitMergeInputChains;
579 }
580
581 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
582};
583
Chris Lattner9a515172010-02-25 02:04:40 +0000584/// EmitCopyToRegMatcher - Emit a CopyToReg node from a value to a physreg,
Chris Lattner3163ca52010-02-21 03:22:59 +0000585/// pushing the chain and flag results.
586///
Chris Lattner9a515172010-02-25 02:04:40 +0000587class EmitCopyToRegMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000588 unsigned SrcSlot; // Value to copy into the physreg.
589 Record *DestPhysReg;
590public:
Chris Lattner9a515172010-02-25 02:04:40 +0000591 EmitCopyToRegMatcher(unsigned srcSlot, Record *destPhysReg)
592 : Matcher(EmitCopyToReg), SrcSlot(srcSlot), DestPhysReg(destPhysReg) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000593
594 unsigned getSrcSlot() const { return SrcSlot; }
595 Record *getDestPhysReg() const { return DestPhysReg; }
596
Chris Lattner9a515172010-02-25 02:04:40 +0000597 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000598 return N->getKind() == EmitCopyToReg;
599 }
600
601 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
602};
603
604
605
Chris Lattner9a515172010-02-25 02:04:40 +0000606/// EmitNodeXFormMatcher - Emit an operation that runs an SDNodeXForm on a
Chris Lattner3163ca52010-02-21 03:22:59 +0000607/// recorded node and records the result.
Chris Lattner9a515172010-02-25 02:04:40 +0000608class EmitNodeXFormMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000609 unsigned Slot;
610 Record *NodeXForm;
611public:
Chris Lattner9a515172010-02-25 02:04:40 +0000612 EmitNodeXFormMatcher(unsigned slot, Record *nodeXForm)
613 : Matcher(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000614
615 unsigned getSlot() const { return Slot; }
616 Record *getNodeXForm() const { return NodeXForm; }
617
Chris Lattner9a515172010-02-25 02:04:40 +0000618 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000619 return N->getKind() == EmitNodeXForm;
620 }
621
622 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
623};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000624
Chris Lattner9a515172010-02-25 02:04:40 +0000625/// EmitNodeMatcher - This signals a successful match and generates a node.
626class EmitNodeMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000627 std::string OpcodeName;
628 const SmallVector<MVT::SimpleValueType, 3> VTs;
629 const SmallVector<unsigned, 6> Operands;
630 bool HasChain, HasFlag, HasMemRefs;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000631
Chris Lattner3163ca52010-02-21 03:22:59 +0000632 /// NumFixedArityOperands - If this is a fixed arity node, this is set to -1.
633 /// If this is a varidic node, this is set to the number of fixed arity
634 /// operands in the root of the pattern. The rest are appended to this node.
635 int NumFixedArityOperands;
636public:
Chris Lattner9a515172010-02-25 02:04:40 +0000637 EmitNodeMatcher(const std::string &opcodeName,
Chris Lattner3163ca52010-02-21 03:22:59 +0000638 const MVT::SimpleValueType *vts, unsigned numvts,
639 const unsigned *operands, unsigned numops,
640 bool hasChain, bool hasFlag, bool hasmemrefs,
641 int numfixedarityoperands)
Chris Lattner9a515172010-02-25 02:04:40 +0000642 : Matcher(EmitNode), OpcodeName(opcodeName),
Chris Lattner3163ca52010-02-21 03:22:59 +0000643 VTs(vts, vts+numvts), Operands(operands, operands+numops),
644 HasChain(hasChain), HasFlag(hasFlag), HasMemRefs(hasmemrefs),
645 NumFixedArityOperands(numfixedarityoperands) {}
646
647 const std::string &getOpcodeName() const { return OpcodeName; }
648
649 unsigned getNumVTs() const { return VTs.size(); }
650 MVT::SimpleValueType getVT(unsigned i) const {
651 assert(i < VTs.size());
652 return VTs[i];
653 }
654
655 unsigned getNumOperands() const { return Operands.size(); }
656 unsigned getOperand(unsigned i) const {
657 assert(i < Operands.size());
658 return Operands[i];
659 }
660
661 bool hasChain() const { return HasChain; }
662 bool hasFlag() const { return HasFlag; }
663 bool hasMemRefs() const { return HasMemRefs; }
664 int getNumFixedArityOperands() const { return NumFixedArityOperands; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000665
Chris Lattner9a515172010-02-25 02:04:40 +0000666 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000667 return N->getKind() == EmitNode;
668 }
669
670 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
671};
Chris Lattnerb085ea12010-02-21 06:03:07 +0000672
Chris Lattner9a515172010-02-25 02:04:40 +0000673/// MarkFlagResultsMatcher - This node indicates which non-root nodes in the
674/// pattern produce flags. This allows CompleteMatchMatcher to update them
Chris Lattner69f60c82010-02-24 05:33:42 +0000675/// with the output flag of the resultant code.
Chris Lattner9a515172010-02-25 02:04:40 +0000676class MarkFlagResultsMatcher : public Matcher {
Chris Lattner69f60c82010-02-24 05:33:42 +0000677 SmallVector<unsigned, 3> FlagResultNodes;
678public:
Chris Lattner9a515172010-02-25 02:04:40 +0000679 MarkFlagResultsMatcher(const unsigned *nodes, unsigned NumNodes)
680 : Matcher(MarkFlagResults), FlagResultNodes(nodes, nodes+NumNodes) {}
Chris Lattner69f60c82010-02-24 05:33:42 +0000681
682 unsigned getNumNodes() const { return FlagResultNodes.size(); }
683
684 unsigned getNode(unsigned i) const {
685 assert(i < FlagResultNodes.size());
686 return FlagResultNodes[i];
687 }
688
Chris Lattner9a515172010-02-25 02:04:40 +0000689 static inline bool classof(const Matcher *N) {
Chris Lattner69f60c82010-02-24 05:33:42 +0000690 return N->getKind() == MarkFlagResults;
691 }
692
693 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
694};
695
Chris Lattner9a515172010-02-25 02:04:40 +0000696/// CompleteMatchMatcher - Complete a match by replacing the results of the
Chris Lattnerb085ea12010-02-21 06:03:07 +0000697/// pattern with the newly generated nodes. This also prints a comment
698/// indicating the source and dest patterns.
Chris Lattner9a515172010-02-25 02:04:40 +0000699class CompleteMatchMatcher : public Matcher {
Chris Lattnerb085ea12010-02-21 06:03:07 +0000700 SmallVector<unsigned, 2> Results;
Chris Lattner3163ca52010-02-21 03:22:59 +0000701 const PatternToMatch &Pattern;
702public:
Chris Lattner9a515172010-02-25 02:04:40 +0000703 CompleteMatchMatcher(const unsigned *results, unsigned numresults,
Chris Lattnerb085ea12010-02-21 06:03:07 +0000704 const PatternToMatch &pattern)
Chris Lattner9a515172010-02-25 02:04:40 +0000705 : Matcher(CompleteMatch), Results(results, results+numresults),
Chris Lattnerb085ea12010-02-21 06:03:07 +0000706 Pattern(pattern) {}
707
708 unsigned getNumResults() const { return Results.size(); }
709 unsigned getResult(unsigned R) const { return Results[R]; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000710 const PatternToMatch &getPattern() const { return Pattern; }
711
Chris Lattner9a515172010-02-25 02:04:40 +0000712 static inline bool classof(const Matcher *N) {
Chris Lattnerb085ea12010-02-21 06:03:07 +0000713 return N->getKind() == CompleteMatch;
Chris Lattner3163ca52010-02-21 03:22:59 +0000714 }
715
716 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
717};
718
Chris Lattnerddfb5222010-02-18 22:03:03 +0000719
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000720} // end namespace llvm
721
722#endif