CodeGenDAGPatterns.h revision 47661320363a8bf0bb1401a8c1893755fb77c8f6
1//===- CodeGenDAGPatterns.h - Read DAG patterns from .td file ---*- C++ -*-===//
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// This file declares the CodeGenDAGPatterns class, which is used to read and
11// represent the patterns present in a .td file for instructions.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef CODEGEN_DAGPATTERNS_H
16#define CODEGEN_DAGPATTERNS_H
17
18#include <set>
19#include <algorithm>
20#include <vector>
21
22#include "CodeGenTarget.h"
23#include "CodeGenIntrinsics.h"
24
25namespace llvm {
26  class Record;
27  struct Init;
28  class ListInit;
29  class DagInit;
30  class SDNodeInfo;
31  class TreePattern;
32  class TreePatternNode;
33  class CodeGenDAGPatterns;
34  class ComplexPattern;
35
36/// EEVT::DAGISelGenValueType - These are some extended forms of
37/// MVT::SimpleValueType that we use as lattice values during type inference.
38/// The existing MVT iAny, fAny and vAny types suffice to represent
39/// arbitrary integer, floating-point, and vector types, so only an unknown
40/// value is needed.
41namespace EEVT {
42  enum DAGISelGenValueType {
43    isUnknown  = MVT::LAST_VALUETYPE
44  };
45
46  /// isExtIntegerInVTs - Return true if the specified extended value type
47  /// vector contains iAny or an integer value type.
48  bool isExtIntegerInVTs(const std::vector<unsigned char> &EVTs);
49
50  /// isExtFloatingPointInVTs - Return true if the specified extended value
51  /// type vector contains fAny or a FP value type.
52  bool isExtFloatingPointInVTs(const std::vector<unsigned char> &EVTs);
53
54  /// isExtVectorinVTs - Return true if the specified extended value type
55  /// vector contains vAny or a vector value type.
56  bool isExtVectorInVTs(const std::vector<unsigned char> &EVTs);
57}
58
59/// Set type used to track multiply used variables in patterns
60typedef std::set<std::string> MultipleUseVarSet;
61
62/// SDTypeConstraint - This is a discriminated union of constraints,
63/// corresponding to the SDTypeConstraint tablegen class in Target.td.
64struct SDTypeConstraint {
65  SDTypeConstraint(Record *R);
66
67  unsigned OperandNo;   // The operand # this constraint applies to.
68  enum {
69    SDTCisVT, SDTCisPtrTy, SDTCisInt, SDTCisFP, SDTCisVec, SDTCisSameAs,
70    SDTCisVTSmallerThanOp, SDTCisOpSmallerThanOp, SDTCisEltOfVec
71  } ConstraintType;
72
73  union {   // The discriminated union.
74    struct {
75      unsigned char VT;
76    } SDTCisVT_Info;
77    struct {
78      unsigned OtherOperandNum;
79    } SDTCisSameAs_Info;
80    struct {
81      unsigned OtherOperandNum;
82    } SDTCisVTSmallerThanOp_Info;
83    struct {
84      unsigned BigOperandNum;
85    } SDTCisOpSmallerThanOp_Info;
86    struct {
87      unsigned OtherOperandNum;
88    } SDTCisEltOfVec_Info;
89  } x;
90
91  /// ApplyTypeConstraint - Given a node in a pattern, apply this type
92  /// constraint to the nodes operands.  This returns true if it makes a
93  /// change, false otherwise.  If a type contradiction is found, throw an
94  /// exception.
95  bool ApplyTypeConstraint(TreePatternNode *N, const SDNodeInfo &NodeInfo,
96                           TreePattern &TP) const;
97
98  /// getOperandNum - Return the node corresponding to operand #OpNo in tree
99  /// N, which has NumResults results.
100  TreePatternNode *getOperandNum(unsigned OpNo, TreePatternNode *N,
101                                 unsigned NumResults) const;
102};
103
104/// SDNodeInfo - One of these records is created for each SDNode instance in
105/// the target .td file.  This represents the various dag nodes we will be
106/// processing.
107class SDNodeInfo {
108  Record *Def;
109  std::string EnumName;
110  std::string SDClassName;
111  unsigned Properties;
112  unsigned NumResults;
113  int NumOperands;
114  std::vector<SDTypeConstraint> TypeConstraints;
115public:
116  SDNodeInfo(Record *R);  // Parse the specified record.
117
118  unsigned getNumResults() const { return NumResults; }
119  int getNumOperands() const { return NumOperands; }
120  Record *getRecord() const { return Def; }
121  const std::string &getEnumName() const { return EnumName; }
122  const std::string &getSDClassName() const { return SDClassName; }
123
124  const std::vector<SDTypeConstraint> &getTypeConstraints() const {
125    return TypeConstraints;
126  }
127
128  /// hasProperty - Return true if this node has the specified property.
129  ///
130  bool hasProperty(enum SDNP Prop) const { return Properties & (1 << Prop); }
131
132  /// ApplyTypeConstraints - Given a node in a pattern, apply the type
133  /// constraints for this node to the operands of the node.  This returns
134  /// true if it makes a change, false otherwise.  If a type contradiction is
135  /// found, throw an exception.
136  bool ApplyTypeConstraints(TreePatternNode *N, TreePattern &TP) const {
137    bool MadeChange = false;
138    for (unsigned i = 0, e = TypeConstraints.size(); i != e; ++i)
139      MadeChange |= TypeConstraints[i].ApplyTypeConstraint(N, *this, TP);
140    return MadeChange;
141  }
142};
143
144/// FIXME: TreePatternNode's can be shared in some cases (due to dag-shaped
145/// patterns), and as such should be ref counted.  We currently just leak all
146/// TreePatternNode objects!
147class TreePatternNode {
148  /// The inferred type for this node, or EEVT::isUnknown if it hasn't
149  /// been determined yet. This is a std::vector because during inference
150  /// there may be multiple possible types.
151  std::vector<unsigned char> Types;
152
153  /// Operator - The Record for the operator if this is an interior node (not
154  /// a leaf).
155  Record *Operator;
156
157  /// Val - The init value (e.g. the "GPRC" record, or "7") for a leaf.
158  ///
159  Init *Val;
160
161  /// Name - The name given to this node with the :$foo notation.
162  ///
163  std::string Name;
164
165  /// PredicateFns - The predicate functions to execute on this node to check
166  /// for a match.  If this list is empty, no predicate is involved.
167  std::vector<std::string> PredicateFns;
168
169  /// TransformFn - The transformation function to execute on this node before
170  /// it can be substituted into the resulting instruction on a pattern match.
171  Record *TransformFn;
172
173  std::vector<TreePatternNode*> Children;
174public:
175  TreePatternNode(Record *Op, const std::vector<TreePatternNode*> &Ch)
176    : Types(), Operator(Op), Val(0), TransformFn(0),
177    Children(Ch) { Types.push_back(EEVT::isUnknown); }
178  TreePatternNode(Init *val)    // leaf ctor
179    : Types(), Operator(0), Val(val), TransformFn(0) {
180    Types.push_back(EEVT::isUnknown);
181  }
182  ~TreePatternNode();
183
184  const std::string &getName() const { return Name; }
185  void setName(const std::string &N) { Name = N; }
186
187  bool isLeaf() const { return Val != 0; }
188  bool hasTypeSet() const {
189    return (Types[0] < MVT::LAST_VALUETYPE) || (Types[0] == MVT::iPTR) ||
190          (Types[0] == MVT::iPTRAny);
191  }
192  bool isTypeCompletelyUnknown() const {
193    return Types[0] == EEVT::isUnknown;
194  }
195  bool isTypeDynamicallyResolved() const {
196    return (Types[0] == MVT::iPTR) || (Types[0] == MVT::iPTRAny);
197  }
198  MVT::SimpleValueType getTypeNum(unsigned Num) const {
199    assert(hasTypeSet() && "Doesn't have a type yet!");
200    assert(Types.size() > Num && "Type num out of range!");
201    return (MVT::SimpleValueType)Types[Num];
202  }
203  unsigned char getExtTypeNum(unsigned Num) const {
204    assert(Types.size() > Num && "Extended type num out of range!");
205    return Types[Num];
206  }
207  const std::vector<unsigned char> &getExtTypes() const { return Types; }
208  void setTypes(const std::vector<unsigned char> &T) { Types = T; }
209  void removeTypes() { Types = std::vector<unsigned char>(1, EEVT::isUnknown); }
210
211  Init *getLeafValue() const { assert(isLeaf()); return Val; }
212  Record *getOperator() const { assert(!isLeaf()); return Operator; }
213
214  unsigned getNumChildren() const { return Children.size(); }
215  TreePatternNode *getChild(unsigned N) const { return Children[N]; }
216  void setChild(unsigned i, TreePatternNode *N) {
217    Children[i] = N;
218  }
219
220  const std::vector<std::string> &getPredicateFns() const {return PredicateFns;}
221  void clearPredicateFns() { PredicateFns.clear(); }
222  void setPredicateFns(const std::vector<std::string> &Fns) {
223    assert(PredicateFns.empty() && "Overwriting non-empty predicate list!");
224    PredicateFns = Fns;
225  }
226  void addPredicateFn(const std::string &Fn) {
227    assert(!Fn.empty() && "Empty predicate string!");
228    if (std::find(PredicateFns.begin(), PredicateFns.end(), Fn) ==
229          PredicateFns.end())
230      PredicateFns.push_back(Fn);
231  }
232
233  Record *getTransformFn() const { return TransformFn; }
234  void setTransformFn(Record *Fn) { TransformFn = Fn; }
235
236  /// getIntrinsicInfo - If this node corresponds to an intrinsic, return the
237  /// CodeGenIntrinsic information for it, otherwise return a null pointer.
238  const CodeGenIntrinsic *getIntrinsicInfo(const CodeGenDAGPatterns &CDP) const;
239
240  /// getComplexPatternInfo - If this node corresponds to a ComplexPattern,
241  /// return the ComplexPattern information, otherwise return null.
242  const ComplexPattern *
243  getComplexPatternInfo(const CodeGenDAGPatterns &CGP) const;
244
245  /// NodeHasProperty - Return true if this node has the specified property.
246  bool NodeHasProperty(SDNP Property, CodeGenDAGPatterns &CGP) const;
247
248  /// TreeHasProperty - Return true if any node in this tree has the specified
249  /// property.
250  bool TreeHasProperty(SDNP Property, CodeGenDAGPatterns &CGP) const;
251
252  /// isCommutativeIntrinsic - Return true if the node is an intrinsic which is
253  /// marked isCommutative.
254  bool isCommutativeIntrinsic(const CodeGenDAGPatterns &CDP) const;
255
256  void print(raw_ostream &OS) const;
257  void dump() const;
258
259public:   // Higher level manipulation routines.
260
261  /// clone - Return a new copy of this tree.
262  ///
263  TreePatternNode *clone() const;
264
265  /// RemoveAllTypes - Recursively strip all the types of this tree.
266  void RemoveAllTypes();
267
268  /// isIsomorphicTo - Return true if this node is recursively isomorphic to
269  /// the specified node.  For this comparison, all of the state of the node
270  /// is considered, except for the assigned name.  Nodes with differing names
271  /// that are otherwise identical are considered isomorphic.
272  bool isIsomorphicTo(const TreePatternNode *N,
273                      const MultipleUseVarSet &DepVars) const;
274
275  /// SubstituteFormalArguments - Replace the formal arguments in this tree
276  /// with actual values specified by ArgMap.
277  void SubstituteFormalArguments(std::map<std::string,
278                                          TreePatternNode*> &ArgMap);
279
280  /// InlinePatternFragments - If this pattern refers to any pattern
281  /// fragments, inline them into place, giving us a pattern without any
282  /// PatFrag references.
283  TreePatternNode *InlinePatternFragments(TreePattern &TP);
284
285  /// ApplyTypeConstraints - Apply all of the type constraints relevant to
286  /// this node and its children in the tree.  This returns true if it makes a
287  /// change, false otherwise.  If a type contradiction is found, throw an
288  /// exception.
289  bool ApplyTypeConstraints(TreePattern &TP, bool NotRegisters);
290
291  /// UpdateNodeType - Set the node type of N to VT if VT contains
292  /// information.  If N already contains a conflicting type, then throw an
293  /// exception.  This returns true if any information was updated.
294  ///
295  bool UpdateNodeType(const std::vector<unsigned char> &ExtVTs,
296                      TreePattern &TP);
297  bool UpdateNodeType(unsigned char ExtVT, TreePattern &TP) {
298    std::vector<unsigned char> ExtVTs(1, ExtVT);
299    return UpdateNodeType(ExtVTs, TP);
300  }
301
302  /// ContainsUnresolvedType - Return true if this tree contains any
303  /// unresolved types.
304  bool ContainsUnresolvedType() const {
305    if (!hasTypeSet() && !isTypeDynamicallyResolved()) return true;
306    for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
307      if (getChild(i)->ContainsUnresolvedType()) return true;
308    return false;
309  }
310
311  /// canPatternMatch - If it is impossible for this pattern to match on this
312  /// target, fill in Reason and return false.  Otherwise, return true.
313  bool canPatternMatch(std::string &Reason, const CodeGenDAGPatterns &CDP);
314};
315
316inline raw_ostream &operator<<(raw_ostream &OS, const TreePatternNode &TPN) {
317  TPN.print(OS);
318  return OS;
319}
320
321
322/// TreePattern - Represent a pattern, used for instructions, pattern
323/// fragments, etc.
324///
325class TreePattern {
326  /// Trees - The list of pattern trees which corresponds to this pattern.
327  /// Note that PatFrag's only have a single tree.
328  ///
329  std::vector<TreePatternNode*> Trees;
330
331  /// TheRecord - The actual TableGen record corresponding to this pattern.
332  ///
333  Record *TheRecord;
334
335  /// Args - This is a list of all of the arguments to this pattern (for
336  /// PatFrag patterns), which are the 'node' markers in this pattern.
337  std::vector<std::string> Args;
338
339  /// CDP - the top-level object coordinating this madness.
340  ///
341  CodeGenDAGPatterns &CDP;
342
343  /// isInputPattern - True if this is an input pattern, something to match.
344  /// False if this is an output pattern, something to emit.
345  bool isInputPattern;
346public:
347
348  /// TreePattern constructor - Parse the specified DagInits into the
349  /// current record.
350  TreePattern(Record *TheRec, ListInit *RawPat, bool isInput,
351              CodeGenDAGPatterns &ise);
352  TreePattern(Record *TheRec, DagInit *Pat, bool isInput,
353              CodeGenDAGPatterns &ise);
354  TreePattern(Record *TheRec, TreePatternNode *Pat, bool isInput,
355              CodeGenDAGPatterns &ise);
356
357  /// getTrees - Return the tree patterns which corresponds to this pattern.
358  ///
359  const std::vector<TreePatternNode*> &getTrees() const { return Trees; }
360  unsigned getNumTrees() const { return Trees.size(); }
361  TreePatternNode *getTree(unsigned i) const { return Trees[i]; }
362  TreePatternNode *getOnlyTree() const {
363    assert(Trees.size() == 1 && "Doesn't have exactly one pattern!");
364    return Trees[0];
365  }
366
367  /// getRecord - Return the actual TableGen record corresponding to this
368  /// pattern.
369  ///
370  Record *getRecord() const { return TheRecord; }
371
372  unsigned getNumArgs() const { return Args.size(); }
373  const std::string &getArgName(unsigned i) const {
374    assert(i < Args.size() && "Argument reference out of range!");
375    return Args[i];
376  }
377  std::vector<std::string> &getArgList() { return Args; }
378
379  CodeGenDAGPatterns &getDAGPatterns() const { return CDP; }
380
381  /// InlinePatternFragments - If this pattern refers to any pattern
382  /// fragments, inline them into place, giving us a pattern without any
383  /// PatFrag references.
384  void InlinePatternFragments() {
385    for (unsigned i = 0, e = Trees.size(); i != e; ++i)
386      Trees[i] = Trees[i]->InlinePatternFragments(*this);
387  }
388
389  /// InferAllTypes - Infer/propagate as many types throughout the expression
390  /// patterns as possible.  Return true if all types are inferred, false
391  /// otherwise.  Throw an exception if a type contradiction is found.
392  bool InferAllTypes();
393
394  /// error - Throw an exception, prefixing it with information about this
395  /// pattern.
396  void error(const std::string &Msg) const;
397
398  void print(raw_ostream &OS) const;
399  void dump() const;
400
401private:
402  TreePatternNode *ParseTreePattern(DagInit *DI);
403};
404
405/// DAGDefaultOperand - One of these is created for each PredicateOperand
406/// or OptionalDefOperand that has a set ExecuteAlways / DefaultOps field.
407struct DAGDefaultOperand {
408  std::vector<TreePatternNode*> DefaultOps;
409};
410
411class DAGInstruction {
412  TreePattern *Pattern;
413  std::vector<Record*> Results;
414  std::vector<Record*> Operands;
415  std::vector<Record*> ImpResults;
416  std::vector<Record*> ImpOperands;
417  TreePatternNode *ResultPattern;
418public:
419  DAGInstruction(TreePattern *TP,
420                 const std::vector<Record*> &results,
421                 const std::vector<Record*> &operands,
422                 const std::vector<Record*> &impresults,
423                 const std::vector<Record*> &impoperands)
424    : Pattern(TP), Results(results), Operands(operands),
425      ImpResults(impresults), ImpOperands(impoperands),
426      ResultPattern(0) {}
427
428  const TreePattern *getPattern() const { return Pattern; }
429  unsigned getNumResults() const { return Results.size(); }
430  unsigned getNumOperands() const { return Operands.size(); }
431  unsigned getNumImpResults() const { return ImpResults.size(); }
432  unsigned getNumImpOperands() const { return ImpOperands.size(); }
433  const std::vector<Record*>& getImpResults() const { return ImpResults; }
434
435  void setResultPattern(TreePatternNode *R) { ResultPattern = R; }
436
437  Record *getResult(unsigned RN) const {
438    assert(RN < Results.size());
439    return Results[RN];
440  }
441
442  Record *getOperand(unsigned ON) const {
443    assert(ON < Operands.size());
444    return Operands[ON];
445  }
446
447  Record *getImpResult(unsigned RN) const {
448    assert(RN < ImpResults.size());
449    return ImpResults[RN];
450  }
451
452  Record *getImpOperand(unsigned ON) const {
453    assert(ON < ImpOperands.size());
454    return ImpOperands[ON];
455  }
456
457  TreePatternNode *getResultPattern() const { return ResultPattern; }
458};
459
460/// PatternToMatch - Used by CodeGenDAGPatterns to keep tab of patterns
461/// processed to produce isel.
462struct PatternToMatch {
463  PatternToMatch(ListInit *preds,
464                 TreePatternNode *src, TreePatternNode *dst,
465                 const std::vector<Record*> &dstregs,
466                 unsigned complexity):
467    Predicates(preds), SrcPattern(src), DstPattern(dst), Dstregs(dstregs),
468    AddedComplexity(complexity) {}
469
470  ListInit        *Predicates;  // Top level predicate conditions to match.
471  TreePatternNode *SrcPattern;  // Source pattern to match.
472  TreePatternNode *DstPattern;  // Resulting pattern.
473  std::vector<Record*> Dstregs; // Physical register defs being matched.
474  unsigned         AddedComplexity; // Add to matching pattern complexity.
475
476  ListInit        *getPredicates() const { return Predicates; }
477  TreePatternNode *getSrcPattern() const { return SrcPattern; }
478  TreePatternNode *getDstPattern() const { return DstPattern; }
479  const std::vector<Record*> &getDstRegs() const { return Dstregs; }
480  unsigned         getAddedComplexity() const { return AddedComplexity; }
481
482  std::string getPredicateCheck() const;
483};
484
485// Deterministic comparison of Record*.
486struct RecordPtrCmp {
487  bool operator()(const Record *LHS, const Record *RHS) const;
488};
489
490class CodeGenDAGPatterns {
491  RecordKeeper &Records;
492  CodeGenTarget Target;
493  std::vector<CodeGenIntrinsic> Intrinsics;
494  std::vector<CodeGenIntrinsic> TgtIntrinsics;
495
496  std::map<Record*, SDNodeInfo, RecordPtrCmp> SDNodes;
497  std::map<Record*, std::pair<Record*, std::string>, RecordPtrCmp> SDNodeXForms;
498  std::map<Record*, ComplexPattern, RecordPtrCmp> ComplexPatterns;
499  std::map<Record*, TreePattern*, RecordPtrCmp> PatternFragments;
500  std::map<Record*, DAGDefaultOperand, RecordPtrCmp> DefaultOperands;
501  std::map<Record*, DAGInstruction, RecordPtrCmp> Instructions;
502
503  // Specific SDNode definitions:
504  Record *intrinsic_void_sdnode;
505  Record *intrinsic_w_chain_sdnode, *intrinsic_wo_chain_sdnode;
506
507  /// PatternsToMatch - All of the things we are matching on the DAG.  The first
508  /// value is the pattern to match, the second pattern is the result to
509  /// emit.
510  std::vector<PatternToMatch> PatternsToMatch;
511public:
512  CodeGenDAGPatterns(RecordKeeper &R);
513  ~CodeGenDAGPatterns();
514
515  CodeGenTarget &getTargetInfo() { return Target; }
516  const CodeGenTarget &getTargetInfo() const { return Target; }
517
518  Record *getSDNodeNamed(const std::string &Name) const;
519
520  const SDNodeInfo &getSDNodeInfo(Record *R) const {
521    assert(SDNodes.count(R) && "Unknown node!");
522    return SDNodes.find(R)->second;
523  }
524
525  // Node transformation lookups.
526  typedef std::pair<Record*, std::string> NodeXForm;
527  const NodeXForm &getSDNodeTransform(Record *R) const {
528    assert(SDNodeXForms.count(R) && "Invalid transform!");
529    return SDNodeXForms.find(R)->second;
530  }
531
532  typedef std::map<Record*, NodeXForm, RecordPtrCmp>::const_iterator
533          nx_iterator;
534  nx_iterator nx_begin() const { return SDNodeXForms.begin(); }
535  nx_iterator nx_end() const { return SDNodeXForms.end(); }
536
537
538  const ComplexPattern &getComplexPattern(Record *R) const {
539    assert(ComplexPatterns.count(R) && "Unknown addressing mode!");
540    return ComplexPatterns.find(R)->second;
541  }
542
543  const CodeGenIntrinsic &getIntrinsic(Record *R) const {
544    for (unsigned i = 0, e = Intrinsics.size(); i != e; ++i)
545      if (Intrinsics[i].TheDef == R) return Intrinsics[i];
546    for (unsigned i = 0, e = TgtIntrinsics.size(); i != e; ++i)
547      if (TgtIntrinsics[i].TheDef == R) return TgtIntrinsics[i];
548    assert(0 && "Unknown intrinsic!");
549    abort();
550  }
551
552  const CodeGenIntrinsic &getIntrinsicInfo(unsigned IID) const {
553    if (IID-1 < Intrinsics.size())
554      return Intrinsics[IID-1];
555    if (IID-Intrinsics.size()-1 < TgtIntrinsics.size())
556      return TgtIntrinsics[IID-Intrinsics.size()-1];
557    assert(0 && "Bad intrinsic ID!");
558    abort();
559  }
560
561  unsigned getIntrinsicID(Record *R) const {
562    for (unsigned i = 0, e = Intrinsics.size(); i != e; ++i)
563      if (Intrinsics[i].TheDef == R) return i;
564    for (unsigned i = 0, e = TgtIntrinsics.size(); i != e; ++i)
565      if (TgtIntrinsics[i].TheDef == R) return i + Intrinsics.size();
566    assert(0 && "Unknown intrinsic!");
567    abort();
568  }
569
570  const DAGDefaultOperand &getDefaultOperand(Record *R) {
571    assert(DefaultOperands.count(R) &&"Isn't an analyzed default operand!");
572    return DefaultOperands.find(R)->second;
573  }
574
575  // Pattern Fragment information.
576  TreePattern *getPatternFragment(Record *R) const {
577    assert(PatternFragments.count(R) && "Invalid pattern fragment request!");
578    return PatternFragments.find(R)->second;
579  }
580  typedef std::map<Record*, TreePattern*, RecordPtrCmp>::const_iterator
581          pf_iterator;
582  pf_iterator pf_begin() const { return PatternFragments.begin(); }
583  pf_iterator pf_end() const { return PatternFragments.end(); }
584
585  // Patterns to match information.
586  typedef std::vector<PatternToMatch>::const_iterator ptm_iterator;
587  ptm_iterator ptm_begin() const { return PatternsToMatch.begin(); }
588  ptm_iterator ptm_end() const { return PatternsToMatch.end(); }
589
590
591
592  const DAGInstruction &getInstruction(Record *R) const {
593    assert(Instructions.count(R) && "Unknown instruction!");
594    return Instructions.find(R)->second;
595  }
596
597  Record *get_intrinsic_void_sdnode() const {
598    return intrinsic_void_sdnode;
599  }
600  Record *get_intrinsic_w_chain_sdnode() const {
601    return intrinsic_w_chain_sdnode;
602  }
603  Record *get_intrinsic_wo_chain_sdnode() const {
604    return intrinsic_wo_chain_sdnode;
605  }
606
607  bool hasTargetIntrinsics() { return !TgtIntrinsics.empty(); }
608
609private:
610  void ParseNodeInfo();
611  void ParseNodeTransforms();
612  void ParseComplexPatterns();
613  void ParsePatternFragments();
614  void ParseDefaultOperands();
615  void ParseInstructions();
616  void ParsePatterns();
617  void InferInstructionFlags();
618  void GenerateVariants();
619
620  void FindPatternInputsAndOutputs(TreePattern *I, TreePatternNode *Pat,
621                                   std::map<std::string,
622                                   TreePatternNode*> &InstInputs,
623                                   std::map<std::string,
624                                   TreePatternNode*> &InstResults,
625                                   std::vector<Record*> &InstImpInputs,
626                                   std::vector<Record*> &InstImpResults);
627};
628} // end namespace llvm
629
630#endif
631