blob: 757bf606588a2fd4c46a8060ef830297ce69ff53 [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 Lattner3ee1bc42010-02-24 07:31:45 +000029MatcherNode *OptimizeMatcher(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.
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:
82 MatcherNode(KindTy K) : Kind(K) {}
83public:
84 virtual ~MatcherNode() {}
85
86 KindTy getKind() const { return Kind; }
Chris Lattner3b31c982010-02-18 02:49:24 +000087
Chris Lattner78039ec2010-02-18 02:53:41 +000088 MatcherNode *getNext() { return Next.get(); }
89 const MatcherNode *getNext() const { return Next.get(); }
90 void setNext(MatcherNode *C) { Next.reset(C); }
Chris Lattner3ee1bc42010-02-24 07:31:45 +000091 MatcherNode *takeNext() { return Next.take(); }
92
93 OwningPtr<MatcherNode> &getNextPtr() { return Next; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +000094
95 static inline bool classof(const MatcherNode *) { return true; }
96
97 virtual void print(raw_ostream &OS, unsigned indent = 0) const = 0;
98 void dump() const;
Chris Lattner3b31c982010-02-18 02:49:24 +000099protected:
Chris Lattner78039ec2010-02-18 02:53:41 +0000100 void printNext(raw_ostream &OS, unsigned indent) const;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000101};
102
Chris Lattnerac10e4f2010-02-25 01:56:48 +0000103/// ScopeMatcherNode - This pushes a failure scope on the stack and evaluates
104/// 'Check'. If 'Check' fails to match, it pops its scope and continues on to
105/// 'Next'.
106class ScopeMatcherNode : public MatcherNode {
107 OwningPtr<MatcherNode> Check;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000108public:
Chris Lattnerac10e4f2010-02-25 01:56:48 +0000109 ScopeMatcherNode(MatcherNode *check = 0, MatcherNode *next = 0)
110 : MatcherNode(Scope), Check(check) {
Chris Lattner78039ec2010-02-18 02:53:41 +0000111 setNext(next);
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000112 }
113
Chris Lattnerac10e4f2010-02-25 01:56:48 +0000114 MatcherNode *getCheck() { return Check.get(); }
115 const MatcherNode *getCheck() const { return Check.get(); }
116 void setCheck(MatcherNode *N) { Check.reset(N); }
117 OwningPtr<MatcherNode> &getCheckPtr() { return Check; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000118
119 static inline bool classof(const MatcherNode *N) {
Chris Lattnerac10e4f2010-02-25 01:56:48 +0000120 return N->getKind() == Scope;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000121 }
122
123 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
124};
125
126/// RecordMatcherNode - Save the current node in the operand list.
Chris Lattner3b31c982010-02-18 02:49:24 +0000127class RecordMatcherNode : public MatcherNode {
Chris Lattner56cf88d2010-02-17 01:03:09 +0000128 /// WhatFor - This is a string indicating why we're recording this. This
129 /// should only be used for comment generation not anything semantic.
130 std::string WhatFor;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000131public:
Chris Lattner086ca522010-02-17 01:27:29 +0000132 RecordMatcherNode(const std::string &whatfor)
Chris Lattnerddfb5222010-02-18 22:03:03 +0000133 : MatcherNode(RecordNode), WhatFor(whatfor) {}
Chris Lattner56cf88d2010-02-17 01:03:09 +0000134
Chris Lattner086ca522010-02-17 01:27:29 +0000135 const std::string &getWhatFor() const { return WhatFor; }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000136
137 static inline bool classof(const MatcherNode *N) {
Chris Lattnerddfb5222010-02-18 22:03:03 +0000138 return N->getKind() == RecordNode;
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000139 }
140
141 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
142};
143
Chris Lattner3ee1bc42010-02-24 07:31:45 +0000144/// RecordChildMatcherNode - Save a numbered child of the current node, or fail
145/// the match if it doesn't exist. This is logically equivalent to:
146/// MoveChild N + RecordNode + MoveParent.
147class RecordChildMatcherNode : public MatcherNode {
148 unsigned ChildNo;
149
150 /// WhatFor - This is a string indicating why we're recording this. This
151 /// should only be used for comment generation not anything semantic.
152 std::string WhatFor;
153public:
154 RecordChildMatcherNode(unsigned childno, const std::string &whatfor)
155 : MatcherNode(RecordChild), ChildNo(childno), WhatFor(whatfor) {}
156
157 unsigned getChildNo() const { return ChildNo; }
158 const std::string &getWhatFor() const { return WhatFor; }
159
160 static inline bool classof(const MatcherNode *N) {
161 return N->getKind() == RecordChild;
162 }
163
164 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
165};
166
Chris Lattner3163ca52010-02-21 03:22:59 +0000167/// RecordMemRefMatcherNode - Save the current node's memref.
168class RecordMemRefMatcherNode : public MatcherNode {
169public:
170 RecordMemRefMatcherNode() : MatcherNode(RecordMemRef) {}
171
172 static inline bool classof(const MatcherNode *N) {
173 return N->getKind() == RecordMemRef;
174 }
175
176 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
177};
178
179
180/// CaptureFlagInputMatcherNode - If the current record has a flag input, record
181/// it so that it is used as an input to the generated code.
182class CaptureFlagInputMatcherNode : public MatcherNode {
183public:
184 CaptureFlagInputMatcherNode()
185 : MatcherNode(CaptureFlagInput) {}
186
187 static inline bool classof(const MatcherNode *N) {
188 return N->getKind() == CaptureFlagInput;
189 }
190
191 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
192};
193
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000194/// MoveChildMatcherNode - This tells the interpreter to move into the
195/// specified child node.
Chris Lattner3b31c982010-02-18 02:49:24 +0000196class MoveChildMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000197 unsigned ChildNo;
198public:
199 MoveChildMatcherNode(unsigned childNo)
Chris Lattner3b31c982010-02-18 02:49:24 +0000200 : MatcherNode(MoveChild), ChildNo(childNo) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000201
202 unsigned getChildNo() const { return ChildNo; }
203
204 static inline bool classof(const MatcherNode *N) {
205 return N->getKind() == MoveChild;
206 }
207
208 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
209};
210
211/// MoveParentMatcherNode - This tells the interpreter to move to the parent
212/// of the current node.
Chris Lattner3b31c982010-02-18 02:49:24 +0000213class MoveParentMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000214public:
215 MoveParentMatcherNode()
Chris Lattner3b31c982010-02-18 02:49:24 +0000216 : MatcherNode(MoveParent) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000217
218 static inline bool classof(const MatcherNode *N) {
219 return N->getKind() == MoveParent;
220 }
221
222 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
223};
224
225/// CheckSameMatcherNode - This checks to see if this node is exactly the same
226/// node as the specified match that was recorded with 'Record'. This is used
227/// when patterns have the same name in them, like '(mul GPR:$in, GPR:$in)'.
Chris Lattner3b31c982010-02-18 02:49:24 +0000228class CheckSameMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000229 unsigned MatchNumber;
230public:
231 CheckSameMatcherNode(unsigned matchnumber)
Chris Lattner3b31c982010-02-18 02:49:24 +0000232 : MatcherNode(CheckSame), MatchNumber(matchnumber) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000233
234 unsigned getMatchNumber() const { return MatchNumber; }
235
236 static inline bool classof(const MatcherNode *N) {
237 return N->getKind() == CheckSame;
238 }
239
240 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
241};
242
243/// CheckPatternPredicateMatcherNode - This checks the target-specific predicate
244/// to see if the entire pattern is capable of matching. This predicate does
245/// not take a node as input. This is used for subtarget feature checks etc.
Chris Lattner3b31c982010-02-18 02:49:24 +0000246class CheckPatternPredicateMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000247 std::string Predicate;
248public:
249 CheckPatternPredicateMatcherNode(StringRef predicate)
Chris Lattner3b31c982010-02-18 02:49:24 +0000250 : MatcherNode(CheckPatternPredicate), Predicate(predicate) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000251
252 StringRef getPredicate() const { return Predicate; }
253
254 static inline bool classof(const MatcherNode *N) {
255 return N->getKind() == CheckPatternPredicate;
256 }
257
258 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
259};
260
261/// CheckPredicateMatcherNode - This checks the target-specific predicate to
262/// see if the node is acceptable.
Chris Lattner3b31c982010-02-18 02:49:24 +0000263class CheckPredicateMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000264 StringRef PredName;
265public:
266 CheckPredicateMatcherNode(StringRef predname)
Chris Lattner3b31c982010-02-18 02:49:24 +0000267 : MatcherNode(CheckPredicate), PredName(predname) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000268
269 StringRef getPredicateName() const { return PredName; }
270
271 static inline bool classof(const MatcherNode *N) {
272 return N->getKind() == CheckPredicate;
273 }
274
275 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
276};
277
278
279/// CheckOpcodeMatcherNode - This checks to see if the current node has the
280/// specified opcode, if not it fails to match.
Chris Lattner3b31c982010-02-18 02:49:24 +0000281class CheckOpcodeMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000282 StringRef OpcodeName;
283public:
284 CheckOpcodeMatcherNode(StringRef opcodename)
Chris Lattner3b31c982010-02-18 02:49:24 +0000285 : MatcherNode(CheckOpcode), OpcodeName(opcodename) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000286
287 StringRef getOpcodeName() const { return OpcodeName; }
288
289 static inline bool classof(const MatcherNode *N) {
290 return N->getKind() == CheckOpcode;
291 }
292
293 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
294};
295
Chris Lattnerf58c08e2010-02-22 22:30:37 +0000296/// CheckMultiOpcodeMatcherNode - This checks to see if the current node has one
297/// of the specified opcode, if not it fails to match.
298class CheckMultiOpcodeMatcherNode : public MatcherNode {
299 SmallVector<StringRef, 4> OpcodeNames;
300public:
301 CheckMultiOpcodeMatcherNode(const StringRef *opcodes, unsigned numops)
302 : MatcherNode(CheckMultiOpcode), OpcodeNames(opcodes, opcodes+numops) {}
303
304 unsigned getNumOpcodeNames() const { return OpcodeNames.size(); }
305 StringRef getOpcodeName(unsigned i) const { return OpcodeNames[i]; }
306
307 static inline bool classof(const MatcherNode *N) {
308 return N->getKind() == CheckMultiOpcode;
309 }
310
311 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
312};
313
314
315
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000316/// CheckTypeMatcherNode - This checks to see if the current node has the
317/// specified type, if not it fails to match.
Chris Lattner3b31c982010-02-18 02:49:24 +0000318class CheckTypeMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000319 MVT::SimpleValueType Type;
320public:
321 CheckTypeMatcherNode(MVT::SimpleValueType type)
Chris Lattner3b31c982010-02-18 02:49:24 +0000322 : MatcherNode(CheckType), Type(type) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000323
324 MVT::SimpleValueType getType() const { return Type; }
325
326 static inline bool classof(const MatcherNode *N) {
327 return N->getKind() == CheckType;
328 }
329
330 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
331};
Chris Lattner3c664b32010-02-24 20:15:25 +0000332
333/// CheckChildTypeMatcherNode - This checks to see if a child node has the
334/// specified type, if not it fails to match.
335class CheckChildTypeMatcherNode : public MatcherNode {
336 unsigned ChildNo;
337 MVT::SimpleValueType Type;
338public:
339 CheckChildTypeMatcherNode(unsigned childno, MVT::SimpleValueType type)
340 : MatcherNode(CheckChildType), ChildNo(childno), Type(type) {}
341
342 unsigned getChildNo() const { return ChildNo; }
343 MVT::SimpleValueType getType() const { return Type; }
344
345 static inline bool classof(const MatcherNode *N) {
346 return N->getKind() == CheckChildType;
347 }
348
349 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
350};
351
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000352
353/// CheckIntegerMatcherNode - This checks to see if the current node is a
354/// ConstantSDNode with the specified integer value, if not it fails to match.
Chris Lattner3b31c982010-02-18 02:49:24 +0000355class CheckIntegerMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000356 int64_t Value;
357public:
358 CheckIntegerMatcherNode(int64_t value)
Chris Lattner3b31c982010-02-18 02:49:24 +0000359 : MatcherNode(CheckInteger), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000360
361 int64_t getValue() const { return Value; }
362
363 static inline bool classof(const MatcherNode *N) {
364 return N->getKind() == CheckInteger;
365 }
366
367 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
368};
369
370/// CheckCondCodeMatcherNode - This checks to see if the current node is a
371/// CondCodeSDNode with the specified condition, if not it fails to match.
Chris Lattner3b31c982010-02-18 02:49:24 +0000372class CheckCondCodeMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000373 StringRef CondCodeName;
374public:
375 CheckCondCodeMatcherNode(StringRef condcodename)
Chris Lattner3b31c982010-02-18 02:49:24 +0000376 : MatcherNode(CheckCondCode), CondCodeName(condcodename) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000377
378 StringRef getCondCodeName() const { return CondCodeName; }
379
380 static inline bool classof(const MatcherNode *N) {
381 return N->getKind() == CheckCondCode;
382 }
383
384 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
385};
386
387/// CheckValueTypeMatcherNode - This checks to see if the current node is a
388/// VTSDNode with the specified type, if not it fails to match.
Chris Lattner3b31c982010-02-18 02:49:24 +0000389class CheckValueTypeMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000390 StringRef TypeName;
391public:
392 CheckValueTypeMatcherNode(StringRef type_name)
Chris Lattner3b31c982010-02-18 02:49:24 +0000393 : MatcherNode(CheckValueType), TypeName(type_name) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000394
395 StringRef getTypeName() const { return TypeName; }
396
397 static inline bool classof(const MatcherNode *N) {
398 return N->getKind() == CheckValueType;
399 }
400
401 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
402};
403
404
405
406/// CheckComplexPatMatcherNode - This node runs the specified ComplexPattern on
407/// the current node.
Chris Lattner3b31c982010-02-18 02:49:24 +0000408class CheckComplexPatMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000409 const ComplexPattern &Pattern;
410public:
411 CheckComplexPatMatcherNode(const ComplexPattern &pattern)
Chris Lattner3b31c982010-02-18 02:49:24 +0000412 : MatcherNode(CheckComplexPat), Pattern(pattern) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000413
Chris Lattnerdc429fd2010-02-17 00:31:50 +0000414 const ComplexPattern &getPattern() const { return Pattern; }
415
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000416 static inline bool classof(const MatcherNode *N) {
417 return N->getKind() == CheckComplexPat;
418 }
419
420 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
421};
422
423/// CheckAndImmMatcherNode - This checks to see if the current node is an 'and'
424/// with something equivalent to the specified immediate.
Chris Lattner3b31c982010-02-18 02:49:24 +0000425class CheckAndImmMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000426 int64_t Value;
427public:
428 CheckAndImmMatcherNode(int64_t value)
Chris Lattner3b31c982010-02-18 02:49:24 +0000429 : MatcherNode(CheckAndImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000430
431 int64_t getValue() const { return Value; }
432
433 static inline bool classof(const MatcherNode *N) {
434 return N->getKind() == CheckAndImm;
435 }
436
437 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
438};
439
440/// CheckOrImmMatcherNode - This checks to see if the current node is an 'and'
441/// with something equivalent to the specified immediate.
Chris Lattner3b31c982010-02-18 02:49:24 +0000442class CheckOrImmMatcherNode : public MatcherNode {
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000443 int64_t Value;
444public:
445 CheckOrImmMatcherNode(int64_t value)
Chris Lattner3b31c982010-02-18 02:49:24 +0000446 : MatcherNode(CheckOrImm), Value(value) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000447
448 int64_t getValue() const { return Value; }
449
450 static inline bool classof(const MatcherNode *N) {
451 return N->getKind() == CheckOrImm;
452 }
453
454 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
455};
Chris Lattner9de39482010-02-16 06:10:58 +0000456
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000457/// CheckFoldableChainNodeMatcherNode - This checks to see if the current node
458/// (which defines a chain operand) is safe to fold into a larger pattern.
Chris Lattner3b31c982010-02-18 02:49:24 +0000459class CheckFoldableChainNodeMatcherNode : public MatcherNode {
Chris Lattner9de39482010-02-16 06:10:58 +0000460public:
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000461 CheckFoldableChainNodeMatcherNode()
Chris Lattner3b31c982010-02-18 02:49:24 +0000462 : MatcherNode(CheckFoldableChainNode) {}
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000463
Chris Lattner9de39482010-02-16 06:10:58 +0000464 static inline bool classof(const MatcherNode *N) {
Chris Lattnerc6dc8f62010-02-16 19:15:55 +0000465 return N->getKind() == CheckFoldableChainNode;
Chris Lattner9de39482010-02-16 06:10:58 +0000466 }
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000467
Chris Lattner9de39482010-02-16 06:10:58 +0000468 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
469};
470
Chris Lattner283adcb2010-02-17 06:23:39 +0000471/// CheckChainCompatibleMatcherNode - Verify that the current node's chain
472/// operand is 'compatible' with the specified recorded node's.
Chris Lattner3b31c982010-02-18 02:49:24 +0000473class CheckChainCompatibleMatcherNode : public MatcherNode {
Chris Lattner283adcb2010-02-17 06:23:39 +0000474 unsigned PreviousOp;
475public:
476 CheckChainCompatibleMatcherNode(unsigned previousop)
Chris Lattner3b31c982010-02-18 02:49:24 +0000477 : MatcherNode(CheckChainCompatible), PreviousOp(previousop) {}
Chris Lattner283adcb2010-02-17 06:23:39 +0000478
479 unsigned getPreviousOp() const { return PreviousOp; }
480
481 static inline bool classof(const MatcherNode *N) {
482 return N->getKind() == CheckChainCompatible;
483 }
484
485 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
486};
487
Chris Lattnerddfb5222010-02-18 22:03:03 +0000488/// EmitIntegerMatcherNode - This creates a new TargetConstant.
489class EmitIntegerMatcherNode : public MatcherNode {
490 int64_t Val;
491 MVT::SimpleValueType VT;
492public:
493 EmitIntegerMatcherNode(int64_t val, MVT::SimpleValueType vt)
494 : MatcherNode(EmitInteger), Val(val), VT(vt) {}
Chris Lattner283adcb2010-02-17 06:23:39 +0000495
Chris Lattner7043e0a2010-02-19 07:49:56 +0000496 int64_t getValue() const { return Val; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000497 MVT::SimpleValueType getVT() const { return VT; }
498
499 static inline bool classof(const MatcherNode *N) {
500 return N->getKind() == EmitInteger;
501 }
502
503 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
504};
Chris Lattner3163ca52010-02-21 03:22:59 +0000505
506/// EmitStringIntegerMatcherNode - A target constant whose value is represented
507/// by a string.
508class EmitStringIntegerMatcherNode : public MatcherNode {
509 std::string Val;
510 MVT::SimpleValueType VT;
511public:
512 EmitStringIntegerMatcherNode(const std::string &val, MVT::SimpleValueType vt)
513 : MatcherNode(EmitStringInteger), Val(val), VT(vt) {}
514
515 const std::string &getValue() const { return Val; }
516 MVT::SimpleValueType getVT() const { return VT; }
517
518 static inline bool classof(const MatcherNode *N) {
519 return N->getKind() == EmitStringInteger;
520 }
521
522 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
523};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000524
525/// EmitRegisterMatcherNode - This creates a new TargetConstant.
526class EmitRegisterMatcherNode : public MatcherNode {
527 /// Reg - The def for the register that we're emitting. If this is null, then
528 /// this is a reference to zero_reg.
529 Record *Reg;
530 MVT::SimpleValueType VT;
531public:
532 EmitRegisterMatcherNode(Record *reg, MVT::SimpleValueType vt)
533 : MatcherNode(EmitRegister), Reg(reg), VT(vt) {}
534
535 Record *getReg() const { return Reg; }
536 MVT::SimpleValueType getVT() const { return VT; }
537
538 static inline bool classof(const MatcherNode *N) {
539 return N->getKind() == EmitRegister;
540 }
541
542 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
543};
Chris Lattner3163ca52010-02-21 03:22:59 +0000544
545/// EmitConvertToTargetMatcherNode - Emit an operation that reads a specified
546/// recorded node and converts it from being a ISD::Constant to
547/// ISD::TargetConstant, likewise for ConstantFP.
548class EmitConvertToTargetMatcherNode : public MatcherNode {
549 unsigned Slot;
550public:
551 EmitConvertToTargetMatcherNode(unsigned slot)
552 : MatcherNode(EmitConvertToTarget), Slot(slot) {}
553
554 unsigned getSlot() const { return Slot; }
555
556 static inline bool classof(const MatcherNode *N) {
557 return N->getKind() == EmitConvertToTarget;
558 }
559
560 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
561};
562
563/// EmitMergeInputChainsMatcherNode - Emit a node that merges a list of input
564/// chains together with a token factor. The list of nodes are the nodes in the
565/// matched pattern that have chain input/outputs. This node adds all input
566/// chains of these nodes if they are not themselves a node in the pattern.
567class EmitMergeInputChainsMatcherNode : public MatcherNode {
568 SmallVector<unsigned, 3> ChainNodes;
569public:
570 EmitMergeInputChainsMatcherNode(const unsigned *nodes, unsigned NumNodes)
571 : MatcherNode(EmitMergeInputChains), ChainNodes(nodes, nodes+NumNodes) {}
572
573 unsigned getNumNodes() const { return ChainNodes.size(); }
574
575 unsigned getNode(unsigned i) const {
576 assert(i < ChainNodes.size());
577 return ChainNodes[i];
578 }
579
580 static inline bool classof(const MatcherNode *N) {
581 return N->getKind() == EmitMergeInputChains;
582 }
583
584 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
585};
586
587/// EmitCopyToRegMatcherNode - Emit a CopyToReg node from a value to a physreg,
588/// pushing the chain and flag results.
589///
590class EmitCopyToRegMatcherNode : public MatcherNode {
591 unsigned SrcSlot; // Value to copy into the physreg.
592 Record *DestPhysReg;
593public:
594 EmitCopyToRegMatcherNode(unsigned srcSlot, Record *destPhysReg)
595 : MatcherNode(EmitCopyToReg), SrcSlot(srcSlot), DestPhysReg(destPhysReg) {}
596
597 unsigned getSrcSlot() const { return SrcSlot; }
598 Record *getDestPhysReg() const { return DestPhysReg; }
599
600 static inline bool classof(const MatcherNode *N) {
601 return N->getKind() == EmitCopyToReg;
602 }
603
604 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
605};
606
607
608
609/// EmitNodeXFormMatcherNode - Emit an operation that runs an SDNodeXForm on a
610/// recorded node and records the result.
611class EmitNodeXFormMatcherNode : public MatcherNode {
612 unsigned Slot;
613 Record *NodeXForm;
614public:
615 EmitNodeXFormMatcherNode(unsigned slot, Record *nodeXForm)
616 : MatcherNode(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm) {}
617
618 unsigned getSlot() const { return Slot; }
619 Record *getNodeXForm() const { return NodeXForm; }
620
621 static inline bool classof(const MatcherNode *N) {
622 return N->getKind() == EmitNodeXForm;
623 }
624
625 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
626};
Chris Lattnerddfb5222010-02-18 22:03:03 +0000627
628/// EmitNodeMatcherNode - This signals a successful match and generates a node.
629class EmitNodeMatcherNode : public MatcherNode {
Chris Lattner3163ca52010-02-21 03:22:59 +0000630 std::string OpcodeName;
631 const SmallVector<MVT::SimpleValueType, 3> VTs;
632 const SmallVector<unsigned, 6> Operands;
633 bool HasChain, HasFlag, HasMemRefs;
Chris Lattnerddfb5222010-02-18 22:03:03 +0000634
Chris Lattner3163ca52010-02-21 03:22:59 +0000635 /// NumFixedArityOperands - If this is a fixed arity node, this is set to -1.
636 /// If this is a varidic node, this is set to the number of fixed arity
637 /// operands in the root of the pattern. The rest are appended to this node.
638 int NumFixedArityOperands;
639public:
640 EmitNodeMatcherNode(const std::string &opcodeName,
641 const MVT::SimpleValueType *vts, unsigned numvts,
642 const unsigned *operands, unsigned numops,
643 bool hasChain, bool hasFlag, bool hasmemrefs,
644 int numfixedarityoperands)
645 : MatcherNode(EmitNode), OpcodeName(opcodeName),
646 VTs(vts, vts+numvts), Operands(operands, operands+numops),
647 HasChain(hasChain), HasFlag(hasFlag), HasMemRefs(hasmemrefs),
648 NumFixedArityOperands(numfixedarityoperands) {}
649
650 const std::string &getOpcodeName() const { return OpcodeName; }
651
652 unsigned getNumVTs() const { return VTs.size(); }
653 MVT::SimpleValueType getVT(unsigned i) const {
654 assert(i < VTs.size());
655 return VTs[i];
656 }
657
658 unsigned getNumOperands() const { return Operands.size(); }
659 unsigned getOperand(unsigned i) const {
660 assert(i < Operands.size());
661 return Operands[i];
662 }
663
664 bool hasChain() const { return HasChain; }
665 bool hasFlag() const { return HasFlag; }
666 bool hasMemRefs() const { return HasMemRefs; }
667 int getNumFixedArityOperands() const { return NumFixedArityOperands; }
Chris Lattnerddfb5222010-02-18 22:03:03 +0000668
669 static inline bool classof(const MatcherNode *N) {
670 return N->getKind() == EmitNode;
671 }
672
673 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
674};
Chris Lattnerb085ea12010-02-21 06:03:07 +0000675
Chris Lattner69f60c82010-02-24 05:33:42 +0000676/// MarkFlagResultsMatcherNode - This node indicates which non-root nodes in the
677/// pattern produce flags. This allows CompleteMatchMatcherNode to update them
678/// with the output flag of the resultant code.
679class MarkFlagResultsMatcherNode : public MatcherNode {
680 SmallVector<unsigned, 3> FlagResultNodes;
681public:
682 MarkFlagResultsMatcherNode(const unsigned *nodes, unsigned NumNodes)
683 : MatcherNode(MarkFlagResults), FlagResultNodes(nodes, nodes+NumNodes) {}
684
685 unsigned getNumNodes() const { return FlagResultNodes.size(); }
686
687 unsigned getNode(unsigned i) const {
688 assert(i < FlagResultNodes.size());
689 return FlagResultNodes[i];
690 }
691
692 static inline bool classof(const MatcherNode *N) {
693 return N->getKind() == MarkFlagResults;
694 }
695
696 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
697};
698
Chris Lattnerb085ea12010-02-21 06:03:07 +0000699/// CompleteMatchMatcherNode - Complete a match by replacing the results of the
700/// pattern with the newly generated nodes. This also prints a comment
701/// indicating the source and dest patterns.
702class CompleteMatchMatcherNode : public MatcherNode {
703 SmallVector<unsigned, 2> Results;
Chris Lattner3163ca52010-02-21 03:22:59 +0000704 const PatternToMatch &Pattern;
705public:
Chris Lattnerb085ea12010-02-21 06:03:07 +0000706 CompleteMatchMatcherNode(const unsigned *results, unsigned numresults,
707 const PatternToMatch &pattern)
708 : MatcherNode(CompleteMatch), Results(results, results+numresults),
709 Pattern(pattern) {}
710
711 unsigned getNumResults() const { return Results.size(); }
712 unsigned getResult(unsigned R) const { return Results[R]; }
Chris Lattner3163ca52010-02-21 03:22:59 +0000713 const PatternToMatch &getPattern() const { return Pattern; }
714
715 static inline bool classof(const MatcherNode *N) {
Chris Lattnerb085ea12010-02-21 06:03:07 +0000716 return N->getKind() == CompleteMatch;
Chris Lattner3163ca52010-02-21 03:22:59 +0000717 }
718
719 virtual void print(raw_ostream &OS, unsigned indent = 0) const;
720};
721
Chris Lattnerddfb5222010-02-18 22:03:03 +0000722
Chris Lattnere7d6e3c2010-02-15 08:04:42 +0000723} // end namespace llvm
724
725#endif