[llvm-commits] [PATCH] instcombine: wire up -fno-builtin to the library call simplifier
Meador Inge
meadori at codesourcery.com
Wed Nov 7 20:24:24 PST 2012
Now that the library call simplifiers are being migrated out of their own
pass into the instruction combiner pass the latter needs to be modified to
work with -fno-builtin. This is accomplished by adding a new parameter
to the InstCombiner constructor and to the createInstructionCombiningPass
factory function that controls whether library call simplification should
be performed or not. The pass manager already has an option to control
library call simplification. This option is now passed through when creating
instances of the instruction combiner class.
OK?
---
include/llvm/Transforms/Scalar.h | 3 ++-
lib/Transforms/IPO/PassManagerBuilder.cpp | 23 +++++++++++---------
lib/Transforms/InstCombine/InstCombine.h | 4 +++-
lib/Transforms/InstCombine/InstCombineCalls.cpp | 2 +-
.../InstCombine/InstructionCombining.cpp | 5 +++--
5 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/include/llvm/Transforms/Scalar.h b/include/llvm/Transforms/Scalar.h
index a5d8eed..d660114 100644
--- a/include/llvm/Transforms/Scalar.h
+++ b/include/llvm/Transforms/Scalar.h
@@ -104,7 +104,8 @@ Pass *createIndVarSimplifyPass();
// into:
// %Z = add int 2, %X
//
-FunctionPass *createInstructionCombiningPass();
+FunctionPass *
+createInstructionCombiningPass(bool DisableSimplifyLibCalls = false);
//===----------------------------------------------------------------------===//
//
diff --git a/lib/Transforms/IPO/PassManagerBuilder.cpp b/lib/Transforms/IPO/PassManagerBuilder.cpp
index 05253fc..dcc9c0a 100644
--- a/lib/Transforms/IPO/PassManagerBuilder.cpp
+++ b/lib/Transforms/IPO/PassManagerBuilder.cpp
@@ -149,8 +149,9 @@ void PassManagerBuilder::populateModulePassManager(PassManagerBase &MPM) {
MPM.add(createIPSCCPPass()); // IP SCCP
MPM.add(createDeadArgEliminationPass()); // Dead argument elimination
- MPM.add(createInstructionCombiningPass());// Clean up after IPCP & DAE
- MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE
+ // Clean up after IPCP & DAE
+ MPM.add(createInstructionCombiningPass(DisableSimplifyLibCalls));
+ MPM.add(createCFGSimplificationPass());
}
// Start of CallGraph SCC passes.
@@ -177,7 +178,8 @@ void PassManagerBuilder::populateModulePassManager(PassManagerBase &MPM) {
MPM.add(createJumpThreadingPass()); // Thread jumps.
MPM.add(createCorrelatedValuePropagationPass()); // Propagate conditionals
MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
- MPM.add(createInstructionCombiningPass()); // Combine silly seq's
+ // Combine silly seq's
+ MPM.add(createInstructionCombiningPass(DisableSimplifyLibCalls));
MPM.add(createTailCallEliminationPass()); // Eliminate tail calls
MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
@@ -185,7 +187,7 @@ void PassManagerBuilder::populateModulePassManager(PassManagerBase &MPM) {
MPM.add(createLoopRotatePass()); // Rotate Loop
MPM.add(createLICMPass()); // Hoist loop invariants
MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3));
- MPM.add(createInstructionCombiningPass());
+ MPM.add(createInstructionCombiningPass(DisableSimplifyLibCalls));
MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars
MPM.add(createLoopIdiomPass()); // Recognize idioms like memset.
MPM.add(createLoopDeletionPass()); // Delete dead loops
@@ -206,7 +208,7 @@ void PassManagerBuilder::populateModulePassManager(PassManagerBase &MPM) {
// Run instcombine after redundancy elimination to exploit opportunities
// opened up by them.
- MPM.add(createInstructionCombiningPass());
+ MPM.add(createInstructionCombiningPass(DisableSimplifyLibCalls));
MPM.add(createJumpThreadingPass()); // Thread jumps
MPM.add(createCorrelatedValuePropagationPass());
MPM.add(createDeadStoreEliminationPass()); // Delete dead stores
@@ -215,7 +217,7 @@ void PassManagerBuilder::populateModulePassManager(PassManagerBase &MPM) {
if (Vectorize) {
MPM.add(createBBVectorizePass());
- MPM.add(createInstructionCombiningPass());
+ MPM.add(createInstructionCombiningPass(DisableSimplifyLibCalls));
if (OptLevel > 1 && UseGVNAfterVectorization)
MPM.add(createGVNPass()); // Remove redundancies
else
@@ -224,7 +226,8 @@ void PassManagerBuilder::populateModulePassManager(PassManagerBase &MPM) {
MPM.add(createAggressiveDCEPass()); // Delete dead instructions
MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
- MPM.add(createInstructionCombiningPass()); // Clean up after everything.
+ // Clean up after everything.
+ MPM.add(createInstructionCombiningPass(DisableSimplifyLibCalls));
if (!DisableUnitAtATime) {
// FIXME: We shouldn't bother with this anymore.
@@ -275,7 +278,7 @@ void PassManagerBuilder::populateLTOPassManager(PassManagerBase &PM,
// simplification opportunities, and both can propagate functions through
// function pointers. When this happens, we often have to resolve varargs
// calls, etc, so let instcombine do this.
- PM.add(createInstructionCombiningPass());
+ PM.add(createInstructionCombiningPass(DisableSimplifyLibCalls));
// Inline small functions
if (RunInliner)
@@ -293,7 +296,7 @@ void PassManagerBuilder::populateLTOPassManager(PassManagerBase &PM,
PM.add(createArgumentPromotionPass());
// The IPO passes may leave cruft around. Clean up after them.
- PM.add(createInstructionCombiningPass());
+ PM.add(createInstructionCombiningPass(DisableSimplifyLibCalls));
PM.add(createJumpThreadingPass());
// Break up allocas
if (UseNewSROA)
@@ -312,7 +315,7 @@ void PassManagerBuilder::populateLTOPassManager(PassManagerBase &PM,
PM.add(createDeadStoreEliminationPass());
// Cleanup and simplify the code after the scalar optimizations.
- PM.add(createInstructionCombiningPass());
+ PM.add(createInstructionCombiningPass(DisableSimplifyLibCalls));
PM.add(createJumpThreadingPass());
diff --git a/lib/Transforms/InstCombine/InstCombine.h b/lib/Transforms/InstCombine/InstCombine.h
index 7467eca..8ae7cb3 100644
--- a/lib/Transforms/InstCombine/InstCombine.h
+++ b/lib/Transforms/InstCombine/InstCombine.h
@@ -76,6 +76,7 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner
TargetLibraryInfo *TLI;
bool MadeIRChange;
LibCallSimplifier *Simplifier;
+ bool DisableSimplifyLibCalls;
public:
/// Worklist - All of the instructions that need to be simplified.
InstCombineWorklist Worklist;
@@ -86,7 +87,8 @@ public:
BuilderTy *Builder;
static char ID; // Pass identification, replacement for typeid
- InstCombiner() : FunctionPass(ID), TD(0), Builder(0) {
+ InstCombiner(bool DSLC = false) : FunctionPass(ID), TD(0),
+ DisableSimplifyLibCalls(DSLC), Builder(0) {
initializeInstCombinerPass(*PassRegistry::getPassRegistry());
}
diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 5ad6f91..da0eae9 100644
--- a/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -783,7 +783,7 @@ static bool isSafeToEliminateVarargsCast(const CallSite CS,
// mempcpy_chk, memmove_chk, memset_chk, strcpy_chk, stpcpy_chk, strncpy_chk,
// strcat_chk and strncat_chk.
Instruction *InstCombiner::tryOptimizeCall(CallInst *CI, const DataLayout *TD) {
- if (CI->getCalledFunction() == 0) return 0;
+ if (DisableSimplifyLibCalls || CI->getCalledFunction() == 0) return 0;
if (Value *With = Simplifier->optimizeCall(CI))
return ReplaceInstUsesWith(*CI, With);
diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp
index ccf75bc..29df35a 100644
--- a/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -2397,6 +2397,7 @@ bool InstCombiner::runOnFunction(Function &F) {
return EverMadeChange;
}
-FunctionPass *llvm::createInstructionCombiningPass() {
- return new InstCombiner();
+FunctionPass *
+llvm::createInstructionCombiningPass(bool DisableSimplifyLibCalls) {
+ return new InstCombiner(DisableSimplifyLibCalls);
}
--
1.7.10.2 (Apple Git-33)
More information about the llvm-commits
mailing list