Implement same-module pragma(inline, {true|false}).

This commit is contained in:
Johan Engelen 2016-06-15 23:56:54 +02:00
parent b12854df57
commit b8048be6e4
2 changed files with 74 additions and 0 deletions

View file

@ -527,8 +527,15 @@ void DtoDeclareFunction(FuncDeclaration *fdecl) {
gIR->mainFunc = func; gIR->mainFunc = func;
} }
// Set inlining attribute
if (fdecl->neverInline) { if (fdecl->neverInline) {
irFunc->setNeverInline(); irFunc->setNeverInline();
} else {
if (fdecl->inlining == PINLINEalways) {
irFunc->setAlwaysInline();
} else if (fdecl->inlining == PINLINEnever) {
irFunc->setNeverInline();
}
} }
if (fdecl->llvmInternal == LLVMglobal_crt_ctor || if (fdecl->llvmInternal == LLVMglobal_crt_ctor ||

View file

@ -0,0 +1,67 @@
// Test inlining of functions marked with pragma(inline)
// RUN: %ldc %s -I%S -c -output-ll -O0 -of=%t.O0.ll && FileCheck %s --check-prefix OPTNONE < %t.O0.ll
// RUN: %ldc %s -I%S -c -output-ll -O3 -of=%t.O3.ll && FileCheck %s --check-prefix OPT3 < %t.O3.ll
extern (C): // simplify mangling for easier matching
int dummy;
// OPTNONE-LABEL: define{{.*}} @never_inline
// OPTNONE-SAME: #[[NEVER:[0-9]+]]
pragma(inline, false) int never_inline()
{
dummy = 111;
return 222;
}
int external();
// OPTNONE-LABEL: define{{.*}} @always_inline
// OPTNONE-SAME: #[[ALWAYS:[0-9]+]]
pragma(inline, true) int always_inline()
{
int a;
foreach (i; 1 .. 10)
{
foreach (ii; 1 .. 10)
{
foreach (iii; 1 .. 10)
{
a += i * external();
}
}
}
dummy = 444;
return a;
}
// OPTNONE-LABEL: define{{.*}} @foo
// OPTNONE-SAME: #[[FOO:[0-9]+]]
int foo()
{
return 333;
}
// OPT3-LABEL: define{{.*}} @call_always_inline
int call_always_inline()
{
// OPT3-NOT: call {{.*}} @always_inline()
// OPT3: ret
return always_inline();
}
// OPT3-LABEL: define{{.*}} @call_never_inline
int call_never_inline()
{
// OPT3: call {{.*}} @never_inline()
// OPT3: ret
return never_inline();
}
// OPTNONE-NOT: attributes #[[FOO]] ={{.*}} alwaysinline
// OPTNONE-NOT: attributes #[[FOO]] ={{.*}} noinline
// OPTNONE-NOT: attributes #[[NEVER]] ={{.*}} alwaysinline
// OPTNONE-NOT: attributes #[[ALWAYS]] ={{.*}} noinline
// OPTNONE-DAG: attributes #[[NEVER]] ={{.*}} noinline
// OPTNONE-DAG: attributes #[[ALWAYS]] ={{.*}} alwaysinline