Changeset 1650:40bd4a0d4870 for gen
- Timestamp:
- 05/19/10 06:42:32 (2 years ago)
- Files:
-
- gen/arrays.cpp (modified) (2 diffs)
- gen/asmstmt.cpp (modified) (12 diffs)
- gen/cl_helpers.cpp (modified) (4 diffs)
- gen/cl_helpers.h (modified) (5 diffs)
- gen/configfile.cpp (modified) (4 diffs)
- gen/functions.cpp (modified) (6 diffs)
- gen/linker.cpp (modified) (8 diffs)
- gen/llvmhelpers.cpp (modified) (18 diffs)
- gen/llvmhelpers.h (modified) (1 diff)
- gen/logger.cpp (modified) (2 diffs)
- gen/logger.h (modified) (4 diffs)
- gen/main.cpp (modified) (9 diffs)
- gen/optimizer.cpp (modified) (6 diffs)
- gen/passes/SimplifyDRuntimeCalls.cpp (modified) (19 diffs)
- gen/statements.cpp (modified) (24 diffs)
- gen/tocall.cpp (modified) (3 diffs)
- gen/todebug.cpp (modified) (4 diffs)
- gen/todebug.h (modified) (3 diffs)
- gen/tollvm.cpp (modified) (4 diffs)
- gen/toobj.cpp (modified) (26 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gen/arrays.cpp
r1643 r1650 310 310 LLConstant* constarr; 311 311 if (mismatch) 312 constarr = LLConstantStruct::get(gIR->context(), initvals );312 constarr = LLConstantStruct::get(gIR->context(), initvals, false); // FIXME should this pack? 313 313 else 314 314 constarr = LLConstantArray::get(LLArrayType::get(llelemty, arrlen), initvals); … … 395 395 { 396 396 LLConstant* values[2] = { dim, ptr }; 397 return LLConstantStruct::get(gIR->context(), values, 2 );397 return LLConstantStruct::get(gIR->context(), values, 2, false); 398 398 } 399 399 gen/asmstmt.cpp
r1571 r1650 95 95 bool sep = 0, nsep = 0; 96 96 buf->writestring("asm { "); 97 98 for (Token * t = tokens; t; t = t->next) { 97 98 for (Token * t = tokens; t; t = t->next) { 99 99 switch (t->value) { 100 100 case TOKlparen: … … 162 162 // %% need to set DECL_UNINLINABLE too? 163 163 sc->func->hasReturnExp = 1; // %% DMD does this, apparently... 164 164 165 165 // empty statement -- still do the above things because they might be expected? 166 166 if (! tokens) 167 167 return this; 168 168 169 169 if (!asmparser) 170 170 if (global.params.cpu == ARCHx86) … … 197 197 assert(asmblock); 198 198 199 #ifndef DISABLE_DEBUG_INFO 199 200 // debug info 200 201 if (global.params.symdebug) 201 202 DtoDwarfStopPoint(loc.linnum); 203 #endif 202 204 203 205 if (! asmcode) … … 258 260 case Arg_FrameRelative: 259 261 // FIXME 260 llvm::cout << "asm fixme Arg_FrameRelative" << std::endl; 261 assert(0); 262 assert(0 && "asm fixme Arg_FrameRelative"); 262 263 /* if (arg->expr->op == TOKvar) 263 264 arg_val = ((VarExp *) arg->expr)->var->toSymbol()->Stree; … … 276 277 case Arg_LocalSize: 277 278 // FIXME 278 llvm::cout << "asm fixme Arg_LocalSize" << std::endl; 279 assert(0); 279 assert(0 && "asm fixme Arg_LocalSize"); 280 280 /* var_frame_offset = cfun->x_frame_offset; 281 281 if (var_frame_offset < 0) … … 301 301 // those registers. This changes the stack from what a naked function 302 302 // expects. 303 303 304 304 // FIXME 305 305 // if (! irs->func->naked) { … … 319 319 arg_map[i] = -arg_map[i] - 1 + n_outputs; 320 320 } 321 321 322 322 bool pct = false; 323 323 std::string::iterator … … 344 344 Logger::cout() << "final asm: " << code->insnTemplate << '\n'; 345 345 std::ostringstream ss; 346 346 347 347 ss << "GCC-style output constraints: {"; 348 348 for (It i = output_constraints.begin(), e = output_constraints.end(); i != e; ++i) { … … 351 351 ss << " }"; 352 352 Logger::println("%s", ss.str().c_str()); 353 353 354 354 ss.str(""); 355 355 ss << "GCC-style input constraints: {"; … … 359 359 ss << " }"; 360 360 Logger::println("%s", ss.str().c_str()); 361 361 362 362 ss.str(""); 363 363 ss << "GCC-style clobbers: {"; … … 380 380 * and an output operand. 381 381 */ 382 382 383 383 // Change update operand to pure output operand. 384 384 *i = mw_cns; 385 385 386 386 // Add input operand with same value, with original as "matching output". 387 387 std::ostringstream ss; … … 573 573 if((*it)->equals(a->isBranchToLabel)) 574 574 skip = true; 575 if(skip) 575 if(skip) 576 576 continue; 577 577 gen/cl_helpers.cpp
r1103 r1650 18 18 } 19 19 20 bool FlagParser::parse(cl::Option &O, const char *ArgName, const std::string &Arg, bool &Val) {20 bool FlagParser::parse(cl::Option &O, llvm::StringRef ArgName, llvm::StringRef Arg, bool &Val) { 21 21 // Make a std::string out of it to make comparisons easier 22 22 // (and avoid repeated conversion) 23 std::stringargname = ArgName;24 23 llvm::StringRef argname = ArgName; 24 25 25 typedef std::vector<std::pair<std::string, bool> >::iterator It; 26 26 for (It I = switches.begin(), E = switches.end(); I != E; ++I) { 27 std::stringname = I->first;27 llvm::StringRef name = I->first; 28 28 if (name == argname 29 || (name. length() < argname.length()30 && argname.substr(0, name. length()) == name31 && argname[name. length()] == '=')) {32 29 || (name.size() < argname.size() 30 && argname.substr(0, name.size()) == name 31 && argname[name.size()] == '=')) { 32 33 33 if (!cl::parser<bool>::parse(O, ArgName, Arg, Val)) { 34 34 Val = (Val == I->second); … … 42 42 } 43 43 44 void FlagParser::getExtraOptionNames( std::vector<const char*> &Names) {44 void FlagParser::getExtraOptionNames(llvm::SmallVectorImpl<const char*> &Names) { 45 45 typedef std::vector<std::pair<std::string, bool> >::iterator It; 46 46 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()); 48 48 } 49 49 } … … 61 61 } 62 62 } 63 63 64 64 void MultiSetter::operator=(bool val) { 65 65 typedef std::vector<bool*>::iterator It; … … 73 73 if (!cstr || !*cstr) 74 74 error("Expected argument to '-%s'", name); 75 75 76 76 if (!*arrp) 77 77 *arrp = new Array; gen/cl_helpers.h
r1200 r1650 11 11 namespace opts { 12 12 namespace cl = llvm::cl; 13 13 14 14 /// Helper class for fancier options 15 15 class FlagParser : public cl::parser<bool> { … … 22 22 switches.push_back(make_pair("disable-" + Name, false)); 23 23 // Replace <foo> with -enable-<foo> 24 O.ArgStr = switches[0].first. c_str();24 O.ArgStr = switches[0].first.data(); 25 25 } 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); 30 30 }; 31 31 32 32 /// Helper class for options that set multiple flags 33 33 class MultiSetter { … … 37 37 public: 38 38 MultiSetter(bool invert, bool* p, ...) END_WITH_NULL; 39 39 40 40 void operator=(bool val); 41 41 }; 42 42 43 43 /// Helper class to fill Array with char* when given strings 44 44 /// (Errors on empty strings) … … 53 53 assert(arrp); 54 54 } 55 55 56 56 void push_back(const char* cstr); 57 57 58 58 void push_back(const std::string& str) { 59 59 push_back(str.c_str()); 60 60 } 61 61 }; 62 62 63 63 /// Helper class to allow use of a parser<bool> with BoolOrDefault 64 64 class BoolOrDefaultAdapter { … … 68 68 return value; 69 69 } 70 70 71 71 void operator=(cl::boolOrDefault val) { 72 72 value = val; 73 73 } 74 74 75 75 void operator=(bool val) { 76 76 *this = (val ? cl::BOU_TRUE : cl::BOU_FALSE); gen/configfile.cpp
r1537 r1650 95 95 if (p.exists()) 96 96 return true; 97 97 98 98 return false; 99 99 } … … 103 103 sys::Path p; 104 104 if (!locate(p, argv0, mainAddr, filename)) 105 { 105 { 106 106 // failed to find cfg, users still have the DFLAGS environment var 107 107 std::cerr << "Error failed to locate the configuration file: " << filename << std::endl; … … 110 110 111 111 // save config file path for -v output 112 pathstr = p. toString();112 pathstr = p.str(); 113 113 114 114 try … … 142 142 { 143 143 std::string v = arr[i]; 144 144 145 145 // replace binpathkey with binpath 146 146 size_t p; 147 147 while (std::string::npos != (p = v.find(binpathkey))) 148 148 v.replace(p, binpathkey.size(), binpath); 149 149 150 150 switches.push_back(strdup(v.c_str())); 151 151 } gen/functions.cpp
r1607 r1650 600 600 } 601 601 602 #ifndef DISABLE_DEBUG_INFO 602 603 // debug info 603 if (global.params.symdebug) {604 if (global.params.symdebug) 604 605 fd->ir.irFunc->diSubprogram = DtoDwarfSubProgram(fd); 605 }606 #endif 606 607 607 608 Type* t = fd->type->toBasetype(); … … 643 644 irfunction->allocapoint = allocaPoint; 644 645 646 #ifndef DISABLE_DEBUG_INFO 645 647 // debug info - after all allocas, but before any llvm.dbg.declare etc 646 648 if (global.params.symdebug) DtoDwarfFuncStart(fd); 649 #endif 647 650 648 651 // this hack makes sure the frame pointer elimination optimization is disabled. … … 669 672 fd->vthis->ir.irLocal->value = thismem; 670 673 674 #ifndef DISABLE_DEBUG_INFO 671 675 if (global.params.symdebug) 672 676 DtoDwarfLocalVariable(thismem, fd->vthis); 677 #endif 673 678 674 679 #if DMDV1 … … 723 728 } 724 729 730 #ifndef DISABLE_DEBUG_INFO 725 731 if (global.params.symdebug && !(isaArgument(irloc->value) && !isaArgument(irloc->value)->hasByValAttr()) && !refout) 726 732 DtoDwarfLocalVariable(irloc->value, vd); 733 #endif 727 734 } 728 735 } … … 759 766 fd->vresult->ir.irLocal->value = DtoAlloca(fd->vresult->type, fd->vresult->toChars()); 760 767 } 761 768 762 769 // copy _argptr and _arguments to a memory location 763 770 if (f->linkage == LINKd && f->varargs == 1) … … 795 802 // llvm requires all basic blocks to end with a TerminatorInst but DMD does not put a return statement 796 803 // in automatically, so we do it here. 797 804 798 805 // pass the previous block into this block 806 #ifndef DISABLE_DEBUG_INFO 799 807 if (global.params.symdebug) DtoDwarfFuncEnd(fd); 808 #endif 800 809 if (func->getReturnType() == LLType::getVoidTy(gIR->context())) { 801 810 llvm::ReturnInst::Create(gIR->context(), gIR->scopebb()); gen/linker.cpp
r1600 r1650 107 107 fatal(); 108 108 } 109 } 109 } 110 110 111 111 // strip debug info … … 223 223 llvm::sys::Path gcc = getGcc(); 224 224 // get a string version for argv[0] 225 std::string gccStr = gcc.toString();225 const char* gccStr = gcc.c_str(); 226 226 227 227 // build arguments … … 229 229 230 230 // first the program name ?? 231 args.push_back(gccStr .c_str());231 args.push_back(gccStr); 232 232 233 233 // object files … … 275 275 fatal(); 276 276 } 277 } 277 } 278 278 279 279 // additional linker switches … … 293 293 // default libs 294 294 switch(global.params.os) { 295 case OSLinux: 295 case OSLinux: 296 296 case OSMacOSX: 297 297 args.push_back("-ldl"); … … 331 331 332 332 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(); 334 334 Stream logstr = Logger::cout(); 335 335 for (; I != E; ++I) 336 336 if (*I) 337 337 logstr << "'" << *I << "'" << " "; 338 logstr << "\n" << std::flush;338 logstr << "\n"; // FIXME where's flush ? 339 339 340 340 … … 350 350 return status; 351 351 } 352 352 353 353 return 0; 354 354 } … … 376 376 std::vector<const char*> args; 377 377 // args[0] should be the name of the executable 378 args.push_back(gExePath. toString().c_str());378 args.push_back(gExePath.c_str()); 379 379 // Skip first argument to -run; it's a D source file. 380 380 for (size_t i = 1, length = opts::runargs.size(); i < length; i++) gen/llvmhelpers.cpp
r1643 r1650 161 161 gIR->CreateCallOrInvoke(fn, args.begin(), args.end()); 162 162 163 #ifndef DISABLE_DEBUG_INFO 163 164 // end debug info 164 165 if (global.params.symdebug) 165 166 DtoDwarfFuncEnd(gIR->func()->decl); 167 #endif 166 168 167 169 // after assert is always unreachable … … 269 271 // labels are a special case: they are not required to enclose the current scope 270 272 // 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; 272 274 if (lblstmt) 273 275 target = lblstmt->enclosingScopeExit; … … 486 488 487 489 // unknown 488 llvm::cout << "unsupported: null value for " << type->toChars() << '\n';490 error("unsupported: null value for %s", type->toChars()); 489 491 assert(0); 490 492 return 0; … … 855 857 gvar->setInitializer(initVal); 856 858 859 #ifndef DISABLE_DEBUG_INFO 857 860 // do debug info 858 861 if (global.params.symdebug) … … 862 865 gIR->usedArray.push_back(llvm::ConstantExpr::getBitCast(gv, getVoidPtrType())); 863 866 } 867 #endif 864 868 } 865 869 } … … 907 911 assert(ex && "ref vars must have expression initializer"); 908 912 assert(ex->exp); 909 AssignExp* as = dynamic_cast<AssignExp*>(ex->exp);913 AssignExp* as = ex->exp->isAssignExp(); 910 914 assert(as && "ref vars must be initialized by an assign exp"); 911 915 vd->ir.irLocal->value = as->e2->toElem(gIR)->getLVal(); 912 916 } 913 917 914 918 // referenced by nested delegate? 915 919 #if DMDV2 … … 920 924 Logger::println("has nestedref set"); 921 925 assert(vd->ir.irLocal); 922 926 923 927 DtoNestedInit(vd); 924 928 } … … 938 942 vd->ir.irLocal->value = allocainst; 939 943 944 #ifndef DISABLE_DEBUG_INFO 940 945 if (global.params.symdebug) 941 {942 946 DtoDwarfLocalVariable(allocainst, vd); 943 }947 #endif 944 948 } 945 949 else … … 1047 1051 // we don't handle aliases either 1048 1052 assert(!var->aliassym); 1049 1053 1050 1054 // alloca if necessary 1051 1055 LLValue* allocaval = NULL; … … 1053 1057 { 1054 1058 addr = DtoAlloca(var->type, var->toChars()); 1055 1059 1060 #ifndef DISABLE_DEBUG_INFO 1056 1061 // add debug info 1057 1062 if (global.params.symdebug) 1058 1063 DtoDwarfLocalVariable(addr, var); 1059 } 1060 1064 #endif 1065 } 1066 1061 1067 // referenced by nested function? 1062 1068 #if DMDV2 … … 1295 1301 Logger::println("template declaration: %s", td->toChars()); 1296 1302 Logger::println("intrinsic name: %s", td->intrinsicName.c_str()); 1297 1303 1298 1304 // for now use the size in bits of the first template param in the instance 1299 1305 assert(ti->tdtypes.dim == 1); … … 1308 1314 char tmp[21]; // probably excessive, but covers a uint64_t 1309 1315 sprintf(tmp, "%lu", (unsigned long) gTargetData->getTypeSizeInBits(DtoType(T))); 1310 1316 1311 1317 // replace # in name with bitsize 1312 1318 name = td->intrinsicName; … … 1331 1337 } 1332 1338 } 1333 1339 1334 1340 Logger::println("final intrinsic name: %s", name.c_str()); 1335 1341 } … … 1341 1347 if (FuncDeclaration* fd = s->isFuncDeclaration()) 1342 1348 { 1343 // we can't (and probably shouldn't?) define functions 1349 // we can't (and probably shouldn't?) define functions 1344 1350 // that weren't semantic3'ed 1345 1351 if (fd->semanticRun < 4) … … 1353 1359 // These will get available_externally linkage, 1354 1360 // so they shouldn't end up in object code. 1355 1361 1356 1362 assert(fd->type->ty == Tfunction); 1357 1363 TypeFunction* tf = (TypeFunction*) fd->type; … … 1372 1378 return true; 1373 1379 } 1374 1380 1375 1381 // This was only semantic'ed for inlining checks. 1376 1382 // We won't be inlining this, so we only need to emit a declaration. … … 1397 1403 if (!opts::singleObj) 1398 1404 return true; 1399 1405 1400 1406 if (!tinst->emittedInModule) 1401 1407 { … … 1405 1411 return tinst->emittedInModule == gIR->dmodule; 1406 1412 } 1407 1413 1408 1414 return s->getModule() == gIR->dmodule; 1409 1415 } gen/llvmhelpers.h
r1643 r1650 157 157 158 158 /// convert DMD calling conv to LLVM 159 unsignedDtoCallingConv(Loc loc, LINK l);159 llvm::CallingConv::ID DtoCallingConv(Loc loc, LINK l); 160 160 161 161 /// gen/logger.cpp
r1502 r1650 13 13 #include "llvm/GlobalValue.h" 14 14 #include "llvm/Support/Casting.h" 15 #include "llvm/Support/raw_os tream.h"15 #include "llvm/Support/raw_os_ostream.h" 16 16 #include "llvm/Assembly/Writer.h" 17 17 … … 28 28 // (Only treat non-global constants like this, so that e.g. global variables 29 29 // still get their initializers printed) 30 llvm::raw_os_ostream raw(OS); 30 31 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); 32 33 else 33 OS << V;34 V.print(raw); 34 35 } 35 36 gen/logger.h
r1502 r1650 21 21 class Stream { 22 22 std::ostream* OS; 23 23 24 24 public: 25 25 Stream() : OS(0) {} 26 26 Stream(std::ostream* S) : OS(S) {} 27 27 Stream(std::ostream& S) : OS(&S) {} 28 28 29 /* 29 30 Stream operator << (std::ios_base &(*Func)(std::ios_base&)) { 30 31 if (OS) *OS << Func; 31 32 return *this; 32 33 } 33 34 */ 35 34 36 Stream operator << (std::ostream &(*Func)(std::ostream&)) { 35 if (OS) *OS << Func;37 if (OS) Func(*OS); 36 38 return *this; 37 39 } 38 40 39 41 template<typename Ty> 40 42 Stream& operator << (const Ty& Thing) { … … 43 45 return *this; 44 46 } 45 47 46 48 private: 47 49 // Implementation details to treat llvm::Value, llvm::Type and their 48 50 // subclasses specially (to pretty-print types). 49 51 50 52 static void writeType(std::ostream& OS, const llvm::Type& Ty); 51 53 static void writeValue(std::ostream& OS, const llvm::Value& Ty); 52 54 53 55 template<typename Ty, int N> friend struct Writer; 54 56 // error: function template partial specialization is not allowed … … 60 62 } 61 63 }; 62 64 63 65 template<typename Ty> 64 66 struct Writer<Ty, 1> { … … 70 72 } 71 73 }; 72 74 73 75 // NOT IMPLEMENTED 74 76 char sfinae_bait(const llvm::Type&); gen/main.cpp
r1645 r1650 149 149 global.params.objfiles = new Array(); 150 150 global.params.ddocfiles = new Array(); 151 151 152 152 global.params.moduleDeps = NULL; 153 153 global.params.moduleDepsFile = NULL; … … 224 224 initFromString(global.params.objname, objectFile); 225 225 initFromString(global.params.objdir, objectDir); 226 226 227 227 initFromString(global.params.docdir, ddocDir); 228 228 initFromString(global.params.docname, ddocFile); 229 229 global.params.doDocComments |= 230 230 global.params.docdir || global.params.docname; 231 231 232 232 #ifdef _DH 233 233 initFromString(global.params.hdrdir, hdrDir); … … 238 238 239 239 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; 243 243 } 244 244 … … 436 436 437 437 // Allocate target machine. 438 438 439 439 // first initialize llvm 440 440 #define LLVM_TARGET(A) LLVMInitialize##A##TargetInfo(); LLVMInitialize##A##Target(); LLVMInitialize##A##AsmPrinter(); … … 485 485 } 486 486 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(); 491 496 492 497 // get final data layout … … 904 909 905 910 // write module dependencies to file if requested 906 if (global.params.moduleDepsFile != NULL) 907 { 911 if (global.params.moduleDepsFile != NULL) 912 { 908 913 assert (global.params.moduleDepsFile != NULL); 909 914 910 915 File deps(global.params.moduleDepsFile); 911 OutBuffer* ob = global.params.moduleDeps; 916 OutBuffer* ob = global.params.moduleDeps; 912 917 deps.setbuffer((void*)ob->data, ob->offset); 913 918 deps.write(); … … 945 950 } 946 951 } 947 952 948 953 // internal linking for singleobj 949 954 if (singleObj && llvmModules.size() > 0) … … 952 957 char* name = m->toChars(); 953 958 char* filename = m->objfile->name->str; 954 959 955 960 llvm::Linker linker(name, name, context); 956 961 … … 962 967 delete llvmModules[i]; 963 968 } 964 969 965 970 m->deleteObjFile(); 966 971 writeModule(linker.getModule(), filename); 967 972 global.params.objfiles->push(filename); 968 973 } 969 974 970 975 backend_term(); 971 976 if (global.errors) gen/optimizer.cpp
r1576 r1650 96 96 static void addPass(PassManager& pm, Pass* pass) { 97 97 pm.add(pass); 98 98 99 99 if (verifyEach) pm.add(createVerifierPass()); 100 100 } … … 108 108 //addPass(pm, createStripDeadPrototypesPass()); 109 109 addPass(pm, createGlobalDCEPass()); 110 addPass(pm, create RaiseAllocationsPass());110 addPass(pm, createPromoteMemoryToRegisterPass()); 111 111 addPass(pm, createCFGSimplificationPass()); 112 112 if (optimizeLevel == 1) … … 166 166 addPass(pm, createInstructionCombiningPass()); 167 167 } 168 168 169 169 // -O3 170 170 if (optimizeLevel >= 3) … … 178 178 addPass(pm, createScalarReplAggregatesPass()); 179 179 addPass(pm, createInstructionCombiningPass()); 180 addPass(pm, createCon dPropagationPass());180 addPass(pm, createConstantPropagationPass()); 181 181 182 182 addPass(pm, createReassociatePass()); … … 195 195 196 196 addPass(pm, createInstructionCombiningPass()); 197 addPass(pm, createCon dPropagationPass());197 addPass(pm, createConstantPropagationPass()); 198 198 199 199 addPass(pm, createDeadStoreEliminationPass()); … … 221 221 222 222 PassManager pm; 223 223 224 224 if (verifyEach) pm.add(createVerifierPass()); 225 225 226 226 addPass(pm, new TargetData(m)); 227 227 gen/passes/SimplifyDRuntimeCalls.cpp
r1571 r1650 19 19 #include "Passes.h" 20 20 21 #include "llvm/Function.h" 21 22 #include "llvm/Pass.h" 22 23 #include "llvm/Intrinsics.h" … … 49 50 AliasAnalysis *AA; 50 51 LLVMContext *Context; 51 52 52 53 /// CastToCStr - Return V if it is an i8*, otherwise cast it to i8*. 53 54 Value *CastToCStr(Value *V, IRBuilder<> &B); 54 55 55 56 /// EmitMemCpy - Emit a call to the memcpy function to the builder. This 56 57 /// 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, 58 59 unsigned Align, IRBuilder<> &B); 59 60 public: 60 61 LibCallOptimization() { } 61 62 virtual ~LibCallOptimization() {} 62 63 63 64 /// CallOptimizer - This pure virtual method is implemented by base classes to 64 65 /// do various optimizations. If this returns null then no transformation was … … 67 68 /// delete CI. 68 69 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B)=0; 69 70 70 71 Value *OptimizeCall(CallInst *CI, bool& Changed, const TargetData &TD, 71 72 AliasAnalysis& AA, IRBuilder<> &B) { … … 117 118 FT->getParamType(3) != FT->getReturnType()) 118 119 return 0; 119 120 120 121 // Whether or not this allocates is irrelevant if the result isn't used. 121 122 // Just delete if that's the case. 122 123 if (CI->use_empty()) 123 124 return CI; 124 125 125 126 Value* NewLen = CI->getOperand(2); 126 127 if (Constant* NewCst = dyn_cast<Constant>(NewLen)) { 127 128 Value* Data = CI->getOperand(4); 128 129 129 130 // For now, we just catch the simplest of cases. 130 131 // … … 133 134 // (But beware of unsigned overflow! For example, we can't 134 135 // safely transform that example if arr.length may be 0) 135 136 136 137 // Setting length to 0 never reallocates, so replace by data argument 137 138 if (NewCst->isNullValue()) 138 139 return Data; 139 140 140 141 // If both lengths are constant integers, see if NewLen <= OldLen 141 142 Value* OldLen = CI->getOperand(3); … … 158 159 FT->getParamType(1) != RetTy || FT->getParamType(2) != RetTy) 159 160 return 0; 160 161 161 162 Value* OldLen = CI->getOperand(1); 162 163 Value* OldSize = CI->getOperand(2); 163 164 Value* NewSize = CI->getOperand(3); 164 165 165 166 // If the old length was zero, always return zero. 166 167 if (Constant* LenCst = dyn_cast<Constant>(OldLen)) 167 168 if (LenCst->isNullValue()) 168 169 return OldLen; 169 170 170 171 // Equal sizes are much faster to check for, so do so now. 171 172 if (OldSize == NewSize) 172 173 return OldLen; 173 174 174 175 // If both sizes are constant integers, see if OldSize is a multiple of NewSize 175 176 if (ConstantInt* OldInt = dyn_cast<ConstantInt>(OldSize)) … … 178 179 if (NewInt->isNullValue()) 179 180 return 0; 180 181 181 182 APInt Quot, Rem; 182 183 APInt::udivrem(OldInt->getValue(), NewInt->getValue(), Quot, Rem); … … 196 197 for (CallInst::use_iterator I = CI->use_begin(), E = CI->use_end() ; I != E;) { 197 198 Instruction* User = cast<Instruction>(*I++); 198 199 199 200 if (ICmpInst* Cmp = dyn_cast<ICmpInst>(User)) { 200 201 if (!Cmp->isEquality()) … … 216 217 } 217 218 } 218 219 219 220 // If it's not used (anymore), pre-emptively GC it. 220 221 if (CI->use_empty()) … … 236 237 FT->getParamType(3) != FT->getParamType(1)) 237 238 return 0; 238 239 239 240 Value* Size = CI->getOperand(2); 240 241 241 242 // Check the lengths match 242 243 if (CI->getOperand(4) != Size) 243 244 return 0; 244 245 245 246 // Assume unknown size unless we have constant size (that fits in an uint) 246 247 unsigned Sz = ~0U; … … 248 249 if (Int->getValue().isIntN(32)) 249 250 Sz = Int->getValue().getZExtValue(); 250 251 251 252 // Check if the pointers may alias 252 253 if (AA->alias(CI->getOperand(1), Sz, CI->getOperand(3), Sz)) 253 254 return 0; 254 255 255 256 // Equal length and the pointers definitely don't alias, so it's safe to 256 257 // replace the call with memcpy … … 272 273 class VISIBILITY_HIDDEN SimplifyDRuntimeCalls : public FunctionPass { 273 274 StringMap<LibCallOptimization*> Optimizations; 274 275 275 276 // Array operations 276 277 ArraySetLengthOpt ArraySetLength; 277 278 ArrayCastLenOpt ArrayCastLen; 278 279 ArraySliceCopyOpt ArraySliceCopy; 279 280 280 281 // GC allocations 281 282 AllocationOpt Allocation; 282 283 283 284 public: 284 285 static char ID; // Pass identification 285 286 SimplifyDRuntimeCalls() : FunctionPass(&ID) {} 286 287 287 288 void InitOptimizations(); 288 289 bool runOnFunction(Function &F); 289 290 290 291 bool runOnce(Function &F, const TargetData& TD, AliasAnalysis& AA); 291 292 292 293 virtual void getAnalysisUsage(AnalysisUsage &AU) const { 293 294 AU.addRequired<TargetData>(); … … 303 304 // Public interface to the pass. 304 305 FunctionPass *createSimplifyDRuntimeCalls() { 305 return new SimplifyDRuntimeCalls(); 306 return new SimplifyDRuntimeCalls(); 306 307 } 307 308 … … 314 315 Optimizations["_d_array_cast_len"] = &ArrayCastLen; 315 316 Optimizations["_d_array_slice_copy"] = &ArraySliceCopy; 316 317 317 318 /* Delete calls to runtime functions which aren't needed if their result is 318 319 * unused. That comes down to functions that don't do anything but … … 340 341 if (Optimizations.empty()) 341 342 InitOptimizations(); 342 343 343 344 const TargetData &TD = getAnalysis<TargetData>(); 344 345 AliasAnalysis &AA = getAnalysis<AliasAnalysis>(); 345 346 346 347 // Iterate to catch opportunities opened up by other optimizations, 347 348 // such as calls that are only used as arguments to unused calls: … … 355 356 EverChanged |= Changed; 356 357 } while (Changed); 357 358 358 359 return EverChanged; 359 360 } … … 368 369 CallInst *CI = dyn_cast<CallInst>(I++); 369 370 if (!CI) continue; 370 371 371 372 // Ignore indirect calls and calls to non-external functions. 372 373 Function *Callee = CI->getCalledFunction(); … … 374 375 !(Callee->hasExternalLinkage() || Callee->hasDLLImportLinkage())) 375 376 continue; 376 377 377 378 // Ignore unknown calls. 378 379 StringMap<LibCallOptimization*>::iterator OMI = 379 380 Optimizations.find(Callee->getName()); 380 381 if (OMI == Optimizations.end()) continue; 381 382 382 383 DEBUG(errs() << "SimplifyDRuntimeCalls inspecting: " << *CI); 383 384 384 385 // Set the builder to the instruction after the call. 385 386 Builder.SetInsertPoint(BB, I); 386 387 387 388 // Try to optimize this call. 388 389 Value *Result = OMI->second->OptimizeCall(CI, Changed, TD, AA, Builder); 389 390 if (Result == 0) continue; 390 391 391 392 DEBUG(errs() << "SimplifyDRuntimeCalls simplified: " << *CI; 392 393 errs() << " into: " << *Result << "\n"); 393 394 394 395 // Something changed! 395 396 Changed = true; 396 397 397 398 if (Result == CI) { 398 399 assert(CI->use_empty()); … … 402 403 ++NumSimplified; 403 404 AA.replaceWithNewValue(CI, Result); 404 405 405 406 if (!CI->use_empty()) 406 407 CI->replaceAllUsesWith(Result); 407 408 408 409 if (!Result->hasName()) 409 410 Result->takeName(CI); 410 411 } 411 412 412 413 // Inspect the instruction after the call (which was potentially just 413 414 // added) next. 414 415 I = CI; ++I; 415 416 416 417 CI->eraseFromParent(); 417 418 } gen/statements.cpp
r1647 r1650 54 54 LOG_SCOPE; 55 55 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 59 61 // is there a return value expression? 60 62 if (exp || (!exp && (p->topfunc() == p->mainFunc)) ) … … 79 81 DtoEnclosingHandlers(loc, NULL); 80 82 83 #ifndef DISABLE_DEBUG_INFO 81 84 // emit dbg end function 82 85 if (global.params.symdebug) DtoDwarfFuncEnd(f->decl); 86 #endif 83 87 84 88 // emit ret … … 127 131 DtoEnclosingHandlers(loc, NULL); 128 132 133 #ifndef DISABLE_DEBUG_INFO 129 134 if (global.params.symdebug) DtoDwarfFuncEnd(p->func()->decl); 135 #endif 130 136 llvm::ReturnInst::Create(gIR->context(), v, p->scopebb()); 131 137 } … … 137 143 DtoEnclosingHandlers(loc, NULL); 138 144 145 #ifndef DISABLE_DEBUG_INFO 139 146 if (global.params.symdebug) DtoDwarfFuncEnd(p->func()->decl); 147 #endif 140 148 llvm::ReturnInst::Create(gIR->context(), p->scopebb()); 141 149 } … … 154 162 LOG_SCOPE; 155 163 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 158 168 159 169 if (exp) { … … 183 193 LOG_SCOPE; 184 194 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 187 199 188 200 if (match) … … 271 283 LOG_SCOPE; 272 284 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 275 289 276 290 // create while blocks … … 319 333 LOG_SCOPE; 320 334 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 323 339 324 340 // create while blocks … … 364 380 LOG_SCOPE; 365 381 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 368 386 369 387 // create for blocks … … 444 462 return; 445 463 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 448 468 449 469 if (ident != 0) { … … 499 519 LOG_SCOPE; 500 520 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 503 525 504 526 if (ident != 0) { … … 565 587 LOG_SCOPE; 566 588 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 569 593 570 594 // if there's no finalbody or no body, things are simple … … 643 667 LOG_SCOPE; 644 668 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 647 673 648 674 // create basic blocks … … 699 725 LOG_SCOPE; 700 726 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 703 731 704 732 assert(exp); 705 733 DValue* e = exp->toElem(p); 706 734 735 #ifndef DISABLE_DEBUG_INFO 707 736 if (global.params.symdebug) DtoDwarfFuncEnd(gIR->func()->decl); 737 #endif 708 738 709 739 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_throw_exception"); … … 781 811 LOG_SCOPE; 782 812 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 785 817 786 818 llvm::BasicBlock* oldend = gIR->scopeend(); … … 952 984 return; 953 985 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 956 990 957 991 // DMD doesn't fold stuff like continue/break, and since this isn't really a loop … … 1018 1052 LOG_SCOPE; 1019 1053 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 1022 1058 1023 1059 //assert(arguments->dim == 1); … … 1150 1186 LOG_SCOPE; 1151 1187 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 1154 1192 1155 1193 // evaluate lwr/upr … … 1299 1337 LOG_SCOPE; 1300 1338 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 1303 1343 1304 1344 llvm::BasicBlock* oldend = gIR->scopeend(); … … 1317 1357 LOG_SCOPE; 1318 1358 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 1321 1363 1322 1364 llvm::BasicBlock* oldend = gIR->scopeend(); … … 1339 1381 LOG_SCOPE; 1340 1382 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 1343 1387 1344 1388 llvm::BasicBlock* oldend = gIR->scopeend(); … … 1364 1408 LOG_SCOPE; 1365 1409 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 1368 1414 1369 1415 assert(exp); … … 1394 1440 LOG_SCOPE; 1395 1441 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 1398 1446 1399 1447 // enter lock … … 1431 1479 LOG_SCOPE; 1432 1480 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 1435 1485 1436 1486 // mark in-volatile gen/tocall.cpp
r1607 r1650 36 36 ////////////////////////////////////////////////////////////////////////////////////////// 37 37 38 unsignedDtoCallingConv(Loc loc, LINK l)38 llvm::CallingConv::ID DtoCallingConv(Loc loc, LINK l) 39 39 { 40 40 if (l == LINKc || l == LINKcpp || l == LINKintrinsic) … … 208 208 pinits.push_back(llvm::ConstantExpr::getBitCast(typeinfomem, getPtrToType(typeinfotype))); 209 209 const LLType* tiarrty = DtoType(Type::typeinfo->type->arrayOf()); 210 tiinits = LLConstantStruct::get(gIR->context(), pinits );210 tiinits = LLConstantStruct::get(gIR->context(), pinits, false); 211 211 LLValue* typeinfoarrayparam = new llvm::GlobalVariable(*gIR->module, tiarrty, 212 212 true, llvm::GlobalValue::InternalLinkage, tiinits, "._arguments.array"); … … 280 280 bool dvarargs = (tf->linkage == LINKd && tf->varargs == 1); 281 281 282 unsignedcallconv = DtoCallingConv(loc, tf->linkage);282 llvm::CallingConv::ID callconv = DtoCallingConv(loc, tf->linkage); 283 283 284 284 // get callee llvm value gen/todebug.cpp
r1571 r1650 19 19 20 20 using namespace llvm::dwarf; 21 22 #ifndef DISABLE_DEBUG_INFO 21 23 22 24 #define DBG_NULL ( LLConstant::getNullValue(DBG_TYPE) ) … … 221 223 } 222 224 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 224 226 // handle recursive types properly. 225 227 static llvm::DICompositeType dwarfCompositeType(Type* type, llvm::DICompileUnit compileUnit) … … 531 533 false // isOptimized 532 534 ); 533 535 534 536 // if the linkage stays internal, we can't llvm-link the generated modules together: 535 537 // llvm's DwarfWriter uses path and filename to determine the symbol name and we'd … … 637 639 ); 638 640 } 641 642 #endif gen/todebug.h
r946 r1650 1 1 #ifndef LDC_GEN_TODEBUG_H 2 2 #define LDC_GEN_TODEBUG_H 3 4 #ifndef DISABLE_DEBUG_INFO 3 5 4 6 void RegisterDwarfSymbols(llvm::Module* mod); … … 20 22 /** 21 23 * 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, 23 25 * module ctors/dtors and unittests. 24 26 * @return the Dwarf subprogram global. … … 40 42 /** 41 43 * 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 45 47 */ 46 48 llvm::DIGlobalVariable DtoDwarfGlobalVariable(LLGlobalVariable* ll, VarDeclaration* vd); 47 49 50 #endif // DISABLE_DEBUG_INFO 51 48 52 #endif // LDC_GEN_TODEBUG_H 49 50 gen/tollvm.cpp
r1644 r1650 158 158 159 159 /* 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 161 161 VarDecls for the fields (u -> _u_field_0, ...) 162 162 … … 290 290 assert(0 && "not global/function"); 291 291 } 292 292 293 293 // The following breaks for nested naked functions and other declarations, so check for that. 294 294 bool skipNestedCheck = !mustDefineSymbol(sym); 295 295 if (FuncDeclaration* fd = sym->isFuncDeclaration()) 296 296 skipNestedCheck = (fd->naked != 0); 297 297 298 298 // Any symbol nested in a function can't be referenced directly from 299 299 // outside that function, so we can give such symbols internal linkage. … … 314 314 return llvm::GlobalValue::InternalLinkage; 315 315 } 316 316 317 317 // default to external linkage 318 318 return llvm::GlobalValue::ExternalLinkage; … … 363 363 } 364 364 // ptr is integer pointer 365 else if (ptrTy->isInteger ())365 else if (ptrTy->isIntegerTy()) 366 366 { 367 367 // val is integer gen/toobj.cpp
r1575 r1650 15 15 #include "llvm/Bitcode/ReaderWriter.h" 16 16 #include "llvm/Module.h" 17 #include "llvm/ModuleProvider.h"18 17 #include "llvm/PassManager.h" 19 18 #include "llvm/LinkAllPasses.h" … … 23 22 #include "llvm/Support/FormattedStream.h" 24 23 #include "llvm/Target/TargetMachine.h" 24 #include "llvm/CodeGen/MachineCodeEmitter.h" 25 25 26 26 #include "mars.h" … … 115 115 gABI = TargetABI::getTarget(); 116 116 117 #ifndef DISABLE_DEBUG_INFO 117 118 // debug info 118 119 if (global.params.symdebug) { … … 120 121 DtoDwarfCompileUnit(this); 121 122 } 123 #endif 122 124 123 125 // handle invalid 'objectÞ module … … 130 132 fatal(); 131 133 } 132 134 133 135 LLVM_D_InitRuntime(); 134 136 … … 226 228 bcpath.appendSuffix(std::string(global.bc_ext)); 227 229 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()) 230 233 { 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()); 232 235 fatal(); 233 236 } … … 241 244 llpath.appendSuffix(std::string(global.ll_ext)); 242 245 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()) 245 249 { 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()); 247 251 fatal(); 248 252 } … … 261 265 std::string err; 262 266 { 263 llvm::raw_fd_ostream out(spath.c_str(), false, true,err);267 llvm::raw_fd_ostream out(spath.c_str(), err); 264 268 if (err.empty()) 265 269 { … … 293 297 294 298 // 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); 297 300 298 301 if (const TargetData *TD = Target.getTargetData()) … … 300 303 else 301 304 Passes.add(new TargetData(&m)); 302 303 // Ask the target to add backend passes as necessary.304 MachineCodeEmitter *MCE = 0;305 305 306 306 // Last argument is enum CodeGenOpt::Level OptLevel … … 313 313 314 314 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"); 320 317 321 318 Passes.doInitialization(); … … 329 326 330 327 // 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); 334 331 } 335 332 … … 351 348 // GCC mysteriously knows how to do it. 352 349 std::vector<std::string> args; 353 args.push_back(gcc. toString());350 args.push_back(gcc.str()); 354 351 args.push_back("-fno-strict-aliasing"); 355 352 args.push_back("-O3"); 356 353 args.push_back("-c"); 357 354 args.push_back("-xassembler"); 358 args.push_back(asmpath. toString());355 args.push_back(asmpath.str()); 359 356 args.push_back("-o"); 360 args.push_back(objpath. toString());357 args.push_back(objpath.str()); 361 358 362 359 //FIXME: only use this if needed? … … 432 429 433 430 // debug info 431 #ifndef DISABLE_DEBUG_INFO 434 432 LLGlobalVariable* subprog; 435 433 if(global.params.symdebug) { … … 437 435 builder.CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(subprog)); 438 436 } 437 #endif 439 438 440 439 for (size_t i=0; i<n; i++) { … … 445 444 446 445 // debug info end 446 #ifndef DISABLE_DEBUG_INFO 447 447 if(global.params.symdebug) 448 448 builder.CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(subprog)); 449 #endif 449 450 450 451 builder.CreateRetVoid(); … … 476 477 IRBuilder<> builder(bb); 477 478 479 #ifndef DISABLE_DEBUG_INFO 478 480 // debug info 479 481 LLGlobalVariable* subprog; … … 482 484 builder.CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(subprog)); 483 485 } 486 #endif 484 487 485 488 for (size_t i=0; i<n; i++) { … … 489 492 } 490 493 494 #ifndef DISABLE_DEBUG_INFO 491 495 // debug info end 492 496 if(global.params.symdebug) 493 497 builder.CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(subprog)); 498 #endif 494 499 495 500 builder.CreateRetVoid(); … … 521 526 IRBuilder<> builder(bb); 522 527 528 #ifndef DISABLE_DEBUG_INFO 523 529 // debug info 524 530 LLGlobalVariable* subprog; … … 527 533 builder.CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(subprog)); 528 534 } 535 #endif 529 536 530 537 for (size_t i=0; i<n; i++) { … … 534 541 } 535 542 543 #ifndef DISABLE_DEBUG_INFO 536 544 // debug info end 537 545 if(global.params.symdebug) 538 546 builder.CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(subprog)); 547 #endif 539 548 540 549 builder.CreateRetVoid(); … … 579 588 580 589 // debug info 590 #ifndef DISABLE_DEBUG_INFO 581 591 LLGlobalVariable* subprog; 582 592 if(global.params.symdebug) { … … 584 594 builder.CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(subprog)); 585 595 } 596 #endif 586 597 587 598 // get current beginning … … 595 606 builder.CreateStore(thismref, mref); 596 607 608 #ifndef DISABLE_DEBUG_INFO 597 609 // debug info end 598 610 if(global.params.symdebug) 599 611 builder.CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(subprog)); 612 #endif 600 613 601 614 // return … … 615 628 // ClassInfo[] localClasses; 616 629 // uint flags; 617 // 630 // 618 631 // void function() ctor; 619 632 // void function() dtor; 620 633 // void function() unitTest; 621 // 634 // 622 635 // void* xgetMembers; 623 636 // void function() ictor;

