Refactor common i1ToI8(voidToI8(DtoType(...))) code occurrences

This commit is contained in:
Martin 2015-10-03 22:58:00 +02:00
parent 5617319770
commit b13565c17e
14 changed files with 56 additions and 83 deletions

View file

@ -72,7 +72,7 @@ LLValue* DtoNew(Loc& loc, Type* newtype)
// call runtime allocator
LLValue* mem = gIR->CreateCallOrInvoke(fn, ti, ".gc_mem").getInstruction();
// cast
return DtoBitCast(mem, getPtrToType(i1ToI8(DtoType(newtype))), ".gc_mem");
return DtoBitCast(mem, DtoPtrToType(newtype), ".gc_mem");
}
LLValue* DtoNewStruct(Loc& loc, TypeStruct* newtype)
@ -81,7 +81,7 @@ LLValue* DtoNewStruct(Loc& loc, TypeStruct* newtype)
newtype->isZeroInit(newtype->sym->loc) ? "_d_newitemT" : "_d_newitemiT");
LLConstant* ti = DtoTypeInfoOf(newtype);
LLValue* mem = gIR->CreateCallOrInvoke(fn, ti, ".gc_struct").getInstruction();
return DtoBitCast(mem, getPtrToType(i1ToI8(DtoType(newtype))), ".gc_struct");
return DtoBitCast(mem, DtoPtrToType(newtype), ".gc_struct");
}
void DtoDeleteMemory(Loc& loc, DValue* ptr)
@ -141,8 +141,7 @@ void DtoDeleteArray(Loc& loc, DValue* arr)
llvm::AllocaInst* DtoAlloca(Type* type, const char* name)
{
LLType* lltype = i1ToI8(DtoType(type));
return DtoRawAlloca(lltype, type->alignsize(), name);
return DtoRawAlloca(DtoMemType(type), type->alignsize(), name);
}
llvm::AllocaInst* DtoArrayAlloca(Type* type, unsigned arraysize, const char* name)
@ -201,8 +200,8 @@ LLValue* DtoAllocaDump(LLValue* val, Type* asType, const char* name)
LLValue* DtoAllocaDump(LLValue* val, LLType* asType, int alignment, const char* name)
{
LLType* valType = i1ToI8(val->getType());
asType = i1ToI8(asType);
LLType* valType = i1ToI8(voidToI8(val->getType()));
asType = i1ToI8(voidToI8(asType));
LLType* allocaType = (
getTypeStoreSize(valType) <= getTypeAllocSize(asType) ? asType : valType);
LLValue* mem = DtoRawAlloca(allocaType, alignment, name);
@ -391,7 +390,7 @@ DValue* DtoNullValue(Type* type, Loc loc)
else if (basety == Tarray)
{
LLValue* len = DtoConstSize_t(0);
LLValue* ptr = getNullPtr(getPtrToType(DtoType(basetype->nextOf())));
LLValue* ptr = getNullPtr(DtoPtrToType(basetype->nextOf()));
return new DSliceValue(type, len, ptr);
}
else
@ -727,7 +726,7 @@ DValue* DtoPaintType(Loc& loc, DValue* val, Type* to)
{
LLValue* ptr = val->getLVal();
assert(isaPointer(ptr));
ptr = DtoBitCast(ptr, getPtrToType(DtoType(dgty)));
ptr = DtoBitCast(ptr, DtoPtrToType(dgty));
IF_LOG Logger::cout() << "dg ptr: " << *ptr << '\n';
return new DVarValue(to, ptr);
}
@ -866,7 +865,7 @@ void DtoResolveVariable(VarDeclaration* vd)
}
llvm::GlobalVariable* gvar = getOrCreateGlobal(vd->loc, gIR->module,
i1ToI8(DtoType(vd->type)), isLLConst, linkage, 0, llName,
DtoMemType(vd->type), isLLConst, linkage, 0, llName,
vd->isThreadlocal());
getIrGlobal(vd)->value = gvar;
@ -1183,7 +1182,7 @@ LLConstant* DtoConstInitializer(Loc& loc, Type* type, Initializer* init)
else if (init->isVoidInitializer())
{
Logger::println("const void initializer");
LLType* ty = voidToI8(DtoType(type));
LLType* ty = DtoMemType(type);
_init = LLConstant::getNullValue(ty);
}
else
@ -1225,7 +1224,7 @@ LLConstant* DtoConstExpInit(Loc& loc, Type* targetType, Expression* exp)
}
llvm::Type* llType = val->getType();
llvm::Type* targetLLType = i1ToI8(DtoType(targetBase));
llvm::Type* targetLLType = DtoMemType(targetBase);
if (llType == targetLLType)
{
Logger::println("Matching LLVM types, ignoring frontend glitch.");
@ -1653,7 +1652,7 @@ DValue* DtoSymbolAddress(Loc& loc, Type* type, Declaration* decl)
if (isGlobal)
{
llvm::Type* expectedType = llvm::PointerType::getUnqual(i1ToI8(DtoType(type)));
llvm::Type* expectedType = llvm::PointerType::getUnqual(DtoMemType(type));
// The type of globals is determined by their initializer, so
// we might need to cast. Make sure that the type sizes fit -
// '==' instead of '<=' should probably work as well.
@ -1841,7 +1840,7 @@ LLValue* DtoIndexAggregate(LLValue* src, AggregateDeclaration* ad, VarDeclaratio
}
// Cast the (possibly void*) pointer to the canonical variable type.
val = DtoBitCast(val, getPtrToType(i1ToI8(DtoType(vd->type))));
val = DtoBitCast(val, DtoPtrToType(vd->type));
IF_LOG Logger::cout() << "Value: " << *val << '\n';
return val;