blob: 4dcbc8f55fc20ec828e41a6cd7d6cf156964cc56 [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);
Chris Lattner36e646c2010-02-24 07:06:50 +000029void OptimizeMatcher(const MatcherNode *Matcher);
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000030void 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.
Chris Lattnerf58c08e2010-02-22 22:30:37 +000054 CheckMultiOpcode, // Fail if not in opcode list.
Chris Lattner3163ca52010-02-21 03:22:59 +000055 CheckType, // Fail if not correct type.
56 CheckInteger, // Fail if wrong val.
57 CheckCondCode, // Fail if not condcode.
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000058 CheckValueType,
59 CheckComplexPat,
60 CheckAndImm,
Chris Lattner9de39482010-02-16 06:10:58 +000061 CheckOrImm,
Chris Lattner283adcb2010-02-17 06:23:39 +000062 CheckFoldableChainNode,
Chris Lattnerddfb5222010-02-18 22:03:03 +000063 CheckChainCompatible,
64
65 // Node creation/emisssion.
Chris Lattner3163ca52010-02-21 03:22:59 +000066 EmitInteger, // Create a TargetConstant
67 EmitStringInteger, // Create a TargetConstant from a string.
68 EmitRegister, // Create a register.
69 EmitConvertToTarget, // Convert a imm/fpimm to target imm/fpimm
70 EmitMergeInputChains, // Merge together a chains for an input.
71 EmitCopyToReg, // Emit a copytoreg into a physreg.
72 EmitNode, // Create a DAG node
73 EmitNodeXForm, // Run a SDNodeXForm
Chris Lattner69f60c82010-02-24 05:33:42 +000074 MarkFlagResults, // Indicate which interior nodes have flag results.
Chris Lattnerb085ea12010-02-21 06:03:07 +000075 CompleteMatch // Finish a match and update the results.
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000076 };
77 const KindTy Kind;
Chris Lattner3b31c982010-02-18 02:49:24 +000078
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000079protected:
80 MatcherNode(KindTy K) : Kind(K) {}
81public:
82 virtual ~MatcherNode() {}
83
84 KindTy getKind() const { return Kind; }
Chris Lattner3b31c982010-02-18 02:49:24 +000085
Chris Lattner78039ec2010-02-18 02:53:41 +000086 MatcherNode *getNext() { return Next.get(); }
87 const MatcherNode *getNext() const { return Next.get(); }
88 void setNext(MatcherNode *C) { Next.reset(C); }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000089
90 static inline bool classof(const MatcherNode *) { return true; }
91
92 virtual void print(raw_ostream &OS, unsigned indent = 0) const = 0;
93 void dump() const;
Chris Lattner3b31c982010-02-18 02:49:24 +000094protected:
Chris Lattner78039ec2010-02-18 02:53:41 +000095 void printNext(raw_ostream &OS, unsigned indent) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000096};
97
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000098/// PushMatcherNode - This pushes a failure scope on the stack and evaluates
Chris Lattner78039ec2010-02-18 02:53:41 +000099/// 'Next'. If 'Next' fails to match, it pops its scope and attempts to
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000100/// match 'Failure'.
Chris Lattner3b31c982010-02-18 02:49:24 +0000101class PushMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000102 OwningPtr<MatcherNode> Failure;
103public:
Chris Lattner78039ec2010-02-18 02:53:41 +0000104 PushMatcherNode(MatcherNode *next = 0, MatcherNode *failure = 0)
Chris Lattner3b31c982010-02-18 02:49:24 +0000105 : MatcherNode(Push), Failure(failure) {
Chris Lattner78039ec2010-02-18 02:53:41 +0000106 setNext(next);
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000107 }
108
109 MatcherNode *getFailure() { return Failure.get(); }
110 const MatcherNode *getFailure() const { return Failure.get(); }
111 void setFailure(MatcherNode *N) { Failure.reset(N); }
112
113 static inline bool classof(const MatcherNode *N) {
114 return N->getKind() == Push;
115 }
116
117 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
118};
119
120/// RecordMatcherNode - Save the current node in the operand list.
Chris Lattner3b31c982010-02-18 02:49:24 +0000121class RecordMatcherNode : public MatcherNode {
Chris Lattner56cf88d2010-02-17 01:03:09 +0000122 /// WhatFor - This is a string indicating why we're recording this. This
123 /// should only be used for comment generation not anything semantic.
124 std::string WhatFor;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000125public:
Chris Lattner086ca522010-02-17 01:27:29 +0000126 RecordMatcherNode(const std::string &whatfor)
Chris Lattnerddfb5222010-02-18 22:03:03 +0000127 : MatcherNode(RecordNode), WhatFor(whatfor) {}
Chris Lattner56cf88d2010-02-17 01:03:09 +0000128
Chris Lattner086ca522010-02-17 01:27:29 +0000129 const std::string &getWhatFor() const { return WhatFor; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000130
131 static inline bool classof(const MatcherNode *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000132 return N->getKind() == RecordNode;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000133 }
134
135 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
136};
137
Chris Lattner3163ca52010-02-21 03:22:59 +0000138/// RecordMemRefMatcherNode - Save the current node's memref.
139class RecordMemRefMatcherNode : public MatcherNode {
140public:
141 RecordMemRefMatcherNode() : MatcherNode(RecordMemRef) {}
142
143 static inline bool classof(const MatcherNode *N) {
144 return N->getKind() == RecordMemRef;
145 }
146
147 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
148};
149
150
151/// CaptureFlagInputMatcherNode - If the current record has a flag input, record
152/// it so that it is used as an input to the generated code.
153class CaptureFlagInputMatcherNode : public MatcherNode {
154public:
155 CaptureFlagInputMatcherNode()
156 : MatcherNode(CaptureFlagInput) {}
157
158 static inline bool classof(const MatcherNode *N) {
159 return N->getKind() == CaptureFlagInput;
160 }
161
162 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
163};
164
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000165/// MoveChildMatcherNode - This tells the interpreter to move into the
166/// specified child node.
Chris Lattner3b31c982010-02-18 02:49:24 +0000167class MoveChildMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000168 unsigned ChildNo;
169public:
170 MoveChildMatcherNode(unsigned childNo)
Chris Lattner3b31c982010-02-18 02:49:24 +0000171 : MatcherNode(MoveChild), ChildNo(childNo) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000172
173 unsigned getChildNo() const { return ChildNo; }
174
175 static inline bool classof(const MatcherNode *N) {
176 return N->getKind() == MoveChild;
177 }
178
179 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
180};
181
182/// MoveParentMatcherNode - This tells the interpreter to move to the parent
183/// of the current node.
Chris Lattner3b31c982010-02-18 02:49:24 +0000184class MoveParentMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000185public:
186 MoveParentMatcherNode()
Chris Lattner3b31c982010-02-18 02:49:24 +0000187 : MatcherNode(MoveParent) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000188
189 static inline bool classof(const MatcherNode *N) {
190 return N->getKind() == MoveParent;
191 }
192
193 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
194};
195
196/// CheckSameMatcherNode - This checks to see if this node is exactly the same
197/// node as the specified match that was recorded with 'Record'. This is used
198/// when patterns have the same name in them, like '(mul GPR:$in, GPR:$in)'.
Chris Lattner3b31c982010-02-18 02:49:24 +0000199class CheckSameMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000200 unsigned MatchNumber;
201public:
202 CheckSameMatcherNode(unsigned matchnumber)
Chris Lattner3b31c982010-02-18 02:49:24 +0000203 : MatcherNode(CheckSame), MatchNumber(matchnumber) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000204
205 unsigned getMatchNumber() const { return MatchNumber; }
206
207 static inline bool classof(const MatcherNode *N) {
208 return N->getKind() == CheckSame;
209 }
210
211 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
212};
213
214/// CheckPatternPredicateMatcherNode - This checks the target-specific predicate
215/// to see if the entire pattern is capable of matching. This predicate does
216/// not take a node as input. This is used for subtarget feature checks etc.
Chris Lattner3b31c982010-02-18 02:49:24 +0000217class CheckPatternPredicateMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000218 std::string Predicate;
219public:
220 CheckPatternPredicateMatcherNode(StringRef predicate)
Chris Lattner3b31c982010-02-18 02:49:24 +0000221 : MatcherNode(CheckPatternPredicate), Predicate(predicate) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000222
223 StringRef getPredicate() const { return Predicate; }
224
225 static inline bool classof(const MatcherNode *N) {
226 return N->getKind() == CheckPatternPredicate;
227 }
228
229 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
230};
231
232/// CheckPredicateMatcherNode - This checks the target-specific predicate to
233/// see if the node is acceptable.
Chris Lattner3b31c982010-02-18 02:49:24 +0000234class CheckPredicateMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000235 StringRef PredName;
236public:
237 CheckPredicateMatcherNode(StringRef predname)
Chris Lattner3b31c982010-02-18 02:49:24 +0000238 : MatcherNode(CheckPredicate), PredName(predname) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000239
240 StringRef getPredicateName() const { return PredName; }
241
242 static inline bool classof(const MatcherNode *N) {
243 return N->getKind() == CheckPredicate;
244 }
245
246 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
247};
248
249
250/// CheckOpcodeMatcherNode - This checks to see if the current node has the
251/// specified opcode, if not it fails to match.
Chris Lattner3b31c982010-02-18 02:49:24 +0000252class CheckOpcodeMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000253 StringRef OpcodeName;
254public:
255 CheckOpcodeMatcherNode(StringRef opcodename)
Chris Lattner3b31c982010-02-18 02:49:24 +0000256 : MatcherNode(CheckOpcode), OpcodeName(opcodename) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000257
258 StringRef getOpcodeName() const { return OpcodeName; }
259
260 static inline bool classof(const MatcherNode *N) {
261 return N->getKind() == CheckOpcode;
262 }
263
264 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
265};
266
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000267/// CheckMultiOpcodeMatcherNode - This checks to see if the current node has one
268/// of the specified opcode, if not it fails to match.
269class CheckMultiOpcodeMatcherNode : public MatcherNode {
270 SmallVector<StringRef, 4> OpcodeNames;
271public:
272 CheckMultiOpcodeMatcherNode(const StringRef *opcodes, unsigned numops)
273 : MatcherNode(CheckMultiOpcode), OpcodeNames(opcodes, opcodes+numops) {}
274
275 unsigned getNumOpcodeNames() const { return OpcodeNames.size(); }
276 StringRef getOpcodeName(unsigned i) const { return OpcodeNames[i]; }
277
278 static inline bool classof(const MatcherNode *N) {
279 return N->getKind() == CheckMultiOpcode;
280 }
281
282 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
283};
284
285
286
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000287/// CheckTypeMatcherNode - This checks to see if the current node has the
288/// specified type, if not it fails to match.
Chris Lattner3b31c982010-02-18 02:49:24 +0000289class CheckTypeMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000290 MVT::SimpleValueType Type;
291public:
292 CheckTypeMatcherNode(MVT::SimpleValueType type)
Chris Lattner3b31c982010-02-18 02:49:24 +0000293 : MatcherNode(CheckType), Type(type) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000294
295 MVT::SimpleValueType getType() const { return Type; }
296
297 static inline bool classof(const MatcherNode *N) {
298 return N->getKind() == CheckType;
299 }
300
301 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
302};
303
304/// CheckIntegerMatcherNode - This checks to see if the current node is a
305/// ConstantSDNode with the specified integer value, if not it fails to match.
Chris Lattner3b31c982010-02-18 02:49:24 +0000306class CheckIntegerMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000307 int64_t Value;
308public:
309 CheckIntegerMatcherNode(int64_t value)
Chris Lattner3b31c982010-02-18 02:49:24 +0000310 : MatcherNode(CheckInteger), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000311
312 int64_t getValue() const { return Value; }
313
314 static inline bool classof(const MatcherNode *N) {
315 return N->getKind() == CheckInteger;
316 }
317
318 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
319};
320
321/// CheckCondCodeMatcherNode - This checks to see if the current node is a
322/// CondCodeSDNode with the specified condition, if not it fails to match.
Chris Lattner3b31c982010-02-18 02:49:24 +0000323class CheckCondCodeMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000324 StringRef CondCodeName;
325public:
326 CheckCondCodeMatcherNode(StringRef condcodename)
Chris Lattner3b31c982010-02-18 02:49:24 +0000327 : MatcherNode(CheckCondCode), CondCodeName(condcodename) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000328
329 StringRef getCondCodeName() const { return CondCodeName; }
330
331 static inline bool classof(const MatcherNode *N) {
332 return N->getKind() == CheckCondCode;
333 }
334
335 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
336};
337
338/// CheckValueTypeMatcherNode - This checks to see if the current node is a
339/// VTSDNode with the specified type, if not it fails to match.
Chris Lattner3b31c982010-02-18 02:49:24 +0000340class CheckValueTypeMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000341 StringRef TypeName;
342public:
343 CheckValueTypeMatcherNode(StringRef type_name)
Chris Lattner3b31c982010-02-18 02:49:24 +0000344 : MatcherNode(CheckValueType), TypeName(type_name) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000345
346 StringRef getTypeName() const { return TypeName; }
347
348 static inline bool classof(const MatcherNode *N) {
349 return N->getKind() == CheckValueType;
350 }
351
352 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
353};
354
355
356
357/// CheckComplexPatMatcherNode - This node runs the specified ComplexPattern on
358/// the current node.
Chris Lattner3b31c982010-02-18 02:49:24 +0000359class CheckComplexPatMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000360 const ComplexPattern &Pattern;
361public:
362 CheckComplexPatMatcherNode(const ComplexPattern &pattern)
Chris Lattner3b31c982010-02-18 02:49:24 +0000363 : MatcherNode(CheckComplexPat), Pattern(pattern) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000364
Chris Lattnerdc429fd2010-02-17 00:31:50 +0000365 const ComplexPattern &getPattern() const { return Pattern; }
366
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000367 static inline bool classof(const MatcherNode *N) {
368 return N->getKind() == CheckComplexPat;
369 }
370
371 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
372};
373
374/// CheckAndImmMatcherNode - This checks to see if the current node is an 'and'
375/// with something equivalent to the specified immediate.
Chris Lattner3b31c982010-02-18 02:49:24 +0000376class CheckAndImmMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000377 int64_t Value;
378public:
379 CheckAndImmMatcherNode(int64_t value)
Chris Lattner3b31c982010-02-18 02:49:24 +0000380 : MatcherNode(CheckAndImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000381
382 int64_t getValue() const { return Value; }
383
384 static inline bool classof(const MatcherNode *N) {
385 return N->getKind() == CheckAndImm;
386 }
387
388 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
389};
390
391/// CheckOrImmMatcherNode - This checks to see if the current node is an 'and'
392/// with something equivalent to the specified immediate.
Chris Lattner3b31c982010-02-18 02:49:24 +0000393class CheckOrImmMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000394 int64_t Value;
395public:
396 CheckOrImmMatcherNode(int64_t value)
Chris Lattner3b31c982010-02-18 02:49:24 +0000397 : MatcherNode(CheckOrImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000398
399 int64_t getValue() const { return Value; }
400
401 static inline bool classof(const MatcherNode *N) {
402 return N->getKind() == CheckOrImm;
403 }
404
405 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
406};
Chris Lattner9de39482010-02-16 06:10:58 +0000407
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000408/// CheckFoldableChainNodeMatcherNode - This checks to see if the current node
409/// (which defines a chain operand) is safe to fold into a larger pattern.
Chris Lattner3b31c982010-02-18 02:49:24 +0000410class CheckFoldableChainNodeMatcherNode : public MatcherNode {
Chris Lattner9de39482010-02-16 06:10:58 +0000411public:
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000412 CheckFoldableChainNodeMatcherNode()
Chris Lattner3b31c982010-02-18 02:49:24 +0000413 : MatcherNode(CheckFoldableChainNode) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000414
Chris Lattner9de39482010-02-16 06:10:58 +0000415 static inline bool classof(const MatcherNode *N) {
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000416 return N->getKind() == CheckFoldableChainNode;
Chris Lattner9de39482010-02-16 06:10:58 +0000417 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000418
Chris Lattner9de39482010-02-16 06:10:58 +0000419 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
420};
421
Chris Lattner283adcb2010-02-17 06:23:39 +0000422/// CheckChainCompatibleMatcherNode - Verify that the current node's chain
423/// operand is 'compatible' with the specified recorded node's.
Chris Lattner3b31c982010-02-18 02:49:24 +0000424class CheckChainCompatibleMatcherNode : public MatcherNode {
Chris Lattner283adcb2010-02-17 06:23:39 +0000425 unsigned PreviousOp;
426public:
427 CheckChainCompatibleMatcherNode(unsigned previousop)
Chris Lattner3b31c982010-02-18 02:49:24 +0000428 : MatcherNode(CheckChainCompatible), PreviousOp(previousop) {}
Chris Lattner283adcb2010-02-17 06:23:39 +0000429
430 unsigned getPreviousOp() const { return PreviousOp; }
431
432 static inline bool classof(const MatcherNode *N) {
433 return N->getKind() == CheckChainCompatible;
434 }
435
436 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
437};
438
Chris Lattnerddfb5222010-02-18 22:03:03 +0000439/// EmitIntegerMatcherNode - This creates a new TargetConstant.
440class EmitIntegerMatcherNode : public MatcherNode {
441 int64_t Val;
442 MVT::SimpleValueType VT;
443public:
444 EmitIntegerMatcherNode(int64_t val, MVT::SimpleValueType vt)
445 : MatcherNode(EmitInteger), Val(val), VT(vt) {}
Chris Lattner283adcb2010-02-17 06:23:39 +0000446
Chris Lattner7043e0a2010-02-19 07:49:56 +0000447 int64_t getValue() const { return Val; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000448 MVT::SimpleValueType getVT() const { return VT; }
449
450 static inline bool classof(const MatcherNode *N) {
451 return N->getKind() == EmitInteger;
452 }
453
454 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
455};
Chris Lattner3163ca52010-02-21 03:22:59 +0000456
457/// EmitStringIntegerMatcherNode - A target constant whose value is represented
458/// by a string.
459class EmitStringIntegerMatcherNode : public MatcherNode {
460 std::string Val;
461 MVT::SimpleValueType VT;
462public:
463 EmitStringIntegerMatcherNode(const std::string &val, MVT::SimpleValueType vt)
464 : MatcherNode(EmitStringInteger), Val(val), VT(vt) {}
465
466 const std::string &getValue() const { return Val; }
467 MVT::SimpleValueType getVT() const { return VT; }
468
469 static inline bool classof(const MatcherNode *N) {
470 return N->getKind() == EmitStringInteger;
471 }
472
473 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
474};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000475
476/// EmitRegisterMatcherNode - This creates a new TargetConstant.
477class EmitRegisterMatcherNode : public MatcherNode {
478 /// Reg - The def for the register that we're emitting. If this is null, then
479 /// this is a reference to zero_reg.
480 Record *Reg;
481 MVT::SimpleValueType VT;
482public:
483 EmitRegisterMatcherNode(Record *reg, MVT::SimpleValueType vt)
484 : MatcherNode(EmitRegister), Reg(reg), VT(vt) {}
485
486 Record *getReg() const { return Reg; }
487 MVT::SimpleValueType getVT() const { return VT; }
488
489 static inline bool classof(const MatcherNode *N) {
490 return N->getKind() == EmitRegister;
491 }
492
493 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
494};
Chris Lattner3163ca52010-02-21 03:22:59 +0000495
496/// EmitConvertToTargetMatcherNode - Emit an operation that reads a specified
497/// recorded node and converts it from being a ISD::Constant to
498/// ISD::TargetConstant, likewise for ConstantFP.
499class EmitConvertToTargetMatcherNode : public MatcherNode {
500 unsigned Slot;
501public:
502 EmitConvertToTargetMatcherNode(unsigned slot)
503 : MatcherNode(EmitConvertToTarget), Slot(slot) {}
504
505 unsigned getSlot() const { return Slot; }
506
507 static inline bool classof(const MatcherNode *N) {
508 return N->getKind() == EmitConvertToTarget;
509 }
510
511 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
512};
513
514/// EmitMergeInputChainsMatcherNode - Emit a node that merges a list of input
515/// chains together with a token factor. The list of nodes are the nodes in the
516/// matched pattern that have chain input/outputs. This node adds all input
517/// chains of these nodes if they are not themselves a node in the pattern.
518class EmitMergeInputChainsMatcherNode : public MatcherNode {
519 SmallVector<unsigned, 3> ChainNodes;
520public:
521 EmitMergeInputChainsMatcherNode(const unsigned *nodes, unsigned NumNodes)
522 : MatcherNode(EmitMergeInputChains), ChainNodes(nodes, nodes+NumNodes) {}
523
524 unsigned getNumNodes() const { return ChainNodes.size(); }
525
526 unsigned getNode(unsigned i) const {
527 assert(i < ChainNodes.size());
528 return ChainNodes[i];
529 }
530
531 static inline bool classof(const MatcherNode *N) {
532 return N->getKind() == EmitMergeInputChains;
533 }
534
535 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
536};
537
538/// EmitCopyToRegMatcherNode - Emit a CopyToReg node from a value to a physreg,
539/// pushing the chain and flag results.
540///
541class EmitCopyToRegMatcherNode : public MatcherNode {
542 unsigned SrcSlot; // Value to copy into the physreg.
543 Record *DestPhysReg;
544public:
545 EmitCopyToRegMatcherNode(unsigned srcSlot, Record *destPhysReg)
546 : MatcherNode(EmitCopyToReg), SrcSlot(srcSlot), DestPhysReg(destPhysReg) {}
547
548 unsigned getSrcSlot() const { return SrcSlot; }
549 Record *getDestPhysReg() const { return DestPhysReg; }
550
551 static inline bool classof(const MatcherNode *N) {
552 return N->getKind() == EmitCopyToReg;
553 }
554
555 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
556};
557
558
559
560/// EmitNodeXFormMatcherNode - Emit an operation that runs an SDNodeXForm on a
561/// recorded node and records the result.
562class EmitNodeXFormMatcherNode : public MatcherNode {
563 unsigned Slot;
564 Record *NodeXForm;
565public:
566 EmitNodeXFormMatcherNode(unsigned slot, Record *nodeXForm)
567 : MatcherNode(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm) {}
568
569 unsigned getSlot() const { return Slot; }
570 Record *getNodeXForm() const { return NodeXForm; }
571
572 static inline bool classof(const MatcherNode *N) {
573 return N->getKind() == EmitNodeXForm;
574 }
575
576 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
577};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000578
579/// EmitNodeMatcherNode - This signals a successful match and generates a node.
580class EmitNodeMatcherNode : public MatcherNode {
Chris Lattner3163ca52010-02-21 03:22:59 +0000581 std::string OpcodeName;
582 const SmallVector<MVT::SimpleValueType, 3> VTs;
583 const SmallVector<unsigned, 6> Operands;
584 bool HasChain, HasFlag, HasMemRefs;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000585
Chris Lattner3163ca52010-02-21 03:22:59 +0000586 /// NumFixedArityOperands - If this is a fixed arity node, this is set to -1.
587 /// If this is a varidic node, this is set to the number of fixed arity
588 /// operands in the root of the pattern. The rest are appended to this node.
589 int NumFixedArityOperands;
590public:
591 EmitNodeMatcherNode(const std::string &opcodeName,
592 const MVT::SimpleValueType *vts, unsigned numvts,
593 const unsigned *operands, unsigned numops,
594 bool hasChain, bool hasFlag, bool hasmemrefs,
595 int numfixedarityoperands)
596 : MatcherNode(EmitNode), OpcodeName(opcodeName),
597 VTs(vts, vts+numvts), Operands(operands, operands+numops),
598 HasChain(hasChain), HasFlag(hasFlag), HasMemRefs(hasmemrefs),
599 NumFixedArityOperands(numfixedarityoperands) {}
600
601 const std::string &getOpcodeName() const { return OpcodeName; }
602
603 unsigned getNumVTs() const { return VTs.size(); }
604 MVT::SimpleValueType getVT(unsigned i) const {
605 assert(i < VTs.size());
606 return VTs[i];
607 }
608
609 unsigned getNumOperands() const { return Operands.size(); }
610 unsigned getOperand(unsigned i) const {
611 assert(i < Operands.size());
612 return Operands[i];
613 }
614
615 bool hasChain() const { return HasChain; }
616 bool hasFlag() const { return HasFlag; }
617 bool hasMemRefs() const { return HasMemRefs; }
618 int getNumFixedArityOperands() const { return NumFixedArityOperands; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000619
620 static inline bool classof(const MatcherNode *N) {
621 return N->getKind() == EmitNode;
622 }
623
624 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
625};
Chris Lattnerb085ea12010-02-21 06:03:07 +0000626
Chris Lattner69f60c82010-02-24 05:33:42 +0000627/// MarkFlagResultsMatcherNode - This node indicates which non-root nodes in the
628/// pattern produce flags. This allows CompleteMatchMatcherNode to update them
629/// with the output flag of the resultant code.
630class MarkFlagResultsMatcherNode : public MatcherNode {
631 SmallVector<unsigned, 3> FlagResultNodes;
632public:
633 MarkFlagResultsMatcherNode(const unsigned *nodes, unsigned NumNodes)
634 : MatcherNode(MarkFlagResults), FlagResultNodes(nodes, nodes+NumNodes) {}
635
636 unsigned getNumNodes() const { return FlagResultNodes.size(); }
637
638 unsigned getNode(unsigned i) const {
639 assert(i < FlagResultNodes.size());
640 return FlagResultNodes[i];
641 }
642
643 static inline bool classof(const MatcherNode *N) {
644 return N->getKind() == MarkFlagResults;
645 }
646
647 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
648};
649
Chris Lattnerb085ea12010-02-21 06:03:07 +0000650/// CompleteMatchMatcherNode - Complete a match by replacing the results of the
651/// pattern with the newly generated nodes. This also prints a comment
652/// indicating the source and dest patterns.
653class CompleteMatchMatcherNode : public MatcherNode {
654 SmallVector<unsigned, 2> Results;
Chris Lattner3163ca52010-02-21 03:22:59 +0000655 const PatternToMatch &Pattern;
656public:
Chris Lattnerb085ea12010-02-21 06:03:07 +0000657 CompleteMatchMatcherNode(const unsigned *results, unsigned numresults,
658 const PatternToMatch &pattern)
659 : MatcherNode(CompleteMatch), Results(results, results+numresults),
660 Pattern(pattern) {}
661
662 unsigned getNumResults() const { return Results.size(); }
663 unsigned getResult(unsigned R) const { return Results[R]; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000664 const PatternToMatch &getPattern() const { return Pattern; }
665
666 static inline bool classof(const MatcherNode *N) {
Chris Lattnerb085ea12010-02-21 06:03:07 +0000667 return N->getKind() == CompleteMatch;
Chris Lattner3163ca52010-02-21 03:22:59 +0000668 }
669
670 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
671};
672
Chris Lattnerddfb5222010-02-18 22:03:03 +0000673
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000674} // end namespace llvm
675
676#endif