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

Changeset 1650:40bd4a0d4870 for gen

Show
Ignore:
Timestamp:
05/19/10 06:42:32 (2 years ago)
Author:
Tomas Lindquist Olsen
branch:
default
Message:

Update to work with LLVM 2.7.

Removed use of dyn_cast, llvm no compiles
without exceptions and rtti by
default. We do need exceptions for the libconfig stuff, but rtti isn't
necessary (anymore).

Debug info needs to be rewritten, as in LLVM 2.7 the format has
completely changed. To have something to look at while rewriting, the
old code has been wrapped inside #ifndef DISABLE_DEBUG_INFO , this means
that you have to define this to compile at the moment.

Updated tango 0.99.9 patch to include updated EH runtime code, which is
needed for LLVM 2.7 as well.

Files:

Legend:

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

    r1643 r1650  
    310310    LLConstant* constarr; 
    311311    if (mismatch) 
    312         constarr = LLConstantStruct::get(gIR->context(), initvals); 
     312        constarr = LLConstantStruct::get(gIR->context(), initvals, false); // FIXME should this pack? 
    313313    else 
    314314        constarr = LLConstantArray::get(LLArrayType::get(llelemty, arrlen), initvals); 
     
    395395{ 
    396396    LLConstant* values[2] = { dim, ptr }; 
    397     return LLConstantStruct::get(gIR->context(), values, 2); 
     397    return LLConstantStruct::get(gIR->context(), values, 2, false); 
    398398} 
    399399 
  • gen/asmstmt.cpp

    r1571 r1650  
    9595    bool sep = 0, nsep = 0; 
    9696    buf->writestring("asm { "); 
    97      
    98     for (Token * t = tokens; t; t = t->next) {  
     97 
     98    for (Token * t = tokens; t; t = t->next) { 
    9999    switch (t->value) { 
    100100    case TOKlparen: 
     
    162162    // %% need to set DECL_UNINLINABLE too? 
    163163    sc->func->hasReturnExp = 1; // %% DMD does this, apparently... 
    164      
     164 
    165165    // empty statement -- still do the above things because they might be expected? 
    166166    if (! tokens) 
    167167    return this; 
    168      
     168 
    169169    if (!asmparser) 
    170170        if (global.params.cpu == ARCHx86) 
     
    197197    assert(asmblock); 
    198198 
     199    #ifndef DISABLE_DEBUG_INFO 
    199200    // debug info 
    200201    if (global.params.symdebug) 
    201202        DtoDwarfStopPoint(loc.linnum); 
     203    #endif 
    202204 
    203205    if (! asmcode) 
     
    258260    case Arg_FrameRelative: 
    259261// FIXME 
    260 llvm::cout << "asm fixme Arg_FrameRelative" << std::endl; 
    261 assert(0); 
     262assert(0 && "asm fixme Arg_FrameRelative"); 
    262263/*      if (arg->expr->op == TOKvar) 
    263264        arg_val = ((VarExp *) arg->expr)->var->toSymbol()->Stree; 
     
    276277    case Arg_LocalSize: 
    277278// FIXME 
    278 llvm::cout << "asm fixme Arg_LocalSize" << std::endl; 
    279 assert(0); 
     279assert(0 && "asm fixme Arg_LocalSize"); 
    280280/*      var_frame_offset = cfun->x_frame_offset; 
    281281        if (var_frame_offset < 0) 
     
    301301    // those registers.   This changes the stack from what a naked function 
    302302    // expects. 
    303      
     303 
    304304// FIXME 
    305305//    if (! irs->func->naked) { 
     
    319319        arg_map[i] = -arg_map[i] - 1 + n_outputs; 
    320320    } 
    321      
     321 
    322322    bool pct = false; 
    323323    std::string::iterator 
     
    344344        Logger::cout() << "final asm: " << code->insnTemplate << '\n'; 
    345345        std::ostringstream ss; 
    346          
     346 
    347347        ss << "GCC-style output constraints: {"; 
    348348        for (It i = output_constraints.begin(), e = output_constraints.end(); i != e; ++i) { 
     
    351351        ss << " }"; 
    352352        Logger::println("%s", ss.str().c_str()); 
    353          
     353 
    354354        ss.str(""); 
    355355        ss << "GCC-style input constraints: {"; 
     
    359359        ss << " }"; 
    360360        Logger::println("%s", ss.str().c_str()); 
    361          
     361 
    362362        ss.str(""); 
    363363        ss << "GCC-style clobbers: {"; 
     
    380380             * and an output operand. 
    381381             */ 
    382              
     382 
    383383            // Change update operand to pure output operand. 
    384384            *i = mw_cns; 
    385              
     385 
    386386            // Add input operand with same value, with original as "matching output". 
    387387            std::ostringstream ss; 
     
    573573                if((*it)->equals(a->isBranchToLabel)) 
    574574                    skip = true; 
    575             if(skip)  
     575            if(skip) 
    576576                continue; 
    577577 
  • gen/cl_helpers.cpp

    r1103 r1650  
    1818} 
    1919 
    20 bool FlagParser::parse(cl::Option &O, const char *ArgName, const std::string &Arg, bool &Val) { 
     20bool FlagParser::parse(cl::Option &O, llvm::StringRef ArgName, llvm::StringRef Arg, bool &Val) { 
    2121    // Make a std::string out of it to make comparisons easier 
    2222    // (and avoid repeated conversion) 
    23     std::string argname = ArgName; 
    24      
     23    llvm::StringRef argname = ArgName; 
     24 
    2525    typedef std::vector<std::pair<std::string, bool> >::iterator It; 
    2626    for (It I = switches.begin(), E = switches.end(); I != E; ++I) { 
    27         std::string name = I->first; 
     27        llvm::StringRef name = I->first; 
    2828        if (name == argname 
    29                 || (name.length() < argname.length() 
    30                     && argname.substr(0, name.length()) == name 
    31                     && argname[name.length()] == '=')) { 
    32              
     29                || (name.size() < argname.size() 
     30                    && argname.substr(0, name.size()) == name 
     31                    && argname[name.size()] == '=')) { 
     32 
    3333            if (!cl::parser<bool>::parse(O, ArgName, Arg, Val)) { 
    3434                Val = (Val == I->second); 
     
    4242} 
    4343 
    44 void FlagParser::getExtraOptionNames(std::vector<const char*> &Names) { 
     44void FlagParser::getExtraOptionNames(llvm::SmallVectorImpl<const char*> &Names) { 
    4545    typedef std::vector<std::pair<std::string, bool> >::iterator It; 
    4646    for (It I = switches.begin() + 1, E = switches.end(); I != E; ++I) { 
    47         Names.push_back(I->first.c_str()); 
     47        Names.push_back(I->first.data()); 
    4848    } 
    4949} 
     
    6161    } 
    6262} 
    63          
     63 
    6464void MultiSetter::operator=(bool val) { 
    6565    typedef std::vector<bool*>::iterator It; 
     
    7373    if (!cstr || !*cstr) 
    7474        error("Expected argument to '-%s'", name); 
    75      
     75 
    7676    if (!*arrp) 
    7777        *arrp = new Array; 
  • gen/cl_helpers.h

    r1200 r1650  
    1111namespace opts { 
    1212    namespace cl = llvm::cl; 
    13      
     13 
    1414    /// Helper class for fancier options 
    1515    class FlagParser : public cl::parser<bool> { 
     
    2222            switches.push_back(make_pair("disable-" + Name, false)); 
    2323            // Replace <foo> with -enable-<foo> 
    24             O.ArgStr = switches[0].first.c_str(); 
     24            O.ArgStr = switches[0].first.data(); 
    2525        } 
    26          
    27         bool parse(cl::Option &O, const char *ArgName, const std::string &ArgValue, bool &Val); 
    28          
    29         void getExtraOptionNames(std::vector<const char*> &Names); 
     26 
     27        bool parse(cl::Option &O, llvm::StringRef ArgName, llvm::StringRef ArgValue, bool &Val); 
     28 
     29        void getExtraOptionNames(llvm::SmallVectorImpl<const char*> &Names); 
    3030    }; 
    31      
     31 
    3232    /// Helper class for options that set multiple flags 
    3333    class MultiSetter { 
     
    3737    public: 
    3838        MultiSetter(bool invert, bool* p, ...) END_WITH_NULL; 
    39          
     39 
    4040        void operator=(bool val); 
    4141    }; 
    42      
     42 
    4343    /// Helper class to fill Array with char* when given strings 
    4444    /// (Errors on empty strings) 
     
    5353            assert(arrp); 
    5454        } 
    55          
     55 
    5656        void push_back(const char* cstr); 
    57          
     57 
    5858        void push_back(const std::string& str) { 
    5959            push_back(str.c_str()); 
    6060        } 
    6161    }; 
    62      
     62 
    6363    /// Helper class to allow use of a parser<bool> with BoolOrDefault 
    6464    class BoolOrDefaultAdapter { 
     
    6868            return value; 
    6969        } 
    70          
     70 
    7171        void operator=(cl::boolOrDefault val) { 
    7272            value = val; 
    7373        } 
    74          
     74 
    7575        void operator=(bool val) { 
    7676            *this = (val ? cl::BOU_TRUE : cl::BOU_FALSE); 
  • gen/configfile.cpp

    r1537 r1650  
    9595    if (p.exists()) 
    9696        return true; 
    97          
     97 
    9898    return false; 
    9999} 
     
    103103    sys::Path p; 
    104104    if (!locate(p, argv0, mainAddr, filename)) 
    105     {         
     105    { 
    106106        // failed to find cfg, users still have the DFLAGS environment var 
    107107        std::cerr << "Error failed to locate the configuration file: " << filename << std::endl; 
     
    110110 
    111111    // save config file path for -v output 
    112     pathstr = p.toString(); 
     112    pathstr = p.str(); 
    113113 
    114114    try 
     
    142142            { 
    143143                std::string v = arr[i]; 
    144                  
     144 
    145145                // replace binpathkey with binpath 
    146146                size_t p; 
    147147                while (std::string::npos != (p = v.find(binpathkey))) 
    148148                    v.replace(p, binpathkey.size(), binpath); 
    149                  
     149 
    150150                switches.push_back(strdup(v.c_str())); 
    151151            } 
  • gen/functions.cpp

    r1607 r1650  
    600600    } 
    601601 
     602    #ifndef DISABLE_DEBUG_INFO 
    602603    // debug info 
    603     if (global.params.symdebug) { 
     604    if (global.params.symdebug) 
    604605        fd->ir.irFunc->diSubprogram = DtoDwarfSubProgram(fd); 
    605     } 
     606    #endif 
    606607 
    607608    Type* t = fd->type->toBasetype(); 
     
    643644    irfunction->allocapoint = allocaPoint; 
    644645 
     646    #ifndef DISABLE_DEBUG_INFO 
    645647    // debug info - after all allocas, but before any llvm.dbg.declare etc 
    646648    if (global.params.symdebug) DtoDwarfFuncStart(fd); 
     649    #endif 
    647650 
    648651    // this hack makes sure the frame pointer elimination optimization is disabled. 
     
    669672        fd->vthis->ir.irLocal->value = thismem; 
    670673 
     674        #ifndef DISABLE_DEBUG_INFO 
    671675        if (global.params.symdebug) 
    672676            DtoDwarfLocalVariable(thismem, fd->vthis); 
     677        #endif 
    673678 
    674679    #if DMDV1 
     
    723728            } 
    724729 
     730            #ifndef DISABLE_DEBUG_INFO 
    725731            if (global.params.symdebug && !(isaArgument(irloc->value) && !isaArgument(irloc->value)->hasByValAttr()) && !refout) 
    726732                DtoDwarfLocalVariable(irloc->value, vd); 
     733            #endif 
    727734        } 
    728735    } 
     
    759766        fd->vresult->ir.irLocal->value = DtoAlloca(fd->vresult->type, fd->vresult->toChars()); 
    760767    } 
    761      
     768 
    762769    // copy _argptr and _arguments to a memory location 
    763770    if (f->linkage == LINKd && f->varargs == 1) 
     
    795802        // llvm requires all basic blocks to end with a TerminatorInst but DMD does not put a return statement 
    796803        // in automatically, so we do it here. 
    797          
     804 
    798805        // pass the previous block into this block 
     806        #ifndef DISABLE_DEBUG_INFO 
    799807        if (global.params.symdebug) DtoDwarfFuncEnd(fd); 
     808        #endif 
    800809        if (func->getReturnType() == LLType::getVoidTy(gIR->context())) { 
    801810            llvm::ReturnInst::Create(gIR->context(), gIR->scopebb()); 
  • gen/linker.cpp

    r1600 r1650  
    107107            fatal(); 
    108108        } 
    109     }     
     109    } 
    110110 
    111111    // strip debug info 
     
    223223    llvm::sys::Path gcc = getGcc(); 
    224224    // get a string version for argv[0] 
    225     std::string gccStr = gcc.toString(); 
     225    const char* gccStr = gcc.c_str(); 
    226226 
    227227    // build arguments 
     
    229229 
    230230    // first the program name ?? 
    231     args.push_back(gccStr.c_str()); 
     231    args.push_back(gccStr); 
    232232 
    233233    // object files 
     
    275275            fatal(); 
    276276        } 
    277     }     
     277    } 
    278278 
    279279    // additional linker switches 
     
    293293    // default libs 
    294294    switch(global.params.os) { 
    295     case OSLinux:  
     295    case OSLinux: 
    296296    case OSMacOSX: 
    297297        args.push_back("-ldl"); 
     
    331331 
    332332    Logger::println("Linking with: "); 
    333     std::vector<const char*>::const_iterator I = args.begin(), E = args.end();  
     333    std::vector<const char*>::const_iterator I = args.begin(), E = args.end(); 
    334334    Stream logstr = Logger::cout(); 
    335335    for (; I != E; ++I) 
    336336        if (*I) 
    337337            logstr << "'" << *I << "'" << " "; 
    338     logstr << "\n" << std::flush; 
     338    logstr << "\n"; // FIXME where's flush ? 
    339339 
    340340 
     
    350350        return status; 
    351351    } 
    352      
     352 
    353353    return 0; 
    354354} 
     
    376376    std::vector<const char*> args; 
    377377    // args[0] should be the name of the executable 
    378     args.push_back(gExePath.toString().c_str()); 
     378    args.push_back(gExePath.c_str()); 
    379379    // Skip first argument to -run; it's a D source file. 
    380380    for (size_t i = 1, length = opts::runargs.size(); i < length; i++) 
  • gen/llvmhelpers.cpp

    r1643 r1650  
    161161    gIR->CreateCallOrInvoke(fn, args.begin(), args.end()); 
    162162 
     163    #ifndef DISABLE_DEBUG_INFO 
    163164    // end debug info 
    164165    if (global.params.symdebug) 
    165166        DtoDwarfFuncEnd(gIR->func()->decl); 
     167    #endif 
    166168 
    167169    // after assert is always unreachable 
     
    269271    // labels are a special case: they are not required to enclose the current scope 
    270272    // for them we use the enclosing scope handler as a reference point 
    271     LabelStatement* lblstmt = dynamic_cast<LabelStatement*>(target)
     273    LabelStatement* lblstmt = target ? target->isLabelStatement() : 0
    272274    if (lblstmt) 
    273275        target = lblstmt->enclosingScopeExit; 
     
    486488 
    487489    // unknown 
    488     llvm::cout << "unsupported: null value for " << type->toChars() << '\n'
     490    error("unsupported: null value for %s", type->toChars())
    489491    assert(0); 
    490492    return 0; 
     
    855857        gvar->setInitializer(initVal); 
    856858 
     859        #ifndef DISABLE_DEBUG_INFO 
    857860        // do debug info 
    858861        if (global.params.symdebug) 
     
    862865            gIR->usedArray.push_back(llvm::ConstantExpr::getBitCast(gv, getVoidPtrType())); 
    863866        } 
     867        #endif 
    864868    } 
    865869} 
     
    907911                assert(ex && "ref vars must have expression initializer"); 
    908912                assert(ex->exp); 
    909                 AssignExp* as = dynamic_cast<AssignExp*>(ex->exp); 
     913                AssignExp* as = ex->exp->isAssignExp(); 
    910914                assert(as && "ref vars must be initialized by an assign exp"); 
    911915                vd->ir.irLocal->value = as->e2->toElem(gIR)->getLVal(); 
    912916            } 
    913              
     917 
    914918            // referenced by nested delegate? 
    915919        #if DMDV2 
     
    920924                Logger::println("has nestedref set"); 
    921925                assert(vd->ir.irLocal); 
    922                  
     926 
    923927                DtoNestedInit(vd); 
    924928            } 
     
    938942                vd->ir.irLocal->value = allocainst; 
    939943 
     944                #ifndef DISABLE_DEBUG_INFO 
    940945                if (global.params.symdebug) 
    941                 { 
    942946                    DtoDwarfLocalVariable(allocainst, vd); 
    943                 } 
     947                #endif 
    944948            } 
    945949            else 
     
    10471051    // we don't handle aliases either 
    10481052    assert(!var->aliassym); 
    1049      
     1053 
    10501054    // alloca if necessary 
    10511055    LLValue* allocaval = NULL; 
     
    10531057    { 
    10541058        addr = DtoAlloca(var->type, var->toChars()); 
    1055          
     1059 
     1060        #ifndef DISABLE_DEBUG_INFO 
    10561061        // add debug info 
    10571062        if (global.params.symdebug) 
    10581063            DtoDwarfLocalVariable(addr, var); 
    1059     } 
    1060          
     1064        #endif 
     1065    } 
     1066 
    10611067    // referenced by nested function? 
    10621068#if DMDV2 
     
    12951301    Logger::println("template declaration: %s", td->toChars()); 
    12961302    Logger::println("intrinsic name: %s", td->intrinsicName.c_str()); 
    1297      
     1303 
    12981304    // for now use the size in bits of the first template param in the instance 
    12991305    assert(ti->tdtypes.dim == 1); 
     
    13081314    char tmp[21]; // probably excessive, but covers a uint64_t 
    13091315    sprintf(tmp, "%lu", (unsigned long) gTargetData->getTypeSizeInBits(DtoType(T))); 
    1310      
     1316 
    13111317    // replace # in name with bitsize 
    13121318    name = td->intrinsicName; 
     
    13311337        } 
    13321338    } 
    1333      
     1339 
    13341340    Logger::println("final intrinsic name: %s", name.c_str()); 
    13351341} 
     
    13411347    if (FuncDeclaration* fd = s->isFuncDeclaration()) 
    13421348    { 
    1343         // we can't (and probably shouldn't?) define functions  
     1349        // we can't (and probably shouldn't?) define functions 
    13441350        // that weren't semantic3'ed 
    13451351        if (fd->semanticRun < 4) 
     
    13531359            // These will get available_externally linkage, 
    13541360            // so they shouldn't end up in object code. 
    1355              
     1361 
    13561362            assert(fd->type->ty == Tfunction); 
    13571363            TypeFunction* tf = (TypeFunction*) fd->type; 
     
    13721378                return true; 
    13731379            } 
    1374              
     1380 
    13751381            // This was only semantic'ed for inlining checks. 
    13761382            // We won't be inlining this, so we only need to emit a declaration. 
     
    13971403        if (!opts::singleObj) 
    13981404            return true; 
    1399      
     1405 
    14001406        if (!tinst->emittedInModule) 
    14011407        { 
     
    14051411        return tinst->emittedInModule == gIR->dmodule; 
    14061412    } 
    1407      
     1413 
    14081414    return s->getModule() == gIR->dmodule; 
    14091415} 
  • gen/llvmhelpers.h

    r1643 r1650  
    157157 
    158158/// convert DMD calling conv to LLVM 
    159 unsigned DtoCallingConv(Loc loc, LINK l); 
     159llvm::CallingConv::ID DtoCallingConv(Loc loc, LINK l); 
    160160 
    161161/// 
  • gen/logger.cpp

    r1502 r1650  
    1313#include "llvm/GlobalValue.h" 
    1414#include "llvm/Support/Casting.h" 
    15 #include "llvm/Support/raw_ostream.h" 
     15#include "llvm/Support/raw_os_ostream.h" 
    1616#include "llvm/Assembly/Writer.h" 
    1717 
     
    2828    // (Only treat non-global constants like this, so that e.g. global variables 
    2929    // still get their initializers printed) 
     30    llvm::raw_os_ostream raw(OS); 
    3031    if (llvm::isa<llvm::Constant>(V) && !llvm::isa<llvm::GlobalValue>(V)) 
    31         llvm::WriteAsOperand(OS, &V, true, gIR->module); 
     32        llvm::WriteAsOperand(raw, &V, true, gIR->module); 
    3233    else 
    33         OS << V
     34        V.print(raw)
    3435} 
    3536 
  • gen/logger.h

    r1502 r1650  
    2121class Stream { 
    2222    std::ostream* OS; 
    23      
     23 
    2424public: 
    2525    Stream() : OS(0) {} 
    2626    Stream(std::ostream* S) : OS(S) {} 
    2727    Stream(std::ostream& S) : OS(&S) {} 
    28      
     28 
     29    /* 
    2930    Stream operator << (std::ios_base &(*Func)(std::ios_base&)) { 
    3031      if (OS) *OS << Func; 
    3132      return *this; 
    3233    } 
    33      
     34    */ 
     35 
    3436    Stream operator << (std::ostream &(*Func)(std::ostream&)) { 
    35       if (OS) *OS << Func
     37      if (OS) Func(*OS)
    3638      return *this; 
    3739    } 
    38      
     40 
    3941    template<typename Ty> 
    4042    Stream& operator << (const Ty& Thing) { 
     
    4345        return *this; 
    4446    } 
    45      
     47 
    4648private: 
    4749    // Implementation details to treat llvm::Value, llvm::Type and their 
    4850    // subclasses specially (to pretty-print types). 
    49      
     51 
    5052    static void writeType(std::ostream& OS, const llvm::Type& Ty); 
    5153    static void writeValue(std::ostream& OS, const llvm::Value& Ty); 
    52      
     54 
    5355    template<typename Ty, int N> friend struct Writer; 
    5456    // error: function template partial specialization is not allowed 
     
    6062        } 
    6163    }; 
    62      
     64 
    6365    template<typename Ty> 
    6466    struct Writer<Ty, 1> { 
     
    7072        } 
    7173    }; 
    72      
     74 
    7375    // NOT IMPLEMENTED 
    7476    char sfinae_bait(const llvm::Type&); 
  • gen/main.cpp

    r1645 r1650  
    149149    global.params.objfiles = new Array(); 
    150150    global.params.ddocfiles = new Array(); 
    151      
     151 
    152152    global.params.moduleDeps = NULL; 
    153153    global.params.moduleDepsFile = NULL; 
     
    224224    initFromString(global.params.objname, objectFile); 
    225225    initFromString(global.params.objdir, objectDir); 
    226      
     226 
    227227    initFromString(global.params.docdir, ddocDir); 
    228228    initFromString(global.params.docname, ddocFile); 
    229229    global.params.doDocComments |= 
    230230        global.params.docdir || global.params.docname; 
    231      
     231 
    232232#ifdef _DH 
    233233    initFromString(global.params.hdrdir, hdrDir); 
     
    238238 
    239239    initFromString(global.params.moduleDepsFile, moduleDepsFile); 
    240     if (global.params.moduleDepsFile != NULL)  
    241     {  
    242          global.params.moduleDeps = new OutBuffer;  
     240    if (global.params.moduleDepsFile != NULL) 
     241    { 
     242         global.params.moduleDeps = new OutBuffer; 
    243243    } 
    244244 
     
    436436 
    437437    // Allocate target machine. 
    438      
     438 
    439439    // first initialize llvm 
    440440#define LLVM_TARGET(A) LLVMInitialize##A##TargetInfo(); LLVMInitialize##A##Target(); LLVMInitialize##A##AsmPrinter(); 
     
    485485    } 
    486486 
    487     std::auto_ptr<llvm::TargetMachine> target(theTarget->createTargetMachine(triple, FeaturesStr)); 
    488     assert(target.get() && "Could not allocate target machine!"); 
    489     gTargetMachine = target.get(); 
    490     gTargetData = gTargetMachine->getTargetData(); 
     487    // FIXME 
     488    //std::auto_ptr<llvm::TargetMachine> target(theTarget->createTargetMachine(triple, FeaturesStr)); 
     489    //assert(target.get() && "Could not allocate target machine!"); 
     490    //gTargetMachine = target.get(); 
     491 
     492    llvm::TargetMachine* target = theTarget->createTargetMachine(triple, FeaturesStr); 
     493    gTargetMachine = target; 
     494 
     495    gTargetData = target->getTargetData(); 
    491496 
    492497    // get final data layout 
     
    904909 
    905910    // write module dependencies to file if requested 
    906     if (global.params.moduleDepsFile != NULL)  
    907     {  
     911    if (global.params.moduleDepsFile != NULL) 
     912    { 
    908913        assert (global.params.moduleDepsFile != NULL); 
    909914 
    910915        File deps(global.params.moduleDepsFile); 
    911         OutBuffer* ob = global.params.moduleDeps;  
     916        OutBuffer* ob = global.params.moduleDeps; 
    912917        deps.setbuffer((void*)ob->data, ob->offset); 
    913918        deps.write(); 
     
    945950        } 
    946951    } 
    947      
     952 
    948953    // internal linking for singleobj 
    949954    if (singleObj && llvmModules.size() > 0) 
     
    952957        char* name = m->toChars(); 
    953958        char* filename = m->objfile->name->str; 
    954          
     959 
    955960        llvm::Linker linker(name, name, context); 
    956961 
     
    962967            delete llvmModules[i]; 
    963968        } 
    964          
     969 
    965970        m->deleteObjFile(); 
    966971        writeModule(linker.getModule(), filename); 
    967972        global.params.objfiles->push(filename); 
    968973    } 
    969      
     974 
    970975    backend_term(); 
    971976    if (global.errors) 
  • gen/optimizer.cpp

    r1576 r1650  
    9696static void addPass(PassManager& pm, Pass* pass) { 
    9797    pm.add(pass); 
    98      
     98 
    9999    if (verifyEach) pm.add(createVerifierPass()); 
    100100} 
     
    108108        //addPass(pm, createStripDeadPrototypesPass()); 
    109109        addPass(pm, createGlobalDCEPass()); 
    110         addPass(pm, createRaiseAllocationsPass()); 
     110        addPass(pm, createPromoteMemoryToRegisterPass()); 
    111111        addPass(pm, createCFGSimplificationPass()); 
    112112        if (optimizeLevel == 1) 
     
    166166        addPass(pm, createInstructionCombiningPass()); 
    167167    } 
    168      
     168 
    169169    // -O3 
    170170    if (optimizeLevel >= 3) 
     
    178178        addPass(pm, createScalarReplAggregatesPass()); 
    179179        addPass(pm, createInstructionCombiningPass()); 
    180         addPass(pm, createCondPropagationPass()); 
     180        addPass(pm, createConstantPropagationPass()); 
    181181 
    182182        addPass(pm, createReassociatePass()); 
     
    195195 
    196196        addPass(pm, createInstructionCombiningPass()); 
    197         addPass(pm, createCondPropagationPass()); 
     197        addPass(pm, createConstantPropagationPass()); 
    198198 
    199199        addPass(pm, createDeadStoreEliminationPass()); 
     
    221221 
    222222    PassManager pm; 
    223      
     223 
    224224    if (verifyEach) pm.add(createVerifierPass()); 
    225      
     225 
    226226    addPass(pm, new TargetData(m)); 
    227227 
  • gen/passes/SimplifyDRuntimeCalls.cpp

    r1571 r1650  
    1919#include "Passes.h" 
    2020 
     21#include "llvm/Function.h" 
    2122#include "llvm/Pass.h" 
    2223#include "llvm/Intrinsics.h" 
     
    4950        AliasAnalysis *AA; 
    5051        LLVMContext *Context; 
    51          
     52 
    5253        /// CastToCStr - Return V if it is an i8*, otherwise cast it to i8*. 
    5354        Value *CastToCStr(Value *V, IRBuilder<> &B); 
    54          
     55 
    5556        /// EmitMemCpy - Emit a call to the memcpy function to the builder.  This 
    5657        /// always expects that the size has type 'intptr_t' and Dst/Src are pointers. 
    57         Value *EmitMemCpy(Value *Dst, Value *Src, Value *Len,  
     58        Value *EmitMemCpy(Value *Dst, Value *Src, Value *Len, 
    5859                          unsigned Align, IRBuilder<> &B); 
    5960    public: 
    6061        LibCallOptimization() { } 
    6162        virtual ~LibCallOptimization() {} 
    62          
     63 
    6364        /// CallOptimizer - This pure virtual method is implemented by base classes to 
    6465        /// do various optimizations.  If this returns null then no transformation was 
     
    6768        /// delete CI. 
    6869        virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B)=0; 
    69          
     70 
    7071        Value *OptimizeCall(CallInst *CI, bool& Changed, const TargetData &TD, 
    7172                AliasAnalysis& AA, IRBuilder<> &B) { 
     
    117118            FT->getParamType(3) != FT->getReturnType()) 
    118119          return 0; 
    119          
     120 
    120121        // Whether or not this allocates is irrelevant if the result isn't used. 
    121122        // Just delete if that's the case. 
    122123        if (CI->use_empty()) 
    123124            return CI; 
    124          
     125 
    125126        Value* NewLen = CI->getOperand(2); 
    126127        if (Constant* NewCst = dyn_cast<Constant>(NewLen)) { 
    127128            Value* Data = CI->getOperand(4); 
    128              
     129 
    129130            // For now, we just catch the simplest of cases. 
    130131            // 
     
    133134            //       (But beware of unsigned overflow! For example, we can't 
    134135            //       safely transform that example if arr.length may be 0) 
    135              
     136 
    136137            // Setting length to 0 never reallocates, so replace by data argument 
    137138            if (NewCst->isNullValue()) 
    138139                return Data; 
    139              
     140 
    140141            // If both lengths are constant integers, see if NewLen <= OldLen 
    141142            Value* OldLen = CI->getOperand(3); 
     
    158159            FT->getParamType(1) != RetTy || FT->getParamType(2) != RetTy) 
    159160          return 0; 
    160          
     161 
    161162        Value* OldLen = CI->getOperand(1); 
    162163        Value* OldSize = CI->getOperand(2); 
    163164        Value* NewSize = CI->getOperand(3); 
    164          
     165 
    165166        // If the old length was zero, always return zero. 
    166167        if (Constant* LenCst = dyn_cast<Constant>(OldLen)) 
    167168            if (LenCst->isNullValue()) 
    168169                return OldLen; 
    169          
     170 
    170171        // Equal sizes are much faster to check for, so do so now. 
    171172        if (OldSize == NewSize) 
    172173            return OldLen; 
    173          
     174 
    174175        // If both sizes are constant integers, see if OldSize is a multiple of NewSize 
    175176        if (ConstantInt* OldInt = dyn_cast<ConstantInt>(OldSize)) 
     
    178179                if (NewInt->isNullValue()) 
    179180                    return 0; 
    180                  
     181 
    181182                APInt Quot, Rem; 
    182183                APInt::udivrem(OldInt->getValue(), NewInt->getValue(), Quot, Rem); 
     
    196197        for (CallInst::use_iterator I = CI->use_begin(), E = CI->use_end() ; I != E;) { 
    197198            Instruction* User = cast<Instruction>(*I++); 
    198              
     199 
    199200            if (ICmpInst* Cmp = dyn_cast<ICmpInst>(User)) { 
    200201                if (!Cmp->isEquality()) 
     
    216217            } 
    217218        } 
    218          
     219 
    219220        // If it's not used (anymore), pre-emptively GC it. 
    220221        if (CI->use_empty()) 
     
    236237            FT->getParamType(3) != FT->getParamType(1)) 
    237238          return 0; 
    238          
     239 
    239240        Value* Size = CI->getOperand(2); 
    240          
     241 
    241242        // Check the lengths match 
    242243        if (CI->getOperand(4) != Size) 
    243244            return 0; 
    244          
     245 
    245246        // Assume unknown size unless we have constant size (that fits in an uint) 
    246247        unsigned Sz = ~0U; 
     
    248249            if (Int->getValue().isIntN(32)) 
    249250                Sz = Int->getValue().getZExtValue(); 
    250          
     251 
    251252        // Check if the pointers may alias 
    252253        if (AA->alias(CI->getOperand(1), Sz, CI->getOperand(3), Sz)) 
    253254            return 0; 
    254          
     255 
    255256        // Equal length and the pointers definitely don't alias, so it's safe to 
    256257        // replace the call with memcpy 
     
    272273    class VISIBILITY_HIDDEN SimplifyDRuntimeCalls : public FunctionPass { 
    273274        StringMap<LibCallOptimization*> Optimizations; 
    274          
     275 
    275276        // Array operations 
    276277        ArraySetLengthOpt ArraySetLength; 
    277278        ArrayCastLenOpt ArrayCastLen; 
    278279        ArraySliceCopyOpt ArraySliceCopy; 
    279          
     280 
    280281        // GC allocations 
    281282        AllocationOpt Allocation; 
    282          
     283 
    283284        public: 
    284285        static char ID; // Pass identification 
    285286        SimplifyDRuntimeCalls() : FunctionPass(&ID) {} 
    286          
     287 
    287288        void InitOptimizations(); 
    288289        bool runOnFunction(Function &F); 
    289          
     290 
    290291        bool runOnce(Function &F, const TargetData& TD, AliasAnalysis& AA); 
    291              
     292 
    292293        virtual void getAnalysisUsage(AnalysisUsage &AU) const { 
    293294          AU.addRequired<TargetData>(); 
     
    303304// Public interface to the pass. 
    304305FunctionPass *createSimplifyDRuntimeCalls() { 
    305   return new SimplifyDRuntimeCalls();  
     306  return new SimplifyDRuntimeCalls(); 
    306307} 
    307308 
     
    314315    Optimizations["_d_array_cast_len"] = &ArrayCastLen; 
    315316    Optimizations["_d_array_slice_copy"] = &ArraySliceCopy; 
    316      
     317 
    317318    /* Delete calls to runtime functions which aren't needed if their result is 
    318319     * unused. That comes down to functions that don't do anything but 
     
    340341    if (Optimizations.empty()) 
    341342        InitOptimizations(); 
    342      
     343 
    343344    const TargetData &TD = getAnalysis<TargetData>(); 
    344345    AliasAnalysis &AA = getAnalysis<AliasAnalysis>(); 
    345      
     346 
    346347    // Iterate to catch opportunities opened up by other optimizations, 
    347348    // such as calls that are only used as arguments to unused calls: 
     
    355356        EverChanged |= Changed; 
    356357    } while (Changed); 
    357      
     358 
    358359    return EverChanged; 
    359360} 
     
    368369            CallInst *CI = dyn_cast<CallInst>(I++); 
    369370            if (!CI) continue; 
    370              
     371 
    371372            // Ignore indirect calls and calls to non-external functions. 
    372373            Function *Callee = CI->getCalledFunction(); 
     
    374375                    !(Callee->hasExternalLinkage() || Callee->hasDLLImportLinkage())) 
    375376                continue; 
    376              
     377 
    377378            // Ignore unknown calls. 
    378379            StringMap<LibCallOptimization*>::iterator OMI = 
    379380                Optimizations.find(Callee->getName()); 
    380381            if (OMI == Optimizations.end()) continue; 
    381              
     382 
    382383            DEBUG(errs() << "SimplifyDRuntimeCalls inspecting: " << *CI); 
    383              
     384 
    384385            // Set the builder to the instruction after the call. 
    385386            Builder.SetInsertPoint(BB, I); 
    386              
     387 
    387388            // Try to optimize this call. 
    388389            Value *Result = OMI->second->OptimizeCall(CI, Changed, TD, AA, Builder); 
    389390            if (Result == 0) continue; 
    390              
     391 
    391392            DEBUG(errs() << "SimplifyDRuntimeCalls simplified: " << *CI; 
    392393                  errs() << "  into: " << *Result << "\n"); 
    393              
     394 
    394395            // Something changed! 
    395396            Changed = true; 
    396              
     397 
    397398            if (Result == CI) { 
    398399                assert(CI->use_empty()); 
     
    402403                ++NumSimplified; 
    403404                AA.replaceWithNewValue(CI, Result); 
    404                  
     405 
    405406                if (!CI->use_empty()) 
    406407                    CI->replaceAllUsesWith(Result); 
    407                  
     408 
    408409                if (!Result->hasName()) 
    409410                    Result->takeName(CI); 
    410411            } 
    411              
     412 
    412413            // Inspect the instruction after the call (which was potentially just 
    413414            // added) next. 
    414415            I = CI; ++I; 
    415              
     416 
    416417            CI->eraseFromParent(); 
    417418        } 
  • gen/statements.cpp

    r1647 r1650  
    5454    LOG_SCOPE; 
    5555 
    56     if (global.params.symdebug) 
    57         DtoDwarfStopPoint(loc.linnum); 
    58      
     56    #ifndef DISABLE_DEBUG_INFO 
     57    if (global.params.symdebug) 
     58        DtoDwarfStopPoint(loc.linnum); 
     59    #endif 
     60 
    5961    // is there a return value expression? 
    6062    if (exp || (!exp && (p->topfunc() == p->mainFunc)) ) 
     
    7981            DtoEnclosingHandlers(loc, NULL); 
    8082 
     83            #ifndef DISABLE_DEBUG_INFO 
    8184            // emit dbg end function 
    8285            if (global.params.symdebug) DtoDwarfFuncEnd(f->decl); 
     86            #endif 
    8387 
    8488            // emit ret 
     
    127131            DtoEnclosingHandlers(loc, NULL); 
    128132 
     133            #ifndef DISABLE_DEBUG_INFO 
    129134            if (global.params.symdebug) DtoDwarfFuncEnd(p->func()->decl); 
     135            #endif 
    130136            llvm::ReturnInst::Create(gIR->context(), v, p->scopebb()); 
    131137        } 
     
    137143        DtoEnclosingHandlers(loc, NULL); 
    138144 
     145        #ifndef DISABLE_DEBUG_INFO 
    139146        if (global.params.symdebug) DtoDwarfFuncEnd(p->func()->decl); 
     147        #endif 
    140148        llvm::ReturnInst::Create(gIR->context(), p->scopebb()); 
    141149    } 
     
    154162    LOG_SCOPE; 
    155163 
    156     if (global.params.symdebug) 
    157         DtoDwarfStopPoint(loc.linnum); 
     164    #ifndef DISABLE_DEBUG_INFO 
     165    if (global.params.symdebug) 
     166        DtoDwarfStopPoint(loc.linnum); 
     167    #endif 
    158168 
    159169    if (exp) { 
     
    183193    LOG_SCOPE; 
    184194 
    185     if (global.params.symdebug) 
    186         DtoDwarfStopPoint(loc.linnum); 
     195    #ifndef DISABLE_DEBUG_INFO 
     196    if (global.params.symdebug) 
     197        DtoDwarfStopPoint(loc.linnum); 
     198    #endif 
    187199 
    188200    if (match) 
     
    271283    LOG_SCOPE; 
    272284 
    273     if (global.params.symdebug) 
    274         DtoDwarfStopPoint(loc.linnum); 
     285    #ifndef DISABLE_DEBUG_INFO 
     286    if (global.params.symdebug) 
     287        DtoDwarfStopPoint(loc.linnum); 
     288    #endif 
    275289 
    276290    // create while blocks 
     
    319333    LOG_SCOPE; 
    320334 
    321     if (global.params.symdebug) 
    322         DtoDwarfStopPoint(loc.linnum); 
     335    #ifndef DISABLE_DEBUG_INFO 
     336    if (global.params.symdebug) 
     337        DtoDwarfStopPoint(loc.linnum); 
     338    #endif 
    323339 
    324340    // create while blocks 
     
    364380    LOG_SCOPE; 
    365381 
    366     if (global.params.symdebug) 
    367         DtoDwarfStopPoint(loc.linnum); 
     382    #ifndef DISABLE_DEBUG_INFO 
     383    if (global.params.symdebug) 
     384        DtoDwarfStopPoint(loc.linnum); 
     385    #endif 
    368386 
    369387    // create for blocks 
     
    444462        return; 
    445463 
    446     if (global.params.symdebug) 
    447         DtoDwarfStopPoint(loc.linnum); 
     464    #ifndef DISABLE_DEBUG_INFO 
     465    if (global.params.symdebug) 
     466        DtoDwarfStopPoint(loc.linnum); 
     467    #endif 
    448468 
    449469    if (ident != 0) { 
     
    499519    LOG_SCOPE; 
    500520 
    501     if (global.params.symdebug) 
    502         DtoDwarfStopPoint(loc.linnum); 
     521    #ifndef DISABLE_DEBUG_INFO 
     522    if (global.params.symdebug) 
     523        DtoDwarfStopPoint(loc.linnum); 
     524    #endif 
    503525 
    504526    if (ident != 0) { 
     
    565587    LOG_SCOPE; 
    566588 
    567     if (global.params.symdebug) 
    568         DtoDwarfStopPoint(loc.linnum); 
     589    #ifndef DISABLE_DEBUG_INFO 
     590    if (global.params.symdebug) 
     591        DtoDwarfStopPoint(loc.linnum); 
     592    #endif 
    569593 
    570594    // if there's no finalbody or no body, things are simple 
     
    643667    LOG_SCOPE; 
    644668 
    645     if (global.params.symdebug) 
    646         DtoDwarfStopPoint(loc.linnum); 
     669    #ifndef DISABLE_DEBUG_INFO 
     670    if (global.params.symdebug) 
     671        DtoDwarfStopPoint(loc.linnum); 
     672    #endif 
    647673 
    648674    // create basic blocks 
     
    699725    LOG_SCOPE; 
    700726 
    701     if (global.params.symdebug) 
    702         DtoDwarfStopPoint(loc.linnum); 
     727    #ifndef DISABLE_DEBUG_INFO 
     728    if (global.params.symdebug) 
     729        DtoDwarfStopPoint(loc.linnum); 
     730    #endif 
    703731 
    704732    assert(exp); 
    705733    DValue* e = exp->toElem(p); 
    706734 
     735    #ifndef DISABLE_DEBUG_INFO 
    707736    if (global.params.symdebug) DtoDwarfFuncEnd(gIR->func()->decl); 
     737    #endif 
    708738 
    709739    llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_throw_exception"); 
     
    781811    LOG_SCOPE; 
    782812 
    783     if (global.params.symdebug) 
    784         DtoDwarfStopPoint(loc.linnum); 
     813    #ifndef DISABLE_DEBUG_INFO 
     814    if (global.params.symdebug) 
     815        DtoDwarfStopPoint(loc.linnum); 
     816    #endif 
    785817 
    786818    llvm::BasicBlock* oldend = gIR->scopeend(); 
     
    952984        return; 
    953985 
    954     if (global.params.symdebug) 
    955         DtoDwarfStopPoint(loc.linnum); 
     986    #ifndef DISABLE_DEBUG_INFO 
     987    if (global.params.symdebug) 
     988        DtoDwarfStopPoint(loc.linnum); 
     989    #endif 
    956990 
    957991    // DMD doesn't fold stuff like continue/break, and since this isn't really a loop 
     
    10181052    LOG_SCOPE; 
    10191053 
    1020     if (global.params.symdebug) 
    1021         DtoDwarfStopPoint(loc.linnum); 
     1054    #ifndef DISABLE_DEBUG_INFO 
     1055    if (global.params.symdebug) 
     1056        DtoDwarfStopPoint(loc.linnum); 
     1057    #endif 
    10221058 
    10231059    //assert(arguments->dim == 1); 
     
    11501186    LOG_SCOPE; 
    11511187 
    1152     if (global.params.symdebug) 
    1153         DtoDwarfStopPoint(loc.linnum); 
     1188    #ifndef DISABLE_DEBUG_INFO 
     1189    if (global.params.symdebug) 
     1190        DtoDwarfStopPoint(loc.linnum); 
     1191    #endif 
    11541192 
    11551193    // evaluate lwr/upr 
     
    12991337    LOG_SCOPE; 
    13001338 
    1301     if (global.params.symdebug) 
    1302         DtoDwarfStopPoint(loc.linnum); 
     1339    #ifndef DISABLE_DEBUG_INFO 
     1340    if (global.params.symdebug) 
     1341        DtoDwarfStopPoint(loc.linnum); 
     1342    #endif 
    13031343 
    13041344    llvm::BasicBlock* oldend = gIR->scopeend(); 
     
    13171357    LOG_SCOPE; 
    13181358 
    1319     if (global.params.symdebug) 
    1320         DtoDwarfStopPoint(loc.linnum); 
     1359    #ifndef DISABLE_DEBUG_INFO 
     1360    if (global.params.symdebug) 
     1361        DtoDwarfStopPoint(loc.linnum); 
     1362    #endif 
    13211363 
    13221364    llvm::BasicBlock* oldend = gIR->scopeend(); 
     
    13391381    LOG_SCOPE; 
    13401382 
    1341     if (global.params.symdebug) 
    1342         DtoDwarfStopPoint(loc.linnum); 
     1383    #ifndef DISABLE_DEBUG_INFO 
     1384    if (global.params.symdebug) 
     1385        DtoDwarfStopPoint(loc.linnum); 
     1386    #endif 
    13431387 
    13441388    llvm::BasicBlock* oldend = gIR->scopeend(); 
     
    13641408    LOG_SCOPE; 
    13651409 
    1366     if (global.params.symdebug) 
    1367         DtoDwarfStopPoint(loc.linnum); 
     1410    #ifndef DISABLE_DEBUG_INFO 
     1411    if (global.params.symdebug) 
     1412        DtoDwarfStopPoint(loc.linnum); 
     1413    #endif 
    13681414 
    13691415    assert(exp); 
     
    13941440    LOG_SCOPE; 
    13951441 
    1396     if (global.params.symdebug) 
    1397         DtoDwarfStopPoint(loc.linnum); 
     1442    #ifndef DISABLE_DEBUG_INFO 
     1443    if (global.params.symdebug) 
     1444        DtoDwarfStopPoint(loc.linnum); 
     1445    #endif 
    13981446 
    13991447    // enter lock 
     
    14311479    LOG_SCOPE; 
    14321480 
    1433     if (global.params.symdebug) 
    1434         DtoDwarfStopPoint(loc.linnum); 
     1481    #ifndef DISABLE_DEBUG_INFO 
     1482    if (global.params.symdebug) 
     1483        DtoDwarfStopPoint(loc.linnum); 
     1484    #endif 
    14351485 
    14361486    // mark in-volatile 
  • gen/tocall.cpp

    r1607 r1650  
    3636////////////////////////////////////////////////////////////////////////////////////////// 
    3737 
    38 unsigned DtoCallingConv(Loc loc, LINK l) 
     38llvm::CallingConv::ID DtoCallingConv(Loc loc, LINK l) 
    3939{ 
    4040    if (l == LINKc || l == LINKcpp || l == LINKintrinsic) 
     
    208208    pinits.push_back(llvm::ConstantExpr::getBitCast(typeinfomem, getPtrToType(typeinfotype))); 
    209209    const LLType* tiarrty = DtoType(Type::typeinfo->type->arrayOf()); 
    210     tiinits = LLConstantStruct::get(gIR->context(), pinits); 
     210    tiinits = LLConstantStruct::get(gIR->context(), pinits, false); 
    211211    LLValue* typeinfoarrayparam = new llvm::GlobalVariable(*gIR->module, tiarrty, 
    212212        true, llvm::GlobalValue::InternalLinkage, tiinits, "._arguments.array"); 
     
    280280    bool dvarargs = (tf->linkage == LINKd && tf->varargs == 1); 
    281281 
    282     unsigned callconv = DtoCallingConv(loc, tf->linkage); 
     282    llvm::CallingConv::ID callconv = DtoCallingConv(loc, tf->linkage); 
    283283 
    284284    // get callee llvm value 
  • gen/todebug.cpp

    r1571 r1650  
    1919 
    2020using namespace llvm::dwarf; 
     21 
     22#ifndef DISABLE_DEBUG_INFO 
    2123 
    2224#define DBG_NULL    ( LLConstant::getNullValue(DBG_TYPE) ) 
     
    221223} 
    222224 
    223 //FIXME: This does not use llvm's DIFactory as it can't  
     225//FIXME: This does not use llvm's DIFactory as it can't 
    224226//   handle recursive types properly. 
    225227static llvm::DICompositeType dwarfCompositeType(Type* type, llvm::DICompileUnit compileUnit) 
     
    531533        false // isOptimized 
    532534    ); 
    533      
     535 
    534536    // if the linkage stays internal, we can't llvm-link the generated modules together: 
    535537    // llvm's DwarfWriter uses path and filename to determine the symbol name and we'd 
     
    637639    ); 
    638640} 
     641 
     642#endif 
  • gen/todebug.h

    r946 r1650  
    11#ifndef LDC_GEN_TODEBUG_H 
    22#define LDC_GEN_TODEBUG_H 
     3 
     4#ifndef DISABLE_DEBUG_INFO 
    35 
    46void RegisterDwarfSymbols(llvm::Module* mod); 
     
    2022/** 
    2123 * Emit the Dwarf subprogram global for a internal function. 
    22  * This is used for generated functions like moduleinfoctors,  
     24 * This is used for generated functions like moduleinfoctors, 
    2325 * module ctors/dtors and unittests. 
    2426 * @return the Dwarf subprogram global. 
     
    4042/** 
    4143 * Emits all things necessary for making debug info for a global variable vd. 
    42  * @param ll  
    43  * @param vd  
    44  * @return  
     44 * @param ll 
     45 * @param vd 
     46 * @return 
    4547 */ 
    4648llvm::DIGlobalVariable DtoDwarfGlobalVariable(LLGlobalVariable* ll, VarDeclaration* vd); 
    4749 
     50#endif // DISABLE_DEBUG_INFO 
     51 
    4852#endif // LDC_GEN_TODEBUG_H 
    49  
    50  
  • gen/tollvm.cpp

    r1644 r1650  
    158158 
    159159/* 
    160     Not needed atm as VarDecls for tuples are rewritten as a string of  
     160    Not needed atm as VarDecls for tuples are rewritten as a string of 
    161161    VarDecls for the fields (u -> _u_field_0, ...) 
    162162 
     
    290290        assert(0 && "not global/function"); 
    291291    } 
    292      
     292 
    293293    // The following breaks for nested naked functions and other declarations, so check for that. 
    294294    bool skipNestedCheck = !mustDefineSymbol(sym); 
    295295    if (FuncDeclaration* fd = sym->isFuncDeclaration()) 
    296296        skipNestedCheck = (fd->naked != 0); 
    297      
     297 
    298298    // Any symbol nested in a function can't be referenced directly from 
    299299    // outside that function, so we can give such symbols internal linkage. 
     
    314314                return llvm::GlobalValue::InternalLinkage; 
    315315        } 
    316      
     316 
    317317    // default to external linkage 
    318318    return llvm::GlobalValue::ExternalLinkage; 
     
    363363    } 
    364364    // ptr is integer pointer 
    365     else if (ptrTy->isInteger()) 
     365    else if (ptrTy->isIntegerTy()) 
    366366    { 
    367367        // val is integer 
  • gen/toobj.cpp

    r1575 r1650  
    1515#include "llvm/Bitcode/ReaderWriter.h" 
    1616#include "llvm/Module.h" 
    17 #include "llvm/ModuleProvider.h" 
    1817#include "llvm/PassManager.h" 
    1918#include "llvm/LinkAllPasses.h" 
     
    2322#include "llvm/Support/FormattedStream.h" 
    2423#include "llvm/Target/TargetMachine.h" 
     24#include "llvm/CodeGen/MachineCodeEmitter.h" 
    2525 
    2626#include "mars.h" 
     
    115115    gABI = TargetABI::getTarget(); 
    116116 
     117    #ifndef DISABLE_DEBUG_INFO 
    117118    // debug info 
    118119    if (global.params.symdebug) { 
     
    120121        DtoDwarfCompileUnit(this); 
    121122    } 
     123    #endif 
    122124 
    123125    // handle invalid 'objectÞ module 
     
    130132        fatal(); 
    131133    } 
    132      
     134 
    133135    LLVM_D_InitRuntime(); 
    134136 
     
    226228        bcpath.appendSuffix(std::string(global.bc_ext)); 
    227229        Logger::println("Writing LLVM bitcode to: %s\n", bcpath.c_str()); 
    228         std::ofstream bos(bcpath.c_str(), std::ios::binary); 
    229         if (bos.fail()) 
     230        std::string errinfo; 
     231        llvm::raw_fd_ostream bos(bcpath.c_str(), errinfo, llvm::raw_fd_ostream::F_Binary); 
     232        if (bos.has_error()) 
    230233        { 
    231             error("cannot write LLVM bitcode, failed to open file '%s'", bcpath.c_str()); 
     234            error("cannot write LLVM bitcode file '%s': %s", bcpath.c_str(), errinfo.c_str()); 
    232235            fatal(); 
    233236        } 
     
    241244        llpath.appendSuffix(std::string(global.ll_ext)); 
    242245        Logger::println("Writing LLVM asm to: %s\n", llpath.c_str()); 
    243         std::ofstream aos(llpath.c_str()); 
    244         if (aos.fail()) 
     246        std::string errinfo; 
     247        llvm::raw_fd_ostream aos(llpath.c_str(), errinfo); 
     248        if (aos.has_error()) 
    245249        { 
    246             error("cannot write LLVM asm, failed to open file '%s'", llpath.c_str()); 
     250            error("cannot write LLVM asm file '%s': %s", llpath.c_str(), errinfo.c_str()); 
    247251            fatal(); 
    248252        } 
     
    261265        std::string err; 
    262266        { 
    263             llvm::raw_fd_ostream out(spath.c_str(), false, true, err); 
     267            llvm::raw_fd_ostream out(spath.c_str(), err); 
    264268            if (err.empty()) 
    265269            { 
     
    293297 
    294298    // Build up all of the passes that we want to do to the module. 
    295     ExistingModuleProvider Provider(&m); 
    296     FunctionPassManager Passes(&Provider); 
     299    FunctionPassManager Passes(&m); 
    297300 
    298301    if (const TargetData *TD = Target.getTargetData()) 
     
    300303    else 
    301304        Passes.add(new TargetData(&m)); 
    302  
    303     // Ask the target to add backend passes as necessary. 
    304     MachineCodeEmitter *MCE = 0; 
    305305 
    306306    // Last argument is enum CodeGenOpt::Level OptLevel 
     
    313313 
    314314    llvm::formatted_raw_ostream fout(out); 
    315     FileModel::Model mod = Target.addPassesToEmitFile(Passes, fout, TargetMachine::AssemblyFile, LastArg); 
    316     assert(mod == FileModel::AsmFile); 
    317  
    318     bool err = Target.addPassesToEmitFileFinish(Passes, MCE, LastArg); 
    319     assert(!err); 
     315    if (Target.addPassesToEmitFile(Passes, fout, TargetMachine::CGFT_AssemblyFile, LastArg)) 
     316        assert(0 && "no support for asm output"); 
    320317 
    321318    Passes.doInitialization(); 
     
    329326 
    330327    // release module from module provider so we can delete it ourselves 
    331     std::string Err; 
    332     llvm::Module* rmod = Provider.releaseModule(&Err); 
    333     assert(rmod); 
     328    //std::string Err; 
     329    //llvm::Module* rmod = Provider.releaseModule(&Err); 
     330    //assert(rmod); 
    334331} 
    335332 
     
    351348    //  GCC mysteriously knows how to do it. 
    352349    std::vector<std::string> args; 
    353     args.push_back(gcc.toString()); 
     350    args.push_back(gcc.str()); 
    354351    args.push_back("-fno-strict-aliasing"); 
    355352    args.push_back("-O3"); 
    356353    args.push_back("-c"); 
    357354    args.push_back("-xassembler"); 
    358     args.push_back(asmpath.toString()); 
     355    args.push_back(asmpath.str()); 
    359356    args.push_back("-o"); 
    360     args.push_back(objpath.toString()); 
     357    args.push_back(objpath.str()); 
    361358 
    362359    //FIXME: only use this if needed? 
     
    432429 
    433430    // debug info 
     431    #ifndef DISABLE_DEBUG_INFO 
    434432    LLGlobalVariable* subprog; 
    435433    if(global.params.symdebug) { 
     
    437435        builder.CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(subprog)); 
    438436    } 
     437    #endif 
    439438 
    440439    for (size_t i=0; i<n; i++) { 
     
    445444 
    446445    // debug info end 
     446    #ifndef DISABLE_DEBUG_INFO 
    447447    if(global.params.symdebug) 
    448448        builder.CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(subprog)); 
     449    #endif 
    449450 
    450451    builder.CreateRetVoid(); 
     
    476477    IRBuilder<> builder(bb); 
    477478 
     479    #ifndef DISABLE_DEBUG_INFO 
    478480    // debug info 
    479481    LLGlobalVariable* subprog; 
     
    482484        builder.CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(subprog)); 
    483485    } 
     486    #endif 
    484487 
    485488    for (size_t i=0; i<n; i++) { 
     
    489492    } 
    490493 
     494    #ifndef DISABLE_DEBUG_INFO 
    491495    // debug info end 
    492496    if(global.params.symdebug) 
    493497        builder.CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(subprog)); 
     498    #endif 
    494499 
    495500    builder.CreateRetVoid(); 
     
    521526    IRBuilder<> builder(bb); 
    522527 
     528    #ifndef DISABLE_DEBUG_INFO 
    523529    // debug info 
    524530    LLGlobalVariable* subprog; 
     
    527533        builder.CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(subprog)); 
    528534    } 
     535    #endif 
    529536 
    530537    for (size_t i=0; i<n; i++) { 
     
    534541    } 
    535542 
     543    #ifndef DISABLE_DEBUG_INFO 
    536544    // debug info end 
    537545    if(global.params.symdebug) 
    538546        builder.CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(subprog)); 
     547    #endif 
    539548 
    540549    builder.CreateRetVoid(); 
     
    579588 
    580589    // debug info 
     590    #ifndef DISABLE_DEBUG_INFO 
    581591    LLGlobalVariable* subprog; 
    582592    if(global.params.symdebug) { 
     
    584594        builder.CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(subprog)); 
    585595    } 
     596    #endif 
    586597 
    587598    // get current beginning 
     
    595606    builder.CreateStore(thismref, mref); 
    596607 
     608    #ifndef DISABLE_DEBUG_INFO 
    597609    // debug info end 
    598610    if(global.params.symdebug) 
    599611        builder.CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(subprog)); 
     612    #endif 
    600613 
    601614    // return 
     
    615628//         ClassInfo[]     localClasses; 
    616629//         uint            flags; 
    617 //  
     630// 
    618631//         void function() ctor; 
    619632//         void function() dtor; 
    620633//         void function() unitTest; 
    621 //  
     634// 
    622635//         void* xgetMembers; 
    623636//         void function() ictor; 
Copyright © 2008, LDC Development Team.