-
-
Notifications
You must be signed in to change notification settings - Fork 267
/
Copy pathirfunction.cpp
110 lines (91 loc) · 2.91 KB
/
irfunction.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//===-- 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 "driver/cl_options.h"
#include "gen/functions.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)
: irFty(nullptr /*set immediately below*/), FMF(opts::defaultFMF) {
decl = fd;
Type *t = fd->type->toBasetype();
assert(t->ty == TY::Tfunction);
type = static_cast<TypeFunction *>(t);
irFty.type = type;
}
void IrFunction::setNeverInline() {
assert(!func->hasFnAttribute(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->hasFnAttribute(llvm::Attribute::NoInline) &&
"function can't be never- and always-inline at the same time");
func->addFnAttr(llvm::Attribute::AlwaysInline);
}
void IrFunction::setLLVMFunc(llvm::Function *function) {
assert(function != nullptr);
func = function;
}
llvm::Function *IrFunction::getLLVMFunc() const {
return func;
}
llvm::CallingConv::ID IrFunction::getCallingConv() const {
assert(func != nullptr);
return func->getCallingConv();
}
llvm::FunctionType *IrFunction::getLLVMFuncType() const {
assert(func != nullptr);
return func->getFunctionType();
}
bool IrFunction::hasLLVMPersonalityFn() const {
assert(func != nullptr);
return func->hasPersonalityFn();
}
void IrFunction::setLLVMPersonalityFn(llvm::Constant *personality) {
assert(func != nullptr);
func->setPersonalityFn(personality);
}
llvm::StringRef IrFunction::getLLVMFuncName() const {
assert(func != nullptr);
return func->getName();
}
llvm::Function *IrFunction::getLLVMCallee() const {
assert(func != nullptr);
return rtCompileFunc != nullptr ? rtCompileFunc : func;
}
bool IrFunction::isDynamicCompiled() const {
return dynamicCompile || dynamicCompileEmit;
}
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;
}
llvm::Function *DtoCallee(FuncDeclaration *decl, bool create) {
assert(decl != nullptr);
if (create) {
DtoDeclareFunction(decl);
}
return getIrFunc(decl)->getLLVMCallee();
}