Changeset View
Changeset View
Standalone View
Standalone View
llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h
Show First 20 Lines • Show All 712 Lines • ▼ Show 20 Lines | bool isIsomorphicTo(const TreePatternNode *N, | ||||
const MultipleUseVarSet &DepVars) const; | const MultipleUseVarSet &DepVars) const; | ||||
/// SubstituteFormalArguments - Replace the formal arguments in this tree | /// SubstituteFormalArguments - Replace the formal arguments in this tree | ||||
/// with actual values specified by ArgMap. | /// with actual values specified by ArgMap. | ||||
void | void | ||||
SubstituteFormalArguments(std::map<std::string, TreePatternNodePtr> &ArgMap); | SubstituteFormalArguments(std::map<std::string, TreePatternNodePtr> &ArgMap); | ||||
/// InlinePatternFragments - If this pattern refers to any pattern | /// InlinePatternFragments - If this pattern refers to any pattern | ||||
/// fragments, inline them into place, giving us a pattern without any | /// fragments, return the set of inlined versions (this can be more than | ||||
/// PatFrag references. | /// one if a PatFrags record has multiple alternatives). | ||||
TreePatternNodePtr InlinePatternFragments(TreePatternNodePtr T, | void InlinePatternFragments(TreePatternNodePtr T, | ||||
TreePattern &TP); | TreePattern &TP, | ||||
std::vector<TreePatternNodePtr> &OutAlternatives); | |||||
/// ApplyTypeConstraints - Apply all of the type constraints relevant to | /// ApplyTypeConstraints - Apply all of the type constraints relevant to | ||||
/// this node and its children in the tree. This returns true if it makes a | /// this node and its children in the tree. This returns true if it makes a | ||||
/// change, false otherwise. If a type contradiction is found, flag an error. | /// change, false otherwise. If a type contradiction is found, flag an error. | ||||
bool ApplyTypeConstraints(TreePattern &TP, bool NotRegisters); | bool ApplyTypeConstraints(TreePattern &TP, bool NotRegisters); | ||||
/// UpdateNodeType - Set the node type of N to VT if VT contains | /// UpdateNodeType - Set the node type of N to VT if VT contains | ||||
/// information. If N already contains a conflicting type, then flag an | /// information. If N already contains a conflicting type, then flag an | ||||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | const std::string &getArgName(unsigned i) const { | ||||
return Args[i]; | return Args[i]; | ||||
} | } | ||||
std::vector<std::string> &getArgList() { return Args; } | std::vector<std::string> &getArgList() { return Args; } | ||||
CodeGenDAGPatterns &getDAGPatterns() const { return CDP; } | CodeGenDAGPatterns &getDAGPatterns() const { return CDP; } | ||||
/// InlinePatternFragments - If this pattern refers to any pattern | /// InlinePatternFragments - If this pattern refers to any pattern | ||||
/// fragments, inline them into place, giving us a pattern without any | /// fragments, inline them into place, giving us a pattern without any | ||||
/// PatFrag references. | /// PatFrags references. This may increase the number of trees in the | ||||
/// pattern if a PatFrags has multiple alternatives. | |||||
void InlinePatternFragments() { | void InlinePatternFragments() { | ||||
for (unsigned i = 0, e = Trees.size(); i != e; ++i) | std::vector<TreePatternNodePtr> Copy = Trees; | ||||
Trees[i] = Trees[i]->InlinePatternFragments(Trees[i], *this); | Trees.clear(); | ||||
for (unsigned i = 0, e = Copy.size(); i != e; ++i) | |||||
Copy[i]->InlinePatternFragments(Copy[i], *this, Trees); | |||||
} | } | ||||
/// InferAllTypes - Infer/propagate as many types throughout the expression | /// InferAllTypes - Infer/propagate as many types throughout the expression | ||||
/// patterns as possible. Return true if all types are inferred, false | /// patterns as possible. Return true if all types are inferred, false | ||||
/// otherwise. Bail out if a type contradiction is found. | /// otherwise. Bail out if a type contradiction is found. | ||||
bool InferAllTypes( | bool InferAllTypes( | ||||
const StringMap<SmallVector<TreePatternNode *, 1>> *NamedTypes = nullptr); | const StringMap<SmallVector<TreePatternNode *, 1>> *NamedTypes = nullptr); | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
/// DAGDefaultOperand - One of these is created for each OperandWithDefaultOps | /// DAGDefaultOperand - One of these is created for each OperandWithDefaultOps | ||||
/// that has a set ExecuteAlways / DefaultOps field. | /// that has a set ExecuteAlways / DefaultOps field. | ||||
struct DAGDefaultOperand { | struct DAGDefaultOperand { | ||||
std::vector<TreePatternNodePtr> DefaultOps; | std::vector<TreePatternNodePtr> DefaultOps; | ||||
}; | }; | ||||
class DAGInstruction { | class DAGInstruction { | ||||
std::unique_ptr<TreePattern> Pattern; | |||||
std::vector<Record*> Results; | std::vector<Record*> Results; | ||||
std::vector<Record*> Operands; | std::vector<Record*> Operands; | ||||
std::vector<Record*> ImpResults; | std::vector<Record*> ImpResults; | ||||
TreePatternNodePtr SrcPattern; | |||||
TreePatternNodePtr ResultPattern; | TreePatternNodePtr ResultPattern; | ||||
public: | public: | ||||
DAGInstruction(std::unique_ptr<TreePattern> &&TP, | DAGInstruction(const std::vector<Record*> &results, | ||||
const std::vector<Record*> &results, | |||||
const std::vector<Record*> &operands, | const std::vector<Record*> &operands, | ||||
const std::vector<Record*> &impresults) | const std::vector<Record*> &impresults, | ||||
: Pattern(std::move(TP)), Results(results), Operands(operands), | TreePatternNodePtr srcpattern = nullptr, | ||||
ImpResults(impresults), ResultPattern(nullptr) {} | TreePatternNodePtr resultpattern = nullptr) | ||||
: Results(results), Operands(operands), ImpResults(impresults), | |||||
SrcPattern(srcpattern), ResultPattern(resultpattern) {} | |||||
TreePattern *getPattern() const { return Pattern.get(); } | |||||
unsigned getNumResults() const { return Results.size(); } | unsigned getNumResults() const { return Results.size(); } | ||||
unsigned getNumOperands() const { return Operands.size(); } | unsigned getNumOperands() const { return Operands.size(); } | ||||
unsigned getNumImpResults() const { return ImpResults.size(); } | unsigned getNumImpResults() const { return ImpResults.size(); } | ||||
const std::vector<Record*>& getImpResults() const { return ImpResults; } | const std::vector<Record*>& getImpResults() const { return ImpResults; } | ||||
void setResultPattern(TreePatternNodePtr R) { ResultPattern = R; } | |||||
Record *getResult(unsigned RN) const { | Record *getResult(unsigned RN) const { | ||||
assert(RN < Results.size()); | assert(RN < Results.size()); | ||||
return Results[RN]; | return Results[RN]; | ||||
} | } | ||||
Record *getOperand(unsigned ON) const { | Record *getOperand(unsigned ON) const { | ||||
assert(ON < Operands.size()); | assert(ON < Operands.size()); | ||||
return Operands[ON]; | return Operands[ON]; | ||||
} | } | ||||
Record *getImpResult(unsigned RN) const { | Record *getImpResult(unsigned RN) const { | ||||
assert(RN < ImpResults.size()); | assert(RN < ImpResults.size()); | ||||
return ImpResults[RN]; | return ImpResults[RN]; | ||||
} | } | ||||
TreePatternNodePtr getSrcPattern() const { return SrcPattern; } | |||||
TreePatternNodePtr getResultPattern() const { return ResultPattern; } | TreePatternNodePtr getResultPattern() const { return ResultPattern; } | ||||
}; | }; | ||||
/// This class represents a condition that has to be satisfied for a pattern | /// This class represents a condition that has to be satisfied for a pattern | ||||
/// to be tried. It is a generalization of a class "Pattern" from Target.td: | /// to be tried. It is a generalization of a class "Pattern" from Target.td: | ||||
/// in addition to the Target.td's predicates, this class can also represent | /// in addition to the Target.td's predicates, this class can also represent | ||||
/// conditions associated with HW modes. Both types will eventually become | /// conditions associated with HW modes. Both types will eventually become | ||||
/// strings containing C++ code to be executed, the difference is in how | /// strings containing C++ code to be executed, the difference is in how | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
/// processed to produce isel. | /// processed to produce isel. | ||||
class PatternToMatch { | class PatternToMatch { | ||||
public: | public: | ||||
PatternToMatch(Record *srcrecord, std::vector<Predicate> preds, | PatternToMatch(Record *srcrecord, std::vector<Predicate> preds, | ||||
TreePatternNodePtr src, TreePatternNodePtr dst, | TreePatternNodePtr src, TreePatternNodePtr dst, | ||||
std::vector<Record *> dstregs, int complexity, | std::vector<Record *> dstregs, int complexity, | ||||
unsigned uid, unsigned setmode = 0) | unsigned uid, unsigned setmode = 0) | ||||
: SrcRecord(srcrecord), SrcPattern(src), DstPattern(dst), | : SrcRecord(srcrecord), SrcPattern(src), DstPattern(dst), | ||||
Predicates(std::move(preds)), Dstregs(std::move(dstregs)), | Predicates(preds), Dstregs(dstregs), | ||||
AddedComplexity(complexity), ID(uid), ForceMode(setmode) {} | AddedComplexity(complexity), ID(uid), ForceMode(setmode) {} | ||||
Record *SrcRecord; // Originating Record for the pattern. | Record *SrcRecord; // Originating Record for the pattern. | ||||
TreePatternNodePtr SrcPattern; // Source pattern to match. | TreePatternNodePtr SrcPattern; // Source pattern to match. | ||||
TreePatternNodePtr DstPattern; // Resulting pattern. | TreePatternNodePtr DstPattern; // Resulting pattern. | ||||
std::vector<Predicate> Predicates; // Top level predicate conditions | std::vector<Predicate> Predicates; // Top level predicate conditions | ||||
// to match. | // to match. | ||||
std::vector<Record*> Dstregs; // Physical register defs being matched. | std::vector<Record*> Dstregs; // Physical register defs being matched. | ||||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | public: | ||||
// Patterns to match information. | // Patterns to match information. | ||||
typedef std::vector<PatternToMatch>::const_iterator ptm_iterator; | typedef std::vector<PatternToMatch>::const_iterator ptm_iterator; | ||||
ptm_iterator ptm_begin() const { return PatternsToMatch.begin(); } | ptm_iterator ptm_begin() const { return PatternsToMatch.begin(); } | ||||
ptm_iterator ptm_end() const { return PatternsToMatch.end(); } | ptm_iterator ptm_end() const { return PatternsToMatch.end(); } | ||||
iterator_range<ptm_iterator> ptms() const { return PatternsToMatch; } | iterator_range<ptm_iterator> ptms() const { return PatternsToMatch; } | ||||
/// Parse the Pattern for an instruction, and insert the result in DAGInsts. | /// Parse the Pattern for an instruction, and insert the result in DAGInsts. | ||||
typedef std::map<Record*, DAGInstruction, LessRecordByID> DAGInstMap; | typedef std::map<Record*, DAGInstruction, LessRecordByID> DAGInstMap; | ||||
const DAGInstruction &parseInstructionPattern( | void parseInstructionPattern( | ||||
CodeGenInstruction &CGI, ListInit *Pattern, | CodeGenInstruction &CGI, ListInit *Pattern, | ||||
DAGInstMap &DAGInsts); | DAGInstMap &DAGInsts); | ||||
const DAGInstruction &getInstruction(Record *R) const { | const DAGInstruction &getInstruction(Record *R) const { | ||||
auto F = Instructions.find(R); | auto F = Instructions.find(R); | ||||
assert(F != Instructions.end() && "Unknown instruction!"); | assert(F != Instructions.end() && "Unknown instruction!"); | ||||
return F->second; | return F->second; | ||||
} | } | ||||
Show All 20 Lines | private: | ||||
void ParsePatterns(); | void ParsePatterns(); | ||||
void ExpandHwModeBasedTypes(); | void ExpandHwModeBasedTypes(); | ||||
void InferInstructionFlags(); | void InferInstructionFlags(); | ||||
void GenerateVariants(); | void GenerateVariants(); | ||||
void VerifyInstructionFlags(); | void VerifyInstructionFlags(); | ||||
std::vector<Predicate> makePredList(ListInit *L); | std::vector<Predicate> makePredList(ListInit *L); | ||||
void ParseOnePattern(Record *TheDef, | |||||
TreePattern &Pattern, TreePattern &Result, | |||||
const std::vector<Record *> &InstImpResults); | |||||
void AddPatternToMatch(TreePattern *Pattern, PatternToMatch &&PTM); | void AddPatternToMatch(TreePattern *Pattern, PatternToMatch &&PTM); | ||||
void FindPatternInputsAndOutputs( | void FindPatternInputsAndOutputs( | ||||
TreePattern &I, TreePatternNodePtr Pat, | TreePattern &I, TreePatternNodePtr Pat, | ||||
std::map<std::string, TreePatternNodePtr> &InstInputs, | std::map<std::string, TreePatternNodePtr> &InstInputs, | ||||
std::map<std::string, TreePatternNodePtr> &InstResults, | std::map<std::string, TreePatternNodePtr> &InstResults, | ||||
std::vector<Record *> &InstImpResults); | std::vector<Record *> &InstImpResults); | ||||
}; | }; | ||||
Show All 12 Lines |