Factor the code for determining the target-specific instruction
authorDan Gohman <gohman@apple.com>
Wed, 20 Aug 2008 21:45:57 +0000 (21:45 +0000)
committerDan Gohman <gohman@apple.com>
Wed, 20 Aug 2008 21:45:57 +0000 (21:45 +0000)
namespace out of the isel emitters and into common code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55079 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/CodeGenTarget.cpp
utils/TableGen/CodeGenTarget.h
utils/TableGen/DAGISelEmitter.cpp
utils/TableGen/FastISelEmitter.cpp

index d9f4c3e341350d425f7eba3765b74003dfb9fd0d..4e7a10c1d81ddf6379a6457944f21dfa7f7ad3b5 100644 (file)
@@ -135,6 +135,21 @@ const std::string &CodeGenTarget::getName() const {
   return TargetRec->getName();
 }
 
+std::string CodeGenTarget::getInstNamespace() const {
+  std::string InstNS;
+
+  for (inst_iterator i = inst_begin(), e = inst_end(); i != e; ++i) {
+    InstNS = i->second.Namespace;
+
+    // Make sure not to pick up "TargetInstrInfo" by accidentally getting
+    // the namespace off the PHI instruction or something.
+    if (InstNS != "TargetInstrInfo")
+      break;
+  }
+
+  return InstNS;
+}
+
 Record *CodeGenTarget::getInstructionSet() const {
   return TargetRec->getValueAsDef("InstructionSet");
 }
index f53b6a99c15ccea5ac280b3bf293eafd63bba921..ef46b6c61851a8f36c6215e3e8cb19506af4f548 100644 (file)
@@ -78,6 +78,10 @@ public:
   Record *getTargetRecord() const { return TargetRec; }
   const std::string &getName() const;
 
+  /// getInstNamespace - Return the target-specific instruction namespace.
+  ///
+  std::string getInstNamespace() const;
+
   /// getInstructionSet - Return the InstructionSet object.
   ///
   Record *getInstructionSet() const;
index 9f0f155a7fcf6faaaaa166060ff0c8bf9af7b1fa..12667d5656f757263c24f2a63cda637e243b6fe5 100644 (file)
@@ -1604,17 +1604,8 @@ static std::string getLegalCName(std::string OpName) {
 void DAGISelEmitter::EmitInstructionSelector(std::ostream &OS) {
   const CodeGenTarget &Target = CGP.getTargetInfo();
   
-  // Get the namespace to insert instructions into.  Make sure not to pick up
-  // "TargetInstrInfo" by accidentally getting the namespace off the PHI
-  // instruction or something.
-  std::string InstNS;
-  for (CodeGenTarget::inst_iterator i = Target.inst_begin(),
-       e = Target.inst_end(); i != e; ++i) {
-    InstNS = i->second.Namespace;
-    if (InstNS != "TargetInstrInfo")
-      break;
-  }
-  
+  // Get the namespace to insert instructions into.
+  std::string InstNS = Target.getInstNamespace();
   if (!InstNS.empty()) InstNS += "::";
   
   // Group the patterns by their top-level opcodes.
index 9650ea8855b83d265b24423dd6f5baeaf893a639..7edd5fca420eeb33256b0aa2d1eb860442555b00 100644 (file)
@@ -157,13 +157,7 @@ void FastISelEmitter::run(std::ostream &OS) {
   // Get the namespace to insert instructions into.  Make sure not to pick up
   // "TargetInstrInfo" by accidentally getting the namespace off the PHI
   // instruction or something.
-  std::string InstNS;
-  for (CodeGenTarget::inst_iterator i = Target.inst_begin(),
-       e = Target.inst_end(); i != e; ++i) {
-    InstNS = i->second.Namespace;
-    if (InstNS != "TargetInstrInfo")
-      break;
-  }
+  std::string InstNS = Target.getInstNamespace();
 
   OS << "namespace llvm {\n";
   OS << "namespace " << InstNS << " {\n";