LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 1001 - DAGISelEmitter not looking up instruction namespace accurately.
Summary: DAGISelEmitter not looking up instruction namespace accurately.
Status: RESOLVED FIXED
Alias: None
Product: tools
Classification: Unclassified
Component: TableGen (show other bugs)
Version: trunk
Hardware: PC Linux
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords: build-problem
Depends on:
Blocks:
 
Reported: 2006-11-11 00:28 PST by Nikhil Patil
Modified: 2010-02-22 12:53 PST (History)
1 user (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nikhil Patil 2006-11-11 00:28:54 PST
I was trying to write my own simple LLVM backend for my own simple ISA when I 
ran into the following error message:

MCGenDAGISel.inc: In member function 
'llvm::SDNode*<unnamed>::MCDAGToDAGISel::SelectCode(llvm::SDOperand)':
MCGenDAGISel.inc:463: error: 'INSTRUCTION_LIST_END' is not a member of 
'llvm::TargetInstrInfo'

My target description had only one instruction NOP. The problem disappears when 
I change NOP to ADD. In fact anything *alphabetically* before INLINEASM is 
okay. (INLINEASM & PHINODE are in namespace TargetInstrInfo.) I have traced 
down the problem to utils/TableGen/DAGISelEmitter.cpp:3390, where we only look 
at the first instruction in the list of all instructions. So if there happen to 
be no instructions alphabetically before INLINEASM, we get screwed.

Please let me know if you need any more information :)
Comment 1 Chris Lattner 2006-11-11 16:33:03 PST
This looks like a relatively easy bug to fix, but a hard one for me to test without an example.  Can you 
propose a patch please?

Thanks,

-Chris
Comment 2 Nikhil Patil 2006-11-13 21:19:47 PST
There's two ways. (I think I'd prefer (a).)

(a) Check for TargetInstrInfo explicitly
 
--- DAGISelEmitter.cpp  8 Nov 2006 23:01:03 -0000       1.281
+++ DAGISelEmitter.cpp  14 Nov 2006 03:11:13 -0000
@@ -3387,7 +3387,13 @@
 }
 
 void DAGISelEmitter::EmitInstructionSelector(std::ostream &OS) {
-  std::string InstNS = Target.inst_begin()->second.Namespace;
+  std::string InstNS;
+  CodeGenTarget::inst_iterator i;
+  for (i = Target.inst_begin(); i != Target.inst_end(); ++i) {
+    InstNS = i->second.Namespace;
+    if (InstNS != "TargetInstrInfo")
+       break;
+  }
   if (!InstNS.empty()) InstNS += "::";
   
   // Group the patterns by their top-level opcodes.

-------------------------------------------------------------------

(b) Check for INLINEASM & PHI explicitly:

diff -u -r1.281 DAGISelEmitter.cpp
--- DAGISelEmitter.cpp  8 Nov 2006 23:01:03 -0000       1.281
+++ DAGISelEmitter.cpp  14 Nov 2006 03:16:36 -0000
@@ -3387,7 +3387,15 @@
 }
 
 void DAGISelEmitter::EmitInstructionSelector(std::ostream &OS) {
-  std::string InstNS = Target.inst_begin()->second.Namespace;
+  std::string InstNS;
+  CodeGenTarget::inst_iterator i;
+  for (i = Target.inst_begin(); i != Target.inst_end(); ++i) {
+    std::string name = i->second.TheDef->getName();
+    if (name != "INLINEASM" && name != "PHI") {
+       InstNS = i->second.Namespace;
+       break;
+    }
+  }
   if (!InstNS.empty()) InstNS += "::";
   
   // Group the patterns by their top-level opcodes.
-----------------------------------------------------------------------

Thanks,
Comment 3 Chris Lattner 2006-11-20 12:55:25 PST
Option #1 sounds good to me!  Thanks, I applied your patch:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20061120/040138.html

Thanks,

-Chris