comparison gen/llvmhelpers.cpp @ 611:83ca663ecc20

Backed out changeset 1b62222581fb Do not use i8 for bool. Instead rely on the target to store i1 as i8.
author Christian Kamm <kamm incasoftware de>
date Sun, 21 Sep 2008 14:45:41 +0200
parents 1b62222581fb
children 26fce59fe80a
comparison
equal deleted inserted replaced
610:1b62222581fb 611:83ca663ecc20
572 572
573 Type* to = _to->toBasetype(); 573 Type* to = _to->toBasetype();
574 Type* from = val->getType()->toBasetype(); 574 Type* from = val->getType()->toBasetype();
575 assert(from->isintegral()); 575 assert(from->isintegral());
576 576
577 size_t fromsz = getTypeBitSize(val->getRVal()->getType()); 577 size_t fromsz = from->size();
578 size_t tosz = to->size()*8; 578 size_t tosz = to->size();
579 579
580 LLValue* rval = val->getRVal(); 580 LLValue* rval = val->getRVal();
581 if (rval->getType() == tolltype) { 581 if (rval->getType() == tolltype) {
582 return new DImValue(_to, rval); 582 return new DImValue(_to, rval);
583 } 583 }
772 { 772 {
773 // create a flag to make sure initialization only happens once 773 // create a flag to make sure initialization only happens once
774 llvm::GlobalValue::LinkageTypes gflaglink = istempl ? llvm::GlobalValue::WeakLinkage : llvm::GlobalValue::InternalLinkage; 774 llvm::GlobalValue::LinkageTypes gflaglink = istempl ? llvm::GlobalValue::WeakLinkage : llvm::GlobalValue::InternalLinkage;
775 std::string gflagname(gvar->getName()); 775 std::string gflagname(gvar->getName());
776 gflagname.append("__initflag"); 776 gflagname.append("__initflag");
777 llvm::GlobalVariable* gflag = new llvm::GlobalVariable(LLType::Int1Ty,false,gflaglink,DtoConstI1(false),gflagname,gIR->module); 777 llvm::GlobalVariable* gflag = new llvm::GlobalVariable(LLType::Int1Ty,false,gflaglink,DtoConstBool(false),gflagname,gIR->module);
778 778
779 // check flag and do init if not already done 779 // check flag and do init if not already done
780 llvm::BasicBlock* oldend = gIR->scopeend(); 780 llvm::BasicBlock* oldend = gIR->scopeend();
781 llvm::BasicBlock* initbb = llvm::BasicBlock::Create("ifnotinit",gIR->topfunc(),oldend); 781 llvm::BasicBlock* initbb = llvm::BasicBlock::Create("ifnotinit",gIR->topfunc(),oldend);
782 llvm::BasicBlock* endinitbb = llvm::BasicBlock::Create("ifnotinitend",gIR->topfunc(),oldend); 782 llvm::BasicBlock* endinitbb = llvm::BasicBlock::Create("ifnotinitend",gIR->topfunc(),oldend);
783 LLValue* cond = gIR->ir->CreateICmpEQ(gIR->ir->CreateLoad(gflag,"tmp"),DtoConstI1(false)); 783 LLValue* cond = gIR->ir->CreateICmpEQ(gIR->ir->CreateLoad(gflag,"tmp"),DtoConstBool(false));
784 gIR->ir->CreateCondBr(cond, initbb, endinitbb); 784 gIR->ir->CreateCondBr(cond, initbb, endinitbb);
785 gIR->scope() = IRScope(initbb,endinitbb); 785 gIR->scope() = IRScope(initbb,endinitbb);
786 DValue* ie = DtoInitializer(gvar, init); 786 DValue* ie = DtoInitializer(gvar, init);
787 787
788 DVarValue dst(t, gvar); 788 DVarValue dst(t, gvar);
789 DtoAssign(init->loc, &dst, ie); 789 DtoAssign(init->loc, &dst, ie);
790 790
791 gIR->ir->CreateStore(DtoConstI1(true), gflag); 791 gIR->ir->CreateStore(DtoConstBool(true), gflag);
792 gIR->ir->CreateBr(endinitbb); 792 gIR->ir->CreateBr(endinitbb);
793 gIR->scope() = IRScope(endinitbb,oldend); 793 gIR->scope() = IRScope(endinitbb,oldend);
794 } 794 }
795 795
796 /****************************************************************************************/ 796 /****************************************************************************************/
1546 // for now use the size in bits of the first template param in the instance 1546 // for now use the size in bits of the first template param in the instance
1547 assert(ti->tdtypes.dim == 1); 1547 assert(ti->tdtypes.dim == 1);
1548 Type* T = (Type*)ti->tdtypes.data[0]; 1548 Type* T = (Type*)ti->tdtypes.data[0];
1549 1549
1550 char tmp[10]; 1550 char tmp[10];
1551 sprintf(tmp, "%d", T->size()*8); 1551 if (T->toBasetype()->ty == Tbool) // otherwise we'd get a mismatch
1552 sprintf(tmp, "1");
1553 else
1554 sprintf(tmp, "%d", T->size()*8);
1552 1555
1553 // replace # in name with bitsize 1556 // replace # in name with bitsize
1554 name = td->intrinsicName; 1557 name = td->intrinsicName;
1555 1558
1556 std::string needle("#"); 1559 std::string needle("#");