Skip to content

Commit

Permalink
Lookup runtime function before constructing the call args
Browse files Browse the repository at this point in the history
To retain the LoC information in case TypeInfo declarations are missing.
  • Loading branch information
kinke committed Apr 1, 2018
1 parent 13058b8 commit 760d478
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
20 changes: 10 additions & 10 deletions gen/arrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,13 +674,6 @@ DSliceValue *DtoNewDynArray(Loc &loc, Type *arrayType, DValue *dim,
IF_LOG Logger::println("DtoNewDynArray : %s", arrayType->toChars());
LOG_SCOPE;

// typeinfo arg
LLValue *arrayTypeInfo = DtoTypeInfoOf(arrayType);

// dim arg
assert(DtoType(dim->type) == DtoSize_t());
LLValue *arrayLen = DtoRVal(dim);

// get runtime function
Type *eltType = arrayType->toBasetype()->nextOf();
bool zeroInit = eltType->isZeroInit();
Expand All @@ -690,6 +683,13 @@ DSliceValue *DtoNewDynArray(Loc &loc, Type *arrayType, DValue *dim,
: "_d_newarrayU";
LLFunction *fn = getRuntimeFunction(loc, gIR->module, fnname);

// typeinfo arg
LLValue *arrayTypeInfo = DtoTypeInfoOf(arrayType);

// dim arg
assert(DtoType(dim->type) == DtoSize_t());
LLValue *arrayLen = DtoRVal(dim);

// call allocator
LLValue *newArray =
gIR->CreateCallOrInvoke(fn, arrayTypeInfo, arrayLen, ".gc_mem")
Expand All @@ -704,9 +704,6 @@ DSliceValue *DtoNewMulDimDynArray(Loc &loc, Type *arrayType, DValue **dims,
IF_LOG Logger::println("DtoNewMulDimDynArray : %s", arrayType->toChars());
LOG_SCOPE;

// typeinfo arg
LLValue *arrayTypeInfo = DtoTypeInfoOf(arrayType);

// get value type
Type *vtype = arrayType->toBasetype();
for (size_t i = 0; i < ndims; ++i) {
Expand All @@ -718,6 +715,9 @@ DSliceValue *DtoNewMulDimDynArray(Loc &loc, Type *arrayType, DValue **dims,
vtype->isZeroInit() ? "_d_newarraymTX" : "_d_newarraymiTX";
LLFunction *fn = getRuntimeFunction(loc, gIR->module, fnname);

// typeinfo arg
LLValue *arrayTypeInfo = DtoTypeInfoOf(arrayType);

// Check if constant
bool allDimsConst = true;
for (size_t i = 0; i < ndims; ++i) {
Expand Down
8 changes: 4 additions & 4 deletions gen/classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,12 @@ DValue *DtoDynamicCastObject(Loc &loc, DValue *val, Type *_to) {
// call:
// Object _d_dynamic_cast(Object o, ClassInfo c)

resolveObjectAndClassInfoClasses();

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

resolveObjectAndClassInfoClasses();

// Object o
LLValue *obj = DtoRVal(val);
obj = DtoBitCast(obj, funcTy->getParamType(0));
Expand Down Expand Up @@ -397,12 +397,12 @@ DValue *DtoDynamicCastInterface(Loc &loc, DValue *val, Type *_to) {
// call:
// Object _d_interface_cast(void* p, ClassInfo c)

resolveObjectAndClassInfoClasses();

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

resolveObjectAndClassInfoClasses();

// void* p
LLValue *ptr = DtoRVal(val);
ptr = DtoBitCast(ptr, funcTy->getParamType(0));
Expand Down
6 changes: 3 additions & 3 deletions gen/trycatchfinally.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void TryCatchScope::emitCatchBodies(IRState &irs, llvm::Value *ehPtrSlot) {
const bool isCPPclass = cd->isCPPclass();

const auto enterCatchFn = getRuntimeFunction(
Loc(), irs.module,
c->loc, irs.module,
isCPPclass ? "__cxa_begin_catch" : "_d_eh_enter_catch");
const auto ptr = DtoLoad(ehPtrSlot);
const auto throwableObj = irs.ir->CreateCall(enterCatchFn, ptr);
Expand Down Expand Up @@ -273,7 +273,7 @@ void emitBeginCatchMSVC(IRState &irs, Catch *ctch,
irs.funcGen().pgo.emitCounterIncrement(ctch);
if (!isCPPclass) {
auto enterCatchFn =
getRuntimeFunction(Loc(), irs.module, "_d_eh_enter_catch");
getRuntimeFunction(ctch->loc, irs.module, "_d_eh_enter_catch");
irs.CreateCallOrInvoke(enterCatchFn, DtoBitCast(exnObj, getVoidPtrType()),
clssInfo);
}
Expand Down Expand Up @@ -320,7 +320,7 @@ void TryCatchScope::emitCatchBodiesMSVC(IRState &irs, llvm::Value *) {
if (!irs.func()->hasLLVMPersonalityFn()) {
const char *personality = "__CxxFrameHandler3";
irs.func()->setLLVMPersonalityFn(
getRuntimeFunction(Loc(), irs.module, personality));
getRuntimeFunction(stmt->loc, irs.module, personality));
}
}

Expand Down

0 comments on commit 760d478

Please sign in to comment.