mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 04:30:23 +00:00
Remove the simplify-libcalls pass (finally)
This commit completely removes what is left of the simplify-libcalls pass. All of the functionality has now been migrated to the instcombine and functionattrs passes. The following C API functions are now NOPs: 1. LLVMAddSimplifyLibCallsPass 2. LLVMPassManagerBuilderSetDisableSimplifyLibCalls git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184459 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
0382b30eb5
commit
be87bce32b
@ -240,7 +240,6 @@ void initializeScalarEvolutionAliasAnalysisPass(PassRegistry&);
|
||||
void initializeScalarEvolutionPass(PassRegistry&);
|
||||
void initializeSimpleInlinerPass(PassRegistry&);
|
||||
void initializeRegisterCoalescerPass(PassRegistry&);
|
||||
void initializeSimplifyLibCallsPass(PassRegistry&);
|
||||
void initializeSingleLoopExtractorPass(PassRegistry&);
|
||||
void initializeSinkingPass(PassRegistry&);
|
||||
void initializeSlotIndexesPass(PassRegistry&);
|
||||
|
@ -130,7 +130,6 @@ namespace {
|
||||
(void) llvm::createRegionViewerPass();
|
||||
(void) llvm::createSCCPPass();
|
||||
(void) llvm::createScalarReplAggregatesPass();
|
||||
(void) llvm::createSimplifyLibCallsPass();
|
||||
(void) llvm::createSingleLoopExtractorPass();
|
||||
(void) llvm::createStripSymbolsPass();
|
||||
(void) llvm::createStripNonDebugSymbolsPass();
|
||||
|
@ -100,7 +100,6 @@ public:
|
||||
/// added to the per-module passes.
|
||||
Pass *Inliner;
|
||||
|
||||
bool DisableSimplifyLibCalls;
|
||||
bool DisableUnitAtATime;
|
||||
bool DisableUnrollLoops;
|
||||
bool BBVectorize;
|
||||
|
@ -301,12 +301,6 @@ FunctionPass *createMemCpyOptPass();
|
||||
//
|
||||
Pass *createLoopDeletionPass();
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
/// createSimplifyLibCallsPass - This pass optimizes specific calls to
|
||||
/// specific well-known (library) functions.
|
||||
FunctionPass *createSimplifyLibCallsPass();
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// CodeGenPrepare - This pass prepares a function for instruction selection.
|
||||
|
@ -54,7 +54,6 @@ PassManagerBuilder::PassManagerBuilder() {
|
||||
SizeLevel = 0;
|
||||
LibraryInfo = 0;
|
||||
Inliner = 0;
|
||||
DisableSimplifyLibCalls = false;
|
||||
DisableUnitAtATime = false;
|
||||
DisableUnrollLoops = false;
|
||||
BBVectorize = RunBBVectorization;
|
||||
@ -174,8 +173,6 @@ void PassManagerBuilder::populateModulePassManager(PassManagerBase &MPM) {
|
||||
else
|
||||
MPM.add(createScalarReplAggregatesPass(-1, false));
|
||||
MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
|
||||
if (!DisableSimplifyLibCalls)
|
||||
MPM.add(createSimplifyLibCallsPass()); // Library Call Optimizations
|
||||
MPM.add(createJumpThreadingPass()); // Thread jumps.
|
||||
MPM.add(createCorrelatedValuePropagationPass()); // Propagate conditionals
|
||||
MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
|
||||
@ -379,8 +376,7 @@ LLVMPassManagerBuilderSetDisableUnrollLoops(LLVMPassManagerBuilderRef PMB,
|
||||
void
|
||||
LLVMPassManagerBuilderSetDisableSimplifyLibCalls(LLVMPassManagerBuilderRef PMB,
|
||||
LLVMBool Value) {
|
||||
PassManagerBuilder *Builder = unwrap(PMB);
|
||||
Builder->DisableSimplifyLibCalls = Value;
|
||||
// NOTE: The simplify-libcalls pass has been removed.
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -28,7 +28,6 @@ add_llvm_library(LLVMScalarOpts
|
||||
Scalar.cpp
|
||||
ScalarReplAggregates.cpp
|
||||
SimplifyCFGPass.cpp
|
||||
SimplifyLibCalls.cpp
|
||||
Sink.cpp
|
||||
StructurizeCFG.cpp
|
||||
TailRecursionElimination.cpp
|
||||
|
@ -59,7 +59,6 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) {
|
||||
initializeSROA_SSAUpPass(Registry);
|
||||
initializeCFGSimplifyPassPass(Registry);
|
||||
initializeStructurizeCFGPass(Registry);
|
||||
initializeSimplifyLibCallsPass(Registry);
|
||||
initializeSinkingPass(Registry);
|
||||
initializeTailCallElimPass(Registry);
|
||||
}
|
||||
@ -150,7 +149,7 @@ void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM,
|
||||
}
|
||||
|
||||
void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM) {
|
||||
unwrap(PM)->add(createSimplifyLibCallsPass());
|
||||
// NOTE: The simplify-libcalls pass has been removed.
|
||||
}
|
||||
|
||||
void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM) {
|
||||
|
@ -1,247 +0,0 @@
|
||||
//===- SimplifyLibCalls.cpp - Optimize specific well-known library calls --===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file implements a simple pass that applies a variety of small
|
||||
// optimizations for calls to specific well-known function calls (e.g. runtime
|
||||
// library functions). Any optimization that takes the very simple form
|
||||
// "replace call to library function with simpler code that provides the same
|
||||
// result" belongs in this file.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#define DEBUG_TYPE "simplify-libcalls"
|
||||
#include "llvm/Transforms/Scalar.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/ADT/SmallPtrSet.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include "llvm/Analysis/ValueTracking.h"
|
||||
#include "llvm/Config/config.h" // FIXME: Shouldn't depend on host!
|
||||
#include "llvm/IR/DataLayout.h"
|
||||
#include "llvm/IR/IRBuilder.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/Pass.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Target/TargetLibraryInfo.h"
|
||||
#include "llvm/Transforms/Utils/BuildLibCalls.h"
|
||||
using namespace llvm;
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Optimizer Base Class
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// This class is the abstract base class for the set of optimizations that
|
||||
/// corresponds to one library call.
|
||||
namespace {
|
||||
class LibCallOptimization {
|
||||
protected:
|
||||
Function *Caller;
|
||||
const DataLayout *TD;
|
||||
const TargetLibraryInfo *TLI;
|
||||
LLVMContext* Context;
|
||||
public:
|
||||
LibCallOptimization() { }
|
||||
virtual ~LibCallOptimization() {}
|
||||
|
||||
/// CallOptimizer - This pure virtual method is implemented by base classes to
|
||||
/// do various optimizations. If this returns null then no transformation was
|
||||
/// performed. If it returns CI, then it transformed the call and CI is to be
|
||||
/// deleted. If it returns something else, replace CI with the new value and
|
||||
/// delete CI.
|
||||
virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B)
|
||||
=0;
|
||||
|
||||
Value *OptimizeCall(CallInst *CI, const DataLayout *TD,
|
||||
const TargetLibraryInfo *TLI, IRBuilder<> &B) {
|
||||
Caller = CI->getParent()->getParent();
|
||||
this->TD = TD;
|
||||
this->TLI = TLI;
|
||||
if (CI->getCalledFunction())
|
||||
Context = &CI->getCalledFunction()->getContext();
|
||||
|
||||
// We never change the calling convention.
|
||||
if (CI->getCallingConv() != llvm::CallingConv::C)
|
||||
return NULL;
|
||||
|
||||
return CallOptimizer(CI->getCalledFunction(), CI, B);
|
||||
}
|
||||
};
|
||||
} // End anonymous namespace.
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// SimplifyLibCalls Pass Implementation
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
namespace {
|
||||
/// This pass optimizes well known library functions from libc and libm.
|
||||
///
|
||||
class SimplifyLibCalls : public FunctionPass {
|
||||
TargetLibraryInfo *TLI;
|
||||
|
||||
StringMap<LibCallOptimization*> Optimizations;
|
||||
public:
|
||||
static char ID; // Pass identification
|
||||
SimplifyLibCalls() : FunctionPass(ID) {
|
||||
initializeSimplifyLibCallsPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
void AddOpt(LibFunc::Func F, LibCallOptimization* Opt);
|
||||
void AddOpt(LibFunc::Func F1, LibFunc::Func F2, LibCallOptimization* Opt);
|
||||
|
||||
void InitOptimizations();
|
||||
bool runOnFunction(Function &F);
|
||||
|
||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||
AU.addRequired<TargetLibraryInfo>();
|
||||
}
|
||||
};
|
||||
} // end anonymous namespace.
|
||||
|
||||
char SimplifyLibCalls::ID = 0;
|
||||
|
||||
INITIALIZE_PASS_BEGIN(SimplifyLibCalls, "simplify-libcalls",
|
||||
"Simplify well-known library calls", false, false)
|
||||
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfo)
|
||||
INITIALIZE_PASS_END(SimplifyLibCalls, "simplify-libcalls",
|
||||
"Simplify well-known library calls", false, false)
|
||||
|
||||
// Public interface to the Simplify LibCalls pass.
|
||||
FunctionPass *llvm::createSimplifyLibCallsPass() {
|
||||
return new SimplifyLibCalls();
|
||||
}
|
||||
|
||||
void SimplifyLibCalls::AddOpt(LibFunc::Func F, LibCallOptimization* Opt) {
|
||||
if (TLI->has(F))
|
||||
Optimizations[TLI->getName(F)] = Opt;
|
||||
}
|
||||
|
||||
void SimplifyLibCalls::AddOpt(LibFunc::Func F1, LibFunc::Func F2,
|
||||
LibCallOptimization* Opt) {
|
||||
if (TLI->has(F1) && TLI->has(F2))
|
||||
Optimizations[TLI->getName(F1)] = Opt;
|
||||
}
|
||||
|
||||
/// Optimizations - Populate the Optimizations map with all the optimizations
|
||||
/// we know.
|
||||
void SimplifyLibCalls::InitOptimizations() {
|
||||
}
|
||||
|
||||
|
||||
/// runOnFunction - Top level algorithm.
|
||||
///
|
||||
bool SimplifyLibCalls::runOnFunction(Function &F) {
|
||||
TLI = &getAnalysis<TargetLibraryInfo>();
|
||||
|
||||
if (Optimizations.empty())
|
||||
InitOptimizations();
|
||||
|
||||
const DataLayout *TD = getAnalysisIfAvailable<DataLayout>();
|
||||
|
||||
IRBuilder<> Builder(F.getContext());
|
||||
|
||||
bool Changed = false;
|
||||
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
|
||||
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) {
|
||||
// Ignore non-calls.
|
||||
CallInst *CI = dyn_cast<CallInst>(I++);
|
||||
if (!CI || CI->hasFnAttr(Attribute::NoBuiltin)) continue;
|
||||
|
||||
// Ignore indirect calls and calls to non-external functions.
|
||||
Function *Callee = CI->getCalledFunction();
|
||||
if (Callee == 0 || !Callee->isDeclaration() ||
|
||||
!(Callee->hasExternalLinkage() || Callee->hasDLLImportLinkage()))
|
||||
continue;
|
||||
|
||||
// Ignore unknown calls.
|
||||
LibCallOptimization *LCO = Optimizations.lookup(Callee->getName());
|
||||
if (!LCO) continue;
|
||||
|
||||
// Set the builder to the instruction after the call.
|
||||
Builder.SetInsertPoint(BB, I);
|
||||
|
||||
// Use debug location of CI for all new instructions.
|
||||
Builder.SetCurrentDebugLocation(CI->getDebugLoc());
|
||||
|
||||
// Try to optimize this call.
|
||||
Value *Result = LCO->OptimizeCall(CI, TD, TLI, Builder);
|
||||
if (Result == 0) continue;
|
||||
|
||||
DEBUG(dbgs() << "SimplifyLibCalls simplified: " << *CI;
|
||||
dbgs() << " into: " << *Result << "\n");
|
||||
|
||||
// Something changed!
|
||||
Changed = true;
|
||||
|
||||
// Inspect the instruction after the call (which was potentially just
|
||||
// added) next.
|
||||
I = CI; ++I;
|
||||
|
||||
if (CI != Result && !CI->use_empty()) {
|
||||
CI->replaceAllUsesWith(Result);
|
||||
if (!Result->hasName())
|
||||
Result->takeName(CI);
|
||||
}
|
||||
CI->eraseFromParent();
|
||||
}
|
||||
}
|
||||
return Changed;
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// Additional cases that we need to add to this file:
|
||||
//
|
||||
// cbrt:
|
||||
// * cbrt(expN(X)) -> expN(x/3)
|
||||
// * cbrt(sqrt(x)) -> pow(x,1/6)
|
||||
// * cbrt(sqrt(x)) -> pow(x,1/9)
|
||||
//
|
||||
// exp, expf, expl:
|
||||
// * exp(log(x)) -> x
|
||||
//
|
||||
// log, logf, logl:
|
||||
// * log(exp(x)) -> x
|
||||
// * log(x**y) -> y*log(x)
|
||||
// * log(exp(y)) -> y*log(e)
|
||||
// * log(exp2(y)) -> y*log(2)
|
||||
// * log(exp10(y)) -> y*log(10)
|
||||
// * log(sqrt(x)) -> 0.5*log(x)
|
||||
// * log(pow(x,y)) -> y*log(x)
|
||||
//
|
||||
// lround, lroundf, lroundl:
|
||||
// * lround(cnst) -> cnst'
|
||||
//
|
||||
// pow, powf, powl:
|
||||
// * pow(exp(x),y) -> exp(x*y)
|
||||
// * pow(sqrt(x),y) -> pow(x,y*0.5)
|
||||
// * pow(pow(x,y),z)-> pow(x,y*z)
|
||||
//
|
||||
// round, roundf, roundl:
|
||||
// * round(cnst) -> cnst'
|
||||
//
|
||||
// signbit:
|
||||
// * signbit(cnst) -> cnst'
|
||||
// * signbit(nncst) -> 0 (if pstv is a non-negative constant)
|
||||
//
|
||||
// sqrt, sqrtf, sqrtl:
|
||||
// * sqrt(expN(x)) -> expN(x*0.5)
|
||||
// * sqrt(Nroot(x)) -> pow(x,1/(2*N))
|
||||
// * sqrt(pow(x,y)) -> pow(|x|,y*0.5)
|
||||
//
|
||||
// strchr:
|
||||
// * strchr(p, 0) -> strlen(p)
|
||||
// tan, tanf, tanl:
|
||||
// * tan(atan(x)) -> x
|
||||
//
|
||||
// trunc, truncf, truncl:
|
||||
// * trunc(cnst) -> cnst'
|
||||
//
|
||||
//
|
@ -1950,3 +1950,53 @@ void LibCallSimplifier::replaceAllUsesWith(Instruction *I, Value *With) const {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// Additional cases that we need to add to this file:
|
||||
//
|
||||
// cbrt:
|
||||
// * cbrt(expN(X)) -> expN(x/3)
|
||||
// * cbrt(sqrt(x)) -> pow(x,1/6)
|
||||
// * cbrt(sqrt(x)) -> pow(x,1/9)
|
||||
//
|
||||
// exp, expf, expl:
|
||||
// * exp(log(x)) -> x
|
||||
//
|
||||
// log, logf, logl:
|
||||
// * log(exp(x)) -> x
|
||||
// * log(x**y) -> y*log(x)
|
||||
// * log(exp(y)) -> y*log(e)
|
||||
// * log(exp2(y)) -> y*log(2)
|
||||
// * log(exp10(y)) -> y*log(10)
|
||||
// * log(sqrt(x)) -> 0.5*log(x)
|
||||
// * log(pow(x,y)) -> y*log(x)
|
||||
//
|
||||
// lround, lroundf, lroundl:
|
||||
// * lround(cnst) -> cnst'
|
||||
//
|
||||
// pow, powf, powl:
|
||||
// * pow(exp(x),y) -> exp(x*y)
|
||||
// * pow(sqrt(x),y) -> pow(x,y*0.5)
|
||||
// * pow(pow(x,y),z)-> pow(x,y*z)
|
||||
//
|
||||
// round, roundf, roundl:
|
||||
// * round(cnst) -> cnst'
|
||||
//
|
||||
// signbit:
|
||||
// * signbit(cnst) -> cnst'
|
||||
// * signbit(nncst) -> 0 (if pstv is a non-negative constant)
|
||||
//
|
||||
// sqrt, sqrtf, sqrtl:
|
||||
// * sqrt(expN(x)) -> expN(x*0.5)
|
||||
// * sqrt(Nroot(x)) -> pow(x,1/(2*N))
|
||||
// * sqrt(pow(x,y)) -> pow(|x|,y*0.5)
|
||||
//
|
||||
// strchr:
|
||||
// * strchr(p, 0) -> strlen(p)
|
||||
// tan, tanf, tanl:
|
||||
// * tan(atan(x)) -> x
|
||||
//
|
||||
// trunc, truncf, truncl:
|
||||
// * trunc(cnst) -> cnst'
|
||||
//
|
||||
//
|
||||
|
@ -445,7 +445,6 @@ static void AddOptimizationPasses(PassManagerBase &MPM,FunctionPassManager &FPM,
|
||||
}
|
||||
Builder.DisableUnitAtATime = !UnitAtATime;
|
||||
Builder.DisableUnrollLoops = OptLevel == 0;
|
||||
Builder.DisableSimplifyLibCalls = DisableSimplifyLibCalls;
|
||||
|
||||
Builder.populateFunctionPassManager(FPM);
|
||||
Builder.populateModulePassManager(MPM);
|
||||
@ -465,7 +464,6 @@ static void AddStandardCompilePasses(PassManagerBase &PM) {
|
||||
if (!DisableInline)
|
||||
Builder.Inliner = createFunctionInliningPass();
|
||||
Builder.OptLevel = 3;
|
||||
Builder.DisableSimplifyLibCalls = DisableSimplifyLibCalls;
|
||||
Builder.populateModulePassManager(PM);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user