Fix PR1001, patch by Nikhil Patil!
[oota-llvm.git] / utils / TableGen / DAGISelEmitter.cpp
index 1acd549b1f73c26eed8d1d4be8c086eb50516c2a..0b176088a0e20a87c5a4411adcc481dacad8af4b 100644 (file)
@@ -3408,7 +3408,17 @@ static std::string getLegalCName(std::string OpName) {
 }
 
 void DAGISelEmitter::EmitInstructionSelector(std::ostream &OS) {
-  std::string InstNS = Target.inst_begin()->second.Namespace;
+  // 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;
+  }
+  
   if (!InstNS.empty()) InstNS += "::";
   
   // Group the patterns by their top-level opcodes.