From 0b19b81ac93303db88fde287a165adb9f05c8870 Mon Sep 17 00:00:00 2001 From: kai Date: Mon, 11 Mar 2013 22:01:34 +0100 Subject: [PATCH 1/2] Add new intrinsic LDC_never_inline. LDC_never_inline is a complementary intrinsic to LDC_allow_inline. It tells the LLVM optimizer to never inline a function. This can be useful if inlining creates incorrect code. A possible application is core.thread.getStackTop(). --- dmd2/declaration.h | 3 +++ dmd2/func.c | 1 + dmd2/idgen.c | 1 + dmd2/statement.c | 4 ++++ gen/functions.cpp | 5 +++++ 5 files changed, 14 insertions(+) diff --git a/dmd2/declaration.h b/dmd2/declaration.h index ee488b2d..af7b9952 100644 --- a/dmd2/declaration.h +++ b/dmd2/declaration.h @@ -930,6 +930,9 @@ struct FuncDeclaration : Declaration // true if overridden with the pragma(allow_inline); stmt bool allowInlining; + // true if set with pragma(LDC_no_inline) + bool neverInline; + // true if has inline assembler bool inlineAsm; #endif diff --git a/dmd2/func.c b/dmd2/func.c index 7a7b55bc..2f43947c 100644 --- a/dmd2/func.c +++ b/dmd2/func.c @@ -103,6 +103,7 @@ FuncDeclaration::FuncDeclaration(Loc loc, Loc endloc, Identifier *id, StorageCla // LDC isArrayOp = false; allowInlining = false; + neverInline = false; availableExternally = true; // assume this unless proven otherwise // function types in ldc don't merge if the context parameter differs diff --git a/dmd2/idgen.c b/dmd2/idgen.c index edd66bf9..8b71d3f8 100644 --- a/dmd2/idgen.c +++ b/dmd2/idgen.c @@ -278,6 +278,7 @@ Msgtable msgtable[] = { "LDC_va_arg" }, { "LDC_verbose" }, { "LDC_allow_inline" }, + { "LDC_never_inline" }, { "LDC_inline_asm" }, { "LDC_inline_ir" }, { "LDC_fence" }, diff --git a/dmd2/statement.c b/dmd2/statement.c index 15da3909..9f064312 100644 --- a/dmd2/statement.c +++ b/dmd2/statement.c @@ -3175,6 +3175,10 @@ Statement *PragmaStatement::semantic(Scope *sc) { sc->func->allowInlining = true; } + else if (ident == Id::LDC_never_inline) + { + sc->func->neverInline = true; + } #endif #if DMDV2 else if (ident == Id::startaddress) diff --git a/gen/functions.cpp b/gen/functions.cpp index 51a0f48f..4b1bcb3b 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -815,6 +815,11 @@ void DtoDeclareFunction(FuncDeclaration* fdecl) } } + if (fdecl->neverInline) + { + fdecl->ir.irFunc->setNeverInline(); + } + if (fdecl->llvmInternal == LLVMglobal_crt_ctor || fdecl->llvmInternal == LLVMglobal_crt_dtor) { AppendFunctionToLLVMGlobalCtorsDtors(func, fdecl->priority, fdecl->llvmInternal == LLVMglobal_crt_ctor); From 5854fbfeb1b670fe987aa73e649d2ac40cfa044c Mon Sep 17 00:00:00 2001 From: kai Date: Mon, 11 Mar 2013 22:32:33 +0100 Subject: [PATCH 2/2] Fix comments --- dmd2/declaration.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dmd2/declaration.h b/dmd2/declaration.h index af7b9952..7193296c 100644 --- a/dmd2/declaration.h +++ b/dmd2/declaration.h @@ -927,10 +927,10 @@ struct FuncDeclaration : Declaration // Functions that wouldn't have gotten semantic3'ed if we weren't inlining set this flag. bool availableExternally; - // true if overridden with the pragma(allow_inline); stmt + // true if overridden with the pragma(LDC_allow_inline); stmt bool allowInlining; - // true if set with pragma(LDC_no_inline) + // true if set with the pragma(LDC_never_inline); stmt bool neverInline; // true if has inline assembler