summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
diff options
context:
space:
mode:
authorDavide Italiano <davide@freebsd.org>2016-05-20 15:43:39 +0000
committerDavide Italiano <davide@freebsd.org>2016-05-20 15:43:39 +0000
commit08713bd1ed6ee0d28a480d74fbf0f575532b0fab (patch)
treebfbc61bf44204586eb081eef7a75ab38e424a69a /llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
parentf4c520d5d24cca3d2f8c3a8b429ea4ed9415bd96 (diff)
downloadbcm5719-llvm-08713bd1ed6ee0d28a480d74fbf0f575532b0fab.tar.gz
bcm5719-llvm-08713bd1ed6ee0d28a480d74fbf0f575532b0fab.zip
[PM/PartiallyInlineLibCalls] Convert to static function in preparation for porting this pass to the new PM.
llvm-svn: 270225
Diffstat (limited to 'llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp104
1 files changed, 49 insertions, 55 deletions
diff --git a/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp b/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
index 27bb230af2f..45d7c8e05be 100644
--- a/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
+++ b/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
@@ -37,11 +37,6 @@ namespace {
void getAnalysisUsage(AnalysisUsage &AU) const override;
bool runOnFunction(Function &F) override;
-
- private:
- /// Optimize calls to sqrt.
- bool optimizeSQRT(CallInst *Call, Function *CalledFunc,
- BasicBlock &CurrBB, Function::iterator &BB);
};
char PartiallyInlineLibCalls::ID = 0;
@@ -56,57 +51,9 @@ void PartiallyInlineLibCalls::getAnalysisUsage(AnalysisUsage &AU) const {
FunctionPass::getAnalysisUsage(AU);
}
-bool PartiallyInlineLibCalls::runOnFunction(Function &F) {
- if (skipFunction(F))
- return false;
-
- bool Changed = false;
- Function::iterator CurrBB;
- TargetLibraryInfo *TLI =
- &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
- const TargetTransformInfo *TTI =
- &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
- for (Function::iterator BB = F.begin(), BE = F.end(); BB != BE;) {
- CurrBB = BB++;
-
- for (BasicBlock::iterator II = CurrBB->begin(), IE = CurrBB->end();
- II != IE; ++II) {
- CallInst *Call = dyn_cast<CallInst>(&*II);
- Function *CalledFunc;
-
- if (!Call || !(CalledFunc = Call->getCalledFunction()))
- continue;
-
- // Skip if function either has local linkage or is not a known library
- // function.
- LibFunc::Func LibFunc;
- if (CalledFunc->hasLocalLinkage() || !CalledFunc->hasName() ||
- !TLI->getLibFunc(CalledFunc->getName(), LibFunc))
- continue;
-
- switch (LibFunc) {
- case LibFunc::sqrtf:
- case LibFunc::sqrt:
- if (TTI->haveFastSqrt(Call->getType()) &&
- optimizeSQRT(Call, CalledFunc, *CurrBB, BB))
- break;
- continue;
- default:
- continue;
- }
-
- Changed = true;
- break;
- }
- }
-
- return Changed;
-}
-bool PartiallyInlineLibCalls::optimizeSQRT(CallInst *Call,
- Function *CalledFunc,
- BasicBlock &CurrBB,
- Function::iterator &BB) {
+static bool optimizeSQRT(CallInst *Call, Function *CalledFunc,
+ BasicBlock &CurrBB, Function::iterator &BB) {
// There is no need to change the IR, since backend will emit sqrt
// instruction if the call has already been marked read-only.
if (Call->onlyReadsMemory())
@@ -160,6 +107,53 @@ bool PartiallyInlineLibCalls::optimizeSQRT(CallInst *Call,
return true;
}
+bool PartiallyInlineLibCalls::runOnFunction(Function &F) {
+ if (skipFunction(F))
+ return false;
+
+ bool Changed = false;
+ Function::iterator CurrBB;
+ TargetLibraryInfo *TLI =
+ &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
+ const TargetTransformInfo *TTI =
+ &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
+ for (Function::iterator BB = F.begin(), BE = F.end(); BB != BE;) {
+ CurrBB = BB++;
+
+ for (BasicBlock::iterator II = CurrBB->begin(), IE = CurrBB->end();
+ II != IE; ++II) {
+ CallInst *Call = dyn_cast<CallInst>(&*II);
+ Function *CalledFunc;
+
+ if (!Call || !(CalledFunc = Call->getCalledFunction()))
+ continue;
+
+ // Skip if function either has local linkage or is not a known library
+ // function.
+ LibFunc::Func LibFunc;
+ if (CalledFunc->hasLocalLinkage() || !CalledFunc->hasName() ||
+ !TLI->getLibFunc(CalledFunc->getName(), LibFunc))
+ continue;
+
+ switch (LibFunc) {
+ case LibFunc::sqrtf:
+ case LibFunc::sqrt:
+ if (TTI->haveFastSqrt(Call->getType()) &&
+ optimizeSQRT(Call, CalledFunc, *CurrBB, BB))
+ break;
+ continue;
+ default:
+ continue;
+ }
+
+ Changed = true;
+ break;
+ }
+ }
+
+ return Changed;
+}
+
FunctionPass *llvm::createPartiallyInlineLibCallsPass() {
return new PartiallyInlineLibCalls();
}
OpenPOWER on IntegriCloud