mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-04 06:09:05 +00:00
Inliner uses a smaller inline threshold for callees with cold attribute.
Added command line option inlinecold-threshold to set threshold for inlining functions with cold attribute. Listen to the cold attribute when it would decrease the inline threshold. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200886 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
8147752976
commit
df7da79db6
@ -50,6 +50,10 @@ static cl::opt<int>
|
||||
HintThreshold("inlinehint-threshold", cl::Hidden, cl::init(325),
|
||||
cl::desc("Threshold for inlining functions with inline hint"));
|
||||
|
||||
static cl::opt<int>
|
||||
ColdThreshold("inlinecold-threshold", cl::Hidden, cl::init(75),
|
||||
cl::desc("Threshold for inlining functions with cold attribute"));
|
||||
|
||||
// Threshold to use when optsize is specified (and there is no -inline-limit).
|
||||
const int OptSizeThreshold = 75;
|
||||
|
||||
@ -277,6 +281,13 @@ unsigned Inliner::getInlineThreshold(CallSite CS) const {
|
||||
Attribute::MinSize))
|
||||
thres = HintThreshold;
|
||||
|
||||
// Listen to the cold attribute when it would decrease the threshold.
|
||||
bool ColdCallee = Callee && !Callee->isDeclaration() &&
|
||||
Callee->getAttributes().hasAttribute(AttributeSet::FunctionIndex,
|
||||
Attribute::Cold);
|
||||
if (ColdCallee && ColdThreshold < thres)
|
||||
thres = ColdThreshold;
|
||||
|
||||
return thres;
|
||||
}
|
||||
|
||||
|
88
test/Transforms/Inline/inline-cold.ll
Normal file
88
test/Transforms/Inline/inline-cold.ll
Normal file
@ -0,0 +1,88 @@
|
||||
; RUN: opt < %s -inline -S | FileCheck %s
|
||||
|
||||
; Test that functions with attribute Cold are not inlined while the
|
||||
; same function without attribute Cold will be inlined.
|
||||
|
||||
@a = global i32 4
|
||||
|
||||
; This function should be larger than the cold threshold (75), but smaller
|
||||
; than the regular threshold.
|
||||
; Function Attrs: nounwind readnone uwtable
|
||||
define i32 @simpleFunction(i32 %a) #0 {
|
||||
entry:
|
||||
%a1 = load volatile i32* @a
|
||||
%x1 = add i32 %a1, %a1
|
||||
%a2 = load volatile i32* @a
|
||||
%x2 = add i32 %x1, %a2
|
||||
%a3 = load volatile i32* @a
|
||||
%x3 = add i32 %x2, %a3
|
||||
%a4 = load volatile i32* @a
|
||||
%x4 = add i32 %x3, %a4
|
||||
%a5 = load volatile i32* @a
|
||||
%x5 = add i32 %x4, %a5
|
||||
%a6 = load volatile i32* @a
|
||||
%x6 = add i32 %x5, %a6
|
||||
%a7 = load volatile i32* @a
|
||||
%x7 = add i32 %x6, %a6
|
||||
%a8 = load volatile i32* @a
|
||||
%x8 = add i32 %x7, %a8
|
||||
%a9 = load volatile i32* @a
|
||||
%x9 = add i32 %x8, %a9
|
||||
%a10 = load volatile i32* @a
|
||||
%x10 = add i32 %x9, %a10
|
||||
%a11 = load volatile i32* @a
|
||||
%x11 = add i32 %x10, %a11
|
||||
%a12 = load volatile i32* @a
|
||||
%x12 = add i32 %x11, %a12
|
||||
%add = add i32 %x12, %a
|
||||
ret i32 %add
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind cold readnone uwtable
|
||||
define i32 @ColdFunction(i32 %a) #1 {
|
||||
; CHECK-LABEL: @ColdFunction
|
||||
; CHECK: ret
|
||||
entry:
|
||||
%a1 = load volatile i32* @a
|
||||
%x1 = add i32 %a1, %a1
|
||||
%a2 = load volatile i32* @a
|
||||
%x2 = add i32 %x1, %a2
|
||||
%a3 = load volatile i32* @a
|
||||
%x3 = add i32 %x2, %a3
|
||||
%a4 = load volatile i32* @a
|
||||
%x4 = add i32 %x3, %a4
|
||||
%a5 = load volatile i32* @a
|
||||
%x5 = add i32 %x4, %a5
|
||||
%a6 = load volatile i32* @a
|
||||
%x6 = add i32 %x5, %a6
|
||||
%a7 = load volatile i32* @a
|
||||
%x7 = add i32 %x6, %a6
|
||||
%a8 = load volatile i32* @a
|
||||
%x8 = add i32 %x7, %a8
|
||||
%a9 = load volatile i32* @a
|
||||
%x9 = add i32 %x8, %a9
|
||||
%a10 = load volatile i32* @a
|
||||
%x10 = add i32 %x9, %a10
|
||||
%a11 = load volatile i32* @a
|
||||
%x11 = add i32 %x10, %a11
|
||||
%a12 = load volatile i32* @a
|
||||
%x12 = add i32 %x11, %a12
|
||||
%add = add i32 %x12, %a
|
||||
ret i32 %add
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind readnone uwtable
|
||||
define i32 @bar(i32 %a) #0 {
|
||||
; CHECK-LABEL: @bar
|
||||
; CHECK: call i32 @ColdFunction(i32 5)
|
||||
; CHECK-NOT: call i32 @simpleFunction(i32 6)
|
||||
; CHECK: ret
|
||||
entry:
|
||||
%0 = tail call i32 @ColdFunction(i32 5)
|
||||
%1 = tail call i32 @simpleFunction(i32 6)
|
||||
%add = add i32 %0, %1
|
||||
ret i32 %add
|
||||
}
|
||||
|
||||
attributes #0 = { nounwind readnone uwtable }
|
||||
attributes #1 = { nounwind cold readnone uwtable }
|
Loading…
Reference in New Issue
Block a user