Mercurial > projects > ldc
comparison gen/llvmhelpers.cpp @ 482:aa8c050dfd19
Move zero init of padding to DtoInitializer in order to respect void initializers.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Thu, 07 Aug 2008 18:15:27 +0200 |
parents | 18480579dc04 |
children | d86af825e8d9 |
comparison
equal
deleted
inserted
replaced
481:18480579dc04 | 482:aa8c050dfd19 |
---|---|
18 #include "gen/classes.h" | 18 #include "gen/classes.h" |
19 #include "gen/functions.h" | 19 #include "gen/functions.h" |
20 #include "gen/typeinf.h" | 20 #include "gen/typeinf.h" |
21 #include "gen/todebug.h" | 21 #include "gen/todebug.h" |
22 | 22 |
23 #include <stack> | |
24 | |
23 /****************************************************************************************/ | 25 /****************************************************************************************/ |
24 /*//////////////////////////////////////////////////////////////////////////////////////// | 26 /*//////////////////////////////////////////////////////////////////////////////////////// |
25 // DYNAMIC MEMORY HELPERS | 27 // DYNAMIC MEMORY HELPERS |
26 ////////////////////////////////////////////////////////////////////////////////////////*/ | 28 ////////////////////////////////////////////////////////////////////////////////////////*/ |
27 | 29 |
89 ////////////////////////////////////////////////////////////////////////////////////////*/ | 91 ////////////////////////////////////////////////////////////////////////////////////////*/ |
90 | 92 |
91 | 93 |
92 llvm::AllocaInst* DtoAlloca(const LLType* lltype, const std::string& name) | 94 llvm::AllocaInst* DtoAlloca(const LLType* lltype, const std::string& name) |
93 { | 95 { |
94 if(lltype == LLType::X86_FP80Ty) | |
95 { | |
96 llvm::AllocaInst* alloca = new llvm::AllocaInst(lltype, name, gIR->topallocapoint()); | |
97 LLValue* castv = DtoBitCast(alloca, getPtrToType(LLType::Int16Ty), "fp80toi16"); | |
98 LLValue* padding = DtoGEPi1(castv, 5, "fp80padding"); | |
99 DtoStore(llvm::Constant::getNullValue(LLType::Int16Ty), padding); | |
100 | |
101 return alloca; | |
102 } | |
103 | |
104 return new llvm::AllocaInst(lltype, name, gIR->topallocapoint()); | 96 return new llvm::AllocaInst(lltype, name, gIR->topallocapoint()); |
105 } | 97 } |
106 | 98 |
107 llvm::AllocaInst* DtoAlloca(const LLType* lltype, LLValue* arraysize, const std::string& name) | 99 llvm::AllocaInst* DtoAlloca(const LLType* lltype, LLValue* arraysize, const std::string& name) |
108 { | 100 { |
109 assert(lltype != LLType::X86_FP80Ty && "Zero-init of fp80 padding for array allocas not yet implemented"); | |
110 return new llvm::AllocaInst(lltype, arraysize, name, gIR->topallocapoint()); | 101 return new llvm::AllocaInst(lltype, arraysize, name, gIR->topallocapoint()); |
111 } | 102 } |
112 | 103 |
113 | 104 |
114 /****************************************************************************************/ | 105 /****************************************************************************************/ |
885 llvm::BasicBlock* initbb = llvm::BasicBlock::Create("ifnotinit",gIR->topfunc(),oldend); | 876 llvm::BasicBlock* initbb = llvm::BasicBlock::Create("ifnotinit",gIR->topfunc(),oldend); |
886 llvm::BasicBlock* endinitbb = llvm::BasicBlock::Create("ifnotinitend",gIR->topfunc(),oldend); | 877 llvm::BasicBlock* endinitbb = llvm::BasicBlock::Create("ifnotinitend",gIR->topfunc(),oldend); |
887 LLValue* cond = gIR->ir->CreateICmpEQ(gIR->ir->CreateLoad(gflag,"tmp"),DtoConstBool(false)); | 878 LLValue* cond = gIR->ir->CreateICmpEQ(gIR->ir->CreateLoad(gflag,"tmp"),DtoConstBool(false)); |
888 gIR->ir->CreateCondBr(cond, initbb, endinitbb); | 879 gIR->ir->CreateCondBr(cond, initbb, endinitbb); |
889 gIR->scope() = IRScope(initbb,endinitbb); | 880 gIR->scope() = IRScope(initbb,endinitbb); |
890 DValue* ie = DtoInitializer(init); | 881 DValue* ie = DtoInitializer(gvar, init); |
891 if (!ie->inPlace()) { | 882 if (!ie->inPlace()) { |
892 DValue* dst = new DVarValue(t, gvar, true); | 883 DValue* dst = new DVarValue(t, gvar, true); |
893 DtoAssign(init->loc, dst, ie); | 884 DtoAssign(init->loc, dst, ie); |
894 } | 885 } |
895 gIR->ir->CreateStore(DtoConstBool(true), gflag); | 886 gIR->ir->CreateStore(DtoConstBool(true), gflag); |
1250 DtoDwarfLocalVariable(allocainst, vd); | 1241 DtoDwarfLocalVariable(allocainst, vd); |
1251 } | 1242 } |
1252 } | 1243 } |
1253 | 1244 |
1254 Logger::cout() << "llvm value for decl: " << *vd->ir.irLocal->value << '\n'; | 1245 Logger::cout() << "llvm value for decl: " << *vd->ir.irLocal->value << '\n'; |
1255 DValue* ie = DtoInitializer(vd->init); | 1246 DValue* ie = DtoInitializer(vd->ir.irLocal->value, vd->init); |
1256 } | 1247 } |
1257 | 1248 |
1258 return new DVarValue(vd->type, vd, vd->ir.getIrValue(), true); | 1249 return new DVarValue(vd->type, vd, vd->ir.getIrValue(), true); |
1259 } | 1250 } |
1260 // struct declaration | 1251 // struct declaration |
1425 return _init; | 1416 return _init; |
1426 } | 1417 } |
1427 | 1418 |
1428 ////////////////////////////////////////////////////////////////////////////////////////// | 1419 ////////////////////////////////////////////////////////////////////////////////////////// |
1429 | 1420 |
1430 DValue* DtoInitializer(Initializer* init) | 1421 DValue* DtoInitializer(LLValue* target, Initializer* init) |
1431 { | 1422 { |
1432 if (!init) | 1423 if (!init) |
1433 return 0; | 1424 return 0; |
1434 else if (ExpInitializer* ex = init->isExpInitializer()) | 1425 else if (ExpInitializer* ex = init->isExpInitializer()) |
1435 { | 1426 { |
1436 Logger::println("expression initializer"); | 1427 Logger::println("expression initializer"); |
1437 assert(ex->exp); | 1428 assert(ex->exp); |
1438 return ex->exp->toElem(gIR); | 1429 DValue* res = ex->exp->toElem(gIR); |
1430 | |
1431 assert(llvm::isa<llvm::PointerType>(target->getType()) && "init target must be ptr"); | |
1432 const LLType* targetty = target->getType()->getContainedType(0); | |
1433 if(targetty == LLType::X86_FP80Ty) | |
1434 { | |
1435 Logger::println("setting fp80 padding to zero"); | |
1436 | |
1437 LLValue* castv = DtoBitCast(target, getPtrToType(LLType::Int16Ty)); | |
1438 LLValue* padding = DtoGEPi1(castv, 5); | |
1439 DtoStore(llvm::Constant::getNullValue(LLType::Int16Ty), padding); | |
1440 } | |
1441 else if(targetty == DtoComplexType(Type::tcomplex80)) | |
1442 { | |
1443 Logger::println("setting complex fp80 padding to zero"); | |
1444 | |
1445 LLValue* castv = DtoBitCast(target, getPtrToType(LLType::Int16Ty)); | |
1446 LLValue* padding = DtoGEPi1(castv, 5); | |
1447 DtoStore(llvm::Constant::getNullValue(LLType::Int16Ty), padding); | |
1448 padding = DtoGEPi1(castv, 11); | |
1449 DtoStore(llvm::Constant::getNullValue(LLType::Int16Ty), padding); | |
1450 } | |
1439 } | 1451 } |
1440 else if (init->isVoidInitializer()) | 1452 else if (init->isVoidInitializer()) |
1441 { | 1453 { |
1442 // do nothing | 1454 // do nothing |
1443 } | 1455 } |