[llvm-commits] CVS: llvm-gcc/gcc/llvm-representation.h llvm-expand.c llvm-representation.c
Chris Lattner
lattner at cs.uiuc.edu
Sat Nov 27 23:54:57 PST 2004
Changes in directory llvm-gcc/gcc:
llvm-representation.h updated: 1.11 -> 1.12
llvm-expand.c updated: 1.69 -> 1.70
llvm-representation.c updated: 1.14 -> 1.15
---
Log message:
Implement new MarkLLVMNameAsUsed function, remove old MarkNameAsUsed function.
Reimplement PR459: http://llvm.cs.uiuc.edu/PR459 , lazily emitting inline functions instead of emitting them
all.
---
Diffs of the changes: (+56 -17)
Index: llvm-gcc/gcc/llvm-representation.h
diff -u llvm-gcc/gcc/llvm-representation.h:1.11 llvm-gcc/gcc/llvm-representation.h:1.12
--- llvm-gcc/gcc/llvm-representation.h:1.11 Sat Nov 27 17:00:16 2004
+++ llvm-gcc/gcc/llvm-representation.h Sun Nov 28 01:54:45 2004
@@ -67,6 +67,11 @@
it now. */
llvm_value *llvm_get_global_alias(const char *ExternalName);
+/* MarkLLVMNameAsUsed - This is used to implement lazy emission of inline
+ * functions. Whenever we "emit" a reference to a global, call this to tell GCC
+ * that the global was used.
+ */
+void MarkLLVMNameAsUsed(llvm_value*);
/*===---------------------------------------------------------------------===*/
Index: llvm-gcc/gcc/llvm-expand.c
diff -u llvm-gcc/gcc/llvm-expand.c:1.69 llvm-gcc/gcc/llvm-expand.c:1.70
--- llvm-gcc/gcc/llvm-expand.c:1.69 Sun Nov 28 00:34:18 2004
+++ llvm-gcc/gcc/llvm-expand.c Sun Nov 28 01:54:45 2004
@@ -7106,15 +7106,34 @@
if (!DECL_LLVM_SET_P(decl))
llvm_make_decl_llvm(decl, asmspec);
+}
+
+/* This horrible code mirrors code found in varasm.c:assemble_name. It
+ basically marks all external names that are used by the program as
+ REFERENCED, which, if the name corresponds to an inline function, causes the
+ inline function to be code generated for this translation unit. */
+void MarkLLVMNameAsUsed(llvm_value *V) {
+ const char *Name = V->Name;
+ tree id;
- if (DECL_LLVM_SET_P(decl)) { /* Ignore builtin functions */
- /* This horrible code mirrors code found in varasm.c:assemble_name */
- if (!llvm_value_is_global(DECL_LLVM(decl))) abort();
- MarkNameAsUsed(DECL_LLVM(decl)->Name);
+ /* We only need to do this once for each global, and the code below isn't
+ * particularly fast, so keep track of whether we've done this already or not.
+ */
+ if (V->VTy == Function) {
+ if (V2F(V)->MarkedNameUsed) return;
+ V2F(V)->MarkedNameUsed = 1;
+ } else {
+ assert(V->VTy == GlobalVariable && "Only functions and gv's go here!");
+ if (V2GV(V)->MarkedNameUsed) return;
+ V2GV(V)->MarkedNameUsed = 1;
}
+
+ id = maybe_get_identifier(Name);
+ if (id) mark_referenced(id);
}
+
/* llvm_assemble_external - This function is called once for each external
* function and variable as they are used.
*/
@@ -7221,6 +7240,8 @@
/* An initializer was specified for the global */
if (TREE_CODE(DECL_INITIAL(decl)) != STRING_CST) {
G->Init = llvm_expand_constant_expr(DECL_INITIAL(decl), BaseTy);
+ if (llvm_value_is_global(D2V(G->Init)))
+ MarkLLVMNameAsUsed(D2V(G->Init));
} else {
/* Handle string initializers specially to allow zero padding the end. */
llvm_type *BaseTy = GET_POINTER_TYPE_ELEMENT(G2V(G)->Ty);
@@ -7644,7 +7665,7 @@
llvm_instruction *store_dbg_inst;
llvm_basicblock *CurBB = 0;
- // If we're not emitting debug info, just bypass this.
+ /* If we're not emitting debug info, just bypass this. */
if (debug_info_level <= DINFO_LEVEL_NONE)
return;
Index: llvm-gcc/gcc/llvm-representation.c
diff -u llvm-gcc/gcc/llvm-representation.c:1.14 llvm-gcc/gcc/llvm-representation.c:1.15
--- llvm-gcc/gcc/llvm-representation.c:1.14 Sun Nov 28 00:34:18 2004
+++ llvm-gcc/gcc/llvm-representation.c Sun Nov 28 01:54:45 2004
@@ -259,19 +259,10 @@
/* This horrible code mirrors code found in varasm.c:assemble_name. This code
* allows GCC to notice that we are emitting a reference to a function or
* global. If the fn/global is inline, this will cause its body to be
- * compiled to LLVM and emitted. We only need to do this once for each
- * global, and the MarkNameAsUsed code isn't particularly fast, so keep track
- * of whether we've done this already or not.
+ * compiled to LLVM and emitted.
*/
-#if 0
- if (V->VTy == Function && !V2F(V)->MarkedNameUsed) {
- V2F(V)->MarkedNameUsed = 1;
- MarkNameAsUsed(V->Name);
- } else if (V->VTy == GlobalVariable && !V2GV(V)->MarkedNameUsed) {
- V2GV(V)->MarkedNameUsed = 1;
- MarkNameAsUsed(V->Name);
- }
-#endif
+ if (llvm_value_is_global(V))
+ MarkLLVMNameAsUsed(V);
}
/* llvm_constant implementation ********************************************
@@ -370,10 +361,16 @@
/* llvm_constant_expr implementation ******************************************
*/
llvm_constant_expr *llvm_constant_expr_new(llvm_instruction *I) {
+ unsigned i;
llvm_constant_expr *CE =
(llvm_constant_expr*)xcalloc(sizeof(llvm_constant_expr), 1);
llvm_constant_construct(G2C(CE), D2V(I)->Ty, "", ConstantExpr, "");
CE->Inst = I;
+
+
+ for (i = 0; i != I->NumOperands; ++i)
+ if (llvm_value_is_global(I->Operands[i]))
+ MarkLLVMNameAsUsed(I->Operands[i]);
return CE;
}
@@ -446,8 +443,24 @@
llvm_value **Init) {
llvm_constant_aggregate *CA =
(llvm_constant_aggregate*)xcalloc(sizeof(llvm_constant_aggregate), 1);
+ unsigned Size, i;
llvm_constant_construct(G2C(CA), Ty, "", ConstantAggregate, "");
CA->Initializers = Init;
+
+ /* If any of the initializers is a global, make sure we recognize it for
+ * emission.
+ */
+ if (Ty->ID == StructTyID) {
+ Size = Ty->NumElements;
+ } else {
+ assert(Ty->ID == ArrayTyID && "Invalid composite type!");
+ Size = Ty->x.Array.Size;
+ }
+
+ for (i = 0; i != Size; ++i)
+ if (llvm_value_is_global(Init[i]))
+ MarkLLVMNameAsUsed(Init[i]);
+
return CA;
}
More information about the llvm-commits
mailing list