diff --git a/utils/TableGen/DAGISelEmitter.cpp b/utils/TableGen/DAGISelEmitter.cpp index 37000b2b8ee..cae8fe30844 100644 --- a/utils/TableGen/DAGISelEmitter.cpp +++ b/utils/TableGen/DAGISelEmitter.cpp @@ -18,6 +18,13 @@ #include using namespace llvm; +//===----------------------------------------------------------------------===// +// SDNodeInfo implementation +// +SDNodeInfo::SDNodeInfo(Record *R) : Def(R) { + EnumName = R->getValueAsString("Opcode"); + SDClassName = R->getValueAsString("SDClass"); +} //===----------------------------------------------------------------------===// // TreePatternNode implementation @@ -349,6 +356,15 @@ void TreePattern::dump() const { print(std::cerr); } // DAGISelEmitter implementation // +// Parse all of the SDNode definitions for the target, populating SDNodes. +void DAGISelEmitter::ParseNodeInfo() { + std::vector Nodes = Records.getAllDerivedDefinitions("SDNode"); + while (!Nodes.empty()) { + SDNodes.insert(std::make_pair(Nodes.back(), Nodes.back())); + Nodes.pop_back(); + } +} + /// ParseAndResolvePatternFragments - Parse all of the PatFrag definitions in /// the .td file, building up the PatternFragments map. After we've collected /// them all, inline fragments together as necessary, so that there are no @@ -458,6 +474,7 @@ void DAGISelEmitter::run(std::ostream &OS) { EmitSourceFileHeader("DAG Instruction Selector for the " + Target.getName() + " target", OS); + ParseNodeInfo(); ParseAndResolvePatternFragments(OS); ParseAndResolveInstructions(); diff --git a/utils/TableGen/DAGISelEmitter.h b/utils/TableGen/DAGISelEmitter.h index fb19289a465..20ead35a79d 100644 --- a/utils/TableGen/DAGISelEmitter.h +++ b/utils/TableGen/DAGISelEmitter.h @@ -23,6 +23,21 @@ namespace llvm { class DagInit; class TreePattern; class DAGISelEmitter; + + /// SDNodeInfo - One of these records is created for each SDNode instance in + /// the target .td file. This represents the various dag nodes we will be + /// processing. + class SDNodeInfo { + Record *Def; + std::string EnumName; + std::string SDClassName; + public: + SDNodeInfo(Record *R); // Parse the specified record. + + Record *getRecord() const { return Def; } + const std::string &getEnumName() const { return EnumName; } + const std::string &getSDClassName() const { return SDClassName; } + }; /// FIXME: TreePatternNode's can be shared in some cases (due to dag-shaped /// patterns), and as such should be ref counted. We currently just leak all @@ -181,6 +196,7 @@ class DAGISelEmitter : public TableGenBackend { RecordKeeper &Records; CodeGenTarget Target; + std::map SDNodes; std::map PatternFragments; std::vector Instructions; public: @@ -188,6 +204,11 @@ public: // run - Output the isel, returning true on failure. void run(std::ostream &OS); + + 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!"); @@ -195,6 +216,7 @@ public: } private: + void ParseNodeInfo(); void ParseAndResolvePatternFragments(std::ostream &OS); void ParseAndResolveInstructions(); void EmitInstructionSelector(std::ostream &OS);