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

@ -75,7 +75,7 @@ DValue* DtoAAIndex(Loc& loc, Type* type, DValue* aa, DValue* key, bool lvalue)
} }
// cast return value // cast return value
LLType* targettype = getPtrToType(i1ToI8(DtoType(type))); LLType* targettype = DtoPtrToType(type);
if (ret->getType() != targettype) if (ret->getType() != targettype)
ret = DtoBitCast(ret, targettype); ret = DtoBitCast(ret, targettype);

View file

@ -226,7 +226,7 @@ struct ExplicitByvalRewrite : ABIRewrite
LLType* type(Type* dty, LLType* t) LLType* type(Type* dty, LLType* t)
{ {
return getPtrToType(DtoType(dty)); return DtoPtrToType(dty);
} }
}; };

View file

@ -207,7 +207,7 @@ struct ImplicitByvalRewrite : ABIRewrite {
} }
LLType* type(Type* dty, LLType* t) { LLType* type(Type* dty, LLType* t) {
return getPtrToType(DtoType(dty)); return DtoPtrToType(dty);
} }
}; };

View file

@ -47,7 +47,7 @@ static LLValue *DtoSlice(LLValue *ptr, LLValue *length, LLType *elemType = NULL)
{ {
if (elemType == NULL) if (elemType == NULL)
elemType = ptr->getType()->getContainedType(0); elemType = ptr->getType()->getContainedType(0);
elemType = voidToI8(elemType); elemType = i1ToI8(voidToI8(elemType));
LLStructType *type = DtoArrayType(elemType); LLStructType *type = DtoArrayType(elemType);
LLValue *array = DtoRawAlloca(type, 0, ".array"); LLValue *array = DtoRawAlloca(type, 0, ".array");
@ -80,9 +80,7 @@ static LLValue *DtoSlicePtr(DValue *dval)
LLStructType* DtoArrayType(Type* arrayTy) LLStructType* DtoArrayType(Type* arrayTy)
{ {
assert(arrayTy->nextOf()); assert(arrayTy->nextOf());
LLType* elemty = i1ToI8(voidToI8(DtoType(arrayTy->nextOf()))); llvm::Type* elems[] = { DtoSize_t(), DtoPtrToType(arrayTy->nextOf()) };
llvm::Type *elems[] = { DtoSize_t(), getPtrToType(elemty) };
return llvm::StructType::get(gIR->context(), elems, false); return llvm::StructType::get(gIR->context(), elems, false);
} }
@ -101,8 +99,7 @@ LLArrayType* DtoStaticArrayType(Type* t)
TypeSArray* tsa = static_cast<TypeSArray*>(t); TypeSArray* tsa = static_cast<TypeSArray*>(t);
Type* tnext = tsa->nextOf(); Type* tnext = tsa->nextOf();
LLType* elemty = i1ToI8(voidToI8(DtoType(tnext))); return LLArrayType::get(DtoMemType(tnext), tsa->dim->toUInteger());
return LLArrayType::get(elemty, tsa->dim->toUInteger());
} }
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
@ -277,7 +274,7 @@ void DtoArrayAssign(Loc& loc, DValue* lhs, DValue* rhs, int op, bool canSkipPost
if (!needsDestruction && !needsPostblit) if (!needsDestruction && !needsPostblit)
{ {
// fast version // fast version
LLValue* elemSize = DtoConstSize_t(getTypePaddedSize(voidToI8(DtoType(elemType)))); LLValue* elemSize = DtoConstSize_t(getTypePaddedSize(DtoMemType(elemType)));
LLValue* lhsSize = gIR->ir->CreateMul(elemSize, lhsLength); LLValue* lhsSize = gIR->ir->CreateMul(elemSize, lhsLength);
if (rhs->isNull()) if (rhs->isNull())
@ -328,7 +325,7 @@ void DtoArrayAssign(Loc& loc, DValue* lhs, DValue* rhs, int op, bool canSkipPost
// fast version // fast version
LLValue* elemSize = DtoConstSize_t(getTypePaddedSize(realLhsPtr->getType()->getContainedType(0))); LLValue* elemSize = DtoConstSize_t(getTypePaddedSize(realLhsPtr->getType()->getContainedType(0)));
LLValue* lhsSize = gIR->ir->CreateMul(elemSize, lhsLength); LLValue* lhsSize = gIR->ir->CreateMul(elemSize, lhsLength);
LLType* rhsType = i1ToI8(voidToI8(DtoType(t2))); LLType* rhsType = DtoMemType(t2);
LLValue* rhsSize = DtoConstSize_t(getTypePaddedSize(rhsType)); LLValue* rhsSize = DtoConstSize_t(getTypePaddedSize(rhsType));
LLValue* actualPtr = DtoBitCast(lhsPtr, rhsType->getPointerTo()); LLValue* actualPtr = DtoBitCast(lhsPtr, rhsType->getPointerTo());
LLValue* actualLength = gIR->ir->CreateExactUDiv(lhsSize, rhsSize); LLValue* actualLength = gIR->ir->CreateExactUDiv(lhsSize, rhsSize);
@ -397,7 +394,7 @@ LLConstant* DtoConstArrayInitializer(ArrayInitializer* arrinit, Type* targetType
elemty = static_cast<TypeVector *>(arrty)->elementType(); elemty = static_cast<TypeVector *>(arrty)->elementType();
else else
elemty = arrty->nextOf(); elemty = arrty->nextOf();
LLType* llelemty = i1ToI8(voidToI8(DtoType(elemty))); LLType* llelemty = DtoMemType(elemty);
// true if array elements differ in type, can happen with array of unions // true if array elements differ in type, can happen with array of unions
bool mismatch = false; bool mismatch = false;
@ -547,7 +544,7 @@ llvm::Constant* arrayLiteralToConst(IRState* p, ArrayLiteralExp* ale)
if (!elementType) if (!elementType)
{ {
assert(ale->elements->dim == 0); assert(ale->elements->dim == 0);
elementType = i1ToI8(voidToI8(DtoType(ale->type->toBasetype()->nextOf()))); elementType = DtoMemType(ale->type->toBasetype()->nextOf());
return llvm::ConstantArray::get(LLArrayType::get(elementType, 0), vals); return llvm::ConstantArray::get(LLArrayType::get(elementType, 0), vals);
} }
@ -1067,7 +1064,7 @@ LLValue* DtoArrayPtr(DValue* v)
if (DSliceValue* s = v->isSlice()) if (DSliceValue* s = v->isSlice())
return s->ptr; return s->ptr;
else if (v->isNull()) else if (v->isNull())
return getNullPtr(getPtrToType(i1ToI8(DtoType(t->nextOf())))); return getNullPtr(DtoPtrToType(t->nextOf()));
else if (v->isLVal()) else if (v->isLVal())
return DtoLoad(DtoGEPi(v->getLVal(), 0,1), ".ptr"); return DtoLoad(DtoGEPi(v->getLVal(), 0,1), ".ptr");
return gIR->ir->CreateExtractValue(v->getRVal(), 1, ".ptr"); return gIR->ir->CreateExtractValue(v->getRVal(), 1, ".ptr");
@ -1112,7 +1109,7 @@ DValue* DtoCastArray(Loc& loc, DValue* u, Type* to)
IF_LOG Logger::cout() << "to array" << '\n'; IF_LOG Logger::cout() << "to array" << '\n';
LLType* ptrty = DtoArrayType(totype)->getContainedType(1); LLType* ptrty = DtoArrayType(totype)->getContainedType(1);
LLType* ety = voidToI8(DtoType(fromtype->nextOf())); LLType* ety = DtoMemType(fromtype->nextOf());
if (fromtype->ty == Tsarray) { if (fromtype->ty == Tsarray) {
LLValue* uval = u->getRVal(); LLValue* uval = u->getRVal();

View file

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

View file

@ -424,8 +424,7 @@ static void build_dso_ctor_dtor_body(
static void build_module_ref(std::string moduleMangle, llvm::Constant* thisModuleInfo) static void build_module_ref(std::string moduleMangle, llvm::Constant* thisModuleInfo)
{ {
// Build the ModuleInfo reference and bracketing symbols. // Build the ModuleInfo reference and bracketing symbols.
llvm::Type* const moduleInfoPtrTy = llvm::Type* const moduleInfoPtrTy = DtoPtrToType(Module::moduleinfo->type);
getPtrToType(DtoType(Module::moduleinfo->type));
std::string thismrefname = "_D"; std::string thismrefname = "_D";
thismrefname += moduleMangle; thismrefname += moduleMangle;
@ -445,8 +444,7 @@ static void build_module_ref(std::string moduleMangle, llvm::Constant* thisModul
static void build_dso_registry_calls(std::string moduleMangle, llvm::Constant* thisModuleInfo) static void build_dso_registry_calls(std::string moduleMangle, llvm::Constant* thisModuleInfo)
{ {
// Build the ModuleInfo reference and bracketing symbols. // Build the ModuleInfo reference and bracketing symbols.
llvm::Type* const moduleInfoPtrTy = llvm::Type* const moduleInfoPtrTy = DtoPtrToType(Module::moduleinfo->type);
getPtrToType(DtoType(Module::moduleinfo->type));
// Order is important here: We must create the symbols in the // Order is important here: We must create the symbols in the
// bracketing sections right before/after the ModuleInfo reference // bracketing sections right before/after the ModuleInfo reference
@ -789,8 +787,7 @@ static void genModuleInfo(Module *m, bool emitFullModuleInfo)
RTTIBuilder b(Module::moduleinfo); RTTIBuilder b(Module::moduleinfo);
// some types // some types
llvm::Type* const moduleInfoPtrTy = llvm::Type* const moduleInfoPtrTy = DtoPtrToType(Module::moduleinfo->type);
getPtrToType(DtoType(Module::moduleinfo->type));
LLType* classinfoTy = Type::typeinfoclass->type->ctype->getLLType(); LLType* classinfoTy = Type::typeinfoclass->type->ctype->getLLType();
// importedModules[] // importedModules[]

View file

@ -64,7 +64,7 @@ DValue* DtoNestedVariable(Loc& loc, Type* astype, VarDeclaration* vd, bool byref
while (fd != vdparent) { while (fd != vdparent) {
if (fd->isStatic()) { if (fd->isStatic()) {
error(loc, "function %s cannot access frame of function %s", irfunc->decl->toPrettyChars(), vdparent->toPrettyChars()); error(loc, "function %s cannot access frame of function %s", irfunc->decl->toPrettyChars(), vdparent->toPrettyChars());
return new DVarValue(astype, vd, llvm::UndefValue::get(getPtrToType(DtoType(astype)))); return new DVarValue(astype, vd, llvm::UndefValue::get(DtoPtrToType(astype)));
} }
fd = getParentFunc(fd, false); fd = getParentFunc(fd, false);
assert(fd); assert(fd);
@ -379,14 +379,14 @@ static void DtoCreateNestedContextType(FuncDeclaration* fd) {
if (lazy) if (lazy)
types.push_back(irparam->value->getType()->getContainedType(0)); types.push_back(irparam->value->getType()->getContainedType(0));
else else
types.push_back(i1ToI8(DtoType(vd->type))); types.push_back(DtoMemType(vd->type));
} else { } else {
types.push_back(irparam->value->getType()); types.push_back(irparam->value->getType());
} }
} else if (isSpecialRefVar(vd)) { } else if (isSpecialRefVar(vd)) {
types.push_back(DtoType(vd->type->pointerTo())); types.push_back(DtoType(vd->type->pointerTo()));
} else { } else {
types.push_back(i1ToI8(DtoType(vd->type))); types.push_back(DtoMemType(vd->type));
} }
IF_LOG Logger::cout() << "Nested var '" << vd->toChars() IF_LOG Logger::cout() << "Nested var '" << vd->toChars()
<< "' of type " << *types.back() << "\n"; << "' of type " << *types.back() << "\n";

View file

@ -175,7 +175,7 @@ public:
bool nullterm = (t->ty != Tsarray); bool nullterm = (t->ty != Tsarray);
size_t endlen = nullterm ? e->len+1 : e->len; size_t endlen = nullterm ? e->len+1 : e->len;
LLType* ct = voidToI8(DtoType(cty)); LLType* ct = DtoMemType(cty);
LLArrayType* at = LLArrayType::get(ct,endlen); LLArrayType* at = LLArrayType::get(ct,endlen);
llvm::StringMap<llvm::GlobalVariable*>* stringLiteralCache = 0; llvm::StringMap<llvm::GlobalVariable*>* stringLiteralCache = 0;
@ -571,7 +571,7 @@ public:
Type* elemt = bt->nextOf(); Type* elemt = bt->nextOf();
// build llvm array type // build llvm array type
LLArrayType* arrtype = LLArrayType::get(i1ToI8(voidToI8(DtoType(elemt))), e->elements->dim); LLArrayType* arrtype = LLArrayType::get(DtoMemType(elemt), e->elements->dim);
// dynamic arrays can occur here as well ... // dynamic arrays can occur here as well ...
bool dyn = (bt->ty != Tsarray); bool dyn = (bt->ty != Tsarray);

View file

@ -430,7 +430,7 @@ public:
Type* dtype = e->type->toBasetype(); Type* dtype = e->type->toBasetype();
Type* cty = dtype->nextOf()->toBasetype(); Type* cty = dtype->nextOf()->toBasetype();
LLType* ct = voidToI8(DtoType(cty)); LLType* ct = DtoMemType(cty);
LLArrayType* at = LLArrayType::get(ct, e->len+1); LLArrayType* at = LLArrayType::get(ct, e->len+1);
llvm::StringMap<llvm::GlobalVariable*>* stringLiteralCache = 0; llvm::StringMap<llvm::GlobalVariable*>* stringLiteralCache = 0;
@ -992,7 +992,7 @@ public:
// handle cast to void (usually created by frontend to avoid "has no effect" error) // handle cast to void (usually created by frontend to avoid "has no effect" error)
if (e->to == Type::tvoid) { if (e->to == Type::tvoid) {
result = new DImValue(Type::tvoid, llvm::UndefValue::get(voidToI8(DtoType(Type::tvoid)))); result = new DImValue(Type::tvoid, llvm::UndefValue::get(DtoMemType(Type::tvoid)));
return; return;
} }
@ -2370,7 +2370,7 @@ public:
if (retPtr) if (retPtr)
result = new DVarValue(e->type, DtoLoad(retPtr)); result = new DVarValue(e->type, DtoLoad(retPtr));
else else
result = new DConstValue(e->type, getNullValue(voidToI8(DtoType(dtype)))); result = new DConstValue(e->type, getNullValue(DtoMemType(dtype)));
} }
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
@ -2551,7 +2551,7 @@ public:
IF_LOG Logger::cout() << (dyn?"dynamic":"static") << " array literal with length " << len << " of D type: '" << arrayType->toChars() << "' has llvm type: '" << *llType << "'\n"; IF_LOG Logger::cout() << (dyn?"dynamic":"static") << " array literal with length " << len << " of D type: '" << arrayType->toChars() << "' has llvm type: '" << *llType << "'\n";
// llvm storage type // llvm storage type
LLType* llElemType = i1ToI8(voidToI8(DtoType(elemType))); LLType* llElemType = DtoMemType(elemType);
LLType* llStoType = LLArrayType::get(llElemType, len); LLType* llStoType = LLArrayType::get(llElemType, len);
IF_LOG Logger::cout() << "llvm storage type: '" << *llStoType << "'\n"; IF_LOG Logger::cout() << "llvm storage type: '" << *llStoType << "'\n";
@ -2821,7 +2821,7 @@ public:
// (&a.foo).funcptr is a case where toElem(e1) is genuinely not an l-value. // (&a.foo).funcptr is a case where toElem(e1) is genuinely not an l-value.
LLValue* val = makeLValue(exp->loc, toElem(exp->e1)); LLValue* val = makeLValue(exp->loc, toElem(exp->e1));
LLValue* v = DtoGEPi(val, 0, index); LLValue* v = DtoGEPi(val, 0, index);
return new DVarValue(exp->type, DtoBitCast(v, getPtrToType(DtoType(exp->type)))); return new DVarValue(exp->type, DtoBitCast(v, DtoPtrToType(exp->type)));
} }
void visit(DelegatePtrExp *e) void visit(DelegatePtrExp *e)
@ -2885,7 +2885,7 @@ public:
types.reserve(e->exps->dim); types.reserve(e->exps->dim);
for (size_t i = 0; i < e->exps->dim; i++) for (size_t i = 0; i < e->exps->dim; i++)
{ {
types.push_back(i1ToI8(voidToI8(DtoType((*e->exps)[i]->type)))); types.push_back(DtoMemType((*e->exps)[i]->type));
} }
LLValue *val = DtoRawAlloca(LLStructType::get(gIR->context(), types), 0, ".tuple"); LLValue *val = DtoRawAlloca(LLStructType::get(gIR->context(), types), 0, ".tuple");
for (size_t i = 0; i < e->exps->dim; i++) for (size_t i = 0; i < e->exps->dim; i++)

View file

@ -202,44 +202,21 @@ LLType* DtoType(Type* t)
return IrTypeVector::get(t)->getLLType(); return IrTypeVector::get(t)->getLLType();
} }
/*
Not needed atm as VarDecls for tuples are rewritten as a string of
VarDecls for the fields (u -> _u_field_0, ...)
case Ttuple:
{
TypeTuple* ttupl = static_cast<TypeTuple*>(t);
return DtoStructTypeFromArguments(ttupl->arguments);
}
*/
default: default:
llvm_unreachable("Unknown class of D Type!"); llvm_unreachable("Unknown class of D Type!");
} }
return 0; return 0;
} }
////////////////////////////////////////////////////////////////////////////////////////// LLType* DtoMemType(Type* t)
/*
LLType* DtoStructTypeFromArguments(Arguments* arguments)
{ {
if (!arguments) return i1ToI8(voidToI8(DtoType(t)));
return LLType::getVoidTy(gIR->context()); }
std::vector<LLType*> types; LLPointerType* DtoPtrToType(Type* t)
for (size_t i = 0; i < arguments->dim; i++)
{ {
Argument *arg = (*arguments)[i]; return DtoMemType(t)->getPointerTo();
assert(arg && arg->type);
types.push_back(DtoType(arg->type));
} }
return LLStructType::get(types);
}
*/
//////////////////////////////////////////////////////////////////////////////////////////
LLType* voidToI8(LLType* t) LLType* voidToI8(LLType* t)
{ {
@ -248,8 +225,6 @@ LLType* voidToI8(LLType* t)
return t; return t;
} }
//////////////////////////////////////////////////////////////////////////////////////////
LLType* i1ToI8(LLType* t) LLType* i1ToI8(LLType* t)
{ {
if (t == LLType::getInt1Ty(gIR->context())) if (t == LLType::getInt1Ty(gIR->context()))

View file

@ -32,6 +32,11 @@
* DtoTypeFunction(FuncDeclaration*) is to be used instead. * DtoTypeFunction(FuncDeclaration*) is to be used instead.
*/ */
LLType* DtoType(Type* t); LLType* DtoType(Type* t);
// Uses DtoType(), but promotes i1 and void to i8.
LLType* DtoMemType(Type* t);
// Returns a pointer to the type returned by DtoMemType(t).
LLPointerType* DtoPtrToType(Type* t);
LLType* voidToI8(LLType* t); LLType* voidToI8(LLType* t);
LLType* i1ToI8(LLType* t); LLType* i1ToI8(LLType* t);

View file

@ -132,7 +132,7 @@ LLConstant* get_default_initializer(VarDeclaration* vd, Initializer* init)
{ {
// We need to be able to handle void[0] struct members even if void has // We need to be able to handle void[0] struct members even if void has
// no default initializer. // no default initializer.
return llvm::ConstantPointerNull::get(getPtrToType(DtoType(vd->type))); return llvm::ConstantPointerNull::get(DtoPtrToType(vd->type));
} }
return DtoConstExpInit(vd->loc, vd->type, vd->type->defaultInit(vd->loc)); return DtoConstExpInit(vd->loc, vd->type, vd->type->defaultInit(vd->loc));
} }

View file

@ -174,7 +174,7 @@ IrTypePointer* IrTypePointer::get(Type* dt)
} }
else else
{ {
elemType = i1ToI8(voidToI8(DtoType(dt->nextOf()))); elemType = DtoMemType(dt->nextOf());
// DtoType could have already created the same type, e.g. for // DtoType could have already created the same type, e.g. for
// dt == Node* in struct Node { Node* n; }. // dt == Node* in struct Node { Node* n; }.
@ -212,7 +212,7 @@ llvm::Type * IrTypeSArray::sarray2llvm(Type * t)
assert(t->ty == Tsarray && "not static array type"); assert(t->ty == Tsarray && "not static array type");
TypeSArray* tsa = static_cast<TypeSArray*>(t); TypeSArray* tsa = static_cast<TypeSArray*>(t);
uint64_t dim = static_cast<uint64_t>(tsa->dim->toUInteger()); uint64_t dim = static_cast<uint64_t>(tsa->dim->toUInteger());
LLType* elemType = i1ToI8(voidToI8(DtoType(t->nextOf()))); LLType* elemType = DtoMemType(t->nextOf());
return llvm::ArrayType::get(elemType, dim); return llvm::ArrayType::get(elemType, dim);
} }
@ -232,7 +232,7 @@ IrTypeArray* IrTypeArray::get(Type* dt)
assert(!dt->ctype); assert(!dt->ctype);
assert(dt->ty == Tarray && "not dynamic array type"); assert(dt->ty == Tarray && "not dynamic array type");
LLType* elemType = i1ToI8(voidToI8(DtoType(dt->nextOf()))); LLType* elemType = DtoMemType(dt->nextOf());
// Could have already built the type as part of a struct forward reference, // Could have already built the type as part of a struct forward reference,
// just as for pointers. // just as for pointers.
@ -273,7 +273,7 @@ llvm::Type* IrTypeVector::vector2llvm(Type* dt)
assert(tv->basetype->ty == Tsarray); assert(tv->basetype->ty == Tsarray);
TypeSArray* tsa = static_cast<TypeSArray*>(tv->basetype); TypeSArray* tsa = static_cast<TypeSArray*>(tv->basetype);
uint64_t dim = static_cast<uint64_t>(tsa->dim->toUInteger()); uint64_t dim = static_cast<uint64_t>(tsa->dim->toUInteger());
LLType* elemType = voidToI8(DtoType(tsa->next)); LLType* elemType = DtoMemType(tsa->next);
return llvm::VectorType::get(elemType, dim); return llvm::VectorType::get(elemType, dim);
} }

View file

@ -179,7 +179,7 @@ void AggrTypeBuilder::addAggregate(AggregateDeclaration *ad)
} }
// add default type // add default type
m_defaultTypes.push_back(i1ToI8(DtoType(vd->type))); m_defaultTypes.push_back(DtoMemType(vd->type));
// advance offset to right past this field // advance offset to right past this field
m_offset += getMemberSize(vd->type); m_offset += getMemberSize(vd->type);