Adjustments to last patch based on review.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61969 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dale Johannesen
2009-01-09 01:30:11 +00:00
parent 24c047fa6b
commit e345566f8e
6 changed files with 34 additions and 11 deletions

View File

@@ -61,6 +61,11 @@ struct Inliner : public CallGraphSCCPass {
/// ///
virtual float getInlineFudgeFactor(CallSite CS) = 0; virtual float getInlineFudgeFactor(CallSite CS) = 0;
/// resetCachedCostInfo - erase any cached cost data from the derived class.
/// If the derived class has no such data this can be empty.
///
virtual void resetCachedCostInfo(Function* Caller) = 0;
/// removeDeadFunctions - Remove dead functions that are not included in /// removeDeadFunctions - Remove dead functions that are not included in
/// DNR (Do Not Remove) list. /// DNR (Do Not Remove) list.
bool removeDeadFunctions(CallGraph &CG, bool removeDeadFunctions(CallGraph &CG,

View File

@@ -128,6 +128,11 @@ namespace llvm {
/// getInlineFudgeFactor - Return a > 1.0 factor if the inliner should use a /// getInlineFudgeFactor - Return a > 1.0 factor if the inliner should use a
/// higher threshold to determine if the function call should be inlined. /// higher threshold to determine if the function call should be inlined.
float getInlineFudgeFactor(CallSite CS); float getInlineFudgeFactor(CallSite CS);
/// resetCachedFunctionInfo - erase any cached cost info for this function.
void resetCachedCostInfo(Function* Caller) {
CachedFunctionInfo[Caller].NumBlocks = 0;
}
}; };
} }

View File

@@ -45,6 +45,9 @@ namespace {
float getInlineFudgeFactor(CallSite CS) { float getInlineFudgeFactor(CallSite CS) {
return CA.getInlineFudgeFactor(CS); return CA.getInlineFudgeFactor(CS);
} }
void resetCachedCostInfo(Function *Caller) {
return CA.resetCachedCostInfo(Caller);
}
virtual bool doFinalization(CallGraph &CG) { virtual bool doFinalization(CallGraph &CG) {
return removeDeadFunctions(CG, &NeverInline); return removeDeadFunctions(CG, &NeverInline);
} }

View File

@@ -43,6 +43,9 @@ namespace {
float getInlineFudgeFactor(CallSite CS) { float getInlineFudgeFactor(CallSite CS) {
return CA.getInlineFudgeFactor(CS); return CA.getInlineFudgeFactor(CS);
} }
void resetCachedCostInfo(Function *Caller) {
CA.resetCachedCostInfo(Caller);
}
virtual bool doInitialization(CallGraph &CG); virtual bool doInitialization(CallGraph &CG);
}; };
} }

View File

@@ -185,9 +185,14 @@ bool Inliner::runOnSCC(const std::vector<CallGraphNode*> &SCC) {
// try to do so. // try to do so.
CallSite CS = CallSites[CSi]; CallSite CS = CallSites[CSi];
if (shouldInline(CS)) { if (shouldInline(CS)) {
Function *Caller = CS.getCaller();
// Attempt to inline the function... // Attempt to inline the function...
if (InlineCallIfPossible(CS, CG, SCCFunctions, if (InlineCallIfPossible(CS, CG, SCCFunctions,
getAnalysis<TargetData>())) { getAnalysis<TargetData>())) {
// Remove any cached cost info for this caller, as inlining the callee
// has increased the size of the caller.
resetCachedCostInfo(Caller);
// Remove this call site from the list. If possible, use // Remove this call site from the list. If possible, use
// swap/pop_back for efficiency, but do not use it if doing so would // swap/pop_back for efficiency, but do not use it if doing so would
// move a call site to a function in this SCC before the // move a call site to a function in this SCC before the

View File

@@ -127,7 +127,7 @@ void InlineCostAnalyzer::FunctionInfo::analyzeFunction(Function *F) {
} }
if (const AllocaInst *AI = dyn_cast<AllocaInst>(II)) { if (const AllocaInst *AI = dyn_cast<AllocaInst>(II)) {
if (!isa<ConstantInt>(AI->getArraySize())) if (!AI->isStaticAlloca())
this->usesDynamicAlloca = true; this->usesDynamicAlloca = true;
} }
@@ -229,18 +229,20 @@ InlineCost InlineCostAnalyzer::getInlineCost(CallSite CS,
if (CalleeFI.NeverInline) if (CalleeFI.NeverInline)
return InlineCost::getNever(); return InlineCost::getNever();
// Get infomation about the caller... if (CalleeFI.usesDynamicAlloca) {
FunctionInfo &CallerFI = CachedFunctionInfo[Caller]; // Get infomation about the caller...
FunctionInfo &CallerFI = CachedFunctionInfo[Caller];
// If we haven't calculated this information yet, do so now. // If we haven't calculated this information yet, do so now.
if (CallerFI.NumBlocks == 0) if (CallerFI.NumBlocks == 0)
CallerFI.analyzeFunction(Caller); CallerFI.analyzeFunction(Caller);
// Don't inline a callee with dynamic alloca into a caller without them. // Don't inline a callee with dynamic alloca into a caller without them.
// Functions containing dynamic alloca's are inefficient in various ways; // Functions containing dynamic alloca's are inefficient in various ways;
// don't create more inefficiency. // don't create more inefficiency.
if (CalleeFI.usesDynamicAlloca && !CallerFI.usesDynamicAlloca) if (!CallerFI.usesDynamicAlloca)
return InlineCost::getNever(); return InlineCost::getNever();
}
// FIXME: It would be nice to kill off CalleeFI.NeverInline. Then we // FIXME: It would be nice to kill off CalleeFI.NeverInline. Then we
// could move this up and avoid computing the FunctionInfo for // could move this up and avoid computing the FunctionInfo for