mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-07-08 18:30:04 +00:00
whitespace
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@140916 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
0bcd9c70b1
commit
5c655413cf
@ -46,7 +46,7 @@ namespace llvm {
|
|||||||
|
|
||||||
/// NumCalls - Keep track of the number of calls to 'big' functions.
|
/// NumCalls - Keep track of the number of calls to 'big' functions.
|
||||||
unsigned NumCalls;
|
unsigned NumCalls;
|
||||||
|
|
||||||
/// NumInlineCandidates - Keep track of the number of calls to internal
|
/// NumInlineCandidates - Keep track of the number of calls to internal
|
||||||
/// functions with only a single caller. These are likely targets for
|
/// functions with only a single caller. These are likely targets for
|
||||||
/// future inlining, likely exposed by interleaved devirtualization.
|
/// future inlining, likely exposed by interleaved devirtualization.
|
||||||
@ -61,9 +61,9 @@ namespace llvm {
|
|||||||
unsigned NumRets;
|
unsigned NumRets;
|
||||||
|
|
||||||
CodeMetrics() : callsSetJmp(false), isRecursive(false),
|
CodeMetrics() : callsSetJmp(false), isRecursive(false),
|
||||||
containsIndirectBr(false), usesDynamicAlloca(false),
|
containsIndirectBr(false), usesDynamicAlloca(false),
|
||||||
NumInsts(0), NumBlocks(0), NumCalls(0),
|
NumInsts(0), NumBlocks(0), NumCalls(0),
|
||||||
NumInlineCandidates(0), NumVectorInsts(0),
|
NumInlineCandidates(0), NumVectorInsts(0),
|
||||||
NumRets(0) {}
|
NumRets(0) {}
|
||||||
|
|
||||||
/// analyzeBasicBlock - Add information about the specified basic block
|
/// analyzeBasicBlock - Add information about the specified basic block
|
||||||
@ -73,12 +73,12 @@ namespace llvm {
|
|||||||
/// analyzeFunction - Add information about the specified function
|
/// analyzeFunction - Add information about the specified function
|
||||||
/// to the current structure.
|
/// to the current structure.
|
||||||
void analyzeFunction(Function *F);
|
void analyzeFunction(Function *F);
|
||||||
|
|
||||||
/// CountCodeReductionForConstant - Figure out an approximation for how
|
/// CountCodeReductionForConstant - Figure out an approximation for how
|
||||||
/// many instructions will be constant folded if the specified value is
|
/// many instructions will be constant folded if the specified value is
|
||||||
/// constant.
|
/// constant.
|
||||||
unsigned CountCodeReductionForConstant(Value *V);
|
unsigned CountCodeReductionForConstant(Value *V);
|
||||||
|
|
||||||
/// CountBonusForConstant - Figure out an approximation for how much
|
/// CountBonusForConstant - Figure out an approximation for how much
|
||||||
/// per-call performance boost we can expect if the specified value is
|
/// per-call performance boost we can expect if the specified value is
|
||||||
/// constant.
|
/// constant.
|
||||||
|
@ -24,13 +24,13 @@ using namespace llvm;
|
|||||||
/// TODO: Perhaps calls like memcpy, strcpy, etc?
|
/// TODO: Perhaps calls like memcpy, strcpy, etc?
|
||||||
bool llvm::callIsSmall(const Function *F) {
|
bool llvm::callIsSmall(const Function *F) {
|
||||||
if (!F) return false;
|
if (!F) return false;
|
||||||
|
|
||||||
if (F->hasLocalLinkage()) return false;
|
if (F->hasLocalLinkage()) return false;
|
||||||
|
|
||||||
if (!F->hasName()) return false;
|
if (!F->hasName()) return false;
|
||||||
|
|
||||||
StringRef Name = F->getName();
|
StringRef Name = F->getName();
|
||||||
|
|
||||||
// These will all likely lower to a single selection DAG node.
|
// These will all likely lower to a single selection DAG node.
|
||||||
if (Name == "copysign" || Name == "copysignf" || Name == "copysignl" ||
|
if (Name == "copysign" || Name == "copysignf" || Name == "copysignl" ||
|
||||||
Name == "fabs" || Name == "fabsf" || Name == "fabsl" ||
|
Name == "fabs" || Name == "fabsf" || Name == "fabsl" ||
|
||||||
@ -38,7 +38,7 @@ bool llvm::callIsSmall(const Function *F) {
|
|||||||
Name == "cos" || Name == "cosf" || Name == "cosl" ||
|
Name == "cos" || Name == "cosf" || Name == "cosl" ||
|
||||||
Name == "sqrt" || Name == "sqrtf" || Name == "sqrtl" )
|
Name == "sqrt" || Name == "sqrtf" || Name == "sqrtl" )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// These are all likely to be optimized into something smaller.
|
// These are all likely to be optimized into something smaller.
|
||||||
if (Name == "pow" || Name == "powf" || Name == "powl" ||
|
if (Name == "pow" || Name == "powf" || Name == "powl" ||
|
||||||
Name == "exp2" || Name == "exp2l" || Name == "exp2f" ||
|
Name == "exp2" || Name == "exp2l" || Name == "exp2f" ||
|
||||||
@ -46,7 +46,7 @@ bool llvm::callIsSmall(const Function *F) {
|
|||||||
Name == "round" || Name == "ffs" || Name == "ffsl" ||
|
Name == "round" || Name == "ffs" || Name == "ffsl" ||
|
||||||
Name == "abs" || Name == "labs" || Name == "llabs")
|
Name == "abs" || Name == "labs" || Name == "llabs")
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,8 +67,8 @@ void CodeMetrics::analyzeBasicBlock(const BasicBlock *BB) {
|
|||||||
ImmutableCallSite CS(cast<Instruction>(II));
|
ImmutableCallSite CS(cast<Instruction>(II));
|
||||||
|
|
||||||
if (const Function *F = CS.getCalledFunction()) {
|
if (const Function *F = CS.getCalledFunction()) {
|
||||||
// If a function is both internal and has a single use, then it is
|
// If a function is both internal and has a single use, then it is
|
||||||
// extremely likely to get inlined in the future (it was probably
|
// extremely likely to get inlined in the future (it was probably
|
||||||
// exposed by an interleaved devirtualization pass).
|
// exposed by an interleaved devirtualization pass).
|
||||||
if (F->hasInternalLinkage() && F->hasOneUse())
|
if (F->hasInternalLinkage() && F->hasOneUse())
|
||||||
++NumInlineCandidates;
|
++NumInlineCandidates;
|
||||||
@ -91,18 +91,18 @@ void CodeMetrics::analyzeBasicBlock(const BasicBlock *BB) {
|
|||||||
++NumCalls;
|
++NumCalls;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (const AllocaInst *AI = dyn_cast<AllocaInst>(II)) {
|
if (const AllocaInst *AI = dyn_cast<AllocaInst>(II)) {
|
||||||
if (!AI->isStaticAlloca())
|
if (!AI->isStaticAlloca())
|
||||||
this->usesDynamicAlloca = true;
|
this->usesDynamicAlloca = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isa<ExtractElementInst>(II) || II->getType()->isVectorTy())
|
if (isa<ExtractElementInst>(II) || II->getType()->isVectorTy())
|
||||||
++NumVectorInsts;
|
++NumVectorInsts;
|
||||||
|
|
||||||
if (const CastInst *CI = dyn_cast<CastInst>(II)) {
|
if (const CastInst *CI = dyn_cast<CastInst>(II)) {
|
||||||
// Noop casts, including ptr <-> int, don't count.
|
// Noop casts, including ptr <-> int, don't count.
|
||||||
if (CI->isLosslessCast() || isa<IntToPtrInst>(CI) ||
|
if (CI->isLosslessCast() || isa<IntToPtrInst>(CI) ||
|
||||||
isa<PtrToIntInst>(CI))
|
isa<PtrToIntInst>(CI))
|
||||||
continue;
|
continue;
|
||||||
// Result of a cmp instruction is often extended (to be used by other
|
// Result of a cmp instruction is often extended (to be used by other
|
||||||
@ -119,10 +119,10 @@ void CodeMetrics::analyzeBasicBlock(const BasicBlock *BB) {
|
|||||||
|
|
||||||
++NumInsts;
|
++NumInsts;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isa<ReturnInst>(BB->getTerminator()))
|
if (isa<ReturnInst>(BB->getTerminator()))
|
||||||
++NumRets;
|
++NumRets;
|
||||||
|
|
||||||
// We never want to inline functions that contain an indirectbr. This is
|
// We never want to inline functions that contain an indirectbr. This is
|
||||||
// incorrect because all the blockaddress's (in static global initializers
|
// incorrect because all the blockaddress's (in static global initializers
|
||||||
// for example) would be referring to the original function, and this indirect
|
// for example) would be referring to the original function, and this indirect
|
||||||
@ -252,7 +252,7 @@ void InlineCostAnalyzer::FunctionInfo::analyzeFunction(Function *F) {
|
|||||||
/// NeverInline - returns true if the function should never be inlined into
|
/// NeverInline - returns true if the function should never be inlined into
|
||||||
/// any caller
|
/// any caller
|
||||||
bool InlineCostAnalyzer::FunctionInfo::NeverInline() {
|
bool InlineCostAnalyzer::FunctionInfo::NeverInline() {
|
||||||
return (Metrics.callsSetJmp || Metrics.isRecursive ||
|
return (Metrics.callsSetJmp || Metrics.isRecursive ||
|
||||||
Metrics.containsIndirectBr);
|
Metrics.containsIndirectBr);
|
||||||
}
|
}
|
||||||
// getSpecializationBonus - The heuristic used to determine the per-call
|
// getSpecializationBonus - The heuristic used to determine the per-call
|
||||||
@ -263,16 +263,16 @@ int InlineCostAnalyzer::getSpecializationBonus(Function *Callee,
|
|||||||
{
|
{
|
||||||
if (Callee->mayBeOverridden())
|
if (Callee->mayBeOverridden())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
int Bonus = 0;
|
int Bonus = 0;
|
||||||
// If this function uses the coldcc calling convention, prefer not to
|
// If this function uses the coldcc calling convention, prefer not to
|
||||||
// specialize it.
|
// specialize it.
|
||||||
if (Callee->getCallingConv() == CallingConv::Cold)
|
if (Callee->getCallingConv() == CallingConv::Cold)
|
||||||
Bonus -= InlineConstants::ColdccPenalty;
|
Bonus -= InlineConstants::ColdccPenalty;
|
||||||
|
|
||||||
// Get information about the callee.
|
// Get information about the callee.
|
||||||
FunctionInfo *CalleeFI = &CachedFunctionInfo[Callee];
|
FunctionInfo *CalleeFI = &CachedFunctionInfo[Callee];
|
||||||
|
|
||||||
// If we haven't calculated this information yet, do so now.
|
// If we haven't calculated this information yet, do so now.
|
||||||
if (CalleeFI->Metrics.NumBlocks == 0)
|
if (CalleeFI->Metrics.NumBlocks == 0)
|
||||||
CalleeFI->analyzeFunction(Callee);
|
CalleeFI->analyzeFunction(Callee);
|
||||||
@ -286,7 +286,7 @@ int InlineCostAnalyzer::getSpecializationBonus(Function *Callee,
|
|||||||
Bonus += CountBonusForConstant(I);
|
Bonus += CountBonusForConstant(I);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calls usually take a long time, so they make the specialization gain
|
// Calls usually take a long time, so they make the specialization gain
|
||||||
// smaller.
|
// smaller.
|
||||||
Bonus -= CalleeFI->Metrics.NumCalls * InlineConstants::CallPenalty;
|
Bonus -= CalleeFI->Metrics.NumCalls * InlineConstants::CallPenalty;
|
||||||
|
|
||||||
@ -300,13 +300,13 @@ int InlineCostAnalyzer::getSpecializationBonus(Function *Callee,
|
|||||||
// inlining because we decide we don't want to give a bonus for
|
// inlining because we decide we don't want to give a bonus for
|
||||||
// devirtualizing.
|
// devirtualizing.
|
||||||
int InlineCostAnalyzer::ConstantFunctionBonus(CallSite CS, Constant *C) {
|
int InlineCostAnalyzer::ConstantFunctionBonus(CallSite CS, Constant *C) {
|
||||||
|
|
||||||
// This could just be NULL.
|
// This could just be NULL.
|
||||||
if (!C) return 0;
|
if (!C) return 0;
|
||||||
|
|
||||||
Function *F = dyn_cast<Function>(C);
|
Function *F = dyn_cast<Function>(C);
|
||||||
if (!F) return 0;
|
if (!F) return 0;
|
||||||
|
|
||||||
int Bonus = InlineConstants::IndirectCallBonus + getInlineSize(CS, F);
|
int Bonus = InlineConstants::IndirectCallBonus + getInlineSize(CS, F);
|
||||||
return (Bonus > 0) ? 0 : Bonus;
|
return (Bonus > 0) ? 0 : Bonus;
|
||||||
}
|
}
|
||||||
@ -355,18 +355,18 @@ int InlineCostAnalyzer::CountBonusForConstant(Value *V, Constant *C) {
|
|||||||
Bonus += CountBonusForConstant(&Inst);
|
Bonus += CountBonusForConstant(&Inst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Bonus;
|
return Bonus;
|
||||||
}
|
}
|
||||||
|
|
||||||
int InlineCostAnalyzer::getInlineSize(CallSite CS, Function *Callee) {
|
int InlineCostAnalyzer::getInlineSize(CallSite CS, Function *Callee) {
|
||||||
// Get information about the callee.
|
// Get information about the callee.
|
||||||
FunctionInfo *CalleeFI = &CachedFunctionInfo[Callee];
|
FunctionInfo *CalleeFI = &CachedFunctionInfo[Callee];
|
||||||
|
|
||||||
// If we haven't calculated this information yet, do so now.
|
// If we haven't calculated this information yet, do so now.
|
||||||
if (CalleeFI->Metrics.NumBlocks == 0)
|
if (CalleeFI->Metrics.NumBlocks == 0)
|
||||||
CalleeFI->analyzeFunction(Callee);
|
CalleeFI->analyzeFunction(Callee);
|
||||||
|
|
||||||
// InlineCost - This value measures how good of an inline candidate this call
|
// InlineCost - This value measures how good of an inline candidate this call
|
||||||
// site is to inline. A lower inline cost make is more likely for the call to
|
// site is to inline. A lower inline cost make is more likely for the call to
|
||||||
// be inlined. This value may go negative.
|
// be inlined. This value may go negative.
|
||||||
@ -392,9 +392,9 @@ int InlineCostAnalyzer::getInlineSize(CallSite CS, Function *Callee) {
|
|||||||
// weights calculated for the callee to determine how much will be folded
|
// weights calculated for the callee to determine how much will be folded
|
||||||
// away with this information.
|
// away with this information.
|
||||||
else if (isa<Constant>(I))
|
else if (isa<Constant>(I))
|
||||||
InlineCost -= CalleeFI->ArgumentWeights[ArgNo].ConstantWeight;
|
InlineCost -= CalleeFI->ArgumentWeights[ArgNo].ConstantWeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Each argument passed in has a cost at both the caller and the callee
|
// Each argument passed in has a cost at both the caller and the callee
|
||||||
// sides. Measurements show that each argument costs about the same as an
|
// sides. Measurements show that each argument costs about the same as an
|
||||||
// instruction.
|
// instruction.
|
||||||
@ -408,28 +408,28 @@ int InlineCostAnalyzer::getInlineSize(CallSite CS, Function *Callee) {
|
|||||||
|
|
||||||
// Look at the size of the callee. Each instruction counts as 5.
|
// Look at the size of the callee. Each instruction counts as 5.
|
||||||
InlineCost += CalleeFI->Metrics.NumInsts*InlineConstants::InstrCost;
|
InlineCost += CalleeFI->Metrics.NumInsts*InlineConstants::InstrCost;
|
||||||
|
|
||||||
return InlineCost;
|
return InlineCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
int InlineCostAnalyzer::getInlineBonuses(CallSite CS, Function *Callee) {
|
int InlineCostAnalyzer::getInlineBonuses(CallSite CS, Function *Callee) {
|
||||||
// Get information about the callee.
|
// Get information about the callee.
|
||||||
FunctionInfo *CalleeFI = &CachedFunctionInfo[Callee];
|
FunctionInfo *CalleeFI = &CachedFunctionInfo[Callee];
|
||||||
|
|
||||||
// If we haven't calculated this information yet, do so now.
|
// If we haven't calculated this information yet, do so now.
|
||||||
if (CalleeFI->Metrics.NumBlocks == 0)
|
if (CalleeFI->Metrics.NumBlocks == 0)
|
||||||
CalleeFI->analyzeFunction(Callee);
|
CalleeFI->analyzeFunction(Callee);
|
||||||
|
|
||||||
bool isDirectCall = CS.getCalledFunction() == Callee;
|
bool isDirectCall = CS.getCalledFunction() == Callee;
|
||||||
Instruction *TheCall = CS.getInstruction();
|
Instruction *TheCall = CS.getInstruction();
|
||||||
int Bonus = 0;
|
int Bonus = 0;
|
||||||
|
|
||||||
// If there is only one call of the function, and it has internal linkage,
|
// If there is only one call of the function, and it has internal linkage,
|
||||||
// make it almost guaranteed to be inlined.
|
// make it almost guaranteed to be inlined.
|
||||||
//
|
//
|
||||||
if (Callee->hasLocalLinkage() && Callee->hasOneUse() && isDirectCall)
|
if (Callee->hasLocalLinkage() && Callee->hasOneUse() && isDirectCall)
|
||||||
Bonus += InlineConstants::LastCallToStaticBonus;
|
Bonus += InlineConstants::LastCallToStaticBonus;
|
||||||
|
|
||||||
// If the instruction after the call, or if the normal destination of the
|
// If the instruction after the call, or if the normal destination of the
|
||||||
// invoke is an unreachable instruction, the function is noreturn. As such,
|
// invoke is an unreachable instruction, the function is noreturn. As such,
|
||||||
// there is little point in inlining this.
|
// there is little point in inlining this.
|
||||||
@ -438,12 +438,12 @@ int InlineCostAnalyzer::getInlineBonuses(CallSite CS, Function *Callee) {
|
|||||||
Bonus += InlineConstants::NoreturnPenalty;
|
Bonus += InlineConstants::NoreturnPenalty;
|
||||||
} else if (isa<UnreachableInst>(++BasicBlock::iterator(TheCall)))
|
} else if (isa<UnreachableInst>(++BasicBlock::iterator(TheCall)))
|
||||||
Bonus += InlineConstants::NoreturnPenalty;
|
Bonus += InlineConstants::NoreturnPenalty;
|
||||||
|
|
||||||
// If this function uses the coldcc calling convention, prefer not to inline
|
// If this function uses the coldcc calling convention, prefer not to inline
|
||||||
// it.
|
// it.
|
||||||
if (Callee->getCallingConv() == CallingConv::Cold)
|
if (Callee->getCallingConv() == CallingConv::Cold)
|
||||||
Bonus += InlineConstants::ColdccPenalty;
|
Bonus += InlineConstants::ColdccPenalty;
|
||||||
|
|
||||||
// Add to the inline quality for properties that make the call valuable to
|
// Add to the inline quality for properties that make the call valuable to
|
||||||
// inline. This includes factors that indicate that the result of inlining
|
// inline. This includes factors that indicate that the result of inlining
|
||||||
// the function will be optimizable. Currently this just looks at arguments
|
// the function will be optimizable. Currently this just looks at arguments
|
||||||
@ -455,7 +455,7 @@ int InlineCostAnalyzer::getInlineBonuses(CallSite CS, Function *Callee) {
|
|||||||
// Compute any constant bonus due to inlining we want to give here.
|
// Compute any constant bonus due to inlining we want to give here.
|
||||||
if (isa<Constant>(I))
|
if (isa<Constant>(I))
|
||||||
Bonus += CountBonusForConstant(FI, cast<Constant>(I));
|
Bonus += CountBonusForConstant(FI, cast<Constant>(I));
|
||||||
|
|
||||||
return Bonus;
|
return Bonus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -483,7 +483,7 @@ InlineCost InlineCostAnalyzer::getInlineCost(CallSite CS,
|
|||||||
|
|
||||||
// Get information about the callee.
|
// Get information about the callee.
|
||||||
FunctionInfo *CalleeFI = &CachedFunctionInfo[Callee];
|
FunctionInfo *CalleeFI = &CachedFunctionInfo[Callee];
|
||||||
|
|
||||||
// If we haven't calculated this information yet, do so now.
|
// If we haven't calculated this information yet, do so now.
|
||||||
if (CalleeFI->Metrics.NumBlocks == 0)
|
if (CalleeFI->Metrics.NumBlocks == 0)
|
||||||
CalleeFI->analyzeFunction(Callee);
|
CalleeFI->analyzeFunction(Callee);
|
||||||
@ -498,7 +498,7 @@ InlineCost InlineCostAnalyzer::getInlineCost(CallSite CS,
|
|||||||
// requires handling setjmp somewhere else, however.
|
// requires handling setjmp somewhere else, however.
|
||||||
if (!Callee->isDeclaration() && Callee->hasFnAttr(Attribute::AlwaysInline))
|
if (!Callee->isDeclaration() && Callee->hasFnAttr(Attribute::AlwaysInline))
|
||||||
return InlineCost::getAlways();
|
return InlineCost::getAlways();
|
||||||
|
|
||||||
if (CalleeFI->Metrics.usesDynamicAlloca) {
|
if (CalleeFI->Metrics.usesDynamicAlloca) {
|
||||||
// Get information about the caller.
|
// Get information about the caller.
|
||||||
FunctionInfo &CallerFI = CachedFunctionInfo[Caller];
|
FunctionInfo &CallerFI = CachedFunctionInfo[Caller];
|
||||||
@ -506,7 +506,7 @@ InlineCost InlineCostAnalyzer::getInlineCost(CallSite CS,
|
|||||||
// If we haven't calculated this information yet, do so now.
|
// If we haven't calculated this information yet, do so now.
|
||||||
if (CallerFI.Metrics.NumBlocks == 0) {
|
if (CallerFI.Metrics.NumBlocks == 0) {
|
||||||
CallerFI.analyzeFunction(Caller);
|
CallerFI.analyzeFunction(Caller);
|
||||||
|
|
||||||
// Recompute the CalleeFI pointer, getting Caller could have invalidated
|
// Recompute the CalleeFI pointer, getting Caller could have invalidated
|
||||||
// it.
|
// it.
|
||||||
CalleeFI = &CachedFunctionInfo[Callee];
|
CalleeFI = &CachedFunctionInfo[Callee];
|
||||||
@ -538,16 +538,16 @@ InlineCost InlineCostAnalyzer::getSpecializationCost(Function *Callee,
|
|||||||
// something else.
|
// something else.
|
||||||
if (Callee->mayBeOverridden())
|
if (Callee->mayBeOverridden())
|
||||||
return llvm::InlineCost::getNever();
|
return llvm::InlineCost::getNever();
|
||||||
|
|
||||||
// Get information about the callee.
|
// Get information about the callee.
|
||||||
FunctionInfo *CalleeFI = &CachedFunctionInfo[Callee];
|
FunctionInfo *CalleeFI = &CachedFunctionInfo[Callee];
|
||||||
|
|
||||||
// If we haven't calculated this information yet, do so now.
|
// If we haven't calculated this information yet, do so now.
|
||||||
if (CalleeFI->Metrics.NumBlocks == 0)
|
if (CalleeFI->Metrics.NumBlocks == 0)
|
||||||
CalleeFI->analyzeFunction(Callee);
|
CalleeFI->analyzeFunction(Callee);
|
||||||
|
|
||||||
int Cost = 0;
|
int Cost = 0;
|
||||||
|
|
||||||
// Look at the original size of the callee. Each instruction counts as 5.
|
// Look at the original size of the callee. Each instruction counts as 5.
|
||||||
Cost += CalleeFI->Metrics.NumInsts * InlineConstants::InstrCost;
|
Cost += CalleeFI->Metrics.NumInsts * InlineConstants::InstrCost;
|
||||||
|
|
||||||
@ -564,10 +564,10 @@ InlineCost InlineCostAnalyzer::getSpecializationCost(Function *Callee,
|
|||||||
// higher threshold to determine if the function call should be inlined.
|
// higher threshold to determine if the function call should be inlined.
|
||||||
float InlineCostAnalyzer::getInlineFudgeFactor(CallSite CS) {
|
float InlineCostAnalyzer::getInlineFudgeFactor(CallSite CS) {
|
||||||
Function *Callee = CS.getCalledFunction();
|
Function *Callee = CS.getCalledFunction();
|
||||||
|
|
||||||
// Get information about the callee.
|
// Get information about the callee.
|
||||||
FunctionInfo &CalleeFI = CachedFunctionInfo[Callee];
|
FunctionInfo &CalleeFI = CachedFunctionInfo[Callee];
|
||||||
|
|
||||||
// If we haven't calculated this information yet, do so now.
|
// If we haven't calculated this information yet, do so now.
|
||||||
if (CalleeFI.Metrics.NumBlocks == 0)
|
if (CalleeFI.Metrics.NumBlocks == 0)
|
||||||
CalleeFI.analyzeFunction(Callee);
|
CalleeFI.analyzeFunction(Callee);
|
||||||
@ -604,7 +604,7 @@ InlineCostAnalyzer::growCachedCostInfo(Function *Caller, Function *Callee) {
|
|||||||
--CallerMetrics.NumCalls;
|
--CallerMetrics.NumCalls;
|
||||||
|
|
||||||
if (Callee == 0) return;
|
if (Callee == 0) return;
|
||||||
|
|
||||||
CodeMetrics &CalleeMetrics = CachedFunctionInfo[Callee].Metrics;
|
CodeMetrics &CalleeMetrics = CachedFunctionInfo[Callee].Metrics;
|
||||||
|
|
||||||
// If we don't have metrics for the callee, don't recalculate them just to
|
// If we don't have metrics for the callee, don't recalculate them just to
|
||||||
@ -614,7 +614,7 @@ InlineCostAnalyzer::growCachedCostInfo(Function *Caller, Function *Callee) {
|
|||||||
resetCachedCostInfo(Caller);
|
resetCachedCostInfo(Caller);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since CalleeMetrics were already calculated, we know that the CallerMetrics
|
// Since CalleeMetrics were already calculated, we know that the CallerMetrics
|
||||||
// reference isn't invalidated: both were in the DenseMap.
|
// reference isn't invalidated: both were in the DenseMap.
|
||||||
CallerMetrics.usesDynamicAlloca |= CalleeMetrics.usesDynamicAlloca;
|
CallerMetrics.usesDynamicAlloca |= CalleeMetrics.usesDynamicAlloca;
|
||||||
@ -636,7 +636,7 @@ InlineCostAnalyzer::growCachedCostInfo(Function *Caller, Function *Callee) {
|
|||||||
CallerMetrics.NumInsts -= Callee->arg_size();
|
CallerMetrics.NumInsts -= Callee->arg_size();
|
||||||
else
|
else
|
||||||
CallerMetrics.NumInsts = 0;
|
CallerMetrics.NumInsts = 0;
|
||||||
|
|
||||||
// We are not updating the argument weights. We have already determined that
|
// We are not updating the argument weights. We have already determined that
|
||||||
// Caller is a fairly large function, so we accept the loss of precision.
|
// Caller is a fairly large function, so we accept the loss of precision.
|
||||||
}
|
}
|
||||||
|
@ -32,10 +32,10 @@ namespace {
|
|||||||
// AlwaysInliner only inlines functions that are mark as "always inline".
|
// AlwaysInliner only inlines functions that are mark as "always inline".
|
||||||
class AlwaysInliner : public Inliner {
|
class AlwaysInliner : public Inliner {
|
||||||
// Functions that are never inlined
|
// Functions that are never inlined
|
||||||
SmallPtrSet<const Function*, 16> NeverInline;
|
SmallPtrSet<const Function*, 16> NeverInline;
|
||||||
InlineCostAnalyzer CA;
|
InlineCostAnalyzer CA;
|
||||||
public:
|
public:
|
||||||
// Use extremely low threshold.
|
// Use extremely low threshold.
|
||||||
AlwaysInliner() : Inliner(ID, -2000000000) {
|
AlwaysInliner() : Inliner(ID, -2000000000) {
|
||||||
initializeAlwaysInlinerPass(*PassRegistry::getPassRegistry());
|
initializeAlwaysInlinerPass(*PassRegistry::getPassRegistry());
|
||||||
}
|
}
|
||||||
@ -52,8 +52,8 @@ namespace {
|
|||||||
void growCachedCostInfo(Function* Caller, Function* Callee) {
|
void growCachedCostInfo(Function* Caller, Function* Callee) {
|
||||||
CA.growCachedCostInfo(Caller, Callee);
|
CA.growCachedCostInfo(Caller, Callee);
|
||||||
}
|
}
|
||||||
virtual bool doFinalization(CallGraph &CG) {
|
virtual bool doFinalization(CallGraph &CG) {
|
||||||
return removeDeadFunctions(CG, &NeverInline);
|
return removeDeadFunctions(CG, &NeverInline);
|
||||||
}
|
}
|
||||||
virtual bool doInitialization(CallGraph &CG);
|
virtual bool doInitialization(CallGraph &CG);
|
||||||
void releaseMemory() {
|
void releaseMemory() {
|
||||||
@ -71,11 +71,11 @@ INITIALIZE_PASS_END(AlwaysInliner, "always-inline",
|
|||||||
|
|
||||||
Pass *llvm::createAlwaysInlinerPass() { return new AlwaysInliner(); }
|
Pass *llvm::createAlwaysInlinerPass() { return new AlwaysInliner(); }
|
||||||
|
|
||||||
// doInitialization - Initializes the vector of functions that have not
|
// doInitialization - Initializes the vector of functions that have not
|
||||||
// been annotated with the "always inline" attribute.
|
// been annotated with the "always inline" attribute.
|
||||||
bool AlwaysInliner::doInitialization(CallGraph &CG) {
|
bool AlwaysInliner::doInitialization(CallGraph &CG) {
|
||||||
Module &M = CG.getModule();
|
Module &M = CG.getModule();
|
||||||
|
|
||||||
for (Module::iterator I = M.begin(), E = M.end();
|
for (Module::iterator I = M.begin(), E = M.end();
|
||||||
I != E; ++I)
|
I != E; ++I)
|
||||||
if (!I->isDeclaration() && !I->hasFnAttr(Attribute::AlwaysInline))
|
if (!I->isDeclaration() && !I->hasFnAttr(Attribute::AlwaysInline))
|
||||||
|
@ -30,7 +30,7 @@ namespace {
|
|||||||
|
|
||||||
class SimpleInliner : public Inliner {
|
class SimpleInliner : public Inliner {
|
||||||
// Functions that are never inlined
|
// Functions that are never inlined
|
||||||
SmallPtrSet<const Function*, 16> NeverInline;
|
SmallPtrSet<const Function*, 16> NeverInline;
|
||||||
InlineCostAnalyzer CA;
|
InlineCostAnalyzer CA;
|
||||||
public:
|
public:
|
||||||
SimpleInliner() : Inliner(ID) {
|
SimpleInliner() : Inliner(ID) {
|
||||||
@ -68,16 +68,16 @@ INITIALIZE_PASS_END(SimpleInliner, "inline",
|
|||||||
|
|
||||||
Pass *llvm::createFunctionInliningPass() { return new SimpleInliner(); }
|
Pass *llvm::createFunctionInliningPass() { return new SimpleInliner(); }
|
||||||
|
|
||||||
Pass *llvm::createFunctionInliningPass(int Threshold) {
|
Pass *llvm::createFunctionInliningPass(int Threshold) {
|
||||||
return new SimpleInliner(Threshold);
|
return new SimpleInliner(Threshold);
|
||||||
}
|
}
|
||||||
|
|
||||||
// doInitialization - Initializes the vector of functions that have been
|
// doInitialization - Initializes the vector of functions that have been
|
||||||
// annotated with the noinline attribute.
|
// annotated with the noinline attribute.
|
||||||
bool SimpleInliner::doInitialization(CallGraph &CG) {
|
bool SimpleInliner::doInitialization(CallGraph &CG) {
|
||||||
|
|
||||||
Module &M = CG.getModule();
|
Module &M = CG.getModule();
|
||||||
|
|
||||||
for (Module::iterator I = M.begin(), E = M.end();
|
for (Module::iterator I = M.begin(), E = M.end();
|
||||||
I != E; ++I)
|
I != E; ++I)
|
||||||
if (!I->isDeclaration() && I->hasFnAttr(Attribute::NoInline))
|
if (!I->isDeclaration() && I->hasFnAttr(Attribute::NoInline))
|
||||||
@ -85,34 +85,34 @@ bool SimpleInliner::doInitialization(CallGraph &CG) {
|
|||||||
|
|
||||||
// Get llvm.noinline
|
// Get llvm.noinline
|
||||||
GlobalVariable *GV = M.getNamedGlobal("llvm.noinline");
|
GlobalVariable *GV = M.getNamedGlobal("llvm.noinline");
|
||||||
|
|
||||||
if (GV == 0)
|
if (GV == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Don't crash on invalid code
|
// Don't crash on invalid code
|
||||||
if (!GV->hasDefinitiveInitializer())
|
if (!GV->hasDefinitiveInitializer())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const ConstantArray *InitList = dyn_cast<ConstantArray>(GV->getInitializer());
|
const ConstantArray *InitList = dyn_cast<ConstantArray>(GV->getInitializer());
|
||||||
|
|
||||||
if (InitList == 0)
|
if (InitList == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Iterate over each element and add to the NeverInline set
|
// Iterate over each element and add to the NeverInline set
|
||||||
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
|
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
|
||||||
|
|
||||||
// Get Source
|
// Get Source
|
||||||
const Constant *Elt = InitList->getOperand(i);
|
const Constant *Elt = InitList->getOperand(i);
|
||||||
|
|
||||||
if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(Elt))
|
if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(Elt))
|
||||||
if (CE->getOpcode() == Instruction::BitCast)
|
if (CE->getOpcode() == Instruction::BitCast)
|
||||||
Elt = CE->getOperand(0);
|
Elt = CE->getOperand(0);
|
||||||
|
|
||||||
// Insert into set of functions to never inline
|
// Insert into set of functions to never inline
|
||||||
if (const Function *F = dyn_cast<Function>(Elt))
|
if (const Function *F = dyn_cast<Function>(Elt))
|
||||||
NeverInline.insert(F);
|
NeverInline.insert(F);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user