1 //===- CodeGenDAGPatterns.h - Read DAG patterns from .td file ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the CodeGenDAGPatterns class, which is used to read and
11 // represent the patterns present in a .td file for instructions.
13 //===----------------------------------------------------------------------===//
15 #ifndef CODEGEN_DAGPATTERNS_H
16 #define CODEGEN_DAGPATTERNS_H
18 #include "CodeGenTarget.h"
19 #include "CodeGenIntrinsics.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringMap.h"
34 class TreePatternNode;
35 class CodeGenDAGPatterns;
38 /// EEVT::DAGISelGenValueType - These are some extended forms of
39 /// MVT::SimpleValueType that we use as lattice values during type inference.
40 /// The existing MVT iAny, fAny and vAny types suffice to represent
41 /// arbitrary integer, floating-point, and vector types, so only an unknown
44 /// TypeSet - This is either empty if it's completely unknown, or holds a set
45 /// of types. It is used during type inference because register classes can
46 /// have multiple possible types and we don't know which one they get until
47 /// type inference is complete.
49 /// TypeSet can have three states:
50 /// Vector is empty: The type is completely unknown, it can be any valid
52 /// Vector has multiple constrained types: (e.g. v4i32 + v4f32) it is one
53 /// of those types only.
54 /// Vector has one concrete type: The type is completely known.
57 SmallVector<MVT::SimpleValueType, 2> TypeVec;
60 TypeSet(MVT::SimpleValueType VT, TreePattern &TP);
61 TypeSet(const std::vector<MVT::SimpleValueType> &VTList);
63 bool isCompletelyUnknown() const { return TypeVec.empty(); }
65 bool isConcrete() const {
66 if (TypeVec.size() != 1) return false;
67 unsigned char T = TypeVec[0]; (void)T;
68 assert(T < MVT::LAST_VALUETYPE || T == MVT::iPTR || T == MVT::iPTRAny);
72 MVT::SimpleValueType getConcrete() const {
73 assert(isConcrete() && "Type isn't concrete yet");
74 return (MVT::SimpleValueType)TypeVec[0];
77 bool isDynamicallyResolved() const {
78 return getConcrete() == MVT::iPTR || getConcrete() == MVT::iPTRAny;
81 const SmallVectorImpl<MVT::SimpleValueType> &getTypeList() const {
82 assert(!TypeVec.empty() && "Not a type list!");
87 return TypeVec.size() == 1 && TypeVec[0] == MVT::isVoid;
90 /// hasIntegerTypes - Return true if this TypeSet contains any integer value
92 bool hasIntegerTypes() const;
94 /// hasFloatingPointTypes - Return true if this TypeSet contains an fAny or
95 /// a floating point value type.
96 bool hasFloatingPointTypes() const;
98 /// hasVectorTypes - Return true if this TypeSet contains a vector value
100 bool hasVectorTypes() const;
102 /// getName() - Return this TypeSet as a string.
103 std::string getName() const;
105 /// MergeInTypeInfo - This merges in type information from the specified
106 /// argument. If 'this' changes, it returns true. If the two types are
107 /// contradictory (e.g. merge f32 into i32) then this throws an exception.
108 bool MergeInTypeInfo(const EEVT::TypeSet &InVT, TreePattern &TP);
110 bool MergeInTypeInfo(MVT::SimpleValueType InVT, TreePattern &TP) {
111 return MergeInTypeInfo(EEVT::TypeSet(InVT, TP), TP);
114 /// Force this type list to only contain integer types.
115 bool EnforceInteger(TreePattern &TP);
117 /// Force this type list to only contain floating point types.
118 bool EnforceFloatingPoint(TreePattern &TP);
120 /// EnforceScalar - Remove all vector types from this type list.
121 bool EnforceScalar(TreePattern &TP);
123 /// EnforceVector - Remove all non-vector types from this type list.
124 bool EnforceVector(TreePattern &TP);
126 /// EnforceSmallerThan - 'this' must be a smaller VT than Other. Update
127 /// this an other based on this information.
128 bool EnforceSmallerThan(EEVT::TypeSet &Other, TreePattern &TP);
130 /// EnforceVectorEltTypeIs - 'this' is now constrainted to be a vector type
131 /// whose element is VT.
132 bool EnforceVectorEltTypeIs(MVT::SimpleValueType VT, TreePattern &TP);
134 bool operator!=(const TypeSet &RHS) const { return TypeVec != RHS.TypeVec; }
135 bool operator==(const TypeSet &RHS) const { return TypeVec == RHS.TypeVec; }
139 /// Set type used to track multiply used variables in patterns
140 typedef std::set<std::string> MultipleUseVarSet;
142 /// SDTypeConstraint - This is a discriminated union of constraints,
143 /// corresponding to the SDTypeConstraint tablegen class in Target.td.
144 struct SDTypeConstraint {
145 SDTypeConstraint(Record *R);
147 unsigned OperandNo; // The operand # this constraint applies to.
149 SDTCisVT, SDTCisPtrTy, SDTCisInt, SDTCisFP, SDTCisVec, SDTCisSameAs,
150 SDTCisVTSmallerThanOp, SDTCisOpSmallerThanOp, SDTCisEltOfVec
153 union { // The discriminated union.
155 MVT::SimpleValueType VT;
158 unsigned OtherOperandNum;
161 unsigned OtherOperandNum;
162 } SDTCisVTSmallerThanOp_Info;
164 unsigned BigOperandNum;
165 } SDTCisOpSmallerThanOp_Info;
167 unsigned OtherOperandNum;
168 } SDTCisEltOfVec_Info;
171 /// ApplyTypeConstraint - Given a node in a pattern, apply this type
172 /// constraint to the nodes operands. This returns true if it makes a
173 /// change, false otherwise. If a type contradiction is found, throw an
175 bool ApplyTypeConstraint(TreePatternNode *N, const SDNodeInfo &NodeInfo,
176 TreePattern &TP) const;
178 /// getOperandNum - Return the node corresponding to operand #OpNo in tree
179 /// N, which has NumResults results.
180 TreePatternNode *getOperandNum(unsigned OpNo, TreePatternNode *N,
181 unsigned NumResults) const;
184 /// SDNodeInfo - One of these records is created for each SDNode instance in
185 /// the target .td file. This represents the various dag nodes we will be
189 std::string EnumName;
190 std::string SDClassName;
194 std::vector<SDTypeConstraint> TypeConstraints;
196 SDNodeInfo(Record *R); // Parse the specified record.
198 unsigned getNumResults() const { return NumResults; }
199 int getNumOperands() const { return NumOperands; }
200 Record *getRecord() const { return Def; }
201 const std::string &getEnumName() const { return EnumName; }
202 const std::string &getSDClassName() const { return SDClassName; }
204 const std::vector<SDTypeConstraint> &getTypeConstraints() const {
205 return TypeConstraints;
208 /// getKnownType - If the type constraints on this node imply a fixed type
209 /// (e.g. all stores return void, etc), then return it as an
210 /// MVT::SimpleValueType. Otherwise, return MVT::Other.
211 MVT::SimpleValueType getKnownType() const;
213 /// hasProperty - Return true if this node has the specified property.
215 bool hasProperty(enum SDNP Prop) const { return Properties & (1 << Prop); }
217 /// ApplyTypeConstraints - Given a node in a pattern, apply the type
218 /// constraints for this node to the operands of the node. This returns
219 /// true if it makes a change, false otherwise. If a type contradiction is
220 /// found, throw an exception.
221 bool ApplyTypeConstraints(TreePatternNode *N, TreePattern &TP) const {
222 bool MadeChange = false;
223 for (unsigned i = 0, e = TypeConstraints.size(); i != e; ++i)
224 MadeChange |= TypeConstraints[i].ApplyTypeConstraint(N, *this, TP);
229 /// FIXME: TreePatternNode's can be shared in some cases (due to dag-shaped
230 /// patterns), and as such should be ref counted. We currently just leak all
231 /// TreePatternNode objects!
232 class TreePatternNode {
233 /// The type of this node. Before and during type inference, this may be a
234 /// set of possible types. After (successful) type inference, this is a
238 /// Operator - The Record for the operator if this is an interior node (not
242 /// Val - The init value (e.g. the "GPRC" record, or "7") for a leaf.
246 /// Name - The name given to this node with the :$foo notation.
250 /// PredicateFns - The predicate functions to execute on this node to check
251 /// for a match. If this list is empty, no predicate is involved.
252 std::vector<std::string> PredicateFns;
254 /// TransformFn - The transformation function to execute on this node before
255 /// it can be substituted into the resulting instruction on a pattern match.
258 std::vector<TreePatternNode*> Children;
260 TreePatternNode(Record *Op, const std::vector<TreePatternNode*> &Ch)
261 : Operator(Op), Val(0), TransformFn(0), Children(Ch) { }
262 TreePatternNode(Init *val) // leaf ctor
263 : Operator(0), Val(val), TransformFn(0) {
267 const std::string &getName() const { return Name; }
268 void setName(const std::string &N) { Name = N; }
270 bool isLeaf() const { return Val != 0; }
273 MVT::SimpleValueType getType() const { return Type.getConcrete(); }
274 const EEVT::TypeSet &getExtType() const { return Type; }
275 EEVT::TypeSet &getExtType() { return Type; }
276 void setType(const EEVT::TypeSet &T) { Type = T; }
278 bool hasTypeSet() const { return Type.isConcrete(); }
279 bool isTypeCompletelyUnknown() const { return Type.isCompletelyUnknown(); }
280 bool isTypeDynamicallyResolved() const { return Type.isDynamicallyResolved();}
282 Init *getLeafValue() const { assert(isLeaf()); return Val; }
283 Record *getOperator() const { assert(!isLeaf()); return Operator; }
285 unsigned getNumChildren() const { return Children.size(); }
286 TreePatternNode *getChild(unsigned N) const { return Children[N]; }
287 void setChild(unsigned i, TreePatternNode *N) {
291 /// hasChild - Return true if N is any of our children.
292 bool hasChild(const TreePatternNode *N) const {
293 for (unsigned i = 0, e = Children.size(); i != e; ++i)
294 if (Children[i] == N) return true;
298 const std::vector<std::string> &getPredicateFns() const {return PredicateFns;}
299 void clearPredicateFns() { PredicateFns.clear(); }
300 void setPredicateFns(const std::vector<std::string> &Fns) {
301 assert(PredicateFns.empty() && "Overwriting non-empty predicate list!");
304 void addPredicateFn(const std::string &Fn) {
305 assert(!Fn.empty() && "Empty predicate string!");
306 if (std::find(PredicateFns.begin(), PredicateFns.end(), Fn) ==
308 PredicateFns.push_back(Fn);
311 Record *getTransformFn() const { return TransformFn; }
312 void setTransformFn(Record *Fn) { TransformFn = Fn; }
314 /// getIntrinsicInfo - If this node corresponds to an intrinsic, return the
315 /// CodeGenIntrinsic information for it, otherwise return a null pointer.
316 const CodeGenIntrinsic *getIntrinsicInfo(const CodeGenDAGPatterns &CDP) const;
318 /// getComplexPatternInfo - If this node corresponds to a ComplexPattern,
319 /// return the ComplexPattern information, otherwise return null.
320 const ComplexPattern *
321 getComplexPatternInfo(const CodeGenDAGPatterns &CGP) const;
323 /// NodeHasProperty - Return true if this node has the specified property.
324 bool NodeHasProperty(SDNP Property, const CodeGenDAGPatterns &CGP) const;
326 /// TreeHasProperty - Return true if any node in this tree has the specified
328 bool TreeHasProperty(SDNP Property, const CodeGenDAGPatterns &CGP) const;
330 /// isCommutativeIntrinsic - Return true if the node is an intrinsic which is
331 /// marked isCommutative.
332 bool isCommutativeIntrinsic(const CodeGenDAGPatterns &CDP) const;
334 void print(raw_ostream &OS) const;
337 public: // Higher level manipulation routines.
339 /// clone - Return a new copy of this tree.
341 TreePatternNode *clone() const;
343 /// RemoveAllTypes - Recursively strip all the types of this tree.
344 void RemoveAllTypes();
346 /// isIsomorphicTo - Return true if this node is recursively isomorphic to
347 /// the specified node. For this comparison, all of the state of the node
348 /// is considered, except for the assigned name. Nodes with differing names
349 /// that are otherwise identical are considered isomorphic.
350 bool isIsomorphicTo(const TreePatternNode *N,
351 const MultipleUseVarSet &DepVars) const;
353 /// SubstituteFormalArguments - Replace the formal arguments in this tree
354 /// with actual values specified by ArgMap.
355 void SubstituteFormalArguments(std::map<std::string,
356 TreePatternNode*> &ArgMap);
358 /// InlinePatternFragments - If this pattern refers to any pattern
359 /// fragments, inline them into place, giving us a pattern without any
360 /// PatFrag references.
361 TreePatternNode *InlinePatternFragments(TreePattern &TP);
363 /// ApplyTypeConstraints - Apply all of the type constraints relevant to
364 /// this node and its children in the tree. This returns true if it makes a
365 /// change, false otherwise. If a type contradiction is found, throw an
367 bool ApplyTypeConstraints(TreePattern &TP, bool NotRegisters);
369 /// UpdateNodeType - Set the node type of N to VT if VT contains
370 /// information. If N already contains a conflicting type, then throw an
371 /// exception. This returns true if any information was updated.
373 bool UpdateNodeType(const EEVT::TypeSet &InTy, TreePattern &TP) {
374 return Type.MergeInTypeInfo(InTy, TP);
377 bool UpdateNodeType(MVT::SimpleValueType InTy, TreePattern &TP) {
378 return Type.MergeInTypeInfo(EEVT::TypeSet(InTy, TP), TP);
381 /// ContainsUnresolvedType - Return true if this tree contains any
382 /// unresolved types.
383 bool ContainsUnresolvedType() const {
384 if (!hasTypeSet()) return true;
385 for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
386 if (getChild(i)->ContainsUnresolvedType()) return true;
390 /// canPatternMatch - If it is impossible for this pattern to match on this
391 /// target, fill in Reason and return false. Otherwise, return true.
392 bool canPatternMatch(std::string &Reason, const CodeGenDAGPatterns &CDP);
395 inline raw_ostream &operator<<(raw_ostream &OS, const TreePatternNode &TPN) {
401 /// TreePattern - Represent a pattern, used for instructions, pattern
405 /// Trees - The list of pattern trees which corresponds to this pattern.
406 /// Note that PatFrag's only have a single tree.
408 std::vector<TreePatternNode*> Trees;
410 /// NamedNodes - This is all of the nodes that have names in the trees in this
412 StringMap<SmallVector<TreePatternNode*,1> > NamedNodes;
414 /// TheRecord - The actual TableGen record corresponding to this pattern.
418 /// Args - This is a list of all of the arguments to this pattern (for
419 /// PatFrag patterns), which are the 'node' markers in this pattern.
420 std::vector<std::string> Args;
422 /// CDP - the top-level object coordinating this madness.
424 CodeGenDAGPatterns &CDP;
426 /// isInputPattern - True if this is an input pattern, something to match.
427 /// False if this is an output pattern, something to emit.
431 /// TreePattern constructor - Parse the specified DagInits into the
433 TreePattern(Record *TheRec, ListInit *RawPat, bool isInput,
434 CodeGenDAGPatterns &ise);
435 TreePattern(Record *TheRec, DagInit *Pat, bool isInput,
436 CodeGenDAGPatterns &ise);
437 TreePattern(Record *TheRec, TreePatternNode *Pat, bool isInput,
438 CodeGenDAGPatterns &ise);
440 /// getTrees - Return the tree patterns which corresponds to this pattern.
442 const std::vector<TreePatternNode*> &getTrees() const { return Trees; }
443 unsigned getNumTrees() const { return Trees.size(); }
444 TreePatternNode *getTree(unsigned i) const { return Trees[i]; }
445 TreePatternNode *getOnlyTree() const {
446 assert(Trees.size() == 1 && "Doesn't have exactly one pattern!");
450 const StringMap<SmallVector<TreePatternNode*,1> > &getNamedNodesMap() {
451 if (NamedNodes.empty())
456 /// getRecord - Return the actual TableGen record corresponding to this
459 Record *getRecord() const { return TheRecord; }
461 unsigned getNumArgs() const { return Args.size(); }
462 const std::string &getArgName(unsigned i) const {
463 assert(i < Args.size() && "Argument reference out of range!");
466 std::vector<std::string> &getArgList() { return Args; }
468 CodeGenDAGPatterns &getDAGPatterns() const { return CDP; }
470 /// InlinePatternFragments - If this pattern refers to any pattern
471 /// fragments, inline them into place, giving us a pattern without any
472 /// PatFrag references.
473 void InlinePatternFragments() {
474 for (unsigned i = 0, e = Trees.size(); i != e; ++i)
475 Trees[i] = Trees[i]->InlinePatternFragments(*this);
478 /// InferAllTypes - Infer/propagate as many types throughout the expression
479 /// patterns as possible. Return true if all types are inferred, false
480 /// otherwise. Throw an exception if a type contradiction is found.
481 bool InferAllTypes(const StringMap<SmallVector<TreePatternNode*,1> >
484 /// error - Throw an exception, prefixing it with information about this
486 void error(const std::string &Msg) const;
488 void print(raw_ostream &OS) const;
492 TreePatternNode *ParseTreePattern(DagInit *DI);
493 void ComputeNamedNodes();
494 void ComputeNamedNodes(TreePatternNode *N);
497 /// DAGDefaultOperand - One of these is created for each PredicateOperand
498 /// or OptionalDefOperand that has a set ExecuteAlways / DefaultOps field.
499 struct DAGDefaultOperand {
500 std::vector<TreePatternNode*> DefaultOps;
503 class DAGInstruction {
504 TreePattern *Pattern;
505 std::vector<Record*> Results;
506 std::vector<Record*> Operands;
507 std::vector<Record*> ImpResults;
508 std::vector<Record*> ImpOperands;
509 TreePatternNode *ResultPattern;
511 DAGInstruction(TreePattern *TP,
512 const std::vector<Record*> &results,
513 const std::vector<Record*> &operands,
514 const std::vector<Record*> &impresults,
515 const std::vector<Record*> &impoperands)
516 : Pattern(TP), Results(results), Operands(operands),
517 ImpResults(impresults), ImpOperands(impoperands),
520 const TreePattern *getPattern() const { return Pattern; }
521 unsigned getNumResults() const { return Results.size(); }
522 unsigned getNumOperands() const { return Operands.size(); }
523 unsigned getNumImpResults() const { return ImpResults.size(); }
524 unsigned getNumImpOperands() const { return ImpOperands.size(); }
525 const std::vector<Record*>& getImpResults() const { return ImpResults; }
527 void setResultPattern(TreePatternNode *R) { ResultPattern = R; }
529 Record *getResult(unsigned RN) const {
530 assert(RN < Results.size());
534 Record *getOperand(unsigned ON) const {
535 assert(ON < Operands.size());
539 Record *getImpResult(unsigned RN) const {
540 assert(RN < ImpResults.size());
541 return ImpResults[RN];
544 Record *getImpOperand(unsigned ON) const {
545 assert(ON < ImpOperands.size());
546 return ImpOperands[ON];
549 TreePatternNode *getResultPattern() const { return ResultPattern; }
552 /// PatternToMatch - Used by CodeGenDAGPatterns to keep tab of patterns
553 /// processed to produce isel.
554 class PatternToMatch {
556 PatternToMatch(ListInit *preds,
557 TreePatternNode *src, TreePatternNode *dst,
558 const std::vector<Record*> &dstregs,
559 unsigned complexity, unsigned uid)
560 : Predicates(preds), SrcPattern(src), DstPattern(dst),
561 Dstregs(dstregs), AddedComplexity(complexity), ID(uid) {}
563 ListInit *Predicates; // Top level predicate conditions to match.
564 TreePatternNode *SrcPattern; // Source pattern to match.
565 TreePatternNode *DstPattern; // Resulting pattern.
566 std::vector<Record*> Dstregs; // Physical register defs being matched.
567 unsigned AddedComplexity; // Add to matching pattern complexity.
568 unsigned ID; // Unique ID for the record.
570 ListInit *getPredicates() const { return Predicates; }
571 TreePatternNode *getSrcPattern() const { return SrcPattern; }
572 TreePatternNode *getDstPattern() const { return DstPattern; }
573 const std::vector<Record*> &getDstRegs() const { return Dstregs; }
574 unsigned getAddedComplexity() const { return AddedComplexity; }
576 std::string getPredicateCheck() const;
579 // Deterministic comparison of Record*.
580 struct RecordPtrCmp {
581 bool operator()(const Record *LHS, const Record *RHS) const;
584 class CodeGenDAGPatterns {
585 RecordKeeper &Records;
586 CodeGenTarget Target;
587 std::vector<CodeGenIntrinsic> Intrinsics;
588 std::vector<CodeGenIntrinsic> TgtIntrinsics;
590 std::map<Record*, SDNodeInfo, RecordPtrCmp> SDNodes;
591 std::map<Record*, std::pair<Record*, std::string>, RecordPtrCmp> SDNodeXForms;
592 std::map<Record*, ComplexPattern, RecordPtrCmp> ComplexPatterns;
593 std::map<Record*, TreePattern*, RecordPtrCmp> PatternFragments;
594 std::map<Record*, DAGDefaultOperand, RecordPtrCmp> DefaultOperands;
595 std::map<Record*, DAGInstruction, RecordPtrCmp> Instructions;
597 // Specific SDNode definitions:
598 Record *intrinsic_void_sdnode;
599 Record *intrinsic_w_chain_sdnode, *intrinsic_wo_chain_sdnode;
601 /// PatternsToMatch - All of the things we are matching on the DAG. The first
602 /// value is the pattern to match, the second pattern is the result to
604 std::vector<PatternToMatch> PatternsToMatch;
606 CodeGenDAGPatterns(RecordKeeper &R);
607 ~CodeGenDAGPatterns();
609 CodeGenTarget &getTargetInfo() { return Target; }
610 const CodeGenTarget &getTargetInfo() const { return Target; }
612 Record *getSDNodeNamed(const std::string &Name) const;
614 const SDNodeInfo &getSDNodeInfo(Record *R) const {
615 assert(SDNodes.count(R) && "Unknown node!");
616 return SDNodes.find(R)->second;
619 // Node transformation lookups.
620 typedef std::pair<Record*, std::string> NodeXForm;
621 const NodeXForm &getSDNodeTransform(Record *R) const {
622 assert(SDNodeXForms.count(R) && "Invalid transform!");
623 return SDNodeXForms.find(R)->second;
626 typedef std::map<Record*, NodeXForm, RecordPtrCmp>::const_iterator
628 nx_iterator nx_begin() const { return SDNodeXForms.begin(); }
629 nx_iterator nx_end() const { return SDNodeXForms.end(); }
632 const ComplexPattern &getComplexPattern(Record *R) const {
633 assert(ComplexPatterns.count(R) && "Unknown addressing mode!");
634 return ComplexPatterns.find(R)->second;
637 const CodeGenIntrinsic &getIntrinsic(Record *R) const {
638 for (unsigned i = 0, e = Intrinsics.size(); i != e; ++i)
639 if (Intrinsics[i].TheDef == R) return Intrinsics[i];
640 for (unsigned i = 0, e = TgtIntrinsics.size(); i != e; ++i)
641 if (TgtIntrinsics[i].TheDef == R) return TgtIntrinsics[i];
642 assert(0 && "Unknown intrinsic!");
646 const CodeGenIntrinsic &getIntrinsicInfo(unsigned IID) const {
647 if (IID-1 < Intrinsics.size())
648 return Intrinsics[IID-1];
649 if (IID-Intrinsics.size()-1 < TgtIntrinsics.size())
650 return TgtIntrinsics[IID-Intrinsics.size()-1];
651 assert(0 && "Bad intrinsic ID!");
655 unsigned getIntrinsicID(Record *R) const {
656 for (unsigned i = 0, e = Intrinsics.size(); i != e; ++i)
657 if (Intrinsics[i].TheDef == R) return i;
658 for (unsigned i = 0, e = TgtIntrinsics.size(); i != e; ++i)
659 if (TgtIntrinsics[i].TheDef == R) return i + Intrinsics.size();
660 assert(0 && "Unknown intrinsic!");
664 const DAGDefaultOperand &getDefaultOperand(Record *R) const {
665 assert(DefaultOperands.count(R) &&"Isn't an analyzed default operand!");
666 return DefaultOperands.find(R)->second;
669 // Pattern Fragment information.
670 TreePattern *getPatternFragment(Record *R) const {
671 assert(PatternFragments.count(R) && "Invalid pattern fragment request!");
672 return PatternFragments.find(R)->second;
674 typedef std::map<Record*, TreePattern*, RecordPtrCmp>::const_iterator
676 pf_iterator pf_begin() const { return PatternFragments.begin(); }
677 pf_iterator pf_end() const { return PatternFragments.end(); }
679 // Patterns to match information.
680 typedef std::vector<PatternToMatch>::const_iterator ptm_iterator;
681 ptm_iterator ptm_begin() const { return PatternsToMatch.begin(); }
682 ptm_iterator ptm_end() const { return PatternsToMatch.end(); }
686 const DAGInstruction &getInstruction(Record *R) const {
687 assert(Instructions.count(R) && "Unknown instruction!");
688 return Instructions.find(R)->second;
691 Record *get_intrinsic_void_sdnode() const {
692 return intrinsic_void_sdnode;
694 Record *get_intrinsic_w_chain_sdnode() const {
695 return intrinsic_w_chain_sdnode;
697 Record *get_intrinsic_wo_chain_sdnode() const {
698 return intrinsic_wo_chain_sdnode;
701 bool hasTargetIntrinsics() { return !TgtIntrinsics.empty(); }
704 void ParseNodeInfo();
705 void ParseNodeTransforms();
706 void ParseComplexPatterns();
707 void ParsePatternFragments();
708 void ParseDefaultOperands();
709 void ParseInstructions();
710 void ParsePatterns();
711 void InferInstructionFlags();
712 void GenerateVariants();
714 void AddPatternToMatch(const TreePattern *Pattern, const PatternToMatch &PTM);
715 void FindPatternInputsAndOutputs(TreePattern *I, TreePatternNode *Pat,
716 std::map<std::string,
717 TreePatternNode*> &InstInputs,
718 std::map<std::string,
719 TreePatternNode*> &InstResults,
720 std::vector<Record*> &InstImpInputs,
721 std::vector<Record*> &InstImpResults);
723 } // end namespace llvm