llvm.org GIT mirror llvm / 7e789a2
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_28@113912 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 9 years ago
2 changed file(s) with 41 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
1818
1919 #define DEBUG_TYPE "constmerge"
2020 #include "llvm/Transforms/IPO.h"
21 #include "llvm/Constants.h"
2122 #include "llvm/DerivedTypes.h"
2223 #include "llvm/Module.h"
2324 #include "llvm/Pass.h"
2425 #include "llvm/ADT/DenseMap.h"
26 #include "llvm/ADT/SmallPtrSet.h"
2527 #include "llvm/ADT/Statistic.h"
2628 using namespace llvm;
2729
4547
4648 ModulePass *llvm::createConstantMergePass() { return new ConstantMerge(); }
4749
50
51
52 /// Find values that are marked as llvm.used.
53 static void FindUsedValues(GlobalVariable *LLVMUsed,
54 SmallPtrSet &UsedValues) {
55 if (LLVMUsed == 0) return;
56 ConstantArray *Inits = dyn_cast(LLVMUsed->getInitializer());
57 if (Inits == 0) return;
58
59 for (unsigned i = 0, e = Inits->getNumOperands(); i != e; ++i)
60 if (GlobalValue *GV =
61 dyn_cast(Inits->getOperand(i)->stripPointerCasts()))
62 UsedValues.insert(GV);
63 }
64
4865 bool ConstantMerge::runOnModule(Module &M) {
66 // Find all the globals that are marked "used". These cannot be merged.
67 SmallPtrSet UsedGlobals;
68 FindUsedValues(M.getGlobalVariable("llvm.used"), UsedGlobals);
69 FindUsedValues(M.getGlobalVariable("llvm.compiler.used"), UsedGlobals);
70
4971 // Map unique constant/section pairs to globals. We don't want to merge
5072 // globals in different sections.
5173 DenseMap CMap;
78100
79101 // Only process constants with initializers in the default addres space.
80102 if (!GV->isConstant() ||!GV->hasDefinitiveInitializer() ||
81 GV->getType()->getAddressSpace() != 0 || !GV->getSection().empty())
103 GV->getType()->getAddressSpace() != 0 || !GV->getSection().empty() ||
104 // Don't touch values marked with attribute(used).
105 UsedGlobals.count(GV))
82106 continue;
107
108
83109
84110 Constant *Init = GV->getInitializer();
85111
2727 store i32 addrspace(30)* @T2b, i32 addrspace(30)** %P2
2828 ret void
2929 }
30
31 ; PR8144 - Don't merge globals marked attribute(used)
32 ; CHECK: @T3A =
33 ; CHECK: @T3B =
34
35 @T3A = internal constant i32 0
36 @T3B = internal constant i32 0
37 @llvm.used = appending global [2 x i32*] [i32* @T3A, i32* @T3B], section
38 "llvm.metadata"
39
40 define void @test3() {
41 call void asm sideeffect "T3A, T3B",""() ; invisible use of T3A and T3B
42 ret void
43 }