mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-04 17:11:44 +03:00

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.
55 lines
1.8 KiB
C++
55 lines
1.8 KiB
C++
//===-- 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;
|
||
}
|