mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-04-30 15:10:59 +03:00

Previously, the transitory state only needed and valid during generation of the LLVM IR for the function body was conflated with the general codegen metadata for the function declaration in IrFunction. There is further potential for cleanup regarding the use of gIR->func() and so on all over the code base, but this is out of scope of this commit, which is only concerned with those IrFunction members moved to FuncGenState. GitHub: Fixes #1661.
56 lines
1.8 KiB
C++
56 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;
|
||
}
|