[llvm-commits] [llvm] r45634 - in /llvm/trunk/utils/TableGen: CodeGenDAGPatterns.cpp CodeGenDAGPatterns.h DAGISelEmitter.cpp DAGISelEmitter.h
Chris Lattner
sabre at nondot.org
Sat Jan 5 14:43:57 PST 2008
Author: lattner
Date: Sat Jan 5 16:43:57 2008
New Revision: 45634
URL: http://llvm.org/viewvc/llvm-project?rev=45634&view=rev
Log:
move predicate printing code from CodeGenDAGPatterns -> DAGISelEmitter.
Modified:
llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h
llvm/trunk/utils/TableGen/DAGISelEmitter.cpp
llvm/trunk/utils/TableGen/DAGISelEmitter.h
Modified: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp?rev=45634&r1=45633&r2=45634&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp Sat Jan 5 16:43:57 2008
@@ -1119,7 +1119,7 @@
ParseNodeInfo();
ParseNodeTransforms(OS);
ParseComplexPatterns();
- ParsePatternFragments(OS);
+ ParsePatternFragments();
ParseDefaultOperands();
ParseInstructions();
ParsePatterns();
@@ -1200,23 +1200,20 @@
/// inline fragments together as necessary, so that there are no references left
/// inside a pattern fragment to a pattern fragment.
///
-/// This also emits all of the predicate functions to the output file.
-///
-void CodegenDAGPatterns::ParsePatternFragments(std::ostream &OS) {
+void CodegenDAGPatterns::ParsePatternFragments() {
std::vector<Record*> Fragments = Records.getAllDerivedDefinitions("PatFrag");
- // First step, parse all of the fragments and emit predicate functions.
- OS << "\n// Predicate functions.\n";
+ // First step, parse all of the fragments.
for (unsigned i = 0, e = Fragments.size(); i != e; ++i) {
DagInit *Tree = Fragments[i]->getValueAsDag("Fragment");
TreePattern *P = new TreePattern(Fragments[i], Tree, true, *this);
PatternFragments[Fragments[i]] = P;
- // Validate the argument list, converting it to map, to discard duplicates.
+ // Validate the argument list, converting it to set, to discard duplicates.
std::vector<std::string> &Args = P->getArgList();
- std::set<std::string> OperandsMap(Args.begin(), Args.end());
+ std::set<std::string> OperandsSet(Args.begin(), Args.end());
- if (OperandsMap.count(""))
+ if (OperandsSet.count(""))
P->error("Cannot have unnamed 'node' values in pattern fragment!");
// Parse the operands list.
@@ -1239,37 +1236,22 @@
P->error("Operands list should all be 'node' values.");
if (OpsList->getArgName(j).empty())
P->error("Operands list should have names for each operand!");
- if (!OperandsMap.count(OpsList->getArgName(j)))
+ if (!OperandsSet.count(OpsList->getArgName(j)))
P->error("'" + OpsList->getArgName(j) +
"' does not occur in pattern or was multiply specified!");
- OperandsMap.erase(OpsList->getArgName(j));
+ OperandsSet.erase(OpsList->getArgName(j));
Args.push_back(OpsList->getArgName(j));
}
- if (!OperandsMap.empty())
+ if (!OperandsSet.empty())
P->error("Operands list does not contain an entry for operand '" +
- *OperandsMap.begin() + "'!");
+ *OperandsSet.begin() + "'!");
- // If there is a code init for this fragment, emit the predicate code and
- // keep track of the fact that this fragment uses it.
+ // If there is a code init for this fragment, keep track of the fact that
+ // this fragment uses it.
std::string Code = Fragments[i]->getValueAsCode("Predicate");
- if (!Code.empty()) {
- if (P->getOnlyTree()->isLeaf())
- OS << "inline bool Predicate_" << Fragments[i]->getName()
- << "(SDNode *N) {\n";
- else {
- std::string ClassName =
- getSDNodeInfo(P->getOnlyTree()->getOperator()).getSDClassName();
- const char *C2 = ClassName == "SDNode" ? "N" : "inN";
-
- OS << "inline bool Predicate_" << Fragments[i]->getName()
- << "(SDNode *" << C2 << ") {\n";
- if (ClassName != "SDNode")
- OS << " " << ClassName << " *N = cast<" << ClassName << ">(inN);\n";
- }
- OS << Code << "\n}\n";
+ if (!Code.empty())
P->getOnlyTree()->setPredicateFn("Predicate_"+Fragments[i]->getName());
- }
// If there is a node transformation corresponding to this, keep track of
// it.
@@ -1278,8 +1260,6 @@
P->getOnlyTree()->setTransformFn(Transform);
}
- OS << "\n\n";
-
// Now that we've parsed all of the tree fragments, do a closure on them so
// that there are not references to PatFrags left inside of them.
for (std::map<Record*, TreePattern*>::iterator I = PatternFragments.begin(),
Modified: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h?rev=45634&r1=45633&r2=45634&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h (original)
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h Sat Jan 5 16:43:57 2008
@@ -532,7 +532,7 @@
void ParseNodeInfo();
void ParseNodeTransforms(std::ostream &OS);
void ParseComplexPatterns();
- void ParsePatternFragments(std::ostream &OS);
+ void ParsePatternFragments();
void ParseDefaultOperands();
void ParseInstructions();
void ParsePatterns();
Modified: llvm/trunk/utils/TableGen/DAGISelEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DAGISelEmitter.cpp?rev=45634&r1=45633&r2=45634&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/DAGISelEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/DAGISelEmitter.cpp Sat Jan 5 16:43:57 2008
@@ -21,10 +21,9 @@
using namespace llvm;
//===----------------------------------------------------------------------===//
-// DAGISelEmitter implementation
+// DAGISelEmitter Helper methods
//
-
/// NodeIsComplexPattern - return true if N is a leaf node and a subclass of
/// ComplexPattern.
static bool NodeIsComplexPattern(TreePatternNode *N) {
@@ -207,6 +206,55 @@
return false;
}
+//===----------------------------------------------------------------------===//
+// Predicate emitter implementation.
+//
+
+void DAGISelEmitter::EmitPredicateFunctions(std::ostream &OS) {
+ OS << "\n// Predicate functions.\n";
+
+ // Walk the pattern fragments, adding them to a map, which sorts them by
+ // name.
+ typedef std::map<std::string, std::pair<Record*, TreePattern*> > PFsByNameTy;
+ PFsByNameTy PFsByName;
+
+ for (CodegenDAGPatterns::pf_iterator I = CGP->pf_begin(), E = CGP->pf_end();
+ I != E; ++I)
+ PFsByName.insert(std::make_pair(I->first->getName(), *I));
+
+
+ for (PFsByNameTy::iterator I = PFsByName.begin(), E = PFsByName.end();
+ I != E; ++I) {
+ Record *PatFragRecord = I->second.first;// Record that derives from PatFrag.
+ TreePattern *P = I->second.second;
+
+ // If there is a code init for this fragment, emit the predicate code.
+ std::string Code = PatFragRecord->getValueAsCode("Predicate");
+ if (Code.empty()) continue;
+
+ if (P->getOnlyTree()->isLeaf())
+ OS << "inline bool Predicate_" << PatFragRecord->getName()
+ << "(SDNode *N) {\n";
+ else {
+ std::string ClassName =
+ CGP->getSDNodeInfo(P->getOnlyTree()->getOperator()).getSDClassName();
+ const char *C2 = ClassName == "SDNode" ? "N" : "inN";
+
+ OS << "inline bool Predicate_" << PatFragRecord->getName()
+ << "(SDNode *" << C2 << ") {\n";
+ if (ClassName != "SDNode")
+ OS << " " << ClassName << " *N = cast<" << ClassName << ">(inN);\n";
+ }
+ OS << Code << "\n}\n";
+ }
+
+ OS << "\n\n";
+}
+
+
+//===----------------------------------------------------------------------===//
+// PatternCodeEmitter implementation.
+//
class PatternCodeEmitter {
private:
CodegenDAGPatterns &CGP;
@@ -1966,6 +2014,8 @@
this->CGP = &CGP;
+ EmitPredicateFunctions(OS);
+
DOUT << "\n\nALL PATTERNS TO MATCH:\n\n";
for (CodegenDAGPatterns::ptm_iterator I = CGP.ptm_begin(), E = CGP.ptm_end();
I != E; ++I) {
Modified: llvm/trunk/utils/TableGen/DAGISelEmitter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DAGISelEmitter.h?rev=45634&r1=45633&r2=45634&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/DAGISelEmitter.h (original)
+++ llvm/trunk/utils/TableGen/DAGISelEmitter.h Sat Jan 5 16:43:57 2008
@@ -33,6 +33,8 @@
private:
+ void EmitPredicateFunctions(std::ostream &OS);
+
void GenerateCodeForPattern(const PatternToMatch &Pattern,
std::vector<std::pair<unsigned, std::string> > &GeneratedCode,
std::set<std::string> &GeneratedDecl,
@@ -41,6 +43,7 @@
void EmitPatterns(std::vector<std::pair<const PatternToMatch*,
std::vector<std::pair<unsigned, std::string> > > > &Patterns,
unsigned Indent, std::ostream &OS);
+
void EmitInstructionSelector(std::ostream &OS);
};
More information about the llvm-commits
mailing list