[llvm-commits] CVS: llvm-gcc/gcc/llvm-expand.c

Chris Lattner lattner at cs.uiuc.edu
Thu Nov 18 20:39:16 PST 2004



Changes in directory llvm-gcc/gcc:

llvm-expand.c updated: 1.56 -> 1.57
---
Log message:

Simplify debugging intrinsic support by inserting the initialization calls 
into the function when we start the function instead of inserting them after
the function is done being processed.  This allows us to print out a 
function before it is finished without triggering assertion failures in the
printer.


---
Diffs of the changes:  (+23 -52)

Index: llvm-gcc/gcc/llvm-expand.c
diff -u llvm-gcc/gcc/llvm-expand.c:1.56 llvm-gcc/gcc/llvm-expand.c:1.57
--- llvm-gcc/gcc/llvm-expand.c:1.56	Thu Nov 18 15:03:04 2004
+++ llvm-gcc/gcc/llvm-expand.c	Thu Nov 18 22:39:01 2004
@@ -71,7 +71,6 @@
 static void llvm_emit_dbg_declare(llvm_function *Fn, tree t);
 static void llvm_emit_region_end(llvm_function *Fn);
 static void llvm_emit_dbg_function_info(struct llvm_function *Fn);
-static void llvm_emit_dbg_function_start(llvm_function *Fn);
 
 /*===----------------------------------------------------------------------===**
               ... Helper functions for Instruction Emission ...
@@ -727,9 +726,7 @@
   llvm_basicblock *IndirectGotoBlock;
   
   /* Debug info */
-  llvm_instruction *dbg_call_funcstart_inst;
   llvm_value *dbg_global_memloc;
-  llvm_instruction *dbg_entry_alloca;
   int LastDebugLine, LastDebugCol;
   llvm_basicblock *LastDebugBB;
   
@@ -6905,13 +6902,6 @@
                    &DECL_SOURCE_LOCATION (decl), decl);
     }
 
-  /* emit global with info and call to function start intrinsic
-   *  do this after the body is expanded so when we insert at 
-   * the beginning, we don't get bumped later by alloca's.
-   */
-  if (debug_info_level > DINFO_LEVEL_NONE)
-    llvm_emit_dbg_function_start(Fn);
-
   /* Output the label for the actual return from the function. */
   llvm_emit_label(Fn, Fn->ExpandInfo->ReturnBlock);
 
@@ -7342,7 +7332,7 @@
   /* Infer language of file, stolen from dwarf2out.c */
   const char *language_string = lang_hooks.name;
   if (strcmp (language_string, "GNU C++") == 0)
-    LLVM_DEBUG_LANG_CODE = 0x0004; /*DW_LANG_C_plus_plus;*/                     
+    LLVM_DEBUG_LANG_CODE = 0x0004; /*DW_LANG_C_plus_plus;*/
   else if (strcmp (language_string, "GNU Ada") == 0)
     LLVM_DEBUG_LANG_CODE = 0x000d; /* DW_LANG_Ada95; */
   else if (strcmp (language_string, "GNU F77") == 0)
@@ -7392,9 +7382,6 @@
  * it sets a static variable in this file to allow other emitted
  * debug intrinsics to refer to that function.
  */
-/* static llvm_instruction *dbg_call_funcstart_inst; */
-/* static llvm_value *dbg_global_memloc = 0; */
-/* static llvm_instruction *dbg_entry_alloca = 0; */
 
 static llvm_global *dbg_func_info_global;
 
@@ -7406,6 +7393,11 @@
   llvm_global *funcNameStr = 0;
   llvm_value **Elements = 0; 
   llvm_instruction *gep = 0;
+  llvm_instruction *I, *AI;
+  llvm_basicblock *EntryBB = llvm_ilist_front(llvm_basicblock, Fn->BasicBlocks);
+  llvm_instruction *InsertPoint = llvm_ilist_begin(EntryBB->Instructions);
+  llvm_instruction *End = llvm_ilist_end(EntryBB->Instructions);
+
   
   funcNameStr = EmitGlobalString(func_name);
   Elements = (llvm_value**) xcalloc(7, sizeof(llvm_value*));
@@ -7429,38 +7421,11 @@
 
   dbg_func_info_global->Linkage = L_External;
   dbg_func_info_global->Init = CA;
-
   llvm_ilist_push_back(llvm_global, TheProgram.Globals, dbg_func_info_global);
 
-  Fn->ExpandInfo->dbg_entry_alloca = create_alloca_inst("dbg", 
-							ptrToEmptyStructTy, 
-							llvm_constant_uint_1); 
-  Fn->ExpandInfo->dbg_global_memloc = D2V(Fn->ExpandInfo->dbg_entry_alloca);
-
-}
-
-
-/* 
-   llvm_emit_dbg_function_start 
-   emits the instruction that was built in emit_dbg_function_info
- */
-static void llvm_emit_dbg_function_start(llvm_function *Fn) {
-  /* get start of first basic block. */
-  llvm_basicblock *entryBlock = llvm_ilist_front(llvm_basicblock, 
-						 Fn->BasicBlocks);
-
-  llvm_instruction *storeFuncCall = 0;
-
-  /* prep function.start call */
-
-  Fn->ExpandInfo->dbg_call_funcstart_inst = 
-    llvm_instruction_new(ptrToEmptyStructTy, "dbg", O_Call, 2);
-
-  Fn->ExpandInfo->dbg_call_funcstart_inst->Operands[0] = 
-    G2V(dbg_func_start_fn);
-  Fn->ExpandInfo->dbg_call_funcstart_inst->Operands[1] = 
-    G2V(dbg_func_info_global);
-
+  /* Insert the dbg chain start at the end of the allocas in the function. */
+  while (InsertPoint != End && InsertPoint->Opcode == O_Alloca)
+    InsertPoint = InsertPoint->Next;
 
   /* the 'alloca trick': 
      store into a memory location to force debug intrinsics to become SSA
@@ -7471,18 +7436,24 @@
      call dbg.func.start
      store
    */
-  storeFuncCall = create_store_inst(Fn->ExpandInfo->dbg_call_funcstart_inst,
-				    Fn->ExpandInfo->dbg_entry_alloca, 0);
 
-  llvm_ilist_push_front(llvm_instruction, entryBlock->Instructions, 
-			storeFuncCall);
-  llvm_ilist_push_front(llvm_instruction, entryBlock->Instructions, 
-			Fn->ExpandInfo->dbg_call_funcstart_inst);
-  llvm_ilist_push_front(llvm_instruction, entryBlock->Instructions, 
-			Fn->ExpandInfo->dbg_entry_alloca);
+  AI = I = create_alloca_inst("dbg", ptrToEmptyStructTy, llvm_constant_uint_1);
+  llvm_ilist_insert(llvm_instruction, EntryBB->Instructions, InsertPoint, I);
+  Fn->ExpandInfo->dbg_global_memloc = D2V(I);
+
+  /* Emit function.start call */
+  I = llvm_instruction_new(ptrToEmptyStructTy, "dbg", O_Call, 2);
+  I->Operands[0] = G2V(dbg_func_start_fn);
+  I->Operands[1] = G2V(dbg_func_info_global);
+  llvm_ilist_insert(llvm_instruction, EntryBB->Instructions, InsertPoint, I);
+
+  /* Store the result of the dbg.function.start call into the alloca. */
+  I = create_store_inst(D2V(I), D2V(AI), 0);
+  llvm_ilist_insert(llvm_instruction, EntryBB->Instructions, InsertPoint, I);
 }
 
 
+
 /* InitDebuggerTypeDecls inits type decls for debugger types,
  * declarations for debugger intrinsics 
  *    ^--- (some are currently unused in the generated bytecode)






More information about the llvm-commits mailing list