Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

Changeset 778:4adf0f742896

Show
Ignore:
Timestamp:
11/22/08 12:35:52 (2 months ago)
Author:
Christian Kamm <kamm incasoftware de>
branch:
default
Message:

Get rid of DtoBoolean? - use DtoCast?(... Type::tbool) instead.
Fixed some casts to bool that were using truncation.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gen/arrays.cpp

    r758 r778  
    946946        assert(0); 
    947947    } 
     948    else if (totype->ty == Tbool) { 
     949        // return (arr.ptr !is null) 
     950        LLValue* ptr = DtoArrayPtr(u); 
     951        LLConstant* nul = getNullPtr(ptr->getType()); 
     952        rval = gIR->ir->CreateICmpNE(ptr, nul, "tmp"); 
     953    } 
    948954    else { 
    949955        assert(0); 
  • gen/classes.cpp

    r758 r778  
    925925    Type* to = _to->toBasetype(); 
    926926    if (to->ty == Tpointer) { 
     927        Logger::println("to pointer"); 
    927928        const LLType* tolltype = DtoType(_to); 
    928929        LLValue* rval = DtoBitCast(val->getRVal(), tolltype); 
    929930        return new DImValue(_to, rval); 
     931    } 
     932    else if (to->ty == Tbool) { 
     933        Logger::println("to bool"); 
     934        LLValue* llval = val->getRVal(); 
     935        LLValue* zero = LLConstant::getNullValue(llval->getType()); 
     936        return new DImValue(_to, gIR->ir->CreateICmpNE(llval, zero, "tmp")); 
    930937    } 
    931938 
     
    948955    } 
    949956    else { 
    950         Logger::println("to object"); 
     957        Logger::println("to class"); 
    951958        int poffset; 
    952959        if (fc->sym->isInterfaceDeclaration()) { 
  • gen/complex.cpp

    r741 r778  
    455455        return DtoCastFloat(loc, re, to); 
    456456    } 
     457    else if (to->ty == Tbool) { 
     458        return new DImValue(_to, DtoComplexEquals(loc, TOKnotequal, val, DtoNullValue(vty))); 
     459    } 
    457460    else 
    458461    assert(0); 
  • gen/llvmhelpers.cpp

    r773 r778  
    570570    } 
    571571 
    572     if (to->isintegral()) { 
     572    if (to->ty == Tbool) { 
     573        LLValue* zero = LLConstantInt::get(rval->getType(), 0, false); 
     574        rval = gIR->ir->CreateICmpNE(rval, zero, "tmp"); 
     575    } 
     576    else if (to->isintegral()) { 
    573577        if (fromsz < tosz || from->ty == Tbool) { 
    574578            if (Logger::enabled()) 
     
    580584            } 
    581585        } 
    582         else if (fromsz > tosz || to->ty == Tbool) { 
     586        else if (fromsz > tosz) { 
    583587            rval = new llvm::TruncInst(rval, tolltype, "tmp", gIR->scopebb()); 
    584588        } 
     
    627631        rval = DtoBitCast(src, tolltype); 
    628632    } 
     633    else if (totype->ty == Tbool) { 
     634        LLValue* src = val->getRVal(); 
     635        LLValue* zero = LLConstant::getNullValue(src->getType()); 
     636        rval = gIR->ir->CreateICmpNE(src, zero, "tmp"); 
     637    } 
    629638    else if (totype->isintegral()) { 
    630639        rval = new llvm::PtrToIntInst(val->getRVal(), tolltype, "tmp", gIR->scopebb()); 
     
    654663    LLValue* rval; 
    655664 
    656     if (totype->iscomplex()) { 
     665    if (totype->ty == Tbool) { 
     666        rval = val->getRVal(); 
     667        LLValue* zero = LLConstant::getNullValue(rval->getType()); 
     668        rval = gIR->ir->CreateFCmpONE(rval, zero, "tmp"); 
     669    } 
     670    else if (totype->iscomplex()) { 
    657671        return DtoComplex(loc, to, val); 
    658672    } 
     
    694708    { 
    695709        return DtoPaintType(loc, val, to); 
     710    } 
     711    else if (to->toBasetype()->ty == Tbool) 
     712    { 
     713        return new DImValue(to, DtoDelegateEquals(TOKnotequal, val->getRVal(), NULL)); 
    696714    } 
    697715    else 
     
    16151633////////////////////////////////////////////////////////////////////////////////////////// 
    16161634 
    1617 LLValue* DtoBoolean(Loc& loc, DValue* dval) 
    1618 { 
    1619     Type* dtype = dval->getType()->toBasetype(); 
    1620     TY ty = dtype->ty; 
    1621  
    1622     // integer 
    1623     if (dtype->isintegral()) 
    1624     { 
    1625         LLValue* val = dval->getRVal(); 
    1626         if (val->getType() == LLType::Int1Ty) 
    1627             return val; 
    1628         else { 
    1629             LLValue* zero = LLConstantInt::get(val->getType(), 0, false); 
    1630             return gIR->ir->CreateICmpNE(val, zero, "tmp"); 
    1631         } 
    1632     } 
    1633     // complex 
    1634     else if (dtype->iscomplex()) 
    1635     { 
    1636         return DtoComplexEquals(loc, TOKnotequal, dval, DtoNullValue(dtype)); 
    1637     } 
    1638     // floating point 
    1639     else if (dtype->isfloating()) 
    1640     { 
    1641         LLValue* val = dval->getRVal(); 
    1642         LLValue* zero = LLConstant::getNullValue(val->getType()); 
    1643         return gIR->ir->CreateFCmpONE(val, zero, "tmp"); 
    1644     } 
    1645     // pointer/class 
    1646     else if (ty == Tpointer || ty == Tclass) { 
    1647         LLValue* val = dval->getRVal(); 
    1648         LLValue* zero = LLConstant::getNullValue(val->getType()); 
    1649         if (Logger::enabled()) 
    1650         { 
    1651             Logger::cout() << "val:  " << *val << '\n'; 
    1652             Logger::cout() << "zero: " << *zero << '\n'; 
    1653         } 
    1654         return gIR->ir->CreateICmpNE(val, zero, "tmp"); 
    1655     } 
    1656     // dynamic array 
    1657     else if (ty == Tarray) 
    1658     { 
    1659         // return (arr.ptr !is null) 
    1660         LLValue* ptr = DtoArrayPtr(dval); 
    1661         LLConstant* nul = getNullPtr(ptr->getType()); 
    1662         return gIR->ir->CreateICmpNE(ptr, nul, "tmp"); 
    1663     } 
    1664     // delegate 
    1665     else if (ty == Tdelegate) 
    1666     { 
    1667         // return (dg !is null) 
    1668         return DtoDelegateEquals(TOKnotequal, dval->getRVal(), NULL); 
    1669     } 
    1670     // unknown 
    1671     std::cout << "unsupported -> bool : " << dtype->toChars() << '\n'; 
    1672     assert(0); 
    1673     return 0; 
    1674 } 
    1675  
    1676 ////////////////////////////////////////////////////////////////////////////////////////// 
    1677  
    16781635void DtoOverloadedIntrinsicName(TemplateInstance* ti, TemplateDeclaration* td, std::string& name) 
    16791636{ 
  • gen/llvmhelpers.h

    r747 r778  
    109109void findDefaultTarget(); 
    110110 
    111 /// Converts any value to a boolean (llvm i1) 
    112 LLValue* DtoBoolean(Loc& loc, DValue* dval); 
    113  
    114111/// get the default initializer of the type 
    115112LLConstant* DtoDefaultInit(Type* t); 
  • gen/statements.cpp

    r774 r778  
    169169        if (Logger::enabled()) 
    170170            Logger::cout() << "if conditional: " << *cond_val << '\n'; 
    171         cond_val = DtoBoolean(loc, cond_e); 
     171        cond_val = DtoCast(loc, cond_e, Type::tbool)->getRVal(); 
    172172    } 
    173173    LLValue* ifgoback = llvm::BranchInst::Create(ifbb, elsebb, cond_val, gIR->scopebb()); 
     
    257257    // create the condition 
    258258    DValue* cond_e = condition->toElem(p); 
    259     LLValue* cond_val = DtoBoolean(loc, cond_e); 
     259    LLValue* cond_val = DtoCast(loc, cond_e, Type::tbool)->getRVal(); 
    260260    delete cond_e; 
    261261 
     
    313313    // create the condition 
    314314    DValue* cond_e = condition->toElem(p); 
    315     LLValue* cond_val = DtoBoolean(loc, cond_e); 
     315    LLValue* cond_val = DtoCast(loc, cond_e, Type::tbool)->getRVal(); 
    316316    delete cond_e; 
    317317 
     
    358358    { 
    359359        DValue* cond_e = condition->toElem(p); 
    360         cond_val = DtoBoolean(loc, cond_e); 
     360        cond_val = DtoCast(loc, cond_e, Type::tbool)->getRVal(); 
    361361        delete cond_e; 
    362362    } 
  • gen/toir.cpp

    r770 r778  
    16501650 
    16511651        // test condition 
    1652         LLValue* condval = DtoBoolean(loc, cond); 
     1652        LLValue* condval = DtoCast(loc, cond, Type::tbool)->getRVal(); 
    16531653 
    16541654        // branch 
     
    16761676    DValue* u = e1->toElem(p); 
    16771677 
    1678     LLValue* b = DtoBoolean(loc, u); 
     1678    LLValue* b = DtoCast(loc, u, Type::tbool)->getRVal(); 
    16791679 
    16801680    LLConstant* zero = DtoConstBool(false); 
     
    17021702    llvm::BasicBlock* andandend = llvm::BasicBlock::Create("andandend", gIR->topfunc(), oldend); 
    17031703 
    1704     LLValue* ubool = DtoBoolean(loc, u); 
     1704    LLValue* ubool = DtoCast(loc, u, Type::tbool)->getRVal(); 
    17051705    DtoStore(ubool,resval); 
    17061706    llvm::BranchInst::Create(andand,andandend,ubool,p->scopebb()); 
     
    17091709    DValue* v = e2->toElem(p); 
    17101710 
    1711     LLValue* vbool = DtoBoolean(loc, v); 
     1711    LLValue* vbool = DtoCast(loc, v, Type::tbool)->getRVal(); 
    17121712    LLValue* uandvbool = llvm::BinaryOperator::Create(llvm::BinaryOperator::And, ubool, vbool,"tmp",p->scopebb()); 
    17131713    DtoStore(uandvbool,resval); 
     
    17381738    llvm::BasicBlock* ororend = llvm::BasicBlock::Create("ororend", gIR->topfunc(), oldend); 
    17391739 
    1740     LLValue* ubool = DtoBoolean(loc, u); 
     1740    LLValue* ubool = DtoCast(loc, u, Type::tbool)->getRVal(); 
    17411741    DtoStore(ubool,resval); 
    17421742    llvm::BranchInst::Create(ororend,oror,ubool,p->scopebb()); 
     
    17451745    DValue* v = e2->toElem(p); 
    17461746 
    1747     LLValue* vbool = DtoBoolean(loc, v); 
     1747    LLValue* vbool = DtoCast(loc, v, Type::tbool)->getRVal(); 
    17481748    DtoStore(vbool,resval); 
    17491749    llvm::BranchInst::Create(ororend,p->scopebb()); 
     
    20002000 
    20012001    DValue* c = econd->toElem(p); 
    2002     LLValue* cond_val = DtoBoolean(loc, c); 
     2002    LLValue* cond_val = DtoCast(loc, c, Type::tbool)->getRVal(); 
    20032003    llvm::BranchInst::Create(condtrue,condfalse,cond_val,p->scopebb()); 
    20042004 
     
    24212421DValue* BoolExp::toElem(IRState* p) 
    24222422{ 
    2423     return new DImValue(type, DtoBoolean(loc, e1->toElem(p))); 
     2423    return new DImValue(type, DtoCast(loc, e1->toElem(p), Type::tbool)->getRVal()); 
    24242424} 
    24252425 
Copyright © 2008, LDC Development Team.