start parsing SDNode info records
authorChris Lattner <sabre@nondot.org>
Thu, 8 Sep 2005 21:03:01 +0000 (21:03 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 8 Sep 2005 21:03:01 +0000 (21:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23279 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/DAGISelEmitter.cpp
utils/TableGen/DAGISelEmitter.h

index 37000b2b8ee5ed07458860780314b6e19ea8c863..cae8fe308441a49854b93a50695f8c4dacb56763 100644 (file)
 #include <set>
 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<Record*> 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();
   
index fb19289a465c91c4db90a38310e546de505ca4d8..20ead35a79d432b1f811f063b2e4fc6ca3030d8a 100644 (file)
@@ -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<Record*, SDNodeInfo> SDNodes;
   std::map<Record*, TreePattern*> PatternFragments;
   std::vector<TreePattern*> 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);