contract movechild+checktype into a new checkchild node, shrinking the
[oota-llvm.git] / utils / TableGen / DAGISelMatcher.h
1 //===- 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
13 #include "llvm/CodeGen/ValueTypes.h"
14 #include "llvm/ADT/OwningPtr.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/Support/Casting.h"
18
19 namespace llvm {
20   class CodeGenDAGPatterns;
21   class MatcherNode;
22   class PatternToMatch;
23   class raw_ostream;
24   class ComplexPattern;
25   class Record;
26
27 MatcherNode *ConvertPatternToMatcher(const PatternToMatch &Pattern,
28                                      const CodeGenDAGPatterns &CGP);
29 MatcherNode *OptimizeMatcher(MatcherNode *Matcher);
30 void EmitMatcherTable(const MatcherNode *Matcher, raw_ostream &OS);
31
32   
33 /// MatcherNode - Base class for all the the DAG ISel Matcher representation
34 /// nodes.
35 class MatcherNode {
36   // 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;
39 public:
40   enum KindTy {
41     // Matcher state manipulation.
42     Push,                 // Push a checking scope.
43     RecordNode,           // Record the current node.
44     RecordChild,          // Record a child of the current node.
45     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.
49     
50     // Predicate checking.
51     CheckSame,            // Fail if not same as prev match.
52     CheckPatternPredicate,
53     CheckPredicate,       // Fail if node predicate fails.
54     CheckOpcode,          // Fail if not opcode.
55     CheckMultiOpcode,     // Fail if not in opcode list.
56     CheckType,            // Fail if not correct type.
57     CheckChildType,       // Fail if child has wrong type.
58     CheckInteger,         // Fail if wrong val.
59     CheckCondCode,        // Fail if not condcode.
60     CheckValueType,
61     CheckComplexPat,
62     CheckAndImm,
63     CheckOrImm,
64     CheckFoldableChainNode,
65     CheckChainCompatible,
66     
67     // Node creation/emisssion.
68     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
76     MarkFlagResults,      // Indicate which interior nodes have flag results.
77     CompleteMatch         // Finish a match and update the results.
78   };
79   const KindTy Kind;
80
81 protected:
82   MatcherNode(KindTy K) : Kind(K) {}
83 public:
84   virtual ~MatcherNode() {}
85   
86   KindTy getKind() const { return Kind; }
87
88   MatcherNode *getNext() { return Next.get(); }
89   const MatcherNode *getNext() const { return Next.get(); }
90   void setNext(MatcherNode *C) { Next.reset(C); }
91   MatcherNode *takeNext() { return Next.take(); }
92
93   OwningPtr<MatcherNode> &getNextPtr() { return Next; }
94   
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;
99 protected:
100   void printNext(raw_ostream &OS, unsigned indent) const;
101 };
102   
103 /// PushMatcherNode - This pushes a failure scope on the stack and evaluates
104 /// 'Next'.  If 'Next' fails to match, it pops its scope and attempts to
105 /// match 'Failure'.
106 class PushMatcherNode : public MatcherNode {
107   OwningPtr<MatcherNode> Failure;
108 public:
109   PushMatcherNode(MatcherNode *next = 0, MatcherNode *failure = 0)
110     : MatcherNode(Push), Failure(failure) {
111     setNext(next);
112   }
113   
114   MatcherNode *getFailure() { return Failure.get(); }
115   const MatcherNode *getFailure() const { return Failure.get(); }
116   void setFailure(MatcherNode *N) { Failure.reset(N); }
117   OwningPtr<MatcherNode> &getFailurePtr() { return Failure; }
118
119   static inline bool classof(const MatcherNode *N) {
120     return N->getKind() == Push;
121   }
122   
123   virtual void print(raw_ostream &OS, unsigned indent = 0) const;
124 };
125
126 /// RecordMatcherNode - Save the current node in the operand list.
127 class RecordMatcherNode : public MatcherNode {
128   /// 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;
131 public:
132   RecordMatcherNode(const std::string &whatfor)
133     : MatcherNode(RecordNode), WhatFor(whatfor) {}
134   
135   const std::string &getWhatFor() const { return WhatFor; }
136   
137   static inline bool classof(const MatcherNode *N) {
138     return N->getKind() == RecordNode;
139   }
140   
141   virtual void print(raw_ostream &OS, unsigned indent = 0) const;
142 };
143   
144 /// 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.
147 class 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;
153 public:
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   
167 /// RecordMemRefMatcherNode - Save the current node's memref.
168 class RecordMemRefMatcherNode : public MatcherNode {
169 public:
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.
182 class CaptureFlagInputMatcherNode : public MatcherNode {
183 public:
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   
194 /// MoveChildMatcherNode - This tells the interpreter to move into the
195 /// specified child node.
196 class MoveChildMatcherNode : public MatcherNode {
197   unsigned ChildNo;
198 public:
199   MoveChildMatcherNode(unsigned childNo)
200   : MatcherNode(MoveChild), ChildNo(childNo) {}
201   
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.
213 class MoveParentMatcherNode : public MatcherNode {
214 public:
215   MoveParentMatcherNode()
216   : MatcherNode(MoveParent) {}
217   
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)'.
228 class CheckSameMatcherNode : public MatcherNode {
229   unsigned MatchNumber;
230 public:
231   CheckSameMatcherNode(unsigned matchnumber)
232   : MatcherNode(CheckSame), MatchNumber(matchnumber) {}
233   
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.
246 class CheckPatternPredicateMatcherNode : public MatcherNode {
247   std::string Predicate;
248 public:
249   CheckPatternPredicateMatcherNode(StringRef predicate)
250   : MatcherNode(CheckPatternPredicate), Predicate(predicate) {}
251   
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.
263 class CheckPredicateMatcherNode : public MatcherNode {
264   StringRef PredName;
265 public:
266   CheckPredicateMatcherNode(StringRef predname)
267     : MatcherNode(CheckPredicate), PredName(predname) {}
268   
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.
281 class CheckOpcodeMatcherNode : public MatcherNode {
282   StringRef OpcodeName;
283 public:
284   CheckOpcodeMatcherNode(StringRef opcodename)
285     : MatcherNode(CheckOpcode), OpcodeName(opcodename) {}
286   
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   
296 /// CheckMultiOpcodeMatcherNode - This checks to see if the current node has one
297 /// of the specified opcode, if not it fails to match.
298 class CheckMultiOpcodeMatcherNode : public MatcherNode {
299   SmallVector<StringRef, 4> OpcodeNames;
300 public:
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   
316 /// CheckTypeMatcherNode - This checks to see if the current node has the
317 /// specified type, if not it fails to match.
318 class CheckTypeMatcherNode : public MatcherNode {
319   MVT::SimpleValueType Type;
320 public:
321   CheckTypeMatcherNode(MVT::SimpleValueType type)
322     : MatcherNode(CheckType), Type(type) {}
323   
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 };
332   
333 /// CheckChildTypeMatcherNode - This checks to see if a child node has the
334 /// specified type, if not it fails to match.
335 class CheckChildTypeMatcherNode : public MatcherNode {
336   unsigned ChildNo;
337   MVT::SimpleValueType Type;
338 public:
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   
352
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.
355 class CheckIntegerMatcherNode : public MatcherNode {
356   int64_t Value;
357 public:
358   CheckIntegerMatcherNode(int64_t value)
359     : MatcherNode(CheckInteger), Value(value) {}
360   
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.
372 class CheckCondCodeMatcherNode : public MatcherNode {
373   StringRef CondCodeName;
374 public:
375   CheckCondCodeMatcherNode(StringRef condcodename)
376   : MatcherNode(CheckCondCode), CondCodeName(condcodename) {}
377   
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.
389 class CheckValueTypeMatcherNode : public MatcherNode {
390   StringRef TypeName;
391 public:
392   CheckValueTypeMatcherNode(StringRef type_name)
393   : MatcherNode(CheckValueType), TypeName(type_name) {}
394   
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.
408 class CheckComplexPatMatcherNode : public MatcherNode {
409   const ComplexPattern &Pattern;
410 public:
411   CheckComplexPatMatcherNode(const ComplexPattern &pattern)
412   : MatcherNode(CheckComplexPat), Pattern(pattern) {}
413   
414   const ComplexPattern &getPattern() const { return Pattern; }
415   
416   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.
425 class CheckAndImmMatcherNode : public MatcherNode {
426   int64_t Value;
427 public:
428   CheckAndImmMatcherNode(int64_t value)
429   : MatcherNode(CheckAndImm), Value(value) {}
430   
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.
442 class CheckOrImmMatcherNode : public MatcherNode {
443   int64_t Value;
444 public:
445   CheckOrImmMatcherNode(int64_t value)
446     : MatcherNode(CheckOrImm), Value(value) {}
447   
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 };
456
457 /// CheckFoldableChainNodeMatcherNode - This checks to see if the current node
458 /// (which defines a chain operand) is safe to fold into a larger pattern.
459 class CheckFoldableChainNodeMatcherNode : public MatcherNode {
460 public:
461   CheckFoldableChainNodeMatcherNode()
462     : MatcherNode(CheckFoldableChainNode) {}
463   
464   static inline bool classof(const MatcherNode *N) {
465     return N->getKind() == CheckFoldableChainNode;
466   }
467   
468   virtual void print(raw_ostream &OS, unsigned indent = 0) const;
469 };
470
471 /// CheckChainCompatibleMatcherNode - Verify that the current node's chain
472 /// operand is 'compatible' with the specified recorded node's.
473 class CheckChainCompatibleMatcherNode : public MatcherNode {
474   unsigned PreviousOp;
475 public:
476   CheckChainCompatibleMatcherNode(unsigned previousop)
477     : MatcherNode(CheckChainCompatible), PreviousOp(previousop) {}
478   
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   
488 /// EmitIntegerMatcherNode - This creates a new TargetConstant.
489 class EmitIntegerMatcherNode : public MatcherNode {
490   int64_t Val;
491   MVT::SimpleValueType VT;
492 public:
493   EmitIntegerMatcherNode(int64_t val, MVT::SimpleValueType vt)
494   : MatcherNode(EmitInteger), Val(val), VT(vt) {}
495   
496   int64_t getValue() const { return Val; }
497   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 };
505
506 /// EmitStringIntegerMatcherNode - A target constant whose value is represented
507 /// by a string.
508 class EmitStringIntegerMatcherNode : public MatcherNode {
509   std::string Val;
510   MVT::SimpleValueType VT;
511 public:
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 };
524   
525 /// EmitRegisterMatcherNode - This creates a new TargetConstant.
526 class 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;
531 public:
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 };
544
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.
548 class EmitConvertToTargetMatcherNode : public MatcherNode {
549   unsigned Slot;
550 public:
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.
567 class EmitMergeInputChainsMatcherNode : public MatcherNode {
568   SmallVector<unsigned, 3> ChainNodes;
569 public:
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 ///
590 class EmitCopyToRegMatcherNode : public MatcherNode {
591   unsigned SrcSlot; // Value to copy into the physreg.
592   Record *DestPhysReg;
593 public:
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.
611 class EmitNodeXFormMatcherNode : public MatcherNode {
612   unsigned Slot;
613   Record *NodeXForm;
614 public:
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 };
627   
628 /// EmitNodeMatcherNode - This signals a successful match and generates a node.
629 class EmitNodeMatcherNode : public MatcherNode {
630   std::string OpcodeName;
631   const SmallVector<MVT::SimpleValueType, 3> VTs;
632   const SmallVector<unsigned, 6> Operands;
633   bool HasChain, HasFlag, HasMemRefs;
634   
635   /// 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;
639 public:
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; }
668   
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 };
675   
676 /// 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.
679 class MarkFlagResultsMatcherNode : public MatcherNode {
680   SmallVector<unsigned, 3> FlagResultNodes;
681 public:
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
699 /// 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.
702 class CompleteMatchMatcherNode : public MatcherNode {
703   SmallVector<unsigned, 2> Results;
704   const PatternToMatch &Pattern;
705 public:
706   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]; }
713   const PatternToMatch &getPattern() const { return Pattern; }
714   
715   static inline bool classof(const MatcherNode *N) {
716     return N->getKind() == CompleteMatch;
717   }
718   
719   virtual void print(raw_ostream &OS, unsigned indent = 0) const;
720 };
721  
722   
723 } // end namespace llvm
724
725 #endif