comparison lib/Transforms/IPO/StripSymbols.cpp @ 80:67baa08a3894

update to LLVM 3.6
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Thu, 25 Sep 2014 16:56:18 +0900
parents 54457678186b
children 60c9769439b8
comparison
equal deleted inserted replaced
76:9e74acfe8c42 80:67baa08a3894
21 //===----------------------------------------------------------------------===// 21 //===----------------------------------------------------------------------===//
22 22
23 #include "llvm/Transforms/IPO.h" 23 #include "llvm/Transforms/IPO.h"
24 #include "llvm/ADT/DenseMap.h" 24 #include "llvm/ADT/DenseMap.h"
25 #include "llvm/ADT/SmallPtrSet.h" 25 #include "llvm/ADT/SmallPtrSet.h"
26 #include "llvm/DebugInfo.h"
27 #include "llvm/IR/Constants.h" 26 #include "llvm/IR/Constants.h"
27 #include "llvm/IR/DebugInfo.h"
28 #include "llvm/IR/DerivedTypes.h" 28 #include "llvm/IR/DerivedTypes.h"
29 #include "llvm/IR/Instructions.h" 29 #include "llvm/IR/Instructions.h"
30 #include "llvm/IR/Module.h" 30 #include "llvm/IR/Module.h"
31 #include "llvm/IR/TypeFinder.h" 31 #include "llvm/IR/TypeFinder.h"
32 #include "llvm/IR/ValueSymbolTable.h" 32 #include "llvm/IR/ValueSymbolTable.h"
42 explicit StripSymbols(bool ODI = false) 42 explicit StripSymbols(bool ODI = false)
43 : ModulePass(ID), OnlyDebugInfo(ODI) { 43 : ModulePass(ID), OnlyDebugInfo(ODI) {
44 initializeStripSymbolsPass(*PassRegistry::getPassRegistry()); 44 initializeStripSymbolsPass(*PassRegistry::getPassRegistry());
45 } 45 }
46 46
47 virtual bool runOnModule(Module &M); 47 bool runOnModule(Module &M) override;
48 48
49 virtual void getAnalysisUsage(AnalysisUsage &AU) const { 49 void getAnalysisUsage(AnalysisUsage &AU) const override {
50 AU.setPreservesAll(); 50 AU.setPreservesAll();
51 } 51 }
52 }; 52 };
53 53
54 class StripNonDebugSymbols : public ModulePass { 54 class StripNonDebugSymbols : public ModulePass {
57 explicit StripNonDebugSymbols() 57 explicit StripNonDebugSymbols()
58 : ModulePass(ID) { 58 : ModulePass(ID) {
59 initializeStripNonDebugSymbolsPass(*PassRegistry::getPassRegistry()); 59 initializeStripNonDebugSymbolsPass(*PassRegistry::getPassRegistry());
60 } 60 }
61 61
62 virtual bool runOnModule(Module &M); 62 bool runOnModule(Module &M) override;
63 63
64 virtual void getAnalysisUsage(AnalysisUsage &AU) const { 64 void getAnalysisUsage(AnalysisUsage &AU) const override {
65 AU.setPreservesAll(); 65 AU.setPreservesAll();
66 } 66 }
67 }; 67 };
68 68
69 class StripDebugDeclare : public ModulePass { 69 class StripDebugDeclare : public ModulePass {
72 explicit StripDebugDeclare() 72 explicit StripDebugDeclare()
73 : ModulePass(ID) { 73 : ModulePass(ID) {
74 initializeStripDebugDeclarePass(*PassRegistry::getPassRegistry()); 74 initializeStripDebugDeclarePass(*PassRegistry::getPassRegistry());
75 } 75 }
76 76
77 virtual bool runOnModule(Module &M); 77 bool runOnModule(Module &M) override;
78 78
79 virtual void getAnalysisUsage(AnalysisUsage &AU) const { 79 void getAnalysisUsage(AnalysisUsage &AU) const override {
80 AU.setPreservesAll(); 80 AU.setPreservesAll();
81 } 81 }
82 }; 82 };
83 83
84 class StripDeadDebugInfo : public ModulePass { 84 class StripDeadDebugInfo : public ModulePass {
87 explicit StripDeadDebugInfo() 87 explicit StripDeadDebugInfo()
88 : ModulePass(ID) { 88 : ModulePass(ID) {
89 initializeStripDeadDebugInfoPass(*PassRegistry::getPassRegistry()); 89 initializeStripDeadDebugInfoPass(*PassRegistry::getPassRegistry());
90 } 90 }
91 91
92 virtual bool runOnModule(Module &M); 92 bool runOnModule(Module &M) override;
93 93
94 virtual void getAnalysisUsage(AnalysisUsage &AU) const { 94 void getAnalysisUsage(AnalysisUsage &AU) const override {
95 AU.setPreservesAll(); 95 AU.setPreservesAll();
96 } 96 }
97 }; 97 };
98 } 98 }
99 99
130 return new StripDeadDebugInfo(); 130 return new StripDeadDebugInfo();
131 } 131 }
132 132
133 /// OnlyUsedBy - Return true if V is only used by Usr. 133 /// OnlyUsedBy - Return true if V is only used by Usr.
134 static bool OnlyUsedBy(Value *V, Value *Usr) { 134 static bool OnlyUsedBy(Value *V, Value *Usr) {
135 for(Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I) { 135 for (User *U : V->users())
136 User *U = *I;
137 if (U != Usr) 136 if (U != Usr)
138 return false; 137 return false;
139 } 138
140 return true; 139 return true;
141 } 140 }
142 141
143 static void RemoveDeadConstant(Constant *C) { 142 static void RemoveDeadConstant(Constant *C) {
144 assert(C->use_empty() && "Constant is not dead!"); 143 assert(C->use_empty() && "Constant is not dead!");
153 else if (!isa<Function>(C)) 152 else if (!isa<Function>(C))
154 if (isa<CompositeType>(C->getType())) 153 if (isa<CompositeType>(C->getType()))
155 C->destroyConstant(); 154 C->destroyConstant();
156 155
157 // If the constant referenced anything, see if we can delete it as well. 156 // If the constant referenced anything, see if we can delete it as well.
158 for (SmallPtrSet<Constant*, 4>::iterator OI = Operands.begin(), 157 for (Constant *O : Operands)
159 OE = Operands.end(); OI != OE; ++OI) 158 RemoveDeadConstant(O);
160 RemoveDeadConstant(*OI);
161 } 159 }
162 160
163 // Strip the symbol table of its names. 161 // Strip the symbol table of its names.
164 // 162 //
165 static void StripSymtab(ValueSymbolTable &ST, bool PreserveDbgInfo) { 163 static void StripSymtab(ValueSymbolTable &ST, bool PreserveDbgInfo) {
190 } 188 }
191 } 189 }
192 190
193 /// Find values that are marked as llvm.used. 191 /// Find values that are marked as llvm.used.
194 static void findUsedValues(GlobalVariable *LLVMUsed, 192 static void findUsedValues(GlobalVariable *LLVMUsed,
195 SmallPtrSet<const GlobalValue*, 8> &UsedValues) { 193 SmallPtrSetImpl<const GlobalValue*> &UsedValues) {
196 if (LLVMUsed == 0) return; 194 if (!LLVMUsed) return;
197 UsedValues.insert(LLVMUsed); 195 UsedValues.insert(LLVMUsed);
198 196
199 ConstantArray *Inits = cast<ConstantArray>(LLVMUsed->getInitializer()); 197 ConstantArray *Inits = cast<ConstantArray>(LLVMUsed->getInitializer());
200 198
201 for (unsigned i = 0, e = Inits->getNumOperands(); i != e; ++i) 199 for (unsigned i = 0, e = Inits->getNumOperands(); i != e; ++i)
248 Function *Declare = M.getFunction("llvm.dbg.declare"); 246 Function *Declare = M.getFunction("llvm.dbg.declare");
249 std::vector<Constant*> DeadConstants; 247 std::vector<Constant*> DeadConstants;
250 248
251 if (Declare) { 249 if (Declare) {
252 while (!Declare->use_empty()) { 250 while (!Declare->use_empty()) {
253 CallInst *CI = cast<CallInst>(Declare->use_back()); 251 CallInst *CI = cast<CallInst>(Declare->user_back());
254 Value *Arg1 = CI->getArgOperand(0); 252 Value *Arg1 = CI->getArgOperand(0);
255 Value *Arg2 = CI->getArgOperand(1); 253 Value *Arg2 = CI->getArgOperand(1);
256 assert(CI->use_empty() && "llvm.dbg intrinsic should have void result"); 254 assert(CI->use_empty() && "llvm.dbg intrinsic should have void result");
257 CI->eraseFromParent(); 255 CI->eraseFromParent();
258 if (Arg1->use_empty()) { 256 if (Arg1->use_empty()) {
305 // with the live list. 303 // with the live list.
306 SmallVector<Value *, 64> LiveGlobalVariables; 304 SmallVector<Value *, 64> LiveGlobalVariables;
307 SmallVector<Value *, 64> LiveSubprograms; 305 SmallVector<Value *, 64> LiveSubprograms;
308 DenseSet<const MDNode *> VisitedSet; 306 DenseSet<const MDNode *> VisitedSet;
309 307
310 for (DebugInfoFinder::iterator CI = F.compile_unit_begin(), 308 for (DICompileUnit DIC : F.compile_units()) {
311 CE = F.compile_unit_end(); CI != CE; ++CI) {
312 // Create our compile unit.
313 DICompileUnit DIC(*CI);
314 assert(DIC.Verify() && "DIC must verify as a DICompileUnit."); 309 assert(DIC.Verify() && "DIC must verify as a DICompileUnit.");
315 310
316 // Create our live subprogram list. 311 // Create our live subprogram list.
317 DIArray SPs = DIC.getSubprograms(); 312 DIArray SPs = DIC.getSubprograms();
318 bool SubprogramChange = false; 313 bool SubprogramChange = false;