summaryrefslogtreecommitdiff
path: root/lib/Transforms/IPO/Inliner.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2012-03-25 04:03:40 +0000
committerChandler Carruth <chandlerc@gmail.com>2012-03-25 04:03:40 +0000
commitd54f9a4c3bcdb247ea4aa311251c19242b03be63 (patch)
treeb8a2820b65d1697636eb7ea8ac4505ca943aa1cf /lib/Transforms/IPO/Inliner.cpp
parentacdae3e25a03e4e08039cb18f50b7788f71c0b2e (diff)
downloadllvm-d54f9a4c3bcdb247ea4aa311251c19242b03be63.tar.gz
llvm-d54f9a4c3bcdb247ea4aa311251c19242b03be63.tar.bz2
llvm-d54f9a4c3bcdb247ea4aa311251c19242b03be63.tar.xz
Move the instruction simplification of callsite arguments in the inliner
to instead rely on much more generic and powerful instruction simplification in the function cloner (and thus inliner). This teaches the pruning function cloner to use instsimplify rather than just the constant folder to fold values during cloning. This can simplify a large number of things that constant folding alone cannot begin to touch. For example, it will realize that 'or' and 'and' instructions with certain constant operands actually become constants regardless of what their other operand is. It also can thread back through the caller to perform simplifications that are only possible by looking up a few levels. In particular, GEPs and pointer testing tend to fold much more heavily with this change. This should (in some cases) have a positive impact on compile times with optimizations on because the inliner itself will simply avoid cloning a great deal of code. It already attempted to prune proven-dead code, but now it will be use the stronger simplifications to prove more code dead. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153403 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/IPO/Inliner.cpp')
-rw-r--r--lib/Transforms/IPO/Inliner.cpp37
1 files changed, 1 insertions, 36 deletions
diff --git a/lib/Transforms/IPO/Inliner.cpp b/lib/Transforms/IPO/Inliner.cpp
index 9975333976..048a1a0560 100644
--- a/lib/Transforms/IPO/Inliner.cpp
+++ b/lib/Transforms/IPO/Inliner.cpp
@@ -19,7 +19,6 @@
#include "llvm/IntrinsicInst.h"
#include "llvm/Analysis/CallGraph.h"
#include "llvm/Analysis/InlineCost.h"
-#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Transforms/IPO/InlinerPass.h"
#include "llvm/Transforms/Utils/Cloning.h"
@@ -335,38 +334,6 @@ static bool InlineHistoryIncludes(Function *F, int InlineHistoryID,
return false;
}
-/// \brief Simplify arguments going into a particular callsite.
-///
-/// This is important to do each time we add a callsite due to inlining so that
-/// constants and other entities which feed into inline cost estimation are
-/// properly recognized when analyzing the new callsite. Consider:
-/// void outer(int x) {
-/// if (x < 42)
-/// return inner(42 - x);
-/// ...
-/// }
-/// void inner(int x) {
-/// ...
-/// }
-///
-/// The inliner gives calls to 'outer' with a constant argument a bonus because
-/// it will delete one side of a branch. But the resulting call to 'inner'
-/// will, after inlining, also have a constant operand. We need to do just
-/// enough constant folding to expose this for callsite arguments. The rest
-/// will be taken care of after the inliner finishes running.
-static void simplifyCallSiteArguments(const TargetData *TD, CallSite CS) {
- // FIXME: It would be nice to avoid this smallvector if RAUW doesn't
- // invalidate operand iterators in any cases.
- SmallVector<std::pair<Value *, Value*>, 4> SimplifiedArgs;
- for (CallSite::arg_iterator I = CS.arg_begin(), E = CS.arg_end();
- I != E; ++I)
- if (Instruction *Inst = dyn_cast<Instruction>(*I))
- if (Value *SimpleArg = SimplifyInstruction(Inst, TD))
- SimplifiedArgs.push_back(std::make_pair(Inst, SimpleArg));
- for (unsigned Idx = 0, Size = SimplifiedArgs.size(); Idx != Size; ++Idx)
- SimplifiedArgs[Idx].first->replaceAllUsesWith(SimplifiedArgs[Idx].second);
-}
-
bool Inliner::runOnSCC(CallGraphSCC &SCC) {
CallGraph &CG = getAnalysis<CallGraph>();
const TargetData *TD = getAnalysisIfAvailable<TargetData>();
@@ -494,9 +461,7 @@ bool Inliner::runOnSCC(CallGraphSCC &SCC) {
for (unsigned i = 0, e = InlineInfo.InlinedCalls.size();
i != e; ++i) {
Value *Ptr = InlineInfo.InlinedCalls[i];
- CallSite NewCS = Ptr;
- simplifyCallSiteArguments(TD, NewCS);
- CallSites.push_back(std::make_pair(NewCS, NewHistoryID));
+ CallSites.push_back(std::make_pair(CallSite(Ptr), NewHistoryID));
}
}