comparison gen/llvmhelpers.cpp @ 1650:40bd4a0d4870

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.
author Tomas Lindquist Olsen
date Wed, 19 May 2010 12:42:32 +0200
parents 8f121883bce8
children
comparison
equal deleted inserted replaced
1649:36da40ecbbe0 1650:40bd4a0d4870
158 args.push_back(c); 158 args.push_back(c);
159 159
160 // call 160 // call
161 gIR->CreateCallOrInvoke(fn, args.begin(), args.end()); 161 gIR->CreateCallOrInvoke(fn, args.begin(), args.end());
162 162
163 #ifndef DISABLE_DEBUG_INFO
163 // end debug info 164 // end debug info
164 if (global.params.symdebug) 165 if (global.params.symdebug)
165 DtoDwarfFuncEnd(gIR->func()->decl); 166 DtoDwarfFuncEnd(gIR->func()->decl);
167 #endif
166 168
167 // after assert is always unreachable 169 // after assert is always unreachable
168 gIR->ir->CreateUnreachable(); 170 gIR->ir->CreateUnreachable();
169 } 171 }
170 172
266 268
267 void DtoEnclosingHandlers(Loc loc, Statement* target) 269 void DtoEnclosingHandlers(Loc loc, Statement* target)
268 { 270 {
269 // labels are a special case: they are not required to enclose the current scope 271 // labels are a special case: they are not required to enclose the current scope
270 // for them we use the enclosing scope handler as a reference point 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 if (lblstmt) 274 if (lblstmt)
273 target = lblstmt->enclosingScopeExit; 275 target = lblstmt->enclosingScopeExit;
274 276
275 // figure out up until what handler we need to emit 277 // figure out up until what handler we need to emit
276 FuncGen::TargetScopeVec::reverse_iterator targetit = gIR->func()->gen->targetScopes.rbegin(); 278 FuncGen::TargetScopeVec::reverse_iterator targetit = gIR->func()->gen->targetScopes.rbegin();
483 { 485 {
484 return new DNullValue(type, LLConstant::getNullValue(lltype)); 486 return new DNullValue(type, LLConstant::getNullValue(lltype));
485 } 487 }
486 488
487 // unknown 489 // unknown
488 llvm::cout << "unsupported: null value for " << type->toChars() << '\n'; 490 error("unsupported: null value for %s", type->toChars());
489 assert(0); 491 assert(0);
490 return 0; 492 return 0;
491 493
492 } 494 }
493 495
852 #endif 854 #endif
853 } 855 }
854 856
855 gvar->setInitializer(initVal); 857 gvar->setInitializer(initVal);
856 858
859 #ifndef DISABLE_DEBUG_INFO
857 // do debug info 860 // do debug info
858 if (global.params.symdebug) 861 if (global.params.symdebug)
859 { 862 {
860 LLGlobalVariable* gv = DtoDwarfGlobalVariable(gvar, vd).getGV(); 863 LLGlobalVariable* gv = DtoDwarfGlobalVariable(gvar, vd).getGV();
861 // keep a reference so GDCE doesn't delete it ! 864 // keep a reference so GDCE doesn't delete it !
862 gIR->usedArray.push_back(llvm::ConstantExpr::getBitCast(gv, getVoidPtrType())); 865 gIR->usedArray.push_back(llvm::ConstantExpr::getBitCast(gv, getVoidPtrType()));
863 } 866 }
867 #endif
864 } 868 }
865 } 869 }
866 870
867 /****************************************************************************************/ 871 /****************************************************************************************/
868 /*//////////////////////////////////////////////////////////////////////////////////////// 872 /*////////////////////////////////////////////////////////////////////////////////////////
904 vd->ir.irLocal = new IrLocal(vd); 908 vd->ir.irLocal = new IrLocal(vd);
905 909
906 ExpInitializer* ex = vd->init->isExpInitializer(); 910 ExpInitializer* ex = vd->init->isExpInitializer();
907 assert(ex && "ref vars must have expression initializer"); 911 assert(ex && "ref vars must have expression initializer");
908 assert(ex->exp); 912 assert(ex->exp);
909 AssignExp* as = dynamic_cast<AssignExp*>(ex->exp); 913 AssignExp* as = ex->exp->isAssignExp();
910 assert(as && "ref vars must be initialized by an assign exp"); 914 assert(as && "ref vars must be initialized by an assign exp");
911 vd->ir.irLocal->value = as->e2->toElem(gIR)->getLVal(); 915 vd->ir.irLocal->value = as->e2->toElem(gIR)->getLVal();
912 } 916 }
913 917
914 // referenced by nested delegate? 918 // referenced by nested delegate?
915 #if DMDV2 919 #if DMDV2
916 if (vd->nestedrefs.dim) { 920 if (vd->nestedrefs.dim) {
917 #else 921 #else
918 if (vd->nestedref) { 922 if (vd->nestedref) {
919 #endif 923 #endif
920 Logger::println("has nestedref set"); 924 Logger::println("has nestedref set");
921 assert(vd->ir.irLocal); 925 assert(vd->ir.irLocal);
922 926
923 DtoNestedInit(vd); 927 DtoNestedInit(vd);
924 } 928 }
925 // normal stack variable, allocate storage on the stack if it has not already been done 929 // normal stack variable, allocate storage on the stack if it has not already been done
926 else if(!vd->ir.irLocal && !vd->isRef()) { 930 else if(!vd->ir.irLocal && !vd->isRef()) {
927 vd->ir.irLocal = new IrLocal(vd); 931 vd->ir.irLocal = new IrLocal(vd);
935 allocainst = DtoAlloca(vd->type, vd->toChars()); 939 allocainst = DtoAlloca(vd->type, vd->toChars());
936 940
937 //allocainst->setAlignment(vd->type->alignsize()); // TODO 941 //allocainst->setAlignment(vd->type->alignsize()); // TODO
938 vd->ir.irLocal->value = allocainst; 942 vd->ir.irLocal->value = allocainst;
939 943
944 #ifndef DISABLE_DEBUG_INFO
940 if (global.params.symdebug) 945 if (global.params.symdebug)
941 {
942 DtoDwarfLocalVariable(allocainst, vd); 946 DtoDwarfLocalVariable(allocainst, vd);
943 } 947 #endif
944 } 948 }
945 else 949 else
946 { 950 {
947 assert(vd->ir.irLocal->value); 951 assert(vd->ir.irLocal->value);
948 } 952 }
1044 // we don't handle globals with this one 1048 // we don't handle globals with this one
1045 assert(!var->isDataseg()); 1049 assert(!var->isDataseg());
1046 1050
1047 // we don't handle aliases either 1051 // we don't handle aliases either
1048 assert(!var->aliassym); 1052 assert(!var->aliassym);
1049 1053
1050 // alloca if necessary 1054 // alloca if necessary
1051 LLValue* allocaval = NULL; 1055 LLValue* allocaval = NULL;
1052 if (!addr && (!var->ir.irLocal || !var->ir.irLocal->value)) 1056 if (!addr && (!var->ir.irLocal || !var->ir.irLocal->value))
1053 { 1057 {
1054 addr = DtoAlloca(var->type, var->toChars()); 1058 addr = DtoAlloca(var->type, var->toChars());
1055 1059
1060 #ifndef DISABLE_DEBUG_INFO
1056 // add debug info 1061 // add debug info
1057 if (global.params.symdebug) 1062 if (global.params.symdebug)
1058 DtoDwarfLocalVariable(addr, var); 1063 DtoDwarfLocalVariable(addr, var);
1059 } 1064 #endif
1060 1065 }
1066
1061 // referenced by nested function? 1067 // referenced by nested function?
1062 #if DMDV2 1068 #if DMDV2
1063 if (var->nestedrefs.dim) 1069 if (var->nestedrefs.dim)
1064 #else 1070 #else
1065 if (var->nestedref) 1071 if (var->nestedref)
1292 LOG_SCOPE; 1298 LOG_SCOPE;
1293 1299
1294 Logger::println("template instance: %s", ti->toChars()); 1300 Logger::println("template instance: %s", ti->toChars());
1295 Logger::println("template declaration: %s", td->toChars()); 1301 Logger::println("template declaration: %s", td->toChars());
1296 Logger::println("intrinsic name: %s", td->intrinsicName.c_str()); 1302 Logger::println("intrinsic name: %s", td->intrinsicName.c_str());
1297 1303
1298 // for now use the size in bits of the first template param in the instance 1304 // for now use the size in bits of the first template param in the instance
1299 assert(ti->tdtypes.dim == 1); 1305 assert(ti->tdtypes.dim == 1);
1300 Type* T = (Type*)ti->tdtypes.data[0]; 1306 Type* T = (Type*)ti->tdtypes.data[0];
1301 1307
1302 char prefix = T->isreal() ? 'f' : T->isintegral() ? 'i' : 0; 1308 char prefix = T->isreal() ? 'f' : T->isintegral() ? 'i' : 0;
1305 fatal(); // or LLVM asserts 1311 fatal(); // or LLVM asserts
1306 } 1312 }
1307 1313
1308 char tmp[21]; // probably excessive, but covers a uint64_t 1314 char tmp[21]; // probably excessive, but covers a uint64_t
1309 sprintf(tmp, "%lu", (unsigned long) gTargetData->getTypeSizeInBits(DtoType(T))); 1315 sprintf(tmp, "%lu", (unsigned long) gTargetData->getTypeSizeInBits(DtoType(T)));
1310 1316
1311 // replace # in name with bitsize 1317 // replace # in name with bitsize
1312 name = td->intrinsicName; 1318 name = td->intrinsicName;
1313 1319
1314 std::string needle("#"); 1320 std::string needle("#");
1315 size_t pos; 1321 size_t pos;
1328 td->error("has an invalid intrinsic name: %s", name.c_str()); 1334 td->error("has an invalid intrinsic name: %s", name.c_str());
1329 } 1335 }
1330 fatal(); // or LLVM asserts 1336 fatal(); // or LLVM asserts
1331 } 1337 }
1332 } 1338 }
1333 1339
1334 Logger::println("final intrinsic name: %s", name.c_str()); 1340 Logger::println("final intrinsic name: %s", name.c_str());
1335 } 1341 }
1336 1342
1337 ////////////////////////////////////////////////////////////////////////////////////////// 1343 //////////////////////////////////////////////////////////////////////////////////////////
1338 1344
1339 bool mustDefineSymbol(Dsymbol* s) 1345 bool mustDefineSymbol(Dsymbol* s)
1340 { 1346 {
1341 if (FuncDeclaration* fd = s->isFuncDeclaration()) 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 // that weren't semantic3'ed 1350 // that weren't semantic3'ed
1345 if (fd->semanticRun < 4) 1351 if (fd->semanticRun < 4)
1346 return false; 1352 return false;
1347 1353
1348 if (fd->isArrayOp) 1354 if (fd->isArrayOp)
1350 1356
1351 if (global.params.useAvailableExternally && fd->availableExternally) { 1357 if (global.params.useAvailableExternally && fd->availableExternally) {
1352 // Emit extra functions if we're inlining. 1358 // Emit extra functions if we're inlining.
1353 // These will get available_externally linkage, 1359 // These will get available_externally linkage,
1354 // so they shouldn't end up in object code. 1360 // so they shouldn't end up in object code.
1355 1361
1356 assert(fd->type->ty == Tfunction); 1362 assert(fd->type->ty == Tfunction);
1357 TypeFunction* tf = (TypeFunction*) fd->type; 1363 TypeFunction* tf = (TypeFunction*) fd->type;
1358 // * If we define extra static constructors, static destructors 1364 // * If we define extra static constructors, static destructors
1359 // and unittests they'll get registered to run, and we won't 1365 // and unittests they'll get registered to run, and we won't
1360 // be calling them directly anyway. 1366 // be calling them directly anyway.
1369 && !fd->isUnitTestDeclaration() 1375 && !fd->isUnitTestDeclaration()
1370 && fd->canInline(true)) 1376 && fd->canInline(true))
1371 { 1377 {
1372 return true; 1378 return true;
1373 } 1379 }
1374 1380
1375 // This was only semantic'ed for inlining checks. 1381 // This was only semantic'ed for inlining checks.
1376 // We won't be inlining this, so we only need to emit a declaration. 1382 // We won't be inlining this, so we only need to emit a declaration.
1377 return false; 1383 return false;
1378 } 1384 }
1379 } 1385 }
1394 TemplateInstance* tinst = DtoIsTemplateInstance(s); 1400 TemplateInstance* tinst = DtoIsTemplateInstance(s);
1395 if (tinst) 1401 if (tinst)
1396 { 1402 {
1397 if (!opts::singleObj) 1403 if (!opts::singleObj)
1398 return true; 1404 return true;
1399 1405
1400 if (!tinst->emittedInModule) 1406 if (!tinst->emittedInModule)
1401 { 1407 {
1402 gIR->seenTemplateInstances.insert(tinst); 1408 gIR->seenTemplateInstances.insert(tinst);
1403 tinst->emittedInModule = gIR->dmodule; 1409 tinst->emittedInModule = gIR->dmodule;
1404 } 1410 }
1405 return tinst->emittedInModule == gIR->dmodule; 1411 return tinst->emittedInModule == gIR->dmodule;
1406 } 1412 }
1407 1413
1408 return s->getModule() == gIR->dmodule; 1414 return s->getModule() == gIR->dmodule;
1409 } 1415 }
1410 1416
1411 ////////////////////////////////////////////////////////////////////////////////////////// 1417 //////////////////////////////////////////////////////////////////////////////////////////
1412 1418