Mercurial > projects > ldc
comparison gen/tollvm.cpp @ 96:ce7ed8f59b99 trunk
[svn r100] Moved test/ray.d to demos/ray.d.
Cleanups.
author | lindquist |
---|---|
date | Mon, 12 Nov 2007 07:58:44 +0100 |
parents | 61615fa85940 |
children | c4e161556a21 |
comparison
equal
deleted
inserted
replaced
95:71b8fecdae38 | 96:ce7ed8f59b99 |
---|---|
257 } | 257 } |
258 else | 258 else |
259 arg->llvmCopy = true; | 259 arg->llvmCopy = true; |
260 | 260 |
261 const llvm::Type* at = DtoType(argT); | 261 const llvm::Type* at = DtoType(argT); |
262 if (llvm::isa<llvm::StructType>(at)) { | 262 if (isaStruct(at)) { |
263 Logger::println("struct param"); | 263 Logger::println("struct param"); |
264 paramvec.push_back(llvm::PointerType::get(at)); | 264 paramvec.push_back(llvm::PointerType::get(at)); |
265 } | 265 } |
266 else if (llvm::isa<llvm::ArrayType>(at)) { | 266 else if (isaArray(at)) { |
267 Logger::println("sarray param"); | 267 Logger::println("sarray param"); |
268 assert(argT->ty == Tsarray); | 268 assert(argT->ty == Tsarray); |
269 //paramvec.push_back(llvm::PointerType::get(at->getContainedType(0))); | 269 //paramvec.push_back(llvm::PointerType::get(at->getContainedType(0))); |
270 paramvec.push_back(llvm::PointerType::get(at)); | 270 paramvec.push_back(llvm::PointerType::get(at)); |
271 } | 271 } |
272 else if (llvm::isa<llvm::OpaqueType>(at)) { | 272 else if (llvm::isa<llvm::OpaqueType>(at)) { |
273 Logger::println("opaque param"); | 273 Logger::println("opaque param"); |
274 if (argT->ty == Tstruct || argT->ty == Tclass) | 274 assert(argT->ty == Tstruct || argT->ty == Tclass); |
275 paramvec.push_back(llvm::PointerType::get(at)); | |
276 else | |
277 assert(0); | |
278 } | |
279 /*if (llvm::isa<llvm::StructType>(at) || argT->ty == Tstruct || argT->ty == Tsarray) { | |
280 paramvec.push_back(llvm::PointerType::get(at)); | 275 paramvec.push_back(llvm::PointerType::get(at)); |
281 }*/ | 276 } |
282 else { | 277 else { |
283 if (!arg->llvmCopy) { | 278 if (!arg->llvmCopy) { |
284 Logger::println("ref param"); | 279 Logger::println("ref param"); |
285 at = llvm::PointerType::get(at); | 280 at = llvm::PointerType::get(at); |
286 } | 281 } |
344 if (fdecl->needThis()) { | 339 if (fdecl->needThis()) { |
345 if (AggregateDeclaration* ad = fdecl->isMember()) { | 340 if (AggregateDeclaration* ad = fdecl->isMember()) { |
346 Logger::print("isMember = this is: %s\n", ad->type->toChars()); | 341 Logger::print("isMember = this is: %s\n", ad->type->toChars()); |
347 thisty = DtoType(ad->type); | 342 thisty = DtoType(ad->type); |
348 Logger::cout() << "this llvm type: " << *thisty << '\n'; | 343 Logger::cout() << "this llvm type: " << *thisty << '\n'; |
349 if (llvm::isa<llvm::StructType>(thisty) || thisty == gIR->topstruct().recty.get()) | 344 if (isaStruct(thisty) || thisty == gIR->topstruct().recty.get()) |
350 thisty = llvm::PointerType::get(thisty); | 345 thisty = llvm::PointerType::get(thisty); |
351 } | 346 } |
352 else | 347 else |
353 assert(0); | 348 assert(0); |
354 } | 349 } |
607 else { | 602 else { |
608 llvm::Value* zero = llvm::ConstantInt::get(t, 0, false); | 603 llvm::Value* zero = llvm::ConstantInt::get(t, 0, false); |
609 return new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, val, zero, "tmp", gIR->scopebb()); | 604 return new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, val, zero, "tmp", gIR->scopebb()); |
610 } | 605 } |
611 } | 606 } |
612 else if (llvm::isa<llvm::PointerType>(t)) { | 607 else if (isaPointer(t)) { |
613 const llvm::Type* st = DtoSize_t(); | 608 const llvm::Type* st = DtoSize_t(); |
614 llvm::Value* ptrasint = new llvm::PtrToIntInst(val,st,"tmp",gIR->scopebb()); | 609 llvm::Value* ptrasint = new llvm::PtrToIntInst(val,st,"tmp",gIR->scopebb()); |
615 llvm::Value* zero = llvm::ConstantInt::get(st, 0, false); | 610 llvm::Value* zero = llvm::ConstantInt::get(st, 0, false); |
616 return new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, ptrasint, zero, "tmp", gIR->scopebb()); | 611 return new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, ptrasint, zero, "tmp", gIR->scopebb()); |
617 } | 612 } |
878 assert(fn); | 873 assert(fn); |
879 } | 874 } |
880 else | 875 else |
881 assert(0); | 876 assert(0); |
882 | 877 |
883 llvm::Function* func = llvm::cast_or_null<llvm::Function>(fn); | 878 llvm::Function* func = llvm::dyn_cast<llvm::Function>(fn); |
884 assert(func); | 879 assert(func); |
885 assert(func->isIntrinsic()); | 880 assert(func->isIntrinsic()); |
886 fdecl->llvmValue = func; | 881 fdecl->llvmValue = func; |
887 return func; | 882 return func; |
888 } | 883 } |
1097 } | 1092 } |
1098 } | 1093 } |
1099 else { | 1094 else { |
1100 llvm::Value* allocaInst = 0; | 1095 llvm::Value* allocaInst = 0; |
1101 llvm::BasicBlock* entryblock = &gIR->topfunc()->front(); | 1096 llvm::BasicBlock* entryblock = &gIR->topfunc()->front(); |
1102 //const llvm::PointerType* pty = llvm::cast<llvm::PointerType>(arg->mem->getType()); | 1097 |
1103 const llvm::Type* realtypell = DtoType(realtype); | 1098 const llvm::Type* realtypell = DtoType(realtype); |
1104 const llvm::PointerType* pty = llvm::PointerType::get(realtypell); | 1099 const llvm::PointerType* pty = llvm::PointerType::get(realtypell); |
1105 if (argty == Tstruct) { | 1100 if (argty == Tstruct) { |
1106 allocaInst = new llvm::AllocaInst(pty->getElementType(), "tmpparam", gIR->topallocapoint()); | 1101 allocaInst = new llvm::AllocaInst(pty->getElementType(), "tmpparam", gIR->topallocapoint()); |
1107 DValue* dst = new DVarValue(realtype, allocaInst, true); | 1102 DValue* dst = new DVarValue(realtype, allocaInst, true); |
1395 gIR->ir->CreateStore(src,dst); | 1390 gIR->ir->CreateStore(src,dst); |
1396 } | 1391 } |
1397 | 1392 |
1398 bool DtoCanLoad(llvm::Value* ptr) | 1393 bool DtoCanLoad(llvm::Value* ptr) |
1399 { | 1394 { |
1400 if (llvm::isa<llvm::PointerType>(ptr->getType())) { | 1395 if (isaPointer(ptr->getType())) { |
1401 return ptr->getType()->getContainedType(0)->isFirstClassType(); | 1396 return ptr->getType()->getContainedType(0)->isFirstClassType(); |
1402 } | 1397 } |
1403 return false; | 1398 return false; |
1404 } | 1399 } |
1405 | 1400 |
1411 const llvm::PointerType* isaPointer(llvm::Value* v) | 1406 const llvm::PointerType* isaPointer(llvm::Value* v) |
1412 { | 1407 { |
1413 return llvm::dyn_cast<llvm::PointerType>(v->getType()); | 1408 return llvm::dyn_cast<llvm::PointerType>(v->getType()); |
1414 } | 1409 } |
1415 | 1410 |
1411 const llvm::PointerType* isaPointer(const llvm::Type* t) | |
1412 { | |
1413 return llvm::dyn_cast<llvm::PointerType>(t); | |
1414 } | |
1415 | |
1416 const llvm::ArrayType* isaArray(llvm::Value* v) | 1416 const llvm::ArrayType* isaArray(llvm::Value* v) |
1417 { | 1417 { |
1418 return llvm::dyn_cast<llvm::ArrayType>(v->getType()); | 1418 return llvm::dyn_cast<llvm::ArrayType>(v->getType()); |
1419 } | 1419 } |
1420 | 1420 |
1421 const llvm::ArrayType* isaArray(const llvm::Type* t) | |
1422 { | |
1423 return llvm::dyn_cast<llvm::ArrayType>(t); | |
1424 } | |
1425 | |
1421 const llvm::StructType* isaStruct(llvm::Value* v) | 1426 const llvm::StructType* isaStruct(llvm::Value* v) |
1422 { | 1427 { |
1423 return llvm::dyn_cast<llvm::StructType>(v->getType()); | 1428 return llvm::dyn_cast<llvm::StructType>(v->getType()); |
1424 } | 1429 } |
1425 | 1430 |
1431 const llvm::StructType* isaStruct(const llvm::Type* t) | |
1432 { | |
1433 return llvm::dyn_cast<llvm::StructType>(t); | |
1434 } | |
1435 | |
1426 llvm::Constant* isaConstant(llvm::Value* v) | 1436 llvm::Constant* isaConstant(llvm::Value* v) |
1427 { | 1437 { |
1428 return llvm::dyn_cast<llvm::Constant>(v); | 1438 return llvm::dyn_cast<llvm::Constant>(v); |
1429 } | 1439 } |
1430 | 1440 |
1431 llvm::ConstantInt* isaConstantInt(llvm::Value* v) | 1441 llvm::ConstantInt* isaConstantInt(llvm::Value* v) |
1432 { | 1442 { |
1433 return llvm::dyn_cast<llvm::ConstantInt>(v); | 1443 return llvm::dyn_cast<llvm::ConstantInt>(v); |
1444 } | |
1445 | |
1446 llvm::Argument* isaArgument(llvm::Value* v) | |
1447 { | |
1448 return llvm::dyn_cast<llvm::Argument>(v); | |
1434 } | 1449 } |
1435 | 1450 |
1436 ////////////////////////////////////////////////////////////////////////////////////////// | 1451 ////////////////////////////////////////////////////////////////////////////////////////// |
1437 | 1452 |
1438 bool DtoIsTemplateInstance(Dsymbol* s) | 1453 bool DtoIsTemplateInstance(Dsymbol* s) |