Print debug location when JIT encounters inline asm

Yaron Keren yaron.keren at gmail.com
Wed Apr 2 06:26:52 PDT 2014


When JITting a large project such as Boost it's quite hard to figure out
the problematic inline asm without debug location. This patch provides
debug location printout before the JIT aborts due to inline asm.

printDebugLoc() was exposed from MachineInstr.cpp and reused here.

Yaron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140402/c67cbd0d/attachment.html>
-------------- next part --------------
Index: lib/Target/X86/X86CodeEmitter.cpp
===================================================================
--- lib/Target/X86/X86CodeEmitter.cpp	(revision 205331)
+++ lib/Target/X86/X86CodeEmitter.cpp	(working copy)
@@ -1112,8 +1112,16 @@
     case TargetOpcode::INLINEASM:
       // We allow inline assembler nodes with empty bodies - they can
       // implicitly define registers, which is ok for JIT.
-      if (MI.getOperand(0).getSymbolName()[0])
+      if (MI.getOperand(0).getSymbolName()[0]) {
+        DebugLoc DL = MI.getDebugLoc();
+        if (const MachineBasicBlock *MBB = MI.getParent()) {
+          if (const MachineFunction *MF = MBB->getParent()) {
+            printDebugLoc(DL, MF, llvm::errs());
+            llvm::errs() << '\n';
+          }
+        }
         report_fatal_error("JIT does not support inline asm!");
+      }
       break;
     case TargetOpcode::CFI_INSTRUCTION:
       break;
Index: include/llvm/CodeGen/MachineInstr.h
===================================================================
--- include/llvm/CodeGen/MachineInstr.h	(revision 205331)
+++ include/llvm/CodeGen/MachineInstr.h	(working copy)
@@ -1124,6 +1124,9 @@
   return OS;
 }
 
+void printDebugLoc(DebugLoc DL, const MachineFunction *MF,
+                   raw_ostream &CommentOS);
+
 } // End llvm namespace
 
 #endif
Index: lib/CodeGen/MachineInstr.cpp
===================================================================
--- lib/CodeGen/MachineInstr.cpp	(revision 205331)
+++ lib/CodeGen/MachineInstr.cpp	(working copy)
@@ -1445,7 +1445,8 @@
 #endif
 }
 
-static void printDebugLoc(DebugLoc DL, const MachineFunction *MF,
+namespace llvm {
+void printDebugLoc(DebugLoc DL, const MachineFunction *MF,
                          raw_ostream &CommentOS) {
   const LLVMContext &Ctx = MF->getFunction()->getContext();
   if (!DL.isUnknown()) {          // Print source line info.
@@ -1468,6 +1469,7 @@
     }
   }
 }
+}
 
 void MachineInstr::print(raw_ostream &OS, const TargetMachine *TM,
                          bool SkipOpers) const {


More information about the llvm-commits mailing list