blob: 6599b21e93470df323bdc5a8804acb8e3693b206 [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
Chris Lattner136ab782010-02-25 06:49:58 +000097 bool isEqual(const Matcher *M) const {
98 if (getKind() != M->getKind()) return false;
99 return isEqualImpl(M);
100 }
101
102 unsigned getHash() const {
103 return (getHashImpl() << 4) ^ getKind();
104 }
105
Chris Lattner392b1bf2010-02-25 06:53:39 +0000106 void print(raw_ostream &OS, unsigned indent = 0) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000107 void dump() const;
Chris Lattner3b31c982010-02-18 02:49:24 +0000108protected:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000109 virtual void printImpl(raw_ostream &OS, unsigned indent) const = 0;
Chris Lattner136ab782010-02-25 06:49:58 +0000110 virtual bool isEqualImpl(const Matcher *M) const = 0;
111 virtual unsigned getHashImpl() const = 0;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000112};
113
Chris Lattner42363662010-02-25 19:00:39 +0000114/// ScopeMatcher - This attempts to match each of its children to find the first
115/// one that successfully matches. If one child fails, it tries the next child.
116/// If none of the children match then this check fails. It never has a 'next'.
Chris Lattner9a515172010-02-25 02:04:40 +0000117class ScopeMatcher : public Matcher {
Chris Lattner42363662010-02-25 19:00:39 +0000118 SmallVector<Matcher*, 4> Children;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000119public:
Chris Lattner42363662010-02-25 19:00:39 +0000120 ScopeMatcher(Matcher *const *children, unsigned numchildren)
121 : Matcher(Scope), Children(children, children+numchildren) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000122 }
Chris Lattner42363662010-02-25 19:00:39 +0000123 virtual ~ScopeMatcher();
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000124
Chris Lattner42363662010-02-25 19:00:39 +0000125 unsigned getNumChildren() const { return Children.size(); }
126
127 Matcher *getChild(unsigned i) { return Children[i]; }
128 const Matcher *getChild(unsigned i) const { return Children[i]; }
129
130 void resetChild(unsigned i, Matcher *N) {
131 delete Children[i];
132 Children[i] = N;
133 }
134
135 Matcher *takeChild(unsigned i) {
136 Matcher *Res = Children[i];
137 Children[i] = 0;
138 return Res;
139 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000140
Chris Lattner9a515172010-02-25 02:04:40 +0000141 static inline bool classof(const Matcher *N) {
Chris Lattnerac10e4f2010-02-25 01:56:48 +0000142 return N->getKind() == Scope;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000143 }
144
Chris Lattner136ab782010-02-25 06:49:58 +0000145private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000146 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000147 virtual bool isEqualImpl(const Matcher *M) const { return false; }
Chris Lattner42363662010-02-25 19:00:39 +0000148 virtual unsigned getHashImpl() const { return 12312; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000149};
150
Chris Lattner9a515172010-02-25 02:04:40 +0000151/// RecordMatcher - Save the current node in the operand list.
152class RecordMatcher : public Matcher {
Chris Lattner56cf88d2010-02-17 01:03:09 +0000153 /// WhatFor - This is a string indicating why we're recording this. This
154 /// should only be used for comment generation not anything semantic.
155 std::string WhatFor;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000156public:
Chris Lattner9a515172010-02-25 02:04:40 +0000157 RecordMatcher(const std::string &whatfor)
158 : Matcher(RecordNode), WhatFor(whatfor) {}
Chris Lattner56cf88d2010-02-17 01:03:09 +0000159
Chris Lattner086ca522010-02-17 01:27:29 +0000160 const std::string &getWhatFor() const { return WhatFor; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000161
Chris Lattner9a515172010-02-25 02:04:40 +0000162 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000163 return N->getKind() == RecordNode;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000164 }
165
Chris Lattner136ab782010-02-25 06:49:58 +0000166private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000167 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000168 virtual bool isEqualImpl(const Matcher *M) const { return true; }
169 virtual unsigned getHashImpl() const { return 0; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000170};
171
Chris Lattner9a515172010-02-25 02:04:40 +0000172/// RecordChildMatcher - Save a numbered child of the current node, or fail
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000173/// the match if it doesn't exist. This is logically equivalent to:
174/// MoveChild N + RecordNode + MoveParent.
Chris Lattner9a515172010-02-25 02:04:40 +0000175class RecordChildMatcher : public Matcher {
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000176 unsigned ChildNo;
177
178 /// WhatFor - This is a string indicating why we're recording this. This
179 /// should only be used for comment generation not anything semantic.
180 std::string WhatFor;
181public:
Chris Lattner9a515172010-02-25 02:04:40 +0000182 RecordChildMatcher(unsigned childno, const std::string &whatfor)
183 : Matcher(RecordChild), ChildNo(childno), WhatFor(whatfor) {}
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000184
185 unsigned getChildNo() const { return ChildNo; }
186 const std::string &getWhatFor() const { return WhatFor; }
187
Chris Lattner9a515172010-02-25 02:04:40 +0000188 static inline bool classof(const Matcher *N) {
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000189 return N->getKind() == RecordChild;
190 }
191
Chris Lattner136ab782010-02-25 06:49:58 +0000192private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000193 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000194 virtual bool isEqualImpl(const Matcher *M) const {
195 return cast<RecordChildMatcher>(M)->getChildNo() == getChildNo();
196 }
197 virtual unsigned getHashImpl() const { return getChildNo(); }
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000198};
199
Chris Lattner9a515172010-02-25 02:04:40 +0000200/// RecordMemRefMatcher - Save the current node's memref.
201class RecordMemRefMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000202public:
Chris Lattner9a515172010-02-25 02:04:40 +0000203 RecordMemRefMatcher() : Matcher(RecordMemRef) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000204
Chris Lattner9a515172010-02-25 02:04:40 +0000205 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000206 return N->getKind() == RecordMemRef;
207 }
208
Chris Lattner136ab782010-02-25 06:49:58 +0000209private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000210 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000211 virtual bool isEqualImpl(const Matcher *M) const { return true; }
212 virtual unsigned getHashImpl() const { return 0; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000213};
214
215
Chris Lattner9a515172010-02-25 02:04:40 +0000216/// CaptureFlagInputMatcher - If the current record has a flag input, record
Chris Lattner3163ca52010-02-21 03:22:59 +0000217/// it so that it is used as an input to the generated code.
Chris Lattner9a515172010-02-25 02:04:40 +0000218class CaptureFlagInputMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000219public:
Chris Lattner9a515172010-02-25 02:04:40 +0000220 CaptureFlagInputMatcher() : Matcher(CaptureFlagInput) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000221
Chris Lattner9a515172010-02-25 02:04:40 +0000222 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000223 return N->getKind() == CaptureFlagInput;
224 }
225
Chris Lattner136ab782010-02-25 06:49:58 +0000226private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000227 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000228 virtual bool isEqualImpl(const Matcher *M) const { return true; }
229 virtual unsigned getHashImpl() const { return 0; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000230};
231
Chris Lattner9a515172010-02-25 02:04:40 +0000232/// MoveChildMatcher - This tells the interpreter to move into the
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000233/// specified child node.
Chris Lattner9a515172010-02-25 02:04:40 +0000234class MoveChildMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000235 unsigned ChildNo;
236public:
Chris Lattner9a515172010-02-25 02:04:40 +0000237 MoveChildMatcher(unsigned childNo) : Matcher(MoveChild), ChildNo(childNo) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000238
239 unsigned getChildNo() const { return ChildNo; }
240
Chris Lattner9a515172010-02-25 02:04:40 +0000241 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000242 return N->getKind() == MoveChild;
243 }
244
Chris Lattner136ab782010-02-25 06:49:58 +0000245private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000246 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000247 virtual bool isEqualImpl(const Matcher *M) const {
248 return cast<MoveChildMatcher>(M)->getChildNo() == getChildNo();
249 }
250 virtual unsigned getHashImpl() const { return getChildNo(); }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000251};
252
Chris Lattner9a515172010-02-25 02:04:40 +0000253/// MoveParentMatcher - This tells the interpreter to move to the parent
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000254/// of the current node.
Chris Lattner9a515172010-02-25 02:04:40 +0000255class MoveParentMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000256public:
Chris Lattner9a515172010-02-25 02:04:40 +0000257 MoveParentMatcher() : Matcher(MoveParent) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000258
Chris Lattner9a515172010-02-25 02:04:40 +0000259 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000260 return N->getKind() == MoveParent;
261 }
262
Chris Lattner136ab782010-02-25 06:49:58 +0000263private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000264 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000265 virtual bool isEqualImpl(const Matcher *M) const { return true; }
266 virtual unsigned getHashImpl() const { return 0; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000267};
268
Chris Lattner9a515172010-02-25 02:04:40 +0000269/// CheckSameMatcher - This checks to see if this node is exactly the same
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000270/// node as the specified match that was recorded with 'Record'. This is used
271/// when patterns have the same name in them, like '(mul GPR:$in, GPR:$in)'.
Chris Lattner9a515172010-02-25 02:04:40 +0000272class CheckSameMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000273 unsigned MatchNumber;
274public:
Chris Lattner9a515172010-02-25 02:04:40 +0000275 CheckSameMatcher(unsigned matchnumber)
Chris Lattner136ab782010-02-25 06:49:58 +0000276 : Matcher(CheckSame), MatchNumber(matchnumber) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000277
278 unsigned getMatchNumber() const { return MatchNumber; }
279
Chris Lattner9a515172010-02-25 02:04:40 +0000280 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000281 return N->getKind() == CheckSame;
282 }
283
Chris Lattner136ab782010-02-25 06:49:58 +0000284private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000285 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000286 virtual bool isEqualImpl(const Matcher *M) const {
287 return cast<CheckSameMatcher>(M)->getMatchNumber() == getMatchNumber();
288 }
289 virtual unsigned getHashImpl() const { return getMatchNumber(); }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000290};
291
Chris Lattner9a515172010-02-25 02:04:40 +0000292/// CheckPatternPredicateMatcher - This checks the target-specific predicate
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000293/// to see if the entire pattern is capable of matching. This predicate does
294/// not take a node as input. This is used for subtarget feature checks etc.
Chris Lattner9a515172010-02-25 02:04:40 +0000295class CheckPatternPredicateMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000296 std::string Predicate;
297public:
Chris Lattner9a515172010-02-25 02:04:40 +0000298 CheckPatternPredicateMatcher(StringRef predicate)
Chris Lattner136ab782010-02-25 06:49:58 +0000299 : Matcher(CheckPatternPredicate), Predicate(predicate) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000300
301 StringRef getPredicate() const { return Predicate; }
302
Chris Lattner9a515172010-02-25 02:04:40 +0000303 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000304 return N->getKind() == CheckPatternPredicate;
305 }
306
Chris Lattner136ab782010-02-25 06:49:58 +0000307private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000308 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000309 virtual bool isEqualImpl(const Matcher *M) const {
310 return cast<CheckPatternPredicateMatcher>(M)->getPredicate() == Predicate;
311 }
312 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000313};
314
Chris Lattner9a515172010-02-25 02:04:40 +0000315/// CheckPredicateMatcher - This checks the target-specific predicate to
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000316/// see if the node is acceptable.
Chris Lattner9a515172010-02-25 02:04:40 +0000317class CheckPredicateMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000318 StringRef PredName;
319public:
Chris Lattner9a515172010-02-25 02:04:40 +0000320 CheckPredicateMatcher(StringRef predname)
321 : Matcher(CheckPredicate), PredName(predname) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000322
323 StringRef getPredicateName() const { return PredName; }
324
Chris Lattner9a515172010-02-25 02:04:40 +0000325 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000326 return N->getKind() == CheckPredicate;
327 }
328
Chris Lattner136ab782010-02-25 06:49:58 +0000329private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000330 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000331 virtual bool isEqualImpl(const Matcher *M) const {
332 return cast<CheckPredicateMatcher>(M)->PredName == PredName;
333 }
334 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000335};
336
337
Chris Lattner9a515172010-02-25 02:04:40 +0000338/// CheckOpcodeMatcher - This checks to see if the current node has the
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000339/// specified opcode, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000340class CheckOpcodeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000341 StringRef OpcodeName;
342public:
Chris Lattner9a515172010-02-25 02:04:40 +0000343 CheckOpcodeMatcher(StringRef opcodename)
344 : Matcher(CheckOpcode), OpcodeName(opcodename) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000345
346 StringRef getOpcodeName() const { return OpcodeName; }
347
Chris Lattner9a515172010-02-25 02:04:40 +0000348 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000349 return N->getKind() == CheckOpcode;
350 }
351
Chris Lattner136ab782010-02-25 06:49:58 +0000352private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000353 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000354 virtual bool isEqualImpl(const Matcher *M) const {
355 return cast<CheckOpcodeMatcher>(M)->OpcodeName == OpcodeName;
356 }
357 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000358};
359
Chris Lattner9a515172010-02-25 02:04:40 +0000360/// CheckMultiOpcodeMatcher - This checks to see if the current node has one
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000361/// of the specified opcode, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000362class CheckMultiOpcodeMatcher : public Matcher {
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000363 SmallVector<StringRef, 4> OpcodeNames;
364public:
Chris Lattner9a515172010-02-25 02:04:40 +0000365 CheckMultiOpcodeMatcher(const StringRef *opcodes, unsigned numops)
366 : Matcher(CheckMultiOpcode), OpcodeNames(opcodes, opcodes+numops) {}
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000367
368 unsigned getNumOpcodeNames() const { return OpcodeNames.size(); }
369 StringRef getOpcodeName(unsigned i) const { return OpcodeNames[i]; }
370
Chris Lattner9a515172010-02-25 02:04:40 +0000371 static inline bool classof(const Matcher *N) {
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000372 return N->getKind() == CheckMultiOpcode;
373 }
374
Chris Lattner136ab782010-02-25 06:49:58 +0000375private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000376 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000377 virtual bool isEqualImpl(const Matcher *M) const {
378 return cast<CheckMultiOpcodeMatcher>(M)->OpcodeNames == OpcodeNames;
379 }
380 virtual unsigned getHashImpl() const;
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000381};
382
383
384
Chris Lattner9a515172010-02-25 02:04:40 +0000385/// CheckTypeMatcher - This checks to see if the current node has the
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000386/// specified type, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000387class CheckTypeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000388 MVT::SimpleValueType Type;
389public:
Chris Lattner9a515172010-02-25 02:04:40 +0000390 CheckTypeMatcher(MVT::SimpleValueType type)
391 : Matcher(CheckType), Type(type) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000392
393 MVT::SimpleValueType getType() const { return Type; }
394
Chris Lattner9a515172010-02-25 02:04:40 +0000395 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000396 return N->getKind() == CheckType;
397 }
398
Chris Lattner136ab782010-02-25 06:49:58 +0000399private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000400 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000401 virtual bool isEqualImpl(const Matcher *M) const {
402 return cast<CheckTypeMatcher>(this)->Type == Type;
403 }
404 virtual unsigned getHashImpl() const { return Type; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000405};
Chris Lattner3c664b32010-02-24 20:15:25 +0000406
Chris Lattner9a515172010-02-25 02:04:40 +0000407/// CheckChildTypeMatcher - This checks to see if a child node has the
Chris Lattner3c664b32010-02-24 20:15:25 +0000408/// specified type, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000409class CheckChildTypeMatcher : public Matcher {
Chris Lattner3c664b32010-02-24 20:15:25 +0000410 unsigned ChildNo;
411 MVT::SimpleValueType Type;
412public:
Chris Lattner9a515172010-02-25 02:04:40 +0000413 CheckChildTypeMatcher(unsigned childno, MVT::SimpleValueType type)
414 : Matcher(CheckChildType), ChildNo(childno), Type(type) {}
Chris Lattner3c664b32010-02-24 20:15:25 +0000415
416 unsigned getChildNo() const { return ChildNo; }
417 MVT::SimpleValueType getType() const { return Type; }
418
Chris Lattner9a515172010-02-25 02:04:40 +0000419 static inline bool classof(const Matcher *N) {
Chris Lattner3c664b32010-02-24 20:15:25 +0000420 return N->getKind() == CheckChildType;
421 }
422
Chris Lattner136ab782010-02-25 06:49:58 +0000423private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000424 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000425 virtual bool isEqualImpl(const Matcher *M) const {
426 return cast<CheckChildTypeMatcher>(M)->ChildNo == ChildNo &&
427 cast<CheckChildTypeMatcher>(M)->Type == Type;
428 }
429 virtual unsigned getHashImpl() const { return (Type << 3) | ChildNo; }
Chris Lattner3c664b32010-02-24 20:15:25 +0000430};
431
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000432
Chris Lattner9a515172010-02-25 02:04:40 +0000433/// CheckIntegerMatcher - This checks to see if the current node is a
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000434/// ConstantSDNode with the specified integer value, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000435class CheckIntegerMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000436 int64_t Value;
437public:
Chris Lattner9a515172010-02-25 02:04:40 +0000438 CheckIntegerMatcher(int64_t value)
439 : Matcher(CheckInteger), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000440
441 int64_t getValue() const { return Value; }
442
Chris Lattner9a515172010-02-25 02:04:40 +0000443 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000444 return N->getKind() == CheckInteger;
445 }
446
Chris Lattner136ab782010-02-25 06:49:58 +0000447private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000448 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000449 virtual bool isEqualImpl(const Matcher *M) const {
450 return cast<CheckIntegerMatcher>(M)->Value == Value;
451 }
452 virtual unsigned getHashImpl() const { return Value; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000453};
454
Chris Lattner9a515172010-02-25 02:04:40 +0000455/// CheckCondCodeMatcher - This checks to see if the current node is a
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000456/// CondCodeSDNode with the specified condition, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000457class CheckCondCodeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000458 StringRef CondCodeName;
459public:
Chris Lattner9a515172010-02-25 02:04:40 +0000460 CheckCondCodeMatcher(StringRef condcodename)
461 : Matcher(CheckCondCode), CondCodeName(condcodename) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000462
463 StringRef getCondCodeName() const { return CondCodeName; }
464
Chris Lattner9a515172010-02-25 02:04:40 +0000465 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000466 return N->getKind() == CheckCondCode;
467 }
468
Chris Lattner136ab782010-02-25 06:49:58 +0000469private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000470 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000471 virtual bool isEqualImpl(const Matcher *M) const {
472 return cast<CheckCondCodeMatcher>(M)->CondCodeName == CondCodeName;
473 }
474 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000475};
476
Chris Lattner9a515172010-02-25 02:04:40 +0000477/// CheckValueTypeMatcher - This checks to see if the current node is a
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000478/// VTSDNode with the specified type, if not it fails to match.
Chris Lattner9a515172010-02-25 02:04:40 +0000479class CheckValueTypeMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000480 StringRef TypeName;
481public:
Chris Lattner9a515172010-02-25 02:04:40 +0000482 CheckValueTypeMatcher(StringRef type_name)
483 : Matcher(CheckValueType), TypeName(type_name) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000484
485 StringRef getTypeName() const { return TypeName; }
486
Chris Lattner9a515172010-02-25 02:04:40 +0000487 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000488 return N->getKind() == CheckValueType;
489 }
490
Chris Lattner136ab782010-02-25 06:49:58 +0000491private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000492 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000493 virtual bool isEqualImpl(const Matcher *M) const {
494 return cast<CheckValueTypeMatcher>(M)->TypeName == TypeName;
495 }
496 virtual unsigned getHashImpl() const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000497};
498
499
500
Chris Lattner9a515172010-02-25 02:04:40 +0000501/// CheckComplexPatMatcher - This node runs the specified ComplexPattern on
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000502/// the current node.
Chris Lattner9a515172010-02-25 02:04:40 +0000503class CheckComplexPatMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000504 const ComplexPattern &Pattern;
505public:
Chris Lattner9a515172010-02-25 02:04:40 +0000506 CheckComplexPatMatcher(const ComplexPattern &pattern)
507 : Matcher(CheckComplexPat), Pattern(pattern) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000508
Chris Lattnerdc429fd2010-02-17 00:31:50 +0000509 const ComplexPattern &getPattern() const { return Pattern; }
510
Chris Lattner9a515172010-02-25 02:04:40 +0000511 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000512 return N->getKind() == CheckComplexPat;
513 }
514
Chris Lattner136ab782010-02-25 06:49:58 +0000515private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000516 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000517 virtual bool isEqualImpl(const Matcher *M) const {
518 return &cast<CheckComplexPatMatcher>(M)->Pattern == &Pattern;
519 }
520 virtual unsigned getHashImpl() const {
521 return (unsigned)(intptr_t)&Pattern;
522 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000523};
524
Chris Lattner9a515172010-02-25 02:04:40 +0000525/// CheckAndImmMatcher - This checks to see if the current node is an 'and'
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000526/// with something equivalent to the specified immediate.
Chris Lattner9a515172010-02-25 02:04:40 +0000527class CheckAndImmMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000528 int64_t Value;
529public:
Chris Lattner9a515172010-02-25 02:04:40 +0000530 CheckAndImmMatcher(int64_t value)
531 : Matcher(CheckAndImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000532
533 int64_t getValue() const { return Value; }
534
Chris Lattner9a515172010-02-25 02:04:40 +0000535 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000536 return N->getKind() == CheckAndImm;
537 }
538
Chris Lattner136ab782010-02-25 06:49:58 +0000539private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000540 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000541 virtual bool isEqualImpl(const Matcher *M) const {
542 return cast<CheckAndImmMatcher>(M)->Value == Value;
543 }
544 virtual unsigned getHashImpl() const { return Value; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000545};
546
Chris Lattner9a515172010-02-25 02:04:40 +0000547/// CheckOrImmMatcher - This checks to see if the current node is an 'and'
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000548/// with something equivalent to the specified immediate.
Chris Lattner9a515172010-02-25 02:04:40 +0000549class CheckOrImmMatcher : public Matcher {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000550 int64_t Value;
551public:
Chris Lattner9a515172010-02-25 02:04:40 +0000552 CheckOrImmMatcher(int64_t value)
553 : Matcher(CheckOrImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000554
555 int64_t getValue() const { return Value; }
556
Chris Lattner9a515172010-02-25 02:04:40 +0000557 static inline bool classof(const Matcher *N) {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000558 return N->getKind() == CheckOrImm;
559 }
560
Chris Lattner136ab782010-02-25 06:49:58 +0000561private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000562 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000563 virtual bool isEqualImpl(const Matcher *M) const {
564 return cast<CheckOrImmMatcher>(M)->Value == Value;
565 }
566 virtual unsigned getHashImpl() const { return Value; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000567};
Chris Lattner9de39482010-02-16 06:10:58 +0000568
Chris Lattner9a515172010-02-25 02:04:40 +0000569/// CheckFoldableChainNodeMatcher - This checks to see if the current node
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000570/// (which defines a chain operand) is safe to fold into a larger pattern.
Chris Lattner9a515172010-02-25 02:04:40 +0000571class CheckFoldableChainNodeMatcher : public Matcher {
Chris Lattner9de39482010-02-16 06:10:58 +0000572public:
Chris Lattner9a515172010-02-25 02:04:40 +0000573 CheckFoldableChainNodeMatcher()
574 : Matcher(CheckFoldableChainNode) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000575
Chris Lattner9a515172010-02-25 02:04:40 +0000576 static inline bool classof(const Matcher *N) {
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000577 return N->getKind() == CheckFoldableChainNode;
Chris Lattner9de39482010-02-16 06:10:58 +0000578 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000579
Chris Lattner136ab782010-02-25 06:49:58 +0000580private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000581 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000582 virtual bool isEqualImpl(const Matcher *M) const { return true; }
583 virtual unsigned getHashImpl() const { return 0; }
Chris Lattner9de39482010-02-16 06:10:58 +0000584};
585
Chris Lattner9a515172010-02-25 02:04:40 +0000586/// CheckChainCompatibleMatcher - Verify that the current node's chain
Chris Lattner283adcb2010-02-17 06:23:39 +0000587/// operand is 'compatible' with the specified recorded node's.
Chris Lattner9a515172010-02-25 02:04:40 +0000588class CheckChainCompatibleMatcher : public Matcher {
Chris Lattner283adcb2010-02-17 06:23:39 +0000589 unsigned PreviousOp;
590public:
Chris Lattner9a515172010-02-25 02:04:40 +0000591 CheckChainCompatibleMatcher(unsigned previousop)
592 : Matcher(CheckChainCompatible), PreviousOp(previousop) {}
Chris Lattner283adcb2010-02-17 06:23:39 +0000593
594 unsigned getPreviousOp() const { return PreviousOp; }
595
Chris Lattner9a515172010-02-25 02:04:40 +0000596 static inline bool classof(const Matcher *N) {
Chris Lattner283adcb2010-02-17 06:23:39 +0000597 return N->getKind() == CheckChainCompatible;
598 }
599
Chris Lattner136ab782010-02-25 06:49:58 +0000600private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000601 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000602 virtual bool isEqualImpl(const Matcher *M) const {
603 return cast<CheckChainCompatibleMatcher>(this)->PreviousOp == PreviousOp;
604 }
605 virtual unsigned getHashImpl() const { return PreviousOp; }
Chris Lattner283adcb2010-02-17 06:23:39 +0000606};
607
Chris Lattner9a515172010-02-25 02:04:40 +0000608/// EmitIntegerMatcher - This creates a new TargetConstant.
609class EmitIntegerMatcher : public Matcher {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000610 int64_t Val;
611 MVT::SimpleValueType VT;
612public:
Chris Lattner9a515172010-02-25 02:04:40 +0000613 EmitIntegerMatcher(int64_t val, MVT::SimpleValueType vt)
614 : Matcher(EmitInteger), Val(val), VT(vt) {}
Chris Lattner283adcb2010-02-17 06:23:39 +0000615
Chris Lattner7043e0a2010-02-19 07:49:56 +0000616 int64_t getValue() const { return Val; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000617 MVT::SimpleValueType getVT() const { return VT; }
618
Chris Lattner9a515172010-02-25 02:04:40 +0000619 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000620 return N->getKind() == EmitInteger;
621 }
622
Chris Lattner136ab782010-02-25 06:49:58 +0000623private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000624 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000625 virtual bool isEqualImpl(const Matcher *M) const {
626 return cast<EmitIntegerMatcher>(M)->Val == Val &&
627 cast<EmitIntegerMatcher>(M)->VT == VT;
628 }
629 virtual unsigned getHashImpl() const { return (Val << 4) | VT; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000630};
Chris Lattner3163ca52010-02-21 03:22:59 +0000631
Chris Lattner9a515172010-02-25 02:04:40 +0000632/// EmitStringIntegerMatcher - A target constant whose value is represented
Chris Lattner3163ca52010-02-21 03:22:59 +0000633/// by a string.
Chris Lattner9a515172010-02-25 02:04:40 +0000634class EmitStringIntegerMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000635 std::string Val;
636 MVT::SimpleValueType VT;
637public:
Chris Lattner9a515172010-02-25 02:04:40 +0000638 EmitStringIntegerMatcher(const std::string &val, MVT::SimpleValueType vt)
639 : Matcher(EmitStringInteger), Val(val), VT(vt) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000640
641 const std::string &getValue() const { return Val; }
642 MVT::SimpleValueType getVT() const { return VT; }
643
Chris Lattner9a515172010-02-25 02:04:40 +0000644 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000645 return N->getKind() == EmitStringInteger;
646 }
647
Chris Lattner136ab782010-02-25 06:49:58 +0000648private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000649 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000650 virtual bool isEqualImpl(const Matcher *M) const {
651 return cast<EmitStringIntegerMatcher>(M)->Val == Val &&
652 cast<EmitStringIntegerMatcher>(M)->VT == VT;
653 }
654 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +0000655};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000656
Chris Lattner9a515172010-02-25 02:04:40 +0000657/// EmitRegisterMatcher - This creates a new TargetConstant.
658class EmitRegisterMatcher : public Matcher {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000659 /// Reg - The def for the register that we're emitting. If this is null, then
660 /// this is a reference to zero_reg.
661 Record *Reg;
662 MVT::SimpleValueType VT;
663public:
Chris Lattner9a515172010-02-25 02:04:40 +0000664 EmitRegisterMatcher(Record *reg, MVT::SimpleValueType vt)
665 : Matcher(EmitRegister), Reg(reg), VT(vt) {}
Chris Lattnerddfb5222010-02-18 22:03:03 +0000666
667 Record *getReg() const { return Reg; }
668 MVT::SimpleValueType getVT() const { return VT; }
669
Chris Lattner9a515172010-02-25 02:04:40 +0000670 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000671 return N->getKind() == EmitRegister;
672 }
673
Chris Lattner136ab782010-02-25 06:49:58 +0000674private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000675 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000676 virtual bool isEqualImpl(const Matcher *M) const {
677 return cast<EmitRegisterMatcher>(M)->Reg == Reg &&
678 cast<EmitRegisterMatcher>(M)->VT == VT;
679 }
680 virtual unsigned getHashImpl() const {
681 return ((unsigned)(intptr_t)Reg) << 4 | VT;
682 }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000683};
Chris Lattner3163ca52010-02-21 03:22:59 +0000684
Chris Lattner9a515172010-02-25 02:04:40 +0000685/// EmitConvertToTargetMatcher - Emit an operation that reads a specified
Chris Lattner3163ca52010-02-21 03:22:59 +0000686/// recorded node and converts it from being a ISD::Constant to
687/// ISD::TargetConstant, likewise for ConstantFP.
Chris Lattner9a515172010-02-25 02:04:40 +0000688class EmitConvertToTargetMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000689 unsigned Slot;
690public:
Chris Lattner9a515172010-02-25 02:04:40 +0000691 EmitConvertToTargetMatcher(unsigned slot)
692 : Matcher(EmitConvertToTarget), Slot(slot) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000693
694 unsigned getSlot() const { return Slot; }
695
Chris Lattner9a515172010-02-25 02:04:40 +0000696 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000697 return N->getKind() == EmitConvertToTarget;
698 }
699
Chris Lattner136ab782010-02-25 06:49:58 +0000700private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000701 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000702 virtual bool isEqualImpl(const Matcher *M) const {
703 return cast<EmitConvertToTargetMatcher>(M)->Slot == Slot;
704 }
705 virtual unsigned getHashImpl() const { return Slot; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000706};
707
Chris Lattner9a515172010-02-25 02:04:40 +0000708/// EmitMergeInputChainsMatcher - Emit a node that merges a list of input
Chris Lattner3163ca52010-02-21 03:22:59 +0000709/// chains together with a token factor. The list of nodes are the nodes in the
710/// matched pattern that have chain input/outputs. This node adds all input
711/// chains of these nodes if they are not themselves a node in the pattern.
Chris Lattner9a515172010-02-25 02:04:40 +0000712class EmitMergeInputChainsMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000713 SmallVector<unsigned, 3> ChainNodes;
714public:
Chris Lattner9a515172010-02-25 02:04:40 +0000715 EmitMergeInputChainsMatcher(const unsigned *nodes, unsigned NumNodes)
716 : Matcher(EmitMergeInputChains), ChainNodes(nodes, nodes+NumNodes) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000717
718 unsigned getNumNodes() const { return ChainNodes.size(); }
719
720 unsigned getNode(unsigned i) const {
721 assert(i < ChainNodes.size());
722 return ChainNodes[i];
723 }
724
Chris Lattner9a515172010-02-25 02:04:40 +0000725 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000726 return N->getKind() == EmitMergeInputChains;
727 }
728
Chris Lattner136ab782010-02-25 06:49:58 +0000729private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000730 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000731 virtual bool isEqualImpl(const Matcher *M) const {
732 return cast<EmitMergeInputChainsMatcher>(M)->ChainNodes == ChainNodes;
733 }
734 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +0000735};
736
Chris Lattner9a515172010-02-25 02:04:40 +0000737/// EmitCopyToRegMatcher - Emit a CopyToReg node from a value to a physreg,
Chris Lattner3163ca52010-02-21 03:22:59 +0000738/// pushing the chain and flag results.
739///
Chris Lattner9a515172010-02-25 02:04:40 +0000740class EmitCopyToRegMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000741 unsigned SrcSlot; // Value to copy into the physreg.
742 Record *DestPhysReg;
743public:
Chris Lattner9a515172010-02-25 02:04:40 +0000744 EmitCopyToRegMatcher(unsigned srcSlot, Record *destPhysReg)
745 : Matcher(EmitCopyToReg), SrcSlot(srcSlot), DestPhysReg(destPhysReg) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000746
747 unsigned getSrcSlot() const { return SrcSlot; }
748 Record *getDestPhysReg() const { return DestPhysReg; }
749
Chris Lattner9a515172010-02-25 02:04:40 +0000750 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000751 return N->getKind() == EmitCopyToReg;
752 }
753
Chris Lattner136ab782010-02-25 06:49:58 +0000754private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000755 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000756 virtual bool isEqualImpl(const Matcher *M) const {
757 return cast<EmitCopyToRegMatcher>(M)->SrcSlot == SrcSlot &&
758 cast<EmitCopyToRegMatcher>(M)->DestPhysReg == DestPhysReg;
759 }
760 virtual unsigned getHashImpl() const {
761 return SrcSlot ^ ((unsigned)(intptr_t)DestPhysReg << 4);
762 }
Chris Lattner3163ca52010-02-21 03:22:59 +0000763};
764
765
766
Chris Lattner9a515172010-02-25 02:04:40 +0000767/// EmitNodeXFormMatcher - Emit an operation that runs an SDNodeXForm on a
Chris Lattner3163ca52010-02-21 03:22:59 +0000768/// recorded node and records the result.
Chris Lattner9a515172010-02-25 02:04:40 +0000769class EmitNodeXFormMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000770 unsigned Slot;
771 Record *NodeXForm;
772public:
Chris Lattner9a515172010-02-25 02:04:40 +0000773 EmitNodeXFormMatcher(unsigned slot, Record *nodeXForm)
774 : Matcher(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm) {}
Chris Lattner3163ca52010-02-21 03:22:59 +0000775
776 unsigned getSlot() const { return Slot; }
777 Record *getNodeXForm() const { return NodeXForm; }
778
Chris Lattner9a515172010-02-25 02:04:40 +0000779 static inline bool classof(const Matcher *N) {
Chris Lattner3163ca52010-02-21 03:22:59 +0000780 return N->getKind() == EmitNodeXForm;
781 }
782
Chris Lattner136ab782010-02-25 06:49:58 +0000783private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000784 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000785 virtual bool isEqualImpl(const Matcher *M) const {
786 return cast<EmitNodeXFormMatcher>(M)->Slot == Slot &&
787 cast<EmitNodeXFormMatcher>(M)->NodeXForm == NodeXForm;
788 }
789 virtual unsigned getHashImpl() const {
790 return Slot ^ ((unsigned)(intptr_t)NodeXForm << 4);
791 }
Chris Lattner3163ca52010-02-21 03:22:59 +0000792};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000793
Chris Lattner9a515172010-02-25 02:04:40 +0000794/// EmitNodeMatcher - This signals a successful match and generates a node.
795class EmitNodeMatcher : public Matcher {
Chris Lattner3163ca52010-02-21 03:22:59 +0000796 std::string OpcodeName;
797 const SmallVector<MVT::SimpleValueType, 3> VTs;
798 const SmallVector<unsigned, 6> Operands;
799 bool HasChain, HasFlag, HasMemRefs;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000800
Chris Lattner3163ca52010-02-21 03:22:59 +0000801 /// NumFixedArityOperands - If this is a fixed arity node, this is set to -1.
802 /// If this is a varidic node, this is set to the number of fixed arity
803 /// operands in the root of the pattern. The rest are appended to this node.
804 int NumFixedArityOperands;
805public:
Chris Lattner9a515172010-02-25 02:04:40 +0000806 EmitNodeMatcher(const std::string &opcodeName,
Chris Lattner136ab782010-02-25 06:49:58 +0000807 const MVT::SimpleValueType *vts, unsigned numvts,
808 const unsigned *operands, unsigned numops,
809 bool hasChain, bool hasFlag, bool hasmemrefs,
810 int numfixedarityoperands)
Chris Lattner9a515172010-02-25 02:04:40 +0000811 : Matcher(EmitNode), OpcodeName(opcodeName),
Chris Lattner3163ca52010-02-21 03:22:59 +0000812 VTs(vts, vts+numvts), Operands(operands, operands+numops),
813 HasChain(hasChain), HasFlag(hasFlag), HasMemRefs(hasmemrefs),
814 NumFixedArityOperands(numfixedarityoperands) {}
815
816 const std::string &getOpcodeName() const { return OpcodeName; }
817
818 unsigned getNumVTs() const { return VTs.size(); }
819 MVT::SimpleValueType getVT(unsigned i) const {
820 assert(i < VTs.size());
821 return VTs[i];
822 }
823
824 unsigned getNumOperands() const { return Operands.size(); }
825 unsigned getOperand(unsigned i) const {
826 assert(i < Operands.size());
827 return Operands[i];
828 }
829
830 bool hasChain() const { return HasChain; }
831 bool hasFlag() const { return HasFlag; }
832 bool hasMemRefs() const { return HasMemRefs; }
833 int getNumFixedArityOperands() const { return NumFixedArityOperands; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000834
Chris Lattner9a515172010-02-25 02:04:40 +0000835 static inline bool classof(const Matcher *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000836 return N->getKind() == EmitNode;
837 }
838
Chris Lattner136ab782010-02-25 06:49:58 +0000839private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000840 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000841 virtual bool isEqualImpl(const Matcher *M) const;
842 virtual unsigned getHashImpl() const;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000843};
Chris Lattnerb085ea12010-02-21 06:03:07 +0000844
Chris Lattner9a515172010-02-25 02:04:40 +0000845/// MarkFlagResultsMatcher - This node indicates which non-root nodes in the
846/// pattern produce flags. This allows CompleteMatchMatcher to update them
Chris Lattner69f60c82010-02-24 05:33:42 +0000847/// with the output flag of the resultant code.
Chris Lattner9a515172010-02-25 02:04:40 +0000848class MarkFlagResultsMatcher : public Matcher {
Chris Lattner69f60c82010-02-24 05:33:42 +0000849 SmallVector<unsigned, 3> FlagResultNodes;
850public:
Chris Lattner9a515172010-02-25 02:04:40 +0000851 MarkFlagResultsMatcher(const unsigned *nodes, unsigned NumNodes)
852 : Matcher(MarkFlagResults), FlagResultNodes(nodes, nodes+NumNodes) {}
Chris Lattner69f60c82010-02-24 05:33:42 +0000853
854 unsigned getNumNodes() const { return FlagResultNodes.size(); }
855
856 unsigned getNode(unsigned i) const {
857 assert(i < FlagResultNodes.size());
858 return FlagResultNodes[i];
859 }
860
Chris Lattner9a515172010-02-25 02:04:40 +0000861 static inline bool classof(const Matcher *N) {
Chris Lattner69f60c82010-02-24 05:33:42 +0000862 return N->getKind() == MarkFlagResults;
863 }
864
Chris Lattner136ab782010-02-25 06:49:58 +0000865private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000866 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000867 virtual bool isEqualImpl(const Matcher *M) const {
868 return cast<MarkFlagResultsMatcher>(M)->FlagResultNodes == FlagResultNodes;
869 }
870 virtual unsigned getHashImpl() const;
Chris Lattner69f60c82010-02-24 05:33:42 +0000871};
872
Chris Lattner9a515172010-02-25 02:04:40 +0000873/// CompleteMatchMatcher - Complete a match by replacing the results of the
Chris Lattnerb085ea12010-02-21 06:03:07 +0000874/// pattern with the newly generated nodes. This also prints a comment
875/// indicating the source and dest patterns.
Chris Lattner9a515172010-02-25 02:04:40 +0000876class CompleteMatchMatcher : public Matcher {
Chris Lattnerb085ea12010-02-21 06:03:07 +0000877 SmallVector<unsigned, 2> Results;
Chris Lattner3163ca52010-02-21 03:22:59 +0000878 const PatternToMatch &Pattern;
879public:
Chris Lattner9a515172010-02-25 02:04:40 +0000880 CompleteMatchMatcher(const unsigned *results, unsigned numresults,
Chris Lattnerb085ea12010-02-21 06:03:07 +0000881 const PatternToMatch &pattern)
Chris Lattner9a515172010-02-25 02:04:40 +0000882 : Matcher(CompleteMatch), Results(results, results+numresults),
Chris Lattnerb085ea12010-02-21 06:03:07 +0000883 Pattern(pattern) {}
884
885 unsigned getNumResults() const { return Results.size(); }
886 unsigned getResult(unsigned R) const { return Results[R]; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000887 const PatternToMatch &getPattern() const { return Pattern; }
888
Chris Lattner9a515172010-02-25 02:04:40 +0000889 static inline bool classof(const Matcher *N) {
Chris Lattnerb085ea12010-02-21 06:03:07 +0000890 return N->getKind() == CompleteMatch;
Chris Lattner3163ca52010-02-21 03:22:59 +0000891 }
892
Chris Lattner136ab782010-02-25 06:49:58 +0000893private:
Chris Lattner392b1bf2010-02-25 06:53:39 +0000894 virtual void printImpl(raw_ostream &OS, unsigned indent) const;
Chris Lattner136ab782010-02-25 06:49:58 +0000895 virtual bool isEqualImpl(const Matcher *M) const {
896 return cast<CompleteMatchMatcher>(M)->Results == Results &&
897 &cast<CompleteMatchMatcher>(M)->Pattern == &Pattern;
898 }
899 virtual unsigned getHashImpl() const;
Chris Lattner3163ca52010-02-21 03:22:59 +0000900};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000901
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000902} // end namespace llvm
903
904#endif