comparison lib/Transforms/IPO/FunctionAttrs.cpp @ 83:60c9769439b8 LLVM3.7

LLVM 3.7
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Wed, 18 Feb 2015 14:55:36 +0900
parents 54457678186b
children afa8332a0e37
comparison
equal deleted inserted replaced
78:af83660cff7b 83:60c9769439b8
29 #include "llvm/Analysis/CaptureTracking.h" 29 #include "llvm/Analysis/CaptureTracking.h"
30 #include "llvm/IR/GlobalVariable.h" 30 #include "llvm/IR/GlobalVariable.h"
31 #include "llvm/IR/InstIterator.h" 31 #include "llvm/IR/InstIterator.h"
32 #include "llvm/IR/IntrinsicInst.h" 32 #include "llvm/IR/IntrinsicInst.h"
33 #include "llvm/IR/LLVMContext.h" 33 #include "llvm/IR/LLVMContext.h"
34 #include "llvm/Target/TargetLibraryInfo.h" 34 #include "llvm/Analysis/TargetLibraryInfo.h"
35 using namespace llvm; 35 using namespace llvm;
36 36
37 #define DEBUG_TYPE "functionattrs" 37 #define DEBUG_TYPE "functionattrs"
38 38
39 STATISTIC(NumReadNone, "Number of functions marked readnone"); 39 STATISTIC(NumReadNone, "Number of functions marked readnone");
122 bool annotateLibraryCalls(const CallGraphSCC &SCC); 122 bool annotateLibraryCalls(const CallGraphSCC &SCC);
123 123
124 void getAnalysisUsage(AnalysisUsage &AU) const override { 124 void getAnalysisUsage(AnalysisUsage &AU) const override {
125 AU.setPreservesCFG(); 125 AU.setPreservesCFG();
126 AU.addRequired<AliasAnalysis>(); 126 AU.addRequired<AliasAnalysis>();
127 AU.addRequired<TargetLibraryInfo>(); 127 AU.addRequired<TargetLibraryInfoWrapperPass>();
128 CallGraphSCCPass::getAnalysisUsage(AU); 128 CallGraphSCCPass::getAnalysisUsage(AU);
129 } 129 }
130 130
131 private: 131 private:
132 AliasAnalysis *AA; 132 AliasAnalysis *AA;
137 char FunctionAttrs::ID = 0; 137 char FunctionAttrs::ID = 0;
138 INITIALIZE_PASS_BEGIN(FunctionAttrs, "functionattrs", 138 INITIALIZE_PASS_BEGIN(FunctionAttrs, "functionattrs",
139 "Deduce function attributes", false, false) 139 "Deduce function attributes", false, false)
140 INITIALIZE_AG_DEPENDENCY(AliasAnalysis) 140 INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
141 INITIALIZE_PASS_DEPENDENCY(CallGraphWrapperPass) 141 INITIALIZE_PASS_DEPENDENCY(CallGraphWrapperPass)
142 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfo) 142 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
143 INITIALIZE_PASS_END(FunctionAttrs, "functionattrs", 143 INITIALIZE_PASS_END(FunctionAttrs, "functionattrs",
144 "Deduce function attributes", false, false) 144 "Deduce function attributes", false, false)
145 145
146 Pass *llvm::createFunctionAttrsPass() { return new FunctionAttrs(); } 146 Pass *llvm::createFunctionAttrsPass() { return new FunctionAttrs(); }
147 147
444 case Instruction::PHI: 444 case Instruction::PHI:
445 case Instruction::Select: 445 case Instruction::Select:
446 case Instruction::AddrSpaceCast: 446 case Instruction::AddrSpaceCast:
447 // The original value is not read/written via this if the new value isn't. 447 // The original value is not read/written via this if the new value isn't.
448 for (Use &UU : I->uses()) 448 for (Use &UU : I->uses())
449 if (Visited.insert(&UU)) 449 if (Visited.insert(&UU).second)
450 Worklist.push_back(&UU); 450 Worklist.push_back(&UU);
451 break; 451 break;
452 452
453 case Instruction::Call: 453 case Instruction::Call:
454 case Instruction::Invoke: { 454 case Instruction::Invoke: {
458 Captures = false; 458 Captures = false;
459 459
460 auto AddUsersToWorklistIfCapturing = [&] { 460 auto AddUsersToWorklistIfCapturing = [&] {
461 if (Captures) 461 if (Captures)
462 for (Use &UU : I->uses()) 462 for (Use &UU : I->uses())
463 if (Visited.insert(&UU)) 463 if (Visited.insert(&UU).second)
464 Worklist.push_back(&UU); 464 Worklist.push_back(&UU);
465 }; 465 };
466 466
467 CallSite CS(I); 467 CallSite CS(I);
468 if (CS.doesNotAccessMemory()) { 468 if (CS.doesNotAccessMemory()) {
1700 return MadeChange; 1700 return MadeChange;
1701 } 1701 }
1702 1702
1703 bool FunctionAttrs::runOnSCC(CallGraphSCC &SCC) { 1703 bool FunctionAttrs::runOnSCC(CallGraphSCC &SCC) {
1704 AA = &getAnalysis<AliasAnalysis>(); 1704 AA = &getAnalysis<AliasAnalysis>();
1705 TLI = &getAnalysis<TargetLibraryInfo>(); 1705 TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
1706 1706
1707 bool Changed = annotateLibraryCalls(SCC); 1707 bool Changed = annotateLibraryCalls(SCC);
1708 Changed |= AddReadAttrs(SCC); 1708 Changed |= AddReadAttrs(SCC);
1709 Changed |= AddArgumentAttrs(SCC); 1709 Changed |= AddArgumentAttrs(SCC);
1710 Changed |= AddNoAliasAttrs(SCC); 1710 Changed |= AddNoAliasAttrs(SCC);