blob: 4dcb4d6af7197e3fd16b6761b7d4b06aa6a10ed6 [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;
21 class MatcherNode;
22 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
27MatcherNode *ConvertPatternToMatcher(const PatternToMatch &Pattern,
28 const CodeGenDAGPatterns &CGP);
29
30void EmitMatcherTable(const MatcherNode *Matcher, raw_ostream &OS);
31
32
33/// MatcherNode - Base class for all the the DAG ISel Matcher representation
34/// nodes.
35class MatcherNode {
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.
38 OwningPtr<MatcherNode> Next;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000039public:
40 enum KindTy {
Chris Lattner3163ca52010-02-21 03:22:59 +000041 // Matcher state manipulation.
42 Push, // Push a checking scope.
43 RecordNode, // Record the current node.
44 RecordMemRef, // Record the memref in the current node.
45 CaptureFlagInput, // If the current node has an input flag, save it.
46 MoveChild, // Move current node to specified child.
47 MoveParent, // Move current node to parent.
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000048
Chris Lattnerddfb5222010-02-18 22:03:03 +000049 // Predicate checking.
Chris Lattner3163ca52010-02-21 03:22:59 +000050 CheckSame, // Fail if not same as prev match.
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000051 CheckPatternPredicate,
Chris Lattner3163ca52010-02-21 03:22:59 +000052 CheckPredicate, // Fail if node predicate fails.
53 CheckOpcode, // Fail if not opcode.
54 CheckType, // Fail if not correct type.
55 CheckInteger, // Fail if wrong val.
56 CheckCondCode, // Fail if not condcode.
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000057 CheckValueType,
58 CheckComplexPat,
59 CheckAndImm,
Chris Lattner9de39482010-02-16 06:10:58 +000060 CheckOrImm,
Chris Lattner283adcb2010-02-17 06:23:39 +000061 CheckFoldableChainNode,
Chris Lattnerddfb5222010-02-18 22:03:03 +000062 CheckChainCompatible,
63
64 // Node creation/emisssion.
Chris Lattner3163ca52010-02-21 03:22:59 +000065 EmitInteger, // Create a TargetConstant
66 EmitStringInteger, // Create a TargetConstant from a string.
67 EmitRegister, // Create a register.
68 EmitConvertToTarget, // Convert a imm/fpimm to target imm/fpimm
69 EmitMergeInputChains, // Merge together a chains for an input.
70 EmitCopyToReg, // Emit a copytoreg into a physreg.
71 EmitNode, // Create a DAG node
72 EmitNodeXForm, // Run a SDNodeXForm
73 PatternMarker // Comment for printing.
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000074 };
75 const KindTy Kind;
Chris Lattner3b31c982010-02-18 02:49:24 +000076
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000077protected:
78 MatcherNode(KindTy K) : Kind(K) {}
79public:
80 virtual ~MatcherNode() {}
81
82 KindTy getKind() const { return Kind; }
Chris Lattner3b31c982010-02-18 02:49:24 +000083
Chris Lattner78039ec2010-02-18 02:53:41 +000084 MatcherNode *getNext() { return Next.get(); }
85 const MatcherNode *getNext() const { return Next.get(); }
86 void setNext(MatcherNode *C) { Next.reset(C); }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000087
88 static inline bool classof(const MatcherNode *) { return true; }
89
90 virtual void print(raw_ostream &OS, unsigned indent = 0) const = 0;
91 void dump() const;
Chris Lattner3b31c982010-02-18 02:49:24 +000092protected:
Chris Lattner78039ec2010-02-18 02:53:41 +000093 void printNext(raw_ostream &OS, unsigned indent) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000094};
95
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000096/// PushMatcherNode - This pushes a failure scope on the stack and evaluates
Chris Lattner78039ec2010-02-18 02:53:41 +000097/// 'Next'. If 'Next' fails to match, it pops its scope and attempts to
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000098/// match 'Failure'.
Chris Lattner3b31c982010-02-18 02:49:24 +000099class PushMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000100 OwningPtr<MatcherNode> Failure;
101public:
Chris Lattner78039ec2010-02-18 02:53:41 +0000102 PushMatcherNode(MatcherNode *next = 0, MatcherNode *failure = 0)
Chris Lattner3b31c982010-02-18 02:49:24 +0000103 : MatcherNode(Push), Failure(failure) {
Chris Lattner78039ec2010-02-18 02:53:41 +0000104 setNext(next);
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000105 }
106
107 MatcherNode *getFailure() { return Failure.get(); }
108 const MatcherNode *getFailure() const { return Failure.get(); }
109 void setFailure(MatcherNode *N) { Failure.reset(N); }
110
111 static inline bool classof(const MatcherNode *N) {
112 return N->getKind() == Push;
113 }
114
115 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
116};
117
118/// RecordMatcherNode - Save the current node in the operand list.
Chris Lattner3b31c982010-02-18 02:49:24 +0000119class RecordMatcherNode : public MatcherNode {
Chris Lattner56cf88d2010-02-17 01:03:09 +0000120 /// WhatFor - This is a string indicating why we're recording this. This
121 /// should only be used for comment generation not anything semantic.
122 std::string WhatFor;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000123public:
Chris Lattner086ca522010-02-17 01:27:29 +0000124 RecordMatcherNode(const std::string &whatfor)
Chris Lattnerddfb5222010-02-18 22:03:03 +0000125 : MatcherNode(RecordNode), WhatFor(whatfor) {}
Chris Lattner56cf88d2010-02-17 01:03:09 +0000126
Chris Lattner086ca522010-02-17 01:27:29 +0000127 const std::string &getWhatFor() const { return WhatFor; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000128
129 static inline bool classof(const MatcherNode *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000130 return N->getKind() == RecordNode;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000131 }
132
133 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
134};
135
Chris Lattner3163ca52010-02-21 03:22:59 +0000136/// RecordMemRefMatcherNode - Save the current node's memref.
137class RecordMemRefMatcherNode : public MatcherNode {
138public:
139 RecordMemRefMatcherNode() : MatcherNode(RecordMemRef) {}
140
141 static inline bool classof(const MatcherNode *N) {
142 return N->getKind() == RecordMemRef;
143 }
144
145 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
146};
147
148
149/// CaptureFlagInputMatcherNode - If the current record has a flag input, record
150/// it so that it is used as an input to the generated code.
151class CaptureFlagInputMatcherNode : public MatcherNode {
152public:
153 CaptureFlagInputMatcherNode()
154 : MatcherNode(CaptureFlagInput) {}
155
156 static inline bool classof(const MatcherNode *N) {
157 return N->getKind() == CaptureFlagInput;
158 }
159
160 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
161};
162
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000163/// MoveChildMatcherNode - This tells the interpreter to move into the
164/// specified child node.
Chris Lattner3b31c982010-02-18 02:49:24 +0000165class MoveChildMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000166 unsigned ChildNo;
167public:
168 MoveChildMatcherNode(unsigned childNo)
Chris Lattner3b31c982010-02-18 02:49:24 +0000169 : MatcherNode(MoveChild), ChildNo(childNo) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000170
171 unsigned getChildNo() const { return ChildNo; }
172
173 static inline bool classof(const MatcherNode *N) {
174 return N->getKind() == MoveChild;
175 }
176
177 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
178};
179
180/// MoveParentMatcherNode - This tells the interpreter to move to the parent
181/// of the current node.
Chris Lattner3b31c982010-02-18 02:49:24 +0000182class MoveParentMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000183public:
184 MoveParentMatcherNode()
Chris Lattner3b31c982010-02-18 02:49:24 +0000185 : MatcherNode(MoveParent) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000186
187 static inline bool classof(const MatcherNode *N) {
188 return N->getKind() == MoveParent;
189 }
190
191 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
192};
193
194/// CheckSameMatcherNode - This checks to see if this node is exactly the same
195/// node as the specified match that was recorded with 'Record'. This is used
196/// when patterns have the same name in them, like '(mul GPR:$in, GPR:$in)'.
Chris Lattner3b31c982010-02-18 02:49:24 +0000197class CheckSameMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000198 unsigned MatchNumber;
199public:
200 CheckSameMatcherNode(unsigned matchnumber)
Chris Lattner3b31c982010-02-18 02:49:24 +0000201 : MatcherNode(CheckSame), MatchNumber(matchnumber) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000202
203 unsigned getMatchNumber() const { return MatchNumber; }
204
205 static inline bool classof(const MatcherNode *N) {
206 return N->getKind() == CheckSame;
207 }
208
209 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
210};
211
212/// CheckPatternPredicateMatcherNode - This checks the target-specific predicate
213/// to see if the entire pattern is capable of matching. This predicate does
214/// not take a node as input. This is used for subtarget feature checks etc.
Chris Lattner3b31c982010-02-18 02:49:24 +0000215class CheckPatternPredicateMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000216 std::string Predicate;
217public:
218 CheckPatternPredicateMatcherNode(StringRef predicate)
Chris Lattner3b31c982010-02-18 02:49:24 +0000219 : MatcherNode(CheckPatternPredicate), Predicate(predicate) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000220
221 StringRef getPredicate() const { return Predicate; }
222
223 static inline bool classof(const MatcherNode *N) {
224 return N->getKind() == CheckPatternPredicate;
225 }
226
227 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
228};
229
230/// CheckPredicateMatcherNode - This checks the target-specific predicate to
231/// see if the node is acceptable.
Chris Lattner3b31c982010-02-18 02:49:24 +0000232class CheckPredicateMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000233 StringRef PredName;
234public:
235 CheckPredicateMatcherNode(StringRef predname)
Chris Lattner3b31c982010-02-18 02:49:24 +0000236 : MatcherNode(CheckPredicate), PredName(predname) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000237
238 StringRef getPredicateName() const { return PredName; }
239
240 static inline bool classof(const MatcherNode *N) {
241 return N->getKind() == CheckPredicate;
242 }
243
244 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
245};
246
247
248/// CheckOpcodeMatcherNode - This checks to see if the current node has the
249/// specified opcode, if not it fails to match.
Chris Lattner3b31c982010-02-18 02:49:24 +0000250class CheckOpcodeMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000251 StringRef OpcodeName;
252public:
253 CheckOpcodeMatcherNode(StringRef opcodename)
Chris Lattner3b31c982010-02-18 02:49:24 +0000254 : MatcherNode(CheckOpcode), OpcodeName(opcodename) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000255
256 StringRef getOpcodeName() const { return OpcodeName; }
257
258 static inline bool classof(const MatcherNode *N) {
259 return N->getKind() == CheckOpcode;
260 }
261
262 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
263};
264
265/// CheckTypeMatcherNode - This checks to see if the current node has the
266/// specified type, if not it fails to match.
Chris Lattner3b31c982010-02-18 02:49:24 +0000267class CheckTypeMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000268 MVT::SimpleValueType Type;
269public:
270 CheckTypeMatcherNode(MVT::SimpleValueType type)
Chris Lattner3b31c982010-02-18 02:49:24 +0000271 : MatcherNode(CheckType), Type(type) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000272
273 MVT::SimpleValueType getType() const { return Type; }
274
275 static inline bool classof(const MatcherNode *N) {
276 return N->getKind() == CheckType;
277 }
278
279 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
280};
281
282/// CheckIntegerMatcherNode - This checks to see if the current node is a
283/// ConstantSDNode with the specified integer value, if not it fails to match.
Chris Lattner3b31c982010-02-18 02:49:24 +0000284class CheckIntegerMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000285 int64_t Value;
286public:
287 CheckIntegerMatcherNode(int64_t value)
Chris Lattner3b31c982010-02-18 02:49:24 +0000288 : MatcherNode(CheckInteger), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000289
290 int64_t getValue() const { return Value; }
291
292 static inline bool classof(const MatcherNode *N) {
293 return N->getKind() == CheckInteger;
294 }
295
296 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
297};
298
299/// CheckCondCodeMatcherNode - This checks to see if the current node is a
300/// CondCodeSDNode with the specified condition, if not it fails to match.
Chris Lattner3b31c982010-02-18 02:49:24 +0000301class CheckCondCodeMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000302 StringRef CondCodeName;
303public:
304 CheckCondCodeMatcherNode(StringRef condcodename)
Chris Lattner3b31c982010-02-18 02:49:24 +0000305 : MatcherNode(CheckCondCode), CondCodeName(condcodename) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000306
307 StringRef getCondCodeName() const { return CondCodeName; }
308
309 static inline bool classof(const MatcherNode *N) {
310 return N->getKind() == CheckCondCode;
311 }
312
313 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
314};
315
316/// CheckValueTypeMatcherNode - This checks to see if the current node is a
317/// VTSDNode with the specified type, if not it fails to match.
Chris Lattner3b31c982010-02-18 02:49:24 +0000318class CheckValueTypeMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000319 StringRef TypeName;
320public:
321 CheckValueTypeMatcherNode(StringRef type_name)
Chris Lattner3b31c982010-02-18 02:49:24 +0000322 : MatcherNode(CheckValueType), TypeName(type_name) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000323
324 StringRef getTypeName() const { return TypeName; }
325
326 static inline bool classof(const MatcherNode *N) {
327 return N->getKind() == CheckValueType;
328 }
329
330 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
331};
332
333
334
335/// CheckComplexPatMatcherNode - This node runs the specified ComplexPattern on
336/// the current node.
Chris Lattner3b31c982010-02-18 02:49:24 +0000337class CheckComplexPatMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000338 const ComplexPattern &Pattern;
339public:
340 CheckComplexPatMatcherNode(const ComplexPattern &pattern)
Chris Lattner3b31c982010-02-18 02:49:24 +0000341 : MatcherNode(CheckComplexPat), Pattern(pattern) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000342
Chris Lattnerdc429fd2010-02-17 00:31:50 +0000343 const ComplexPattern &getPattern() const { return Pattern; }
344
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000345 static inline bool classof(const MatcherNode *N) {
346 return N->getKind() == CheckComplexPat;
347 }
348
349 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
350};
351
352/// CheckAndImmMatcherNode - This checks to see if the current node is an 'and'
353/// with something equivalent to the specified immediate.
Chris Lattner3b31c982010-02-18 02:49:24 +0000354class CheckAndImmMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000355 int64_t Value;
356public:
357 CheckAndImmMatcherNode(int64_t value)
Chris Lattner3b31c982010-02-18 02:49:24 +0000358 : MatcherNode(CheckAndImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000359
360 int64_t getValue() const { return Value; }
361
362 static inline bool classof(const MatcherNode *N) {
363 return N->getKind() == CheckAndImm;
364 }
365
366 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
367};
368
369/// CheckOrImmMatcherNode - This checks to see if the current node is an 'and'
370/// with something equivalent to the specified immediate.
Chris Lattner3b31c982010-02-18 02:49:24 +0000371class CheckOrImmMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000372 int64_t Value;
373public:
374 CheckOrImmMatcherNode(int64_t value)
Chris Lattner3b31c982010-02-18 02:49:24 +0000375 : MatcherNode(CheckOrImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000376
377 int64_t getValue() const { return Value; }
378
379 static inline bool classof(const MatcherNode *N) {
380 return N->getKind() == CheckOrImm;
381 }
382
383 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
384};
Chris Lattner9de39482010-02-16 06:10:58 +0000385
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000386/// CheckFoldableChainNodeMatcherNode - This checks to see if the current node
387/// (which defines a chain operand) is safe to fold into a larger pattern.
Chris Lattner3b31c982010-02-18 02:49:24 +0000388class CheckFoldableChainNodeMatcherNode : public MatcherNode {
Chris Lattner9de39482010-02-16 06:10:58 +0000389public:
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000390 CheckFoldableChainNodeMatcherNode()
Chris Lattner3b31c982010-02-18 02:49:24 +0000391 : MatcherNode(CheckFoldableChainNode) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000392
Chris Lattner9de39482010-02-16 06:10:58 +0000393 static inline bool classof(const MatcherNode *N) {
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000394 return N->getKind() == CheckFoldableChainNode;
Chris Lattner9de39482010-02-16 06:10:58 +0000395 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000396
Chris Lattner9de39482010-02-16 06:10:58 +0000397 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
398};
399
Chris Lattner283adcb2010-02-17 06:23:39 +0000400/// CheckChainCompatibleMatcherNode - Verify that the current node's chain
401/// operand is 'compatible' with the specified recorded node's.
Chris Lattner3b31c982010-02-18 02:49:24 +0000402class CheckChainCompatibleMatcherNode : public MatcherNode {
Chris Lattner283adcb2010-02-17 06:23:39 +0000403 unsigned PreviousOp;
404public:
405 CheckChainCompatibleMatcherNode(unsigned previousop)
Chris Lattner3b31c982010-02-18 02:49:24 +0000406 : MatcherNode(CheckChainCompatible), PreviousOp(previousop) {}
Chris Lattner283adcb2010-02-17 06:23:39 +0000407
408 unsigned getPreviousOp() const { return PreviousOp; }
409
410 static inline bool classof(const MatcherNode *N) {
411 return N->getKind() == CheckChainCompatible;
412 }
413
414 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
415};
416
Chris Lattnerddfb5222010-02-18 22:03:03 +0000417/// EmitIntegerMatcherNode - This creates a new TargetConstant.
418class EmitIntegerMatcherNode : public MatcherNode {
419 int64_t Val;
420 MVT::SimpleValueType VT;
421public:
422 EmitIntegerMatcherNode(int64_t val, MVT::SimpleValueType vt)
423 : MatcherNode(EmitInteger), Val(val), VT(vt) {}
Chris Lattner283adcb2010-02-17 06:23:39 +0000424
Chris Lattner7043e0a2010-02-19 07:49:56 +0000425 int64_t getValue() const { return Val; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000426 MVT::SimpleValueType getVT() const { return VT; }
427
428 static inline bool classof(const MatcherNode *N) {
429 return N->getKind() == EmitInteger;
430 }
431
432 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
433};
Chris Lattner3163ca52010-02-21 03:22:59 +0000434
435/// EmitStringIntegerMatcherNode - A target constant whose value is represented
436/// by a string.
437class EmitStringIntegerMatcherNode : public MatcherNode {
438 std::string Val;
439 MVT::SimpleValueType VT;
440public:
441 EmitStringIntegerMatcherNode(const std::string &val, MVT::SimpleValueType vt)
442 : MatcherNode(EmitStringInteger), Val(val), VT(vt) {}
443
444 const std::string &getValue() const { return Val; }
445 MVT::SimpleValueType getVT() const { return VT; }
446
447 static inline bool classof(const MatcherNode *N) {
448 return N->getKind() == EmitStringInteger;
449 }
450
451 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
452};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000453
454/// EmitRegisterMatcherNode - This creates a new TargetConstant.
455class EmitRegisterMatcherNode : public MatcherNode {
456 /// Reg - The def for the register that we're emitting. If this is null, then
457 /// this is a reference to zero_reg.
458 Record *Reg;
459 MVT::SimpleValueType VT;
460public:
461 EmitRegisterMatcherNode(Record *reg, MVT::SimpleValueType vt)
462 : MatcherNode(EmitRegister), Reg(reg), VT(vt) {}
463
464 Record *getReg() const { return Reg; }
465 MVT::SimpleValueType getVT() const { return VT; }
466
467 static inline bool classof(const MatcherNode *N) {
468 return N->getKind() == EmitRegister;
469 }
470
471 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
472};
Chris Lattner3163ca52010-02-21 03:22:59 +0000473
474/// EmitConvertToTargetMatcherNode - Emit an operation that reads a specified
475/// recorded node and converts it from being a ISD::Constant to
476/// ISD::TargetConstant, likewise for ConstantFP.
477class EmitConvertToTargetMatcherNode : public MatcherNode {
478 unsigned Slot;
479public:
480 EmitConvertToTargetMatcherNode(unsigned slot)
481 : MatcherNode(EmitConvertToTarget), Slot(slot) {}
482
483 unsigned getSlot() const { return Slot; }
484
485 static inline bool classof(const MatcherNode *N) {
486 return N->getKind() == EmitConvertToTarget;
487 }
488
489 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
490};
491
492/// EmitMergeInputChainsMatcherNode - Emit a node that merges a list of input
493/// chains together with a token factor. The list of nodes are the nodes in the
494/// matched pattern that have chain input/outputs. This node adds all input
495/// chains of these nodes if they are not themselves a node in the pattern.
496class EmitMergeInputChainsMatcherNode : public MatcherNode {
497 SmallVector<unsigned, 3> ChainNodes;
498public:
499 EmitMergeInputChainsMatcherNode(const unsigned *nodes, unsigned NumNodes)
500 : MatcherNode(EmitMergeInputChains), ChainNodes(nodes, nodes+NumNodes) {}
501
502 unsigned getNumNodes() const { return ChainNodes.size(); }
503
504 unsigned getNode(unsigned i) const {
505 assert(i < ChainNodes.size());
506 return ChainNodes[i];
507 }
508
509 static inline bool classof(const MatcherNode *N) {
510 return N->getKind() == EmitMergeInputChains;
511 }
512
513 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
514};
515
516/// EmitCopyToRegMatcherNode - Emit a CopyToReg node from a value to a physreg,
517/// pushing the chain and flag results.
518///
519class EmitCopyToRegMatcherNode : public MatcherNode {
520 unsigned SrcSlot; // Value to copy into the physreg.
521 Record *DestPhysReg;
522public:
523 EmitCopyToRegMatcherNode(unsigned srcSlot, Record *destPhysReg)
524 : MatcherNode(EmitCopyToReg), SrcSlot(srcSlot), DestPhysReg(destPhysReg) {}
525
526 unsigned getSrcSlot() const { return SrcSlot; }
527 Record *getDestPhysReg() const { return DestPhysReg; }
528
529 static inline bool classof(const MatcherNode *N) {
530 return N->getKind() == EmitCopyToReg;
531 }
532
533 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
534};
535
536
537
538/// EmitNodeXFormMatcherNode - Emit an operation that runs an SDNodeXForm on a
539/// recorded node and records the result.
540class EmitNodeXFormMatcherNode : public MatcherNode {
541 unsigned Slot;
542 Record *NodeXForm;
543public:
544 EmitNodeXFormMatcherNode(unsigned slot, Record *nodeXForm)
545 : MatcherNode(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm) {}
546
547 unsigned getSlot() const { return Slot; }
548 Record *getNodeXForm() const { return NodeXForm; }
549
550 static inline bool classof(const MatcherNode *N) {
551 return N->getKind() == EmitNodeXForm;
552 }
553
554 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
555};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000556
557/// EmitNodeMatcherNode - This signals a successful match and generates a node.
558class EmitNodeMatcherNode : public MatcherNode {
Chris Lattner3163ca52010-02-21 03:22:59 +0000559 std::string OpcodeName;
560 const SmallVector<MVT::SimpleValueType, 3> VTs;
561 const SmallVector<unsigned, 6> Operands;
562 bool HasChain, HasFlag, HasMemRefs;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000563
Chris Lattner3163ca52010-02-21 03:22:59 +0000564 /// NumFixedArityOperands - If this is a fixed arity node, this is set to -1.
565 /// If this is a varidic node, this is set to the number of fixed arity
566 /// operands in the root of the pattern. The rest are appended to this node.
567 int NumFixedArityOperands;
568public:
569 EmitNodeMatcherNode(const std::string &opcodeName,
570 const MVT::SimpleValueType *vts, unsigned numvts,
571 const unsigned *operands, unsigned numops,
572 bool hasChain, bool hasFlag, bool hasmemrefs,
573 int numfixedarityoperands)
574 : MatcherNode(EmitNode), OpcodeName(opcodeName),
575 VTs(vts, vts+numvts), Operands(operands, operands+numops),
576 HasChain(hasChain), HasFlag(hasFlag), HasMemRefs(hasmemrefs),
577 NumFixedArityOperands(numfixedarityoperands) {}
578
579 const std::string &getOpcodeName() const { return OpcodeName; }
580
581 unsigned getNumVTs() const { return VTs.size(); }
582 MVT::SimpleValueType getVT(unsigned i) const {
583 assert(i < VTs.size());
584 return VTs[i];
585 }
586
587 unsigned getNumOperands() const { return Operands.size(); }
588 unsigned getOperand(unsigned i) const {
589 assert(i < Operands.size());
590 return Operands[i];
591 }
592
593 bool hasChain() const { return HasChain; }
594 bool hasFlag() const { return HasFlag; }
595 bool hasMemRefs() const { return HasMemRefs; }
596 int getNumFixedArityOperands() const { return NumFixedArityOperands; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000597
598 static inline bool classof(const MatcherNode *N) {
599 return N->getKind() == EmitNode;
600 }
601
602 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
603};
Chris Lattner3163ca52010-02-21 03:22:59 +0000604
605/// PatternMarkerMatcherNode - This prints as a comment indicating the source
606/// and dest patterns.
607class PatternMarkerMatcherNode : public MatcherNode {
608 const PatternToMatch &Pattern;
609public:
610 PatternMarkerMatcherNode(const PatternToMatch &pattern)
611 : MatcherNode(PatternMarker), Pattern(pattern) {}
612
613 const PatternToMatch &getPattern() const { return Pattern; }
614
615 static inline bool classof(const MatcherNode *N) {
616 return N->getKind() == PatternMarker;
617 }
618
619 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
620};
621
Chris Lattnerddfb5222010-02-18 22:03:03 +0000622
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000623} // end namespace llvm
624
625#endif