ldc/ir/irfunction.cpp
Martin f4a22f232b Propagate "nothrow" to LLVM IR (#1202)
Invoke nothrow callees only in try-blocks with at least 1 catch-block,
otherwise call them directly.

Errors thrown by nothrow callees can thus still be caught inside a
try-catch-statement (and this is apparently required for release builds
too).

Most calls will be direct calls though, and this small change will lead
to substantially less IR as we then skip the clean-ups after an Error.
Proper clean-up when unwinding after an Error seems not to be guaranteed
anyway. There are apparent RAII front-end optimizations for structs with
nothrow dtor - see PR #1656.
2016-08-06 00:10:19 +02:00

55 lines
1.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//===-- irfunction.cpp ----------------------------------------------------===//
//
// LDC the LLVM D compiler
//
// This file is distributed under the BSD-style LDC license. See the LICENSE
// file for details.
//
//===----------------------------------------------------------------------===//
#include "ir/irfunction.h"
#include "gen/llvm.h"
#include "gen/llvmhelpers.h"
#include "gen/irstate.h"
#include "gen/tollvm.h"
#include "ir/irdsymbol.h"
IrFunction::IrFunction(FuncDeclaration *fd) : FMF() {
decl = fd;
Type *t = fd->type->toBasetype();
assert(t->ty == Tfunction);
type = static_cast<TypeFunction *>(t);
}
void IrFunction::setNeverInline() {
assert(!func->getAttributes().hasAttribute(llvm::AttributeSet::FunctionIndex,
llvm::Attribute::AlwaysInline) &&
"function can't be never- and always-inline at the same time");
func->addFnAttr(llvm::Attribute::NoInline);
}
void IrFunction::setAlwaysInline() {
assert(!func->getAttributes().hasAttribute(llvm::AttributeSet::FunctionIndex,
llvm::Attribute::NoInline) &&
"function can't be never- and always-inline at the same time");
func->addFnAttr(llvm::Attribute::AlwaysInline);
}
IrFunction *getIrFunc(FuncDeclaration *decl, bool create) {
if (!isIrFuncCreated(decl) && create) {
assert(decl->ir->irFunc == NULL);
decl->ir->irFunc = new IrFunction(decl);
decl->ir->m_type = IrDsymbol::FuncType;
}
assert(decl->ir->irFunc != NULL);
return decl->ir->irFunc;
}
bool isIrFuncCreated(FuncDeclaration *decl) {
assert(decl);
assert(decl->ir);
IrDsymbol::Type t = decl->ir->type();
assert(t == IrDsymbol::FuncType || t == IrDsymbol::NotSet);
return t == IrDsymbol::FuncType;
}