[llvm-branch-commits] [llvm-branch] r113912 - in /llvm/branches/release_28: ./ lib/Transforms/IPO/ConstantMerge.cpp test/Transforms/ConstantMerge/dont-merge.ll

Bill Wendling isanbard at gmail.com
Tue Sep 14 17:32:05 PDT 2010


Author: void
Date: Tue Sep 14 19:32:05 2010
New Revision: 113912

URL: http://llvm.org/viewvc/llvm-project?rev=113912&view=rev
Log:
Approved by Chris:

$ svn merge -c 113911 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r113911 into '.':
U    test/Transforms/ConstantMerge/dont-merge.ll
U    lib/Transforms/IPO/ConstantMerge.cpp


Modified:
    llvm/branches/release_28/   (props changed)
    llvm/branches/release_28/lib/Transforms/IPO/ConstantMerge.cpp
    llvm/branches/release_28/test/Transforms/ConstantMerge/dont-merge.ll

Propchange: llvm/branches/release_28/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Sep 14 19:32:05 2010
@@ -1,2 +1,2 @@
 /llvm/branches/Apple/Pertwee:110850,110961
-/llvm/trunk:113057,113109,113123,113146,113158,113255,113257,113260,113297,113299,113303,113322,113345,113365-113366,113394,113483-113485,113557,113576,113637,113764,113820,113828,113894
+/llvm/trunk:113057,113109,113123,113146,113158,113255,113257,113260,113297,113299,113303,113322,113345,113365-113366,113394,113483-113485,113557,113576,113637,113764,113820,113828,113894,113911

Modified: llvm/branches/release_28/lib/Transforms/IPO/ConstantMerge.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_28/lib/Transforms/IPO/ConstantMerge.cpp?rev=113912&r1=113911&r2=113912&view=diff
==============================================================================
--- llvm/branches/release_28/lib/Transforms/IPO/ConstantMerge.cpp (original)
+++ llvm/branches/release_28/lib/Transforms/IPO/ConstantMerge.cpp Tue Sep 14 19:32:05 2010
@@ -19,10 +19,12 @@
 
 #define DEBUG_TYPE "constmerge"
 #include "llvm/Transforms/IPO.h"
+#include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
 #include "llvm/Pass.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/Statistic.h"
 using namespace llvm;
 
@@ -46,7 +48,27 @@
 
 ModulePass *llvm::createConstantMergePass() { return new ConstantMerge(); }
 
+
+
+/// Find values that are marked as llvm.used.
+static void FindUsedValues(GlobalVariable *LLVMUsed,
+                           SmallPtrSet<const GlobalValue*, 8> &UsedValues) {
+  if (LLVMUsed == 0) return;
+  ConstantArray *Inits = dyn_cast<ConstantArray>(LLVMUsed->getInitializer());
+  if (Inits == 0) return;
+  
+  for (unsigned i = 0, e = Inits->getNumOperands(); i != e; ++i)
+    if (GlobalValue *GV = 
+        dyn_cast<GlobalValue>(Inits->getOperand(i)->stripPointerCasts()))
+      UsedValues.insert(GV);
+}
+
 bool ConstantMerge::runOnModule(Module &M) {
+  // Find all the globals that are marked "used".  These cannot be merged.
+  SmallPtrSet<const GlobalValue*, 8> UsedGlobals;
+  FindUsedValues(M.getGlobalVariable("llvm.used"), UsedGlobals);
+  FindUsedValues(M.getGlobalVariable("llvm.compiler.used"), UsedGlobals);
+  
   // Map unique constant/section pairs to globals.  We don't want to merge
   // globals in different sections.
   DenseMap<Constant*, GlobalVariable*> CMap;
@@ -79,9 +101,13 @@
       
       // Only process constants with initializers in the default addres space.
       if (!GV->isConstant() ||!GV->hasDefinitiveInitializer() ||
-          GV->getType()->getAddressSpace() != 0 || !GV->getSection().empty())
+          GV->getType()->getAddressSpace() != 0 || !GV->getSection().empty() ||
+          // Don't touch values marked with attribute(used).
+          UsedGlobals.count(GV))
         continue;
       
+      
+      
       Constant *Init = GV->getInitializer();
 
       // Check to see if the initializer is already known.

Modified: llvm/branches/release_28/test/Transforms/ConstantMerge/dont-merge.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_28/test/Transforms/ConstantMerge/dont-merge.ll?rev=113912&r1=113911&r2=113912&view=diff
==============================================================================
--- llvm/branches/release_28/test/Transforms/ConstantMerge/dont-merge.ll (original)
+++ llvm/branches/release_28/test/Transforms/ConstantMerge/dont-merge.ll Tue Sep 14 19:32:05 2010
@@ -28,3 +28,17 @@
         store i32 addrspace(30)*  @T2b, i32 addrspace(30)** %P2
         ret void
 }
+
+; PR8144 - Don't merge globals marked attribute(used)
+; CHECK: @T3A = 
+; CHECK: @T3B = 
+
+ at T3A = internal constant i32 0
+ at T3B = internal constant i32 0
+ at llvm.used = appending global [2 x i32*] [i32* @T3A, i32* @T3B], section
+"llvm.metadata"
+
+define void @test3() {
+  call void asm sideeffect "T3A, T3B",""() ; invisible use of T3A and T3B
+  ret void
+}





More information about the llvm-branch-commits mailing list