From 4e0b6b4bf0f6c190868b1d3d4385be88a4598d7e Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Mon, 8 Sep 2008 20:38:55 +0200 Subject: [PATCH] Make sure functions containing inline asm are never inlined to avoid duplicated labels. --- gen/asmstmt.cpp | 3 +++ ir/irfunction.cpp | 14 ++++++++++++++ ir/irfunction.h | 4 ++++ 3 files changed, 21 insertions(+) diff --git a/gen/asmstmt.cpp b/gen/asmstmt.cpp index c62a1d2a..e9ce04c3 100644 --- a/gen/asmstmt.cpp +++ b/gen/asmstmt.cpp @@ -450,6 +450,9 @@ void AsmBlockStatement::toIR(IRState* p) LOG_SCOPE; Logger::println("BEGIN ASM"); + // disable inlining + gIR->func()->setNeverInline(); + // create asm block structure assert(!p->asmBlock); IRAsmBlock* asmblock = new IRAsmBlock; diff --git a/ir/irfunction.cpp b/ir/irfunction.cpp index aeeb048d..dbb96ba9 100644 --- a/ir/irfunction.cpp +++ b/ir/irfunction.cpp @@ -63,3 +63,17 @@ void IrFunction::popLabelScope() labelScopes.pop_back(); nextUnique.pop(); } + +void IrFunction::setNeverInline() +{ + llvm::FunctionNotes cur = func->getNotes(); + assert(!(cur & llvm::FN_NOTE_AlwaysInline) && "function can't be never- and always-inline at the same time"); + func->setNotes(cur | llvm::FN_NOTE_NoInline); +} + +void IrFunction::setAlwaysInline() +{ + llvm::FunctionNotes cur = func->getNotes(); + assert(!(cur & llvm::FN_NOTE_NoInline) && "function can't be never- and always-inline at the same time"); + func->setNotes(cur | llvm::FN_NOTE_AlwaysInline); +} diff --git a/ir/irfunction.h b/ir/irfunction.h index a08d7f22..7f569163 100644 --- a/ir/irfunction.h +++ b/ir/irfunction.h @@ -52,6 +52,10 @@ struct IrFunction : IrBase IrFunction(FuncDeclaration* fd); + // annotations + void setNeverInline(); + void setAlwaysInline(); + private: // prefix for labels and gotos // used for allowing labels to be emitted twice