X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=utils%2FTableGen%2FDAGISelEmitter.h;h=35606f7787c2319387600a7c75d20fb19ca87983;hb=2ca956f8dede03c23f6b497395cd3b99ebd1eb8a;hp=dbedbce2d2fe951ca6ab1194ebacb7e7a42e1ecf;hpb=2ac8510d68a0e3c83adb4b48e3369b7890d5decd;p=oota-llvm.git diff --git a/utils/TableGen/DAGISelEmitter.h b/utils/TableGen/DAGISelEmitter.h index dbedbce2d2f..35606f7787c 100644 --- a/utils/TableGen/DAGISelEmitter.h +++ b/utils/TableGen/DAGISelEmitter.h @@ -16,6 +16,7 @@ #include "TableGenBackend.h" #include "CodeGenTarget.h" +#include namespace llvm { class Record; @@ -26,6 +27,7 @@ namespace llvm { class TreePattern; class TreePatternNode; class DAGISelEmitter; + class ComplexPattern; /// MVT::DAGISelGenValueType - These are some extended forms of MVT::ValueType /// that we use as lattice values during type inferrence. @@ -44,8 +46,8 @@ namespace llvm { unsigned OperandNo; // The operand # this constraint applies to. enum { - SDTCisVT, SDTCisInt, SDTCisFP, SDTCisSameAs, SDTCisVTSmallerThanOp, - SDTCisOpSmallerThanOp + SDTCisVT, SDTCisPtrTy, SDTCisInt, SDTCisFP, SDTCisSameAs, + SDTCisVTSmallerThanOp, SDTCisOpSmallerThanOp, SDTCisIntVectorOfSameSize } ConstraintType; union { // The discriminated union. @@ -61,6 +63,9 @@ namespace llvm { struct { unsigned BigOperandNum; } SDTCisOpSmallerThanOp_Info; + struct { + unsigned OtherOperandNum; + } SDTCisIntVectorOfSameSize_Info; } x; /// ApplyTypeConstraint - Given a node in a pattern, apply this type @@ -101,7 +106,8 @@ namespace llvm { } // SelectionDAG node properties. - enum SDNP { SDNPCommutative, SDNPAssociative }; + enum SDNP { SDNPCommutative, SDNPAssociative, SDNPHasChain, + SDNPOutFlag, SDNPInFlag, SDNPOptInFlag }; /// hasProperty - Return true if this node has the specified property. /// @@ -123,9 +129,9 @@ namespace llvm { /// patterns), and as such should be ref counted. We currently just leak all /// TreePatternNode objects! class TreePatternNode { - /// The inferred type for this node, or MVT::LAST_VALUETYPE if it hasn't + /// The inferred type for this node, or MVT::isUnknown if it hasn't /// been determined yet. - unsigned char Ty; + std::vector Types; /// Operator - The Record for the operator if this is an interior node (not /// a leaf). @@ -150,26 +156,34 @@ namespace llvm { std::vector Children; public: TreePatternNode(Record *Op, const std::vector &Ch) - : Ty(MVT::isUnknown), Operator(Op), Val(0), TransformFn(0), - Children(Ch) {} + : Types(), Operator(Op), Val(0), TransformFn(0), + Children(Ch) { Types.push_back(MVT::isUnknown); } TreePatternNode(Init *val) // leaf ctor - : Ty(MVT::isUnknown), Operator(0), Val(val), TransformFn(0) {} + : Types(), Operator(0), Val(val), TransformFn(0) { + Types.push_back(MVT::isUnknown); + } ~TreePatternNode(); const std::string &getName() const { return Name; } void setName(const std::string &N) { Name = N; } bool isLeaf() const { return Val != 0; } - bool hasTypeSet() const { return Ty < MVT::LAST_VALUETYPE; } + bool hasTypeSet() const { return Types[0] < MVT::LAST_VALUETYPE; } bool isTypeCompletelyUnknown() const { - return Ty == MVT::isUnknown; + return Types[0] == MVT::isUnknown; } - MVT::ValueType getType() const { + MVT::ValueType getTypeNum(unsigned Num) const { assert(hasTypeSet() && "Doesn't have a type yet!"); - return (MVT::ValueType)Ty; + assert(Types.size() > Num && "Type num out of range!"); + return (MVT::ValueType)Types[Num]; } - unsigned char getExtType() const { return Ty; } - void setType(unsigned char VT) { Ty = VT; } + unsigned char getExtTypeNum(unsigned Num) const { + assert(Types.size() > Num && "Extended type num out of range!"); + return Types[Num]; + } + const std::vector &getExtTypes() const { return Types; } + void setTypes(const std::vector &T) { Types = T; } + void removeTypes() { Types = std::vector(1,MVT::isUnknown); } Init *getLeafValue() const { assert(isLeaf()); return Val; } Record *getOperator() const { assert(!isLeaf()); return Operator; } @@ -180,6 +194,7 @@ namespace llvm { Children[i] = N; } + const std::string &getPredicateFn() const { return PredicateFn; } void setPredicateFn(const std::string &Fn) { PredicateFn = Fn; } @@ -221,7 +236,12 @@ namespace llvm { /// information. If N already contains a conflicting type, then throw an /// exception. This returns true if any information was updated. /// - bool UpdateNodeType(unsigned char EVT, TreePattern &TP); + bool UpdateNodeType(const std::vector &ExtVTs, + TreePattern &TP); + bool UpdateNodeType(unsigned char ExtVT, TreePattern &TP) { + std::vector ExtVTs(1, ExtVT); + return UpdateNodeType(ExtVTs, TP); + } /// ContainsUnresolvedType - Return true if this tree contains any /// unresolved types. @@ -258,13 +278,20 @@ namespace llvm { /// ISE - the DAG isel emitter coordinating this madness. /// DAGISelEmitter &ISE; + + /// isInputPattern - True if this is an input pattern, something to match. + /// False if this is an output pattern, something to emit. + bool isInputPattern; public: /// TreePattern constructor - Parse the specified DagInits into the /// current record. - TreePattern(Record *TheRec, ListInit *RawPat, DAGISelEmitter &ise); - TreePattern(Record *TheRec, DagInit *Pat, DAGISelEmitter &ise); - TreePattern(Record *TheRec, TreePatternNode *Pat, DAGISelEmitter &ise); + TreePattern(Record *TheRec, ListInit *RawPat, bool isInput, + DAGISelEmitter &ise); + TreePattern(Record *TheRec, DagInit *Pat, bool isInput, + DAGISelEmitter &ise); + TreePattern(Record *TheRec, TreePatternNode *Pat, bool isInput, + DAGISelEmitter &ise); /// getTrees - Return the tree patterns which corresponds to this pattern. /// @@ -317,49 +344,78 @@ namespace llvm { class DAGInstruction { TreePattern *Pattern; - unsigned NumResults; - unsigned NumOperands; - std::vector ResultTypes; - std::vector OperandTypes; + std::vector Results; + std::vector Operands; + std::vector ImpResults; + std::vector ImpOperands; TreePatternNode *ResultPattern; public: DAGInstruction(TreePattern *TP, - const std::vector &resultTypes, - const std::vector &operandTypes) - : Pattern(TP), ResultTypes(resultTypes), OperandTypes(operandTypes), + const std::vector &results, + const std::vector &operands, + const std::vector &impresults, + const std::vector &impoperands) + : Pattern(TP), Results(results), Operands(operands), + ImpResults(impresults), ImpOperands(impoperands), ResultPattern(0) {} TreePattern *getPattern() const { return Pattern; } - unsigned getNumResults() const { return ResultTypes.size(); } - unsigned getNumOperands() const { return OperandTypes.size(); } + unsigned getNumResults() const { return Results.size(); } + unsigned getNumOperands() const { return Operands.size(); } + unsigned getNumImpResults() const { return ImpResults.size(); } + unsigned getNumImpOperands() const { return ImpOperands.size(); } void setResultPattern(TreePatternNode *R) { ResultPattern = R; } - MVT::ValueType getResultType(unsigned RN) const { - assert(RN < ResultTypes.size()); - return ResultTypes[RN]; + Record *getResult(unsigned RN) const { + assert(RN < Results.size()); + return Results[RN]; + } + + Record *getOperand(unsigned ON) const { + assert(ON < Operands.size()); + return Operands[ON]; + } + + Record *getImpResult(unsigned RN) const { + assert(RN < ImpResults.size()); + return ImpResults[RN]; } - MVT::ValueType getOperandType(unsigned ON) const { - assert(ON < OperandTypes.size()); - return OperandTypes[ON]; + Record *getImpOperand(unsigned ON) const { + assert(ON < ImpOperands.size()); + return ImpOperands[ON]; } + TreePatternNode *getResultPattern() const { return ResultPattern; } }; - -/// InstrSelectorEmitter - The top-level class which coordinates construction +/// PatternToMatch - Used by DAGISelEmitter to keep tab of patterns processed +/// to produce isel. +struct PatternToMatch { + PatternToMatch(ListInit *preds, TreePatternNode *src, TreePatternNode *dst): + Predicates(preds), SrcPattern(src), DstPattern(dst) {}; + + ListInit *Predicates; // Top level predicate conditions to match. + TreePatternNode *SrcPattern; // Source pattern to match. + TreePatternNode *DstPattern; // Resulting pattern. + + ListInit *getPredicates() const { return Predicates; } + TreePatternNode *getSrcPattern() const { return SrcPattern; } + TreePatternNode *getDstPattern() const { return DstPattern; } +}; + +/// DAGISelEmitter - The top-level class which coordinates construction /// and emission of the instruction selector. /// class DAGISelEmitter : public TableGenBackend { -public: - typedef std::pair PatternToMatch; private: RecordKeeper &Records; CodeGenTarget Target; - + std::map SDNodes; std::map > SDNodeXForms; + std::map ComplexPatterns; std::map PatternFragments; std::map Instructions; @@ -375,20 +431,27 @@ public: const CodeGenTarget &getTargetInfo() const { return Target; } + Record *getSDNodeNamed(const std::string &Name) const; + const SDNodeInfo &getSDNodeInfo(Record *R) const { assert(SDNodes.count(R) && "Unknown node!"); return SDNodes.find(R)->second; } - TreePattern *getPatternFragment(Record *R) const { - assert(PatternFragments.count(R) && "Invalid pattern fragment request!"); - return PatternFragments.find(R)->second; - } - const std::pair &getSDNodeTransform(Record *R) const { assert(SDNodeXForms.count(R) && "Invalid transform!"); return SDNodeXForms.find(R)->second; } + + const ComplexPattern &getComplexPattern(Record *R) const { + assert(ComplexPatterns.count(R) && "Unknown addressing mode!"); + return ComplexPatterns.find(R)->second; + } + + TreePattern *getPatternFragment(Record *R) const { + assert(PatternFragments.count(R) && "Invalid pattern fragment request!"); + return PatternFragments.find(R)->second; + } const DAGInstruction &getInstruction(Record *R) const { assert(Instructions.count(R) && "Unknown instruction!"); @@ -398,6 +461,7 @@ public: private: void ParseNodeInfo(); void ParseNodeTransforms(std::ostream &OS); + void ParseComplexPatterns(); void ParsePatternFragments(std::ostream &OS); void ParseInstructions(); void ParsePatterns(); @@ -405,14 +469,17 @@ private: void FindPatternInputsAndOutputs(TreePattern *I, TreePatternNode *Pat, std::map &InstInputs, - std::map &InstResults); - void EmitMatchForPattern(TreePatternNode *N, const std::string &RootName, - std::map &VarMap, - unsigned PatternNo, std::ostream &OS); - unsigned CodeGenPatternResult(TreePatternNode *N, unsigned &Ctr, - std::map &VariableMap, - std::ostream &OS, bool isRoot = false); - void EmitCodeForPattern(PatternToMatch &Pattern, std::ostream &OS); + std::map &InstResults, + std::vector &InstImpInputs, + std::vector &InstImpResults); + void GenerateCodeForPattern(PatternToMatch &Pattern, + std::vector > &GeneratedCode, + std::set > &GeneratedDecl, + bool UseGoto); + void EmitPatterns(std::vector > > > &Patterns, + unsigned Indent, std::ostream &OS); void EmitInstructionSelector(std::ostream &OS); };