comparison gen/toir.cpp @ 217:0806379a5eca trunk

[svn r233] Added: -oq command line option for writing fully qualified object names. Added: started support for x86 80bit floating point. Changed: aggregates passed by value now use the llvm 'byval' parameter attribute, also lays ground work for using other attributes. Changed: eliminated a lot more std::vectorS, these showed up pretty much at the top when profiling! Changed: performed other misc. cleanups. Changed: halt expression now call the new llvm trap intrinsic instead of an assert(0). Changed: dstress suite now passes -O0 by default, this only eliminates unreferenced globals, which speeds up linking quite a bit.
author lindquist
date Thu, 05 Jun 2008 06:38:36 +0200
parents a58d8f4b84df
children df641a27e9fd
comparison
equal deleted inserted replaced
216:3d022aa016ae 217:0806379a5eca
616 Logger::println("add to AddrExp of struct"); 616 Logger::println("add to AddrExp of struct");
617 assert(r->isConst()); 617 assert(r->isConst());
618 llvm::ConstantInt* cofs = llvm::cast<llvm::ConstantInt>(r->isConst()->c); 618 llvm::ConstantInt* cofs = llvm::cast<llvm::ConstantInt>(r->isConst()->c);
619 619
620 TypeStruct* ts = (TypeStruct*)e1next; 620 TypeStruct* ts = (TypeStruct*)e1next;
621 std::vector<unsigned> offsets; 621 DStructIndexVector offsets;
622 LLValue* v = DtoIndexStruct(l->getRVal(), ts->sym, t->next, cofs->getZExtValue(), offsets); 622 LLValue* v = DtoIndexStruct(l->getRVal(), ts->sym, t->next, cofs->getZExtValue(), offsets);
623 return new DFieldValue(type, v, true); 623 return new DFieldValue(type, v, true);
624 } 624 }
625 else if (e1type->ty == Tpointer) { 625 else if (e1type->ty == Tpointer) {
626 Logger::println("add to pointer"); 626 Logger::println("add to pointer");
1016 1016
1017 IRExp* topexp = p->topexp(); 1017 IRExp* topexp = p->topexp();
1018 1018
1019 bool isInPlace = false; 1019 bool isInPlace = false;
1020 1020
1021 // attrs
1022 llvm::PAListPtr palist;
1023
1021 // hidden struct return arguments 1024 // hidden struct return arguments
1025 // TODO: use sret param attr
1022 if (retinptr) { 1026 if (retinptr) {
1023 if (topexp && topexp->e2 == this) { 1027 if (topexp && topexp->e2 == this) {
1024 assert(topexp->v); 1028 assert(topexp->v);
1025 LLValue* tlv = topexp->v->getLVal(); 1029 LLValue* tlv = topexp->v->getLVal();
1026 assert(isaStruct(tlv->getType()->getContainedType(0))); 1030 assert(isaStruct(tlv->getType()->getContainedType(0)));
1165 for (int i=0; i<begin; i++) 1169 for (int i=0; i<begin; i++)
1166 { 1170 {
1167 Argument* fnarg = Argument::getNth(tf->parameters, i); 1171 Argument* fnarg = Argument::getNth(tf->parameters, i);
1168 DValue* argval = DtoArgument(fnarg, (Expression*)arguments->data[i]); 1172 DValue* argval = DtoArgument(fnarg, (Expression*)arguments->data[i]);
1169 llargs[j] = argval->getRVal(); 1173 llargs[j] = argval->getRVal();
1174 #if USE_BYVAL
1175 if (fnarg->llvmByVal)
1176 palist = palist.addAttr(j, llvm::ParamAttr::ByVal);
1177 #endif
1170 j++; 1178 j++;
1171 } 1179 }
1172 1180
1173 // make sure arg vector has the right size 1181 // make sure arg vector has the right size
1174 llargs.resize(nimplicit+begin+2); 1182 llargs.resize(nimplicit+begin+2);
1185 llargs[j] = argval->getRVal(); 1193 llargs[j] = argval->getRVal();
1186 if (fnarg && llargs[j]->getType() != llfnty->getParamType(j)) { 1194 if (fnarg && llargs[j]->getType() != llfnty->getParamType(j)) {
1187 llargs[j] = DtoBitCast(llargs[j], llfnty->getParamType(j)); 1195 llargs[j] = DtoBitCast(llargs[j], llfnty->getParamType(j));
1188 } 1196 }
1189 1197
1198 #if USE_BYVAL
1199 if (fnarg && fnarg->llvmByVal)
1200 palist = palist.addAttr(j+1, llvm::ParamAttr::ByVal);
1201 #endif
1202
1190 // this hack is necessary :/ 1203 // this hack is necessary :/
1191 if (dfn && dfn->func && dfn->func->runTimeHack) { 1204 if (dfn && dfn->func && dfn->func->runTimeHack) {
1192 if (llfnty->getParamType(j) != NULL) { 1205 if (llfnty->getParamType(j) != NULL) {
1193 if (llargs[j]->getType() != llfnty->getParamType(j)) { 1206 if (llargs[j]->getType() != llfnty->getParamType(j)) {
1194 Logger::println("llvmRunTimeHack==true - force casting argument"); 1207 Logger::println("llvmRunTimeHack==true - force casting argument");
1243 } 1256 }
1244 else { 1257 else {
1245 call->setCallingConv(DtoCallingConv(dlink)); 1258 call->setCallingConv(DtoCallingConv(dlink));
1246 } 1259 }
1247 1260
1261 // param attrs
1262 call->setParamAttrs(palist);
1263
1248 return new DImValue(type, retllval, isInPlace); 1264 return new DImValue(type, retllval, isInPlace);
1249 } 1265 }
1250 1266
1251 ////////////////////////////////////////////////////////////////////////////////////////// 1267 //////////////////////////////////////////////////////////////////////////////////////////
1252 1268
1309 const LLType* llt = DtoType(t); 1325 const LLType* llt = DtoType(t);
1310 if (offset == 0) { 1326 if (offset == 0) {
1311 varmem = p->ir->CreateBitCast(llvalue, llt, "tmp"); 1327 varmem = p->ir->CreateBitCast(llvalue, llt, "tmp");
1312 } 1328 }
1313 else { 1329 else {
1314 std::vector<unsigned> dst; 1330 DStructIndexVector dst;
1315 varmem = DtoIndexStruct(llvalue,vdt->sym, tnext, offset, dst); 1331 varmem = DtoIndexStruct(llvalue,vdt->sym, tnext, offset, dst);
1316 } 1332 }
1317 } 1333 }
1318 else if (vdtype->ty == Tsarray) { 1334 else if (vdtype->ty == Tsarray) {
1319 Logger::println("sarray"); 1335 Logger::println("sarray");
1427 TypeStruct* ts = (TypeStruct*)e1type->next; 1443 TypeStruct* ts = (TypeStruct*)e1type->next;
1428 Logger::println("Struct member offset:%d", vd->offset); 1444 Logger::println("Struct member offset:%d", vd->offset);
1429 1445
1430 LLValue* src = l->getRVal(); 1446 LLValue* src = l->getRVal();
1431 1447
1432 std::vector<unsigned> vdoffsets; 1448 DStructIndexVector vdoffsets;
1433 arrptr = DtoIndexStruct(src, ts->sym, vd->type, vd->offset, vdoffsets); 1449 arrptr = DtoIndexStruct(src, ts->sym, vd->type, vd->offset, vdoffsets);
1434 } 1450 }
1435 else if (e1type->ty == Tclass) { 1451 else if (e1type->ty == Tclass) {
1436 TypeClass* tc = (TypeClass*)e1type; 1452 TypeClass* tc = (TypeClass*)e1type;
1437 Logger::println("Class member offset: %d", vd->offset); 1453 Logger::println("Class member offset: %d", vd->offset);
1438 1454
1439 LLValue* src = l->getRVal(); 1455 LLValue* src = l->getRVal();
1440 1456
1441 std::vector<unsigned> vdoffsets; 1457 DStructIndexVector vdoffsets;
1442 arrptr = DtoIndexClass(src, tc->sym, vd->type, vd->offset, vdoffsets); 1458 arrptr = DtoIndexClass(src, tc->sym, vd->type, vd->offset, vdoffsets);
1443 1459
1444 /*std::vector<unsigned> vdoffsets(1,0); 1460 /*std::vector<unsigned> vdoffsets(1,0);
1445 tc->sym->offsetToIndex(vd->type, vd->offset, vdoffsets); 1461 tc->sym->offsetToIndex(vd->type, vd->offset, vdoffsets);
1446 1462
2253 DValue* HaltExp::toElem(IRState* p) 2269 DValue* HaltExp::toElem(IRState* p)
2254 { 2270 {
2255 Logger::print("HaltExp::toElem: %s | %s\n", toChars(), type->toChars()); 2271 Logger::print("HaltExp::toElem: %s | %s\n", toChars(), type->toChars());
2256 LOG_SCOPE; 2272 LOG_SCOPE;
2257 2273
2258 DtoAssert(&loc, NULL); 2274 // call the new (?) trap intrinsic
2275 p->ir->CreateCall(GET_INTRINSIC_DECL(trap),"");
2259 2276
2260 new llvm::UnreachableInst(p->scopebb()); 2277 new llvm::UnreachableInst(p->scopebb());
2261 return 0; 2278 return 0;
2262 } 2279 }
2263 2280