[llvm-commits] [llvm-gcc-4.2] r41738 - in /llvm-gcc-4.2/trunk/gcc: llvm-backend.cpp llvm-convert.cpp llvm-internal.h

Devang Patel dpatel at apple.com
Wed Sep 5 17:26:47 PDT 2007


Author: dpatel
Date: Wed Sep  5 19:26:45 2007
New Revision: 41738

URL: http://llvm.org/viewvc/llvm-project?rev=41738&view=rev
Log:
Replace GV from AttributeUsedGlobals list.

Modified:
    llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp
    llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
    llvm-gcc-4.2/trunk/gcc/llvm-internal.h

Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp?rev=41738&r1=41737&r2=41738&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Wed Sep  5 19:26:45 2007
@@ -85,7 +85,7 @@
 static cl::opt<bool> DisableLLVMOptimizations("disable-llvm-optzns");
 
 std::vector<std::pair<Function*, int> > StaticCtors, StaticDtors;
-std::vector<Constant*> AttributeUsedGlobals;
+SmallPtrSet<Constant*, 32> AttributeUsedGlobals;
 std::vector<Constant*> AttributeNoinlineFunctions;
 std::vector<Constant*> AttributeAnnotateGlobals;
 
@@ -440,6 +440,7 @@
 
   createOptimizationPasses();
   
+  AttributeUsedGlobals.clear();
   timevar_pop(TV_LLVM_INIT);
 }
 
@@ -480,9 +481,16 @@
     CreateStructorsList(StaticDtors, "llvm.global_dtors");
   
   if (!AttributeUsedGlobals.empty()) {
-    const Type *SBP = PointerType::get(Type::Int8Ty);
-    ArrayType *AT = ArrayType::get(SBP, AttributeUsedGlobals.size());
-    Constant *Init = ConstantArray::get(AT, AttributeUsedGlobals);
+    std::vector<Constant *> AUGs;
+    const Type *SBP= PointerType::get(Type::Int8Ty);
+    for (SmallPtrSet<Constant *,32>::iterator AI = AttributeUsedGlobals.begin(),
+           AE = AttributeUsedGlobals.end(); AI != AE; ++AI) {
+      Constant *C = *AI;
+      AUGs.push_back(ConstantExpr::getBitCast(C, SBP));
+    }
+
+    ArrayType *AT = ArrayType::get(SBP, AUGs.size());
+    Constant *Init = ConstantArray::get(AT, AUGs);
     GlobalValue *gv = new GlobalVariable(AT, false, 
                        GlobalValue::AppendingLinkage, Init,
                        "llvm.used", TheModule);
@@ -806,6 +814,10 @@
                                              GlobalValue::ExternalLinkage, 0,
                                              GV->getName(), TheModule);
     GV->replaceAllUsesWith(ConstantExpr::getBitCast(NGV, GV->getType()));
+    if (AttributeUsedGlobals.count(GV)) {
+      AttributeUsedGlobals.erase(GV);
+      AttributeUsedGlobals.insert(NGV);
+    }
     delete GV;
     SET_DECL_LLVM(decl, NGV);
     GV = NGV;
@@ -865,10 +877,8 @@
     }
 
     // Handle used decls
-    if (DECL_PRESERVE_P (decl)) {
-      const Type *SBP= PointerType::get(Type::Int8Ty);
-      AttributeUsedGlobals.push_back(ConstantExpr::getBitCast(GV, SBP));
-    }
+    if (DECL_PRESERVE_P (decl))
+      AttributeUsedGlobals.insert(GV);
   
     // Add annotate attributes for globals
     if (DECL_ATTRIBUTES(decl))

Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=41738&r1=41737&r2=41738&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Wed Sep  5 19:26:45 2007
@@ -622,10 +622,8 @@
     Fn->setSection(TREE_STRING_POINTER(DECL_SECTION_NAME(FnDecl)));
 
   // Handle used Functions
-  if (DECL_PRESERVE_P (FnDecl)) {
-    const Type *SBP= PointerType::get(Type::Int8Ty);
-    AttributeUsedGlobals.push_back(ConstantExpr::getBitCast(Fn,SBP));
-  }
+  if (DECL_PRESERVE_P (FnDecl))
+    AttributeUsedGlobals.insert(Fn);
   
   // Handle noinline Functions
   if (lookup_attribute ("noinline", DECL_ATTRIBUTES (FnDecl))) {

Modified: llvm-gcc-4.2/trunk/gcc/llvm-internal.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-internal.h?rev=41738&r1=41737&r2=41738&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-internal.h (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-internal.h Wed Sep  5 19:26:45 2007
@@ -35,6 +35,7 @@
 #include "llvm/Intrinsics.h"
 #include "llvm/ADT/IndexedMap.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/LLVMBuilder.h"
 #include "llvm/Support/Streams.h"
@@ -91,7 +92,7 @@
 extern std::vector<std::pair<Function*, int> > StaticCtors, StaticDtors;
 
 /// AttributeUsedGlobals - The list of globals that are marked attribute(used).
-extern std::vector<Constant*> AttributeUsedGlobals;
+extern SmallPtrSet<Constant *,32> AttributeUsedGlobals;
 
 /// AttributeNoinlineFunctions - The list of functions that are 
 /// marked attribute(noinline)





More information about the llvm-commits mailing list