From 4b025337456a88d91da26413084df72b95b6131b Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Sat, 20 Sep 2008 10:13:15 +0200 Subject: [PATCH] Change bool type to i8 --- gen/arrays.cpp | 3 --- gen/llvmhelpers.cpp | 15 ++++++--------- gen/statements.cpp | 10 +++++++--- gen/todebug.cpp | 8 ++++---- gen/toir.cpp | 2 +- gen/tollvm.cpp | 16 ++++++++++------ gen/tollvm.h | 1 + 7 files changed, 29 insertions(+), 26 deletions(-) diff --git a/gen/arrays.cpp b/gen/arrays.cpp index d6c9bc23..47e7d981 100644 --- a/gen/arrays.cpp +++ b/gen/arrays.cpp @@ -153,9 +153,6 @@ void DtoArrayInit(Loc& loc, DValue* array, DValue* value) switch (arrayelemty->ty) { case Tbool: - funcname = "_d_array_init_i1"; - break; - case Tvoid: case Tchar: case Tint8: diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index 84e30f44..c8de8810 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -574,8 +574,8 @@ DValue* DtoCastInt(Loc& loc, DValue* val, Type* _to) Type* from = val->getType()->toBasetype(); assert(from->isintegral()); - size_t fromsz = from->size(); - size_t tosz = to->size(); + size_t fromsz = getTypeBitSize(val->getRVal()->getType()); + size_t tosz = to->size()*8; LLValue* rval = val->getRVal(); if (rval->getType() == tolltype) { @@ -774,13 +774,13 @@ void DtoLazyStaticInit(bool istempl, LLValue* gvar, Initializer* init, Type* t) llvm::GlobalValue::LinkageTypes gflaglink = istempl ? llvm::GlobalValue::WeakLinkage : llvm::GlobalValue::InternalLinkage; std::string gflagname(gvar->getName()); gflagname.append("__initflag"); - llvm::GlobalVariable* gflag = new llvm::GlobalVariable(LLType::Int1Ty,false,gflaglink,DtoConstBool(false),gflagname,gIR->module); + llvm::GlobalVariable* gflag = new llvm::GlobalVariable(LLType::Int1Ty,false,gflaglink,DtoConstI1(false),gflagname,gIR->module); // check flag and do init if not already done llvm::BasicBlock* oldend = gIR->scopeend(); llvm::BasicBlock* initbb = llvm::BasicBlock::Create("ifnotinit",gIR->topfunc(),oldend); llvm::BasicBlock* endinitbb = llvm::BasicBlock::Create("ifnotinitend",gIR->topfunc(),oldend); - LLValue* cond = gIR->ir->CreateICmpEQ(gIR->ir->CreateLoad(gflag,"tmp"),DtoConstBool(false)); + LLValue* cond = gIR->ir->CreateICmpEQ(gIR->ir->CreateLoad(gflag,"tmp"),DtoConstI1(false)); gIR->ir->CreateCondBr(cond, initbb, endinitbb); gIR->scope() = IRScope(initbb,endinitbb); DValue* ie = DtoInitializer(gvar, init); @@ -788,7 +788,7 @@ void DtoLazyStaticInit(bool istempl, LLValue* gvar, Initializer* init, Type* t) DVarValue dst(t, gvar); DtoAssign(init->loc, &dst, ie); - gIR->ir->CreateStore(DtoConstBool(true), gflag); + gIR->ir->CreateStore(DtoConstI1(true), gflag); gIR->ir->CreateBr(endinitbb); gIR->scope() = IRScope(endinitbb,oldend); } @@ -1548,10 +1548,7 @@ void DtoOverloadedIntrinsicName(TemplateInstance* ti, TemplateDeclaration* td, s Type* T = (Type*)ti->tdtypes.data[0]; char tmp[10]; - if (T->toBasetype()->ty == Tbool) // otherwise we'd get a mismatch - sprintf(tmp, "1"); - else - sprintf(tmp, "%d", T->size()*8); + sprintf(tmp, "%d", T->size()*8); // replace # in name with bitsize name = td->intrinsicName; diff --git a/gen/statements.cpp b/gen/statements.cpp index c1bf1f71..f3f42378 100644 --- a/gen/statements.cpp +++ b/gen/statements.cpp @@ -81,11 +81,15 @@ void ReturnStatement::toIR(IRState* p) delete e; Logger::cout() << "return value is '" <<*v << "'\n"; - // can happen for classes if (v->getType() != p->topfunc()->getReturnType()) { - v = gIR->ir->CreateBitCast(v, p->topfunc()->getReturnType(), "tmp"); - Logger::cout() << "return value after cast: " << *v << '\n'; + // can happen for classes + if(isaPointer(v) && isaPointer(p->topfunc()->getReturnType())) + v = gIR->ir->CreateBitCast(v, p->topfunc()->getReturnType(), "tmp"); + // or for i1 vs i8 bools + if(v->getType() == LLType::Int1Ty && p->topfunc()->getReturnType() == LLType::Int8Ty) + v = gIR->ir->CreateZExt(v, LLType::Int8Ty); + Logger::cout() << "adjusted return value: " << *v << '\n'; } DtoEnclosingHandlers(enclosinghandler, NULL); diff --git a/gen/todebug.cpp b/gen/todebug.cpp index d6781f58..8d376b3b 100644 --- a/gen/todebug.cpp +++ b/gen/todebug.cpp @@ -162,8 +162,8 @@ static LLGlobalVariable* dwarfSubProgram(FuncDeclaration* fd, llvm::GlobalVariab vals[6] = DBG_CAST( DtoDwarfCompileUnit(fd->getModule()) ); vals[7] = DtoConstUint(fd->loc.linnum); vals[8] = DBG_NULL; - vals[9] = DtoConstBool(fd->protection == PROTprivate); - vals[10] = DtoConstBool(fd->getModule() == gIR->dmodule); + vals[9] = DtoConstI1(fd->protection == PROTprivate); + vals[10] = DtoConstI1(fd->getModule() == gIR->dmodule); Logger::println("emitting subprogram global"); @@ -519,8 +519,8 @@ static LLGlobalVariable* dwarfGlobalVariable(LLGlobalVariable* ll, VarDeclaratio LLGlobalVariable* TY = dwarfTypeDescription_impl(vd->type, compileUnit, NULL); vals[8] = TY ? DBG_CAST(TY) : DBG_NULL; - vals[9] = DtoConstBool(vd->protection == PROTprivate); - vals[10] = DtoConstBool(vd->getModule() == gIR->dmodule); + vals[9] = DtoConstI1(vd->protection == PROTprivate); + vals[10] = DtoConstI1(vd->getModule() == gIR->dmodule); vals[11] = DBG_CAST(ll); diff --git a/gen/toir.cpp b/gen/toir.cpp index 5406dbfa..70cbc408 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -1649,7 +1649,7 @@ DValue* NotExp::toElem(IRState* p) LLValue* b = DtoBoolean(loc, u); - LLConstant* zero = DtoConstBool(false); + LLConstant* zero = llvm::ConstantInt::get(b->getType(), 0); b = p->ir->CreateICmpEQ(b,zero); return new DImValue(type, b); diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index 6fbf0ddd..944b8403 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -77,7 +77,7 @@ const LLType* DtoType(Type* t) return (const LLType*)LLType::Int64Ty; case Tbool: - return (const LLType*)llvm::ConstantInt::getTrue()->getType(); + return (const LLType*)LLType::Int8Ty; // floats case Tfloat32: @@ -462,11 +462,11 @@ void DtoMemoryBarrier(bool ll, bool ls, bool sl, bool ss, bool device) assert(fn != NULL); LLSmallVector llargs; - llargs.push_back(DtoConstBool(ll)); - llargs.push_back(DtoConstBool(ls)); - llargs.push_back(DtoConstBool(sl)); - llargs.push_back(DtoConstBool(ss)); - llargs.push_back(DtoConstBool(device)); + llargs.push_back(DtoConstI1(ll)); + llargs.push_back(DtoConstI1(ls)); + llargs.push_back(DtoConstI1(sl)); + llargs.push_back(DtoConstI1(ss)); + llargs.push_back(DtoConstI1(device)); llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); } @@ -486,6 +486,10 @@ llvm::ConstantInt* DtoConstInt(int i) return llvm::ConstantInt::get(LLType::Int32Ty, i, true); } LLConstant* DtoConstBool(bool b) +{ + return llvm::ConstantInt::get(LLType::Int8Ty, b, false); +} +LLConstant* DtoConstI1(bool b) { return llvm::ConstantInt::get(LLType::Int1Ty, b, false); } diff --git a/gen/tollvm.h b/gen/tollvm.h index fdac7677..770d575e 100644 --- a/gen/tollvm.h +++ b/gen/tollvm.h @@ -58,6 +58,7 @@ llvm::ConstantFP* DtoConstFP(Type* t, long double value); LLConstant* DtoConstString(const char*); LLConstant* DtoConstStringPtr(const char* str, const char* section = 0); LLConstant* DtoConstBool(bool); +LLConstant* DtoConstI1(bool); // llvm wrappers LLValue* DtoLoad(LLValue* src, const char* name=0);