comparison gen/toir.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 d0dad1fe0f45
children 50f6e2337a6b
comparison
equal deleted inserted replaced
478:b657298222d9 479:672eb4893b55
356 LLConstant* idxs[2] = { zero, zero }; 356 LLConstant* idxs[2] = { zero, zero };
357 LLConstant* arrptr = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2); 357 LLConstant* arrptr = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2);
358 358
359 if (dtype->ty == Tarray) { 359 if (dtype->ty == Tarray) {
360 LLConstant* clen = llvm::ConstantInt::get(DtoSize_t(),len,false); 360 LLConstant* clen = llvm::ConstantInt::get(DtoSize_t(),len,false);
361 LLValue* tmpmem = new llvm::AllocaInst(DtoType(dtype),"tempstring",p->topallocapoint()); 361 LLValue* tmpmem = DtoAlloca(DtoType(dtype),"tempstring");
362 DtoSetArray(tmpmem, clen, arrptr); 362 DtoSetArray(tmpmem, clen, arrptr);
363 return new DVarValue(type, tmpmem, true); 363 return new DVarValue(type, tmpmem, true);
364 } 364 }
365 else if (dtype->ty == Tsarray) { 365 else if (dtype->ty == Tsarray) {
366 const LLType* dstType = getPtrToType(LLArrayType::get(ct, len)); 366 const LLType* dstType = getPtrToType(LLArrayType::get(ct, len));
768 else if (fndecl->llvmInternal == LLVMalloca) { 768 else if (fndecl->llvmInternal == LLVMalloca) {
769 Expression* exp = (Expression*)arguments->data[0]; 769 Expression* exp = (Expression*)arguments->data[0];
770 DValue* expv = exp->toElem(p); 770 DValue* expv = exp->toElem(p);
771 if (expv->getType()->toBasetype()->ty != Tint32) 771 if (expv->getType()->toBasetype()->ty != Tint32)
772 expv = DtoCast(loc, expv, Type::tint32); 772 expv = DtoCast(loc, expv, Type::tint32);
773 return new DImValue(type, gIR->ir->CreateAlloca(LLType::Int8Ty, expv->getRVal(), ".alloca")); 773 return new DImValue(type, DtoAlloca(LLType::Int8Ty, expv->getRVal(), ".alloca"));
774 } 774 }
775 } 775 }
776 776
777 return DtoCallFunction(loc, type, fnval, arguments); 777 return DtoCallFunction(loc, type, fnval, arguments);
778 } 778 }
1593 LOG_SCOPE; 1593 LOG_SCOPE;
1594 1594
1595 // allocate a temporary for the final result. failed to come up with a better way :/ 1595 // allocate a temporary for the final result. failed to come up with a better way :/
1596 LLValue* resval = 0; 1596 LLValue* resval = 0;
1597 llvm::BasicBlock* entryblock = &p->topfunc()->front(); 1597 llvm::BasicBlock* entryblock = &p->topfunc()->front();
1598 resval = new llvm::AllocaInst(LLType::Int1Ty,"andandtmp",p->topallocapoint()); 1598 resval = DtoAlloca(LLType::Int1Ty,"andandtmp");
1599 1599
1600 DValue* u = e1->toElem(p); 1600 DValue* u = e1->toElem(p);
1601 1601
1602 llvm::BasicBlock* oldend = p->scopeend(); 1602 llvm::BasicBlock* oldend = p->scopeend();
1603 llvm::BasicBlock* andand = llvm::BasicBlock::Create("andand", gIR->topfunc(), oldend); 1603 llvm::BasicBlock* andand = llvm::BasicBlock::Create("andand", gIR->topfunc(), oldend);
1629 LOG_SCOPE; 1629 LOG_SCOPE;
1630 1630
1631 // allocate a temporary for the final result. failed to come up with a better way :/ 1631 // allocate a temporary for the final result. failed to come up with a better way :/
1632 LLValue* resval = 0; 1632 LLValue* resval = 0;
1633 llvm::BasicBlock* entryblock = &p->topfunc()->front(); 1633 llvm::BasicBlock* entryblock = &p->topfunc()->front();
1634 resval = new llvm::AllocaInst(LLType::Int1Ty,"orortmp",p->topallocapoint()); 1634 resval = DtoAlloca(LLType::Int1Ty,"orortmp");
1635 1635
1636 DValue* u = e1->toElem(p); 1636 DValue* u = e1->toElem(p);
1637 1637
1638 llvm::BasicBlock* oldend = p->scopeend(); 1638 llvm::BasicBlock* oldend = p->scopeend();
1639 llvm::BasicBlock* oror = llvm::BasicBlock::Create("oror", gIR->topfunc(), oldend); 1639 llvm::BasicBlock* oror = llvm::BasicBlock::Create("oror", gIR->topfunc(), oldend);
1756 if(func->isStatic()) 1756 if(func->isStatic())
1757 error("can't take delegate of static function %s, it does not require a context ptr", func->toChars()); 1757 error("can't take delegate of static function %s, it does not require a context ptr", func->toChars());
1758 1758
1759 const LLPointerType* int8ptrty = getPtrToType(LLType::Int8Ty); 1759 const LLPointerType* int8ptrty = getPtrToType(LLType::Int8Ty);
1760 1760
1761 LLValue* lval = new llvm::AllocaInst(DtoType(type), "tmpdelegate", p->topallocapoint()); 1761 LLValue* lval = DtoAlloca(DtoType(type), "tmpdelegate");
1762 1762
1763 DValue* u = e1->toElem(p); 1763 DValue* u = e1->toElem(p);
1764 LLValue* uval; 1764 LLValue* uval;
1765 if (DFuncValue* f = u->isFunc()) { 1765 if (DFuncValue* f = u->isFunc()) {
1766 assert(f->func); 1766 assert(f->func);
1895 Type* dtype = DtoDType(type); 1895 Type* dtype = DtoDType(type);
1896 const LLType* resty = DtoType(dtype); 1896 const LLType* resty = DtoType(dtype);
1897 1897
1898 // allocate a temporary for the final result. failed to come up with a better way :/ 1898 // allocate a temporary for the final result. failed to come up with a better way :/
1899 llvm::BasicBlock* entryblock = &p->topfunc()->front(); 1899 llvm::BasicBlock* entryblock = &p->topfunc()->front();
1900 LLValue* resval = new llvm::AllocaInst(resty,"condtmp",p->topallocapoint()); 1900 LLValue* resval = DtoAlloca(resty,"condtmp");
1901 DVarValue* dvv = new DVarValue(type, resval, true); 1901 DVarValue* dvv = new DVarValue(type, resval, true);
1902 1902
1903 llvm::BasicBlock* oldend = p->scopeend(); 1903 llvm::BasicBlock* oldend = p->scopeend();
1904 llvm::BasicBlock* condtrue = llvm::BasicBlock::Create("condtrue", gIR->topfunc(), oldend); 1904 llvm::BasicBlock* condtrue = llvm::BasicBlock::Create("condtrue", gIR->topfunc(), oldend);
1905 llvm::BasicBlock* condfalse = llvm::BasicBlock::Create("condfalse", gIR->topfunc(), oldend); 1905 llvm::BasicBlock* condfalse = llvm::BasicBlock::Create("condfalse", gIR->topfunc(), oldend);
2032 Logger::println("kind = %s\n", fd->kind()); 2032 Logger::println("kind = %s\n", fd->kind());
2033 2033
2034 DtoForceDefineDsymbol(fd); 2034 DtoForceDefineDsymbol(fd);
2035 2035
2036 const LLType* dgty = DtoType(type); 2036 const LLType* dgty = DtoType(type);
2037 LLValue* lval = new llvm::AllocaInst(dgty,"dgstorage",p->topallocapoint()); 2037 LLValue* lval = DtoAlloca(dgty,"dgstorage");
2038 2038
2039 LLValue* context = DtoGEPi(lval,0,0); 2039 LLValue* context = DtoGEPi(lval,0,0);
2040 const LLPointerType* pty = isaPointer(context->getType()->getContainedType(0)); 2040 const LLPointerType* pty = isaPointer(context->getType()->getContainedType(0));
2041 LLValue* llvmNested = p->func()->decl->ir.irFunc->nestedVar; 2041 LLValue* llvmNested = p->func()->decl->ir.irFunc->nestedVar;
2042 if (llvmNested == NULL) { 2042 if (llvmNested == NULL) {
2083 const LLType* llStoType = LLArrayType::get(DtoType(elemType), len); 2083 const LLType* llStoType = LLArrayType::get(DtoType(elemType), len);
2084 Logger::cout() << "llvm storage type: '" << *llStoType << "'\n"; 2084 Logger::cout() << "llvm storage type: '" << *llStoType << "'\n";
2085 2085
2086 // dst pointer 2086 // dst pointer
2087 LLValue* dstMem = 0; 2087 LLValue* dstMem = 0;
2088 dstMem = new llvm::AllocaInst(llStoType, "arrayliteral", p->topallocapoint()); 2088 dstMem = DtoAlloca(llStoType, "arrayliteral");
2089 2089
2090 // store elements 2090 // store elements
2091 for (size_t i=0; i<len; ++i) 2091 for (size_t i=0; i<len; ++i)
2092 { 2092 {
2093 Expression* expr = (Expression*)elements->data[i]; 2093 Expression* expr = (Expression*)elements->data[i];
2141 2141
2142 const LLType* llt = DtoType(type); 2142 const LLType* llt = DtoType(type);
2143 2143
2144 LLValue* mem = 0; 2144 LLValue* mem = 0;
2145 2145
2146 LLValue* sptr = new llvm::AllocaInst(llt,"tmpstructliteral",p->topallocapoint()); 2146 LLValue* sptr = DtoAlloca(llt,"tmpstructliteral");
2147 2147
2148 2148
2149 // num elements in literal 2149 // num elements in literal
2150 unsigned n = elements->dim; 2150 unsigned n = elements->dim;
2151 2151
2253 Type* aatype = DtoDType(type); 2253 Type* aatype = DtoDType(type);
2254 Type* vtype = aatype->next; 2254 Type* vtype = aatype->next;
2255 const LLType* aalltype = DtoType(type); 2255 const LLType* aalltype = DtoType(type);
2256 2256
2257 // it should be possible to avoid the temporary in some cases 2257 // it should be possible to avoid the temporary in some cases
2258 LLValue* tmp = new llvm::AllocaInst(aalltype,"aaliteral",p->topallocapoint()); 2258 LLValue* tmp = DtoAlloca(aalltype,"aaliteral");
2259 DValue* aa = new DVarValue(type, tmp, true); 2259 DValue* aa = new DVarValue(type, tmp, true);
2260 DtoStore(LLConstant::getNullValue(aalltype), tmp); 2260 DtoStore(LLConstant::getNullValue(aalltype), tmp);
2261 2261
2262 const size_t n = keys->dim; 2262 const size_t n = keys->dim;
2263 for (size_t i=0; i<n; ++i) 2263 for (size_t i=0; i<n; ++i)