summaryrefslogtreecommitdiff
path: root/lib/Analysis/InlineCost.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2012-05-04 00:58:03 +0000
committerChandler Carruth <chandlerc@gmail.com>2012-05-04 00:58:03 +0000
commitd5003cafd6fc86acaf8e09ef0ca1dc899da8850e (patch)
tree16436eec4ec4c6a95b3d9d05d07c64aacebb18f1 /lib/Analysis/InlineCost.cpp
parenta83a6d3725a9a488e2d10c1f2af46d9c6d82958d (diff)
downloadllvm-d5003cafd6fc86acaf8e09ef0ca1dc899da8850e.tar.gz
llvm-d5003cafd6fc86acaf8e09ef0ca1dc899da8850e.tar.bz2
llvm-d5003cafd6fc86acaf8e09ef0ca1dc899da8850e.tar.xz
A pile of long over-due refactorings here. There are some very, *very*
minor behavior changes with this, but nothing I have seen evidence of in the wild or expect to be meaningful. The real goal is unifying our logic and simplifying the interfaces. A summary of the changes follows: - Make 'callIsSmall' actually accept a callsite so it can handle intrinsics, and simplify callers appropriately. - Nuke a completely bogus declaration of 'callIsSmall' that was still lurking in InlineCost.h... No idea how this got missed. - Teach the 'isInstructionFree' about the various more intelligent 'free' heuristics that got added to the inline cost analysis during review and testing. This mostly surrounds int->ptr and ptr->int casts. - Switch most of the interesting parts of the inline cost analysis that were essentially computing 'is this instruction free?' to use the code metrics routine instead. This way we won't keep duplicating logic. All of this is motivated by the desire to allow other passes to compute a roughly equivalent 'cost' metric for a particular basic block as the inline cost analysis. Sadly, re-using the same analysis for both is really messy because only the actual inline cost analysis is ever going to go to the contortions required for simplification, SROA analysis, etc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156140 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/InlineCost.cpp')
-rw-r--r--lib/Analysis/InlineCost.cpp50
1 files changed, 11 insertions, 39 deletions
diff --git a/lib/Analysis/InlineCost.cpp b/lib/Analysis/InlineCost.cpp
index 3e3d2ab753..615a7e6b7e 100644
--- a/lib/Analysis/InlineCost.cpp
+++ b/lib/Analysis/InlineCost.cpp
@@ -398,10 +398,7 @@ bool CallAnalyzer::visitPtrToInt(PtrToIntInst &I) {
if (lookupSROAArgAndCost(I.getOperand(0), SROAArg, CostIt))
SROAArgValues[&I] = SROAArg;
- // A ptrtoint cast is free so long as the result is large enough to store the
- // pointer, and a legal integer type.
- return TD && TD->isLegalInteger(IntegerSize) &&
- IntegerSize >= TD->getPointerSizeInBits();
+ return isInstructionFree(&I, TD);
}
bool CallAnalyzer::visitIntToPtr(IntToPtrInst &I) {
@@ -428,10 +425,7 @@ bool CallAnalyzer::visitIntToPtr(IntToPtrInst &I) {
if (lookupSROAArgAndCost(Op, SROAArg, CostIt))
SROAArgValues[&I] = SROAArg;
- // An inttoptr cast is free so long as the input is a legal integer type
- // which doesn't contain values outside the range of a pointer.
- return TD && TD->isLegalInteger(IntegerSize) &&
- IntegerSize <= TD->getPointerSizeInBits();
+ return isInstructionFree(&I, TD);
}
bool CallAnalyzer::visitCastInst(CastInst &I) {
@@ -445,24 +439,7 @@ bool CallAnalyzer::visitCastInst(CastInst &I) {
// Disable SROA in the face of arbitrary casts we don't whitelist elsewhere.
disableSROA(I.getOperand(0));
- // No-op casts don't have any cost.
- if (I.isLosslessCast())
- return true;
-
- // trunc to a native type is free (assuming the target has compare and
- // shift-right of the same width).
- if (TD && isa<TruncInst>(I) &&
- TD->isLegalInteger(TD->getTypeSizeInBits(I.getType())))
- return true;
-
- // Result of a cmp instruction is often extended (to be used by other
- // cmp instructions, logical or return instructions). These are usually
- // no-ops on most sane targets.
- if (isa<CmpInst>(I.getOperand(0)))
- return true;
-
- // Assume the rest of the casts require work.
- return false;
+ return isInstructionFree(&I, TD);
}
bool CallAnalyzer::visitUnaryInstruction(UnaryInstruction &I) {
@@ -636,21 +613,11 @@ bool CallAnalyzer::visitCallSite(CallSite CS) {
default:
return Base::visitCallSite(CS);
- case Intrinsic::dbg_declare:
- case Intrinsic::dbg_value:
- case Intrinsic::invariant_start:
- case Intrinsic::invariant_end:
- case Intrinsic::lifetime_start:
- case Intrinsic::lifetime_end:
case Intrinsic::memset:
case Intrinsic::memcpy:
case Intrinsic::memmove:
- case Intrinsic::objectsize:
- case Intrinsic::ptr_annotation:
- case Intrinsic::var_annotation:
- // SROA can usually chew through these intrinsics and they have no cost
- // so don't pay the price of analyzing them in detail.
- return true;
+ // SROA can usually chew through these intrinsics, but they aren't free.
+ return false;
}
}
@@ -662,7 +629,7 @@ bool CallAnalyzer::visitCallSite(CallSite CS) {
return false;
}
- if (!callIsSmall(F)) {
+ if (!callIsSmall(CS)) {
// We account for the average 1 instruction per call argument setup
// here.
Cost += CS.arg_size() * InlineConstants::InstrCost;
@@ -706,6 +673,11 @@ bool CallAnalyzer::visitCallSite(CallSite CS) {
}
bool CallAnalyzer::visitInstruction(Instruction &I) {
+ // Some instructions are free. All of the free intrinsics can also be
+ // handled by SROA, etc.
+ if (isInstructionFree(&I, TD))
+ return true;
+
// We found something we don't understand or can't handle. Mark any SROA-able
// values in the operand list as no longer viable.
for (User::op_iterator OI = I.op_begin(), OE = I.op_end(); OI != OE; ++OI)