comparison gen/llvmhelpers.cpp @ 479:672eb4893b55

Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
author Christian Kamm <kamm incasoftware de>
date Tue, 05 Aug 2008 19:28:19 +0200
parents 45a67b6f1310
children fc12214ba4a1
comparison
equal deleted inserted replaced
478:b657298222d9 479:672eb4893b55
83 gIR->CreateCallOrInvoke(fn, arg.begin(), arg.end()); 83 gIR->CreateCallOrInvoke(fn, arg.begin(), arg.end());
84 } 84 }
85 85
86 /****************************************************************************************/ 86 /****************************************************************************************/
87 /*//////////////////////////////////////////////////////////////////////////////////////// 87 /*////////////////////////////////////////////////////////////////////////////////////////
88 // ALLOCA HELPERS
89 ////////////////////////////////////////////////////////////////////////////////////////*/
90
91
92 llvm::AllocaInst* DtoAlloca(const LLType* lltype, const std::string& name)
93 {
94 return new llvm::AllocaInst(lltype, name, gIR->topallocapoint());
95 }
96
97 llvm::AllocaInst* DtoAlloca(const LLType* lltype, LLValue* arraysize, const std::string& name)
98 {
99 return new llvm::AllocaInst(lltype, arraysize, name, gIR->topallocapoint());
100 }
101
102
103 /****************************************************************************************/
104 /*////////////////////////////////////////////////////////////////////////////////////////
88 // ASSERT HELPER 105 // ASSERT HELPER
89 ////////////////////////////////////////////////////////////////////////////////////////*/ 106 ////////////////////////////////////////////////////////////////////////////////////////*/
90 107
91 void DtoAssert(Loc* loc, DValue* msg) 108 void DtoAssert(Loc* loc, DValue* msg)
92 { 109 {
110 if (DSliceValue* s = msg->isSlice()) 127 if (DSliceValue* s = msg->isSlice())
111 { 128 {
112 llvm::AllocaInst* alloc = gIR->func()->msgArg; 129 llvm::AllocaInst* alloc = gIR->func()->msgArg;
113 if (!alloc) 130 if (!alloc)
114 { 131 {
115 alloc = new llvm::AllocaInst(c->getType(), ".assertmsg", gIR->topallocapoint()); 132 alloc = DtoAlloca(c->getType(), ".assertmsg");
116 DtoSetArray(alloc, DtoArrayLen(s), DtoArrayPtr(s)); 133 DtoSetArray(alloc, DtoArrayLen(s), DtoArrayPtr(s));
117 gIR->func()->msgArg = alloc; 134 gIR->func()->msgArg = alloc;
118 } 135 }
119 args.push_back(alloc); 136 args.push_back(alloc);
120 } 137 }
127 144
128 // file param 145 // file param
129 llvm::AllocaInst* alloc = gIR->func()->srcfileArg; 146 llvm::AllocaInst* alloc = gIR->func()->srcfileArg;
130 if (!alloc) 147 if (!alloc)
131 { 148 {
132 alloc = new llvm::AllocaInst(c->getType(), ".srcfile", gIR->topallocapoint()); 149 alloc = DtoAlloca(c->getType(), ".srcfile");
133 gIR->func()->srcfileArg = alloc; 150 gIR->func()->srcfileArg = alloc;
134 } 151 }
135 LLValue* ptr = DtoGEPi(alloc, 0,0, "tmp"); 152 LLValue* ptr = DtoGEPi(alloc, 0,0, "tmp");
136 DtoStore(c->getOperand(0), ptr); 153 DtoStore(c->getOperand(0), ptr);
137 ptr = DtoGEPi(alloc, 0,1, "tmp"); 154 ptr = DtoGEPi(alloc, 0,1, "tmp");
1209 1226
1210 llvm::Value* allocainst; 1227 llvm::Value* allocainst;
1211 if(gTargetData->getTypeSizeInBits(lltype) == 0) 1228 if(gTargetData->getTypeSizeInBits(lltype) == 0)
1212 allocainst = llvm::ConstantPointerNull::get(getPtrToType(lltype)); 1229 allocainst = llvm::ConstantPointerNull::get(getPtrToType(lltype));
1213 else 1230 else
1214 allocainst = new llvm::AllocaInst(lltype, vd->toChars(), gIR->topallocapoint()); 1231 allocainst = DtoAlloca(lltype, vd->toChars());
1215 1232
1216 //allocainst->setAlignment(vd->type->alignsize()); // TODO 1233 //allocainst->setAlignment(vd->type->alignsize()); // TODO
1217 vd->ir.irLocal = new IrLocal(vd); 1234 vd->ir.irLocal = new IrLocal(vd);
1218 vd->ir.irLocal->value = allocainst; 1235 vd->ir.irLocal->value = allocainst;
1219 1236