From bb47b7c4ce22b32667ee094b443423e4089efbf9 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Sun, 21 Sep 2008 14:45:41 +0200 Subject: [PATCH] Backed out changeset 1b62222581fb Do not use i8 for bool. Instead rely on the target to store i1 as 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, 26 insertions(+), 29 deletions(-) diff --git a/gen/arrays.cpp b/gen/arrays.cpp index 47e7d981..d6c9bc23 100644 --- a/gen/arrays.cpp +++ b/gen/arrays.cpp @@ -153,6 +153,9 @@ 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 c8de8810..84e30f44 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 = getTypeBitSize(val->getRVal()->getType()); - size_t tosz = to->size()*8; + size_t fromsz = from->size(); + size_t tosz = to->size(); 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,DtoConstI1(false),gflagname,gIR->module); + llvm::GlobalVariable* gflag = new llvm::GlobalVariable(LLType::Int1Ty,false,gflaglink,DtoConstBool(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"),DtoConstI1(false)); + LLValue* cond = gIR->ir->CreateICmpEQ(gIR->ir->CreateLoad(gflag,"tmp"),DtoConstBool(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(DtoConstI1(true), gflag); + gIR->ir->CreateStore(DtoConstBool(true), gflag); gIR->ir->CreateBr(endinitbb); gIR->scope() = IRScope(endinitbb,oldend); } @@ -1548,7 +1548,10 @@ void DtoOverloadedIntrinsicName(TemplateInstance* ti, TemplateDeclaration* td, s Type* T = (Type*)ti->tdtypes.data[0]; char tmp[10]; - sprintf(tmp, "%d", T->size()*8); + if (T->toBasetype()->ty == Tbool) // otherwise we'd get a mismatch + sprintf(tmp, "1"); + else + 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 f3f42378..c1bf1f71 100644 --- a/gen/statements.cpp +++ b/gen/statements.cpp @@ -81,15 +81,11 @@ void ReturnStatement::toIR(IRState* p) delete e; Logger::cout() << "return value is '" <<*v << "'\n"; + // can happen for classes if (v->getType() != p->topfunc()->getReturnType()) { - // 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'; + v = gIR->ir->CreateBitCast(v, p->topfunc()->getReturnType(), "tmp"); + Logger::cout() << "return value after cast: " << *v << '\n'; } DtoEnclosingHandlers(enclosinghandler, NULL); diff --git a/gen/todebug.cpp b/gen/todebug.cpp index 8d376b3b..d6781f58 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] = DtoConstI1(fd->protection == PROTprivate); - vals[10] = DtoConstI1(fd->getModule() == gIR->dmodule); + vals[9] = DtoConstBool(fd->protection == PROTprivate); + vals[10] = DtoConstBool(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] = DtoConstI1(vd->protection == PROTprivate); - vals[10] = DtoConstI1(vd->getModule() == gIR->dmodule); + vals[9] = DtoConstBool(vd->protection == PROTprivate); + vals[10] = DtoConstBool(vd->getModule() == gIR->dmodule); vals[11] = DBG_CAST(ll); diff --git a/gen/toir.cpp b/gen/toir.cpp index 70cbc408..5406dbfa 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 = llvm::ConstantInt::get(b->getType(), 0); + LLConstant* zero = DtoConstBool(false); b = p->ir->CreateICmpEQ(b,zero); return new DImValue(type, b); diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index 944b8403..6fbf0ddd 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*)LLType::Int8Ty; + return (const LLType*)llvm::ConstantInt::getTrue()->getType(); // 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(DtoConstI1(ll)); - llargs.push_back(DtoConstI1(ls)); - llargs.push_back(DtoConstI1(sl)); - llargs.push_back(DtoConstI1(ss)); - llargs.push_back(DtoConstI1(device)); + 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)); llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); } @@ -486,10 +486,6 @@ 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 770d575e..fdac7677 100644 --- a/gen/tollvm.h +++ b/gen/tollvm.h @@ -58,7 +58,6 @@ 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);