Skip to content

Clean up druntime fwd decls #1208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ int main(int argc, char **argv) {
emitJson(modules);
}

LLVM_D_FreeRuntime();
freeRuntime();
llvm::llvm_shutdown();

if (global.errors) {
Expand Down
10 changes: 5 additions & 5 deletions gen/aa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ DValue *DtoAAIndex(Loc &loc, Type *type, DValue *aa, DValue *key, bool lvalue) {
// extern(C) void* _aaInX(AA aa*, TypeInfo keyti, void* pkey)

// first get the runtime function
llvm::Function *func = LLVM_D_GetRuntimeFunction(
llvm::Function *func = getRuntimeFunction(
loc, gIR->module, lvalue ? "_aaGetY" : "_aaInX");
LLFunctionType *funcTy = func->getFunctionType();

Expand Down Expand Up @@ -92,7 +92,7 @@ DValue *DtoAAIndex(Loc &loc, Type *type, DValue *aa, DValue *key, bool lvalue) {
gIR->scope() = IRScope(failbb);

llvm::Function *errorfn =
LLVM_D_GetRuntimeFunction(loc, gIR->module, "_d_arraybounds");
getRuntimeFunction(loc, gIR->module, "_d_arraybounds");
gIR->CreateCallOrInvoke(
errorfn, DtoModuleFileName(gIR->func()->decl->getModule(), loc),
DtoConstUint(loc.linnum));
Expand All @@ -118,7 +118,7 @@ DValue *DtoAAIn(Loc &loc, Type *type, DValue *aa, DValue *key) {
// extern(C) void* _aaInX(AA aa*, TypeInfo keyti, void* pkey)

// first get the runtime function
llvm::Function *func = LLVM_D_GetRuntimeFunction(loc, gIR->module, "_aaInX");
llvm::Function *func = getRuntimeFunction(loc, gIR->module, "_aaInX");
LLFunctionType *funcTy = func->getFunctionType();

IF_LOG Logger::cout() << "_aaIn = " << *func << '\n';
Expand Down Expand Up @@ -164,7 +164,7 @@ DValue *DtoAARemove(Loc &loc, DValue *aa, DValue *key) {
// extern(C) bool _aaDelX(AA aa, TypeInfo keyti, void* pkey)

// first get the runtime function
llvm::Function *func = LLVM_D_GetRuntimeFunction(loc, gIR->module, "_aaDelX");
llvm::Function *func = getRuntimeFunction(loc, gIR->module, "_aaDelX");
LLFunctionType *funcTy = func->getFunctionType();

IF_LOG Logger::cout() << "_aaDel = " << *func << '\n';
Expand Down Expand Up @@ -198,7 +198,7 @@ LLValue *DtoAAEquals(Loc &loc, TOK op, DValue *l, DValue *r) {
assert(t == r->getType()->toBasetype() &&
"aa equality is only defined for aas of same type");
llvm::Function *func =
LLVM_D_GetRuntimeFunction(loc, gIR->module, "_aaEqual");
getRuntimeFunction(loc, gIR->module, "_aaEqual");
LLFunctionType *funcTy = func->getFunctionType();

LLValue *aaval = DtoBitCast(l->getRVal(), funcTy->getParamType(1));
Expand Down
30 changes: 15 additions & 15 deletions gen/arrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ static void copySlice(Loc &loc, LLValue *dstarr, LLValue *sz1, LLValue *srcarr,
global.params.useAssert || gIR->emitArrayBoundsChecks();
if (checksEnabled && !knownInBounds) {
LLValue *fn =
LLVM_D_GetRuntimeFunction(loc, gIR->module, "_d_array_slice_copy");
getRuntimeFunction(loc, gIR->module, "_d_array_slice_copy");
gIR->CreateCallOrInvoke(fn, dstarr, sz1, srcarr, sz2);
} else {
// We might have dstarr == srcarr at compile time, but as long as
Expand Down Expand Up @@ -285,15 +285,15 @@ void DtoArrayAssign(Loc &loc, DValue *lhs, DValue *rhs, int op,
}
} else if (isConstructing) {
LLFunction *fn =
LLVM_D_GetRuntimeFunction(loc, gIR->module, "_d_arrayctor");
getRuntimeFunction(loc, gIR->module, "_d_arrayctor");
LLCallSite call = gIR->CreateCallOrInvoke(fn, DtoTypeInfoOf(elemType),
DtoSlice(rhsPtr, rhsLength),
DtoSlice(lhsPtr, lhsLength));
call.setCallingConv(llvm::CallingConv::C);
} else // assigning
{
LLValue *tmpSwap = DtoAlloca(elemType, "arrayAssign.tmpSwap");
LLFunction *fn = LLVM_D_GetRuntimeFunction(
LLFunction *fn = getRuntimeFunction(
loc, gIR->module,
!canSkipPostblit ? "_d_arrayassign_l" : "_d_arrayassign_r");
LLCallSite call = gIR->CreateCallOrInvoke(
Expand All @@ -316,7 +316,7 @@ void DtoArrayAssign(Loc &loc, DValue *lhs, DValue *rhs, int op,
LLValue *actualLength = gIR->ir->CreateExactUDiv(lhsSize, rhsSize);
DtoArrayInit(loc, actualPtr, actualLength, rhs, op);
} else {
LLFunction *fn = LLVM_D_GetRuntimeFunction(
LLFunction *fn = getRuntimeFunction(
loc, gIR->module,
isConstructing ? "_d_arraysetctor" : "_d_arraysetassign");
LLCallSite call = gIR->CreateCallOrInvoke(
Expand Down Expand Up @@ -625,7 +625,7 @@ DSliceValue *DtoNewDynArray(Loc &loc, Type *arrayType, DValue *dim,
const char *fnname = defaultInit
? (zeroInit ? "_d_newarrayT" : "_d_newarrayiT")
: "_d_newarrayU";
LLFunction *fn = LLVM_D_GetRuntimeFunction(loc, gIR->module, fnname);
LLFunction *fn = getRuntimeFunction(loc, gIR->module, fnname);

// call allocator
LLValue *newArray =
Expand Down Expand Up @@ -653,7 +653,7 @@ DSliceValue *DtoNewMulDimDynArray(Loc &loc, Type *arrayType, DValue **dims,
// get runtime function
const char *fnname =
vtype->isZeroInit() ? "_d_newarraymTX" : "_d_newarraymiTX";
LLFunction *fn = LLVM_D_GetRuntimeFunction(loc, gIR->module, fnname);
LLFunction *fn = getRuntimeFunction(loc, gIR->module, fnname);

// Check if constant
bool allDimsConst = true;
Expand Down Expand Up @@ -720,7 +720,7 @@ DSliceValue *DtoResizeDynArray(Loc &loc, Type *arrayType, DValue *array,
bool zeroInit = arrayType->toBasetype()->nextOf()->isZeroInit();

// call runtime
LLFunction *fn = LLVM_D_GetRuntimeFunction(loc, gIR->module,
LLFunction *fn = getRuntimeFunction(loc, gIR->module,
zeroInit ? "_d_arraysetlengthT"
: "_d_arraysetlengthiT");

Expand Down Expand Up @@ -750,7 +750,7 @@ void DtoCatAssignElement(Loc &loc, Type *arrayType, DValue *array,
DValue *expVal = toElem(exp);

LLFunction *fn =
LLVM_D_GetRuntimeFunction(loc, gIR->module, "_d_arrayappendcTX");
getRuntimeFunction(loc, gIR->module, "_d_arrayappendcTX");
LLValue *appendedArray =
gIR->CreateCallOrInvoke(
fn, DtoTypeInfoOf(arrayType),
Expand All @@ -774,7 +774,7 @@ DSliceValue *DtoCatAssignArray(Loc &loc, DValue *arr, Expression *exp) {
Type *arrayType = arr->getType();

LLFunction *fn =
LLVM_D_GetRuntimeFunction(loc, gIR->module, "_d_arrayappendT");
getRuntimeFunction(loc, gIR->module, "_d_arrayappendT");
// Call _d_arrayappendT(TypeInfo ti, byte[] *px, byte[] y)
LLValue *newArray =
gIR->CreateCallOrInvoke(
Expand All @@ -799,7 +799,7 @@ DSliceValue *DtoCatArrays(Loc &loc, Type *arrayType, Expression *exp1,
LLFunction *fn = nullptr;

if (exp1->op == TOKcat) { // handle multiple concat
fn = LLVM_D_GetRuntimeFunction(loc, gIR->module, "_d_arraycatnTX");
fn = getRuntimeFunction(loc, gIR->module, "_d_arraycatnTX");

// Create array of slices
typedef llvm::SmallVector<llvm::Value *, 16> ArgVector;
Expand Down Expand Up @@ -839,7 +839,7 @@ DSliceValue *DtoCatArrays(Loc &loc, Type *arrayType, Expression *exp1,
// byte[][] arrs
args.push_back(val);
} else {
fn = LLVM_D_GetRuntimeFunction(loc, gIR->module, "_d_arraycatT");
fn = getRuntimeFunction(loc, gIR->module, "_d_arraycatT");

// TypeInfo ti
args.push_back(DtoTypeInfoOf(arrayType));
Expand Down Expand Up @@ -867,7 +867,7 @@ DSliceValue *DtoAppendDChar(Loc &loc, DValue *arr, Expression *exp,
DValue *valueToAppend = toElem(exp);

// Prepare arguments
LLFunction *fn = LLVM_D_GetRuntimeFunction(loc, gIR->module, func);
LLFunction *fn = getRuntimeFunction(loc, gIR->module, func);

// Call function (ref string x, dchar c)
LLValue *newArray =
Expand Down Expand Up @@ -904,7 +904,7 @@ DSliceValue *DtoAppendDCharToUnicodeString(Loc &loc, DValue *arr,
static LLValue *DtoArrayEqCmp_impl(Loc &loc, const char *func, DValue *l,
DValue *r, bool useti) {
IF_LOG Logger::println("comparing arrays");
LLFunction *fn = LLVM_D_GetRuntimeFunction(loc, gIR->module, func);
LLFunction *fn = getRuntimeFunction(loc, gIR->module, func);
assert(fn);

// find common dynamic array type
Expand Down Expand Up @@ -981,7 +981,7 @@ LLValue *DtoArrayCastLength(Loc &loc, LLValue *len, LLType *elemty,
}

LLFunction *fn =
LLVM_D_GetRuntimeFunction(loc, gIR->module, "_d_array_cast_len");
getRuntimeFunction(loc, gIR->module, "_d_array_cast_len");
return gIR->CreateCallOrInvoke(fn, len,
LLConstantInt::get(DtoSize_t(), esz, false),
LLConstantInt::get(DtoSize_t(), nsz, false))
Expand Down Expand Up @@ -1213,7 +1213,7 @@ void DtoIndexBoundsCheck(Loc &loc, DValue *arr, DValue *index) {

void DtoBoundsCheckFailCall(IRState *irs, Loc &loc) {
llvm::Function *errorfn =
LLVM_D_GetRuntimeFunction(loc, irs->module, "_d_arraybounds");
getRuntimeFunction(loc, irs->module, "_d_arraybounds");
irs->CreateCallOrInvoke(
errorfn, DtoModuleFileName(irs->func()->decl->getModule(), loc),
DtoConstUint(loc.linnum));
Expand Down
16 changes: 14 additions & 2 deletions gen/attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ AttrBuilder &AttrBuilder::merge(const AttrBuilder &other) {
return *this;
}


AttrSet::AttrSet(const AttrSet &base, unsigned index, LLAttribute attribute)
: set(base.set.addAttribute(gIR->context(), index, attribute)) {}

AttrSet
AttrSet::extractFunctionAndReturnAttributes(const llvm::Function *function) {
AttrSet r;
Expand All @@ -56,9 +60,17 @@ AttrSet::extractFunctionAndReturnAttributes(const llvm::Function *function) {

AttrSet &AttrSet::add(unsigned index, const AttrBuilder &builder) {
if (builder.hasAttributes()) {
llvm::AttributeSet as =
llvm::AttributeSet::get(gIR->context(), index, builder);
auto as = llvm::AttributeSet::get(gIR->context(), index, builder);
set = set.addAttributes(gIR->context(), index, as);
}
return *this;
}

AttrSet &AttrSet::merge(const AttrSet &other) {
auto &os = other.set;
for (unsigned i = 0; i < os.getNumSlots(); ++i) {
unsigned index = os.getSlotIndex(i);
set = set.addAttributes(gIR->context(), index, os.getSlotAttributes(i));
}
return *this;
}
4 changes: 4 additions & 0 deletions gen/attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ class AttrSet {

public:
AttrSet() = default;
AttrSet(const llvm::AttributeSet &nativeSet) : set(nativeSet) {}
AttrSet(const AttrSet &base, unsigned index, LLAttribute attribute);

static AttrSet
extractFunctionAndReturnAttributes(const llvm::Function *function);

AttrSet &add(unsigned index, const AttrBuilder &builder);
AttrSet &merge(const AttrSet &other);

operator llvm::AttributeSet &() { return set; }
operator const llvm::AttributeSet &() const { return set; }
Expand Down
8 changes: 4 additions & 4 deletions gen/classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ DValue *DtoNewClass(Loc &loc, TypeClass *tc, NewExp *newexp) {
// default allocator
else {
llvm::Function *fn =
LLVM_D_GetRuntimeFunction(loc, gIR->module, "_d_newclass");
getRuntimeFunction(loc, gIR->module, "_d_newclass");
LLConstant *ci = DtoBitCast(getIrAggr(tc->sym)->getClassInfoSymbol(),
DtoType(Type::typeinfoclass->type));
mem =
Expand Down Expand Up @@ -186,7 +186,7 @@ void DtoInitClass(TypeClass *tc, LLValue *dst) {
void DtoFinalizeClass(Loc &loc, LLValue *inst) {
// get runtime function
llvm::Function *fn =
LLVM_D_GetRuntimeFunction(loc, gIR->module, "_d_callfinalizer");
getRuntimeFunction(loc, gIR->module, "_d_callfinalizer");

gIR->CreateCallOrInvoke(
fn, DtoBitCast(inst, fn->getFunctionType()->getParamType(0)), "");
Expand Down Expand Up @@ -330,7 +330,7 @@ DValue *DtoDynamicCastObject(Loc &loc, DValue *val, Type *_to) {
DtoResolveClass(Type::typeinfoclass);

llvm::Function *func =
LLVM_D_GetRuntimeFunction(loc, gIR->module, "_d_dynamic_cast");
getRuntimeFunction(loc, gIR->module, "_d_dynamic_cast");
LLFunctionType *funcTy = func->getFunctionType();

// Object o
Expand Down Expand Up @@ -368,7 +368,7 @@ DValue *DtoDynamicCastInterface(Loc &loc, DValue *val, Type *_to) {
DtoResolveClass(Type::typeinfoclass);

llvm::Function *func =
LLVM_D_GetRuntimeFunction(loc, gIR->module, "_d_interface_cast");
getRuntimeFunction(loc, gIR->module, "_d_interface_cast");
LLFunctionType *funcTy = func->getFunctionType();

// void* p
Expand Down
44 changes: 5 additions & 39 deletions gen/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,43 +378,10 @@ void DtoResolveFunction(FuncDeclaration *fdecl) {

////////////////////////////////////////////////////////////////////////////////

static void set_param_attrs(TypeFunction *f, llvm::Function *func,
FuncDeclaration *fdecl) {
IrFuncTy &irFty = getIrFunc(fdecl)->irFty;
void applyParamAttrsToLLFunc(TypeFunction *f, IrFuncTy &irFty,
llvm::Function *func) {
AttrSet newAttrs = AttrSet::extractFunctionAndReturnAttributes(func);

int idx = 0;

// handle implicit args
#define ADD_PA(X) \
if (irFty.X) { \
newAttrs.add(idx, irFty.X->attrs); \
idx++; \
}

ADD_PA(ret)

if (irFty.arg_sret && irFty.arg_this && gABI->passThisBeforeSret(f)) {
ADD_PA(arg_this)
ADD_PA(arg_sret)
} else {
ADD_PA(arg_sret)
ADD_PA(arg_this)
}

ADD_PA(arg_nest)
ADD_PA(arg_arguments)

#undef ADD_PA

// Set attributes on the explicit parameters.
const size_t n = irFty.args.size();
for (size_t k = 0; k < n; k++) {
const size_t i = idx + (irFty.reverseParams ? (n - k - 1) : k);
newAttrs.add(i, irFty.args[k]->attrs);
}

// Store the final attribute set
newAttrs.merge(irFty.getParamAttrs(gABI->passThisBeforeSret(f)));
func->setAttributes(newAttrs);
}

Expand Down Expand Up @@ -499,7 +466,7 @@ void DtoDeclareFunction(FuncDeclaration *fdecl) {

// parameter attributes
if (!DtoIsIntrinsic(fdecl)) {
set_param_attrs(f, func, fdecl);
applyParamAttrsToLLFunc(f, getIrFunc(fdecl)->irFty, func);
if (global.params.disableRedZone) {
func->addFnAttr(LLAttribute::NoRedZone);
}
Expand Down Expand Up @@ -928,8 +895,7 @@ void DtoDefineFunction(FuncDeclaration *fd) {
bb->eraseFromParent();
} else if (!gIR->scopereturned()) {
// llvm requires all basic blocks to end with a TerminatorInst but DMD does
// not put a return statement
// in automatically, so we do it here.
// not put a return statement in automatically, so we do it here.

// pass the previous block into this block
gIR->DBuilder.EmitStopPoint(fd->endloc);
Expand Down
1 change: 0 additions & 1 deletion gen/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class Parameter;
class Type;
namespace llvm {
class FunctionType;
class Value;
}

llvm::FunctionType *DtoFunctionType(Type *t, IrFuncTy &irFty, Type *thistype,
Expand Down
Loading