# HG changeset patch # User ChristianK # Date 1215870193 -7200 # Node ID 20446d22f83262add6b8f50fab4ca9d407b4c2d4 # Parent f7190d9eb70c052cd490d6106292a1c92dbf4170 [svn r355] Get rid of IRState::exps and topexp. diff -r f7190d9eb70c -r 20446d22f832 gen/arrays.cpp --- a/gen/arrays.cpp Sat Jul 12 09:23:14 2008 +0200 +++ b/gen/arrays.cpp Sat Jul 12 15:43:13 2008 +0200 @@ -528,9 +528,7 @@ DValue* dptr = new DVarValue(exp->type, ptr, true); - gIR->exps.push_back(IRExp(0,exp,dptr)); DValue* e = exp->toElem(gIR); - gIR->exps.pop_back(); if (!e->inPlace()) DtoAssign(dptr, e); diff -r f7190d9eb70c -r 20446d22f832 gen/dvalue.cpp --- a/gen/dvalue.cpp Sat Jul 12 09:23:14 2008 +0200 +++ b/gen/dvalue.cpp Sat Jul 12 15:43:13 2008 +0200 @@ -72,12 +72,6 @@ cc = (unsigned)-1; } -LLValue* DFuncValue::getLVal() -{ - assert(0); - return 0; -} - LLValue* DFuncValue::getRVal() { assert(val); diff -r f7190d9eb70c -r 20446d22f832 gen/dvalue.h --- a/gen/dvalue.h Sat Jul 12 09:23:14 2008 +0200 +++ b/gen/dvalue.h Sat Jul 12 15:43:13 2008 +0200 @@ -42,6 +42,8 @@ virtual LLValue* getLVal() { assert(0); return 0; } virtual LLValue* getRVal() { assert(0); return 0; } + virtual bool isLVal() { return false; } + virtual DImValue* isIm() { return NULL; } virtual DConstValue* isConst() { return NULL; } virtual DNullValue* isNull() { return NULL; } @@ -113,6 +115,7 @@ DVarValue(Type* vd, LLValue* lv, LLValue* rv); DVarValue(Type* t, LLValue* llvmValue, bool lvalue); + virtual bool isLVal() { return val && lval; } virtual LLValue* getLVal(); virtual LLValue* getRVal(); @@ -134,13 +137,6 @@ virtual DThisValue* isThis() { return this; } }; -// array length d-value -struct DArrayLenValue : DVarValue -{ - DArrayLenValue(Type* t, LLValue* llvmValue) : DVarValue(t, llvmValue, true) {} - virtual DArrayLenValue* isArrayLen() { return this; } -}; - // slice d-value struct DSliceValue : DValue { @@ -165,7 +161,6 @@ DFuncValue(FuncDeclaration* fd, LLValue* v, LLValue* vt = 0); - virtual LLValue* getLVal(); virtual LLValue* getRVal(); virtual Type* getType() { assert(type); return type; } @@ -187,6 +182,7 @@ rval = r; } + virtual bool isLVal() { return lval; } virtual LLValue* getLVal() { assert(lval); return lval; } virtual LLValue* getRVal() { assert(rval); return rval; } @@ -196,6 +192,13 @@ virtual DLRValue* isLRValue() { return this; } }; +// array length d-value +struct DArrayLenValue : DLRValue +{ + DArrayLenValue(Type* lt, LLValue* l, Type* rt, LLValue* r) : DLRValue(lt, l, rt, r) {} + virtual DArrayLenValue* isArrayLen() { return this; } +}; + // complex number immediate d-value (much like slice) struct DComplexValue : DValue { diff -r f7190d9eb70c -r 20446d22f832 gen/functions.cpp --- a/gen/functions.cpp Sat Jul 12 09:23:14 2008 +0200 +++ b/gen/functions.cpp Sat Jul 12 15:43:13 2008 +0200 @@ -828,9 +828,7 @@ Logger::println("DtoVariadicArgument"); LOG_SCOPE; DVarValue* vv = new DVarValue(argexp->type, dst, true); - gIR->exps.push_back(IRExp(NULL, argexp, vv)); DtoAssign(vv, argexp->toElem(gIR)); - gIR->exps.pop_back(); } ////////////////////////////////////////////////////////////////////////////////////////// diff -r f7190d9eb70c -r 20446d22f832 gen/irstate.cpp --- a/gen/irstate.cpp Sat Jul 12 09:23:14 2008 +0200 +++ b/gen/irstate.cpp Sat Jul 12 15:43:13 2008 +0200 @@ -95,11 +95,6 @@ return structs.back(); } -IRExp* IRState::topexp() -{ - return exps.empty() ? NULL : &exps.back(); -} - IRScope& IRState::scope() { assert(!scopes.empty()); @@ -173,18 +168,3 @@ assert(b.GetInsertBlock() != NULL); return &b; } - -////////////////////////////////////////////////////////////////////////////////////////// - -IRExp::IRExp() -{ - e1 = e2 = NULL; - v = NULL; -} - -IRExp::IRExp(Expression* l, Expression* r, DValue* val) -{ - e1 = l; - e2 = r; - v = val; -} diff -r f7190d9eb70c -r 20446d22f832 gen/irstate.h --- a/gen/irstate.h Sat Jul 12 09:23:14 2008 +0200 +++ b/gen/irstate.h Sat Jul 12 15:43:13 2008 +0200 @@ -59,15 +59,6 @@ IRBuilder* operator->(); }; -struct IRExp -{ - Expression* e1; - Expression* e2; - DValue* v; - IRExp(); - IRExp(Expression* l, Expression* r, DValue* val); -}; - struct IRAsmStmt { std::string code; @@ -161,11 +152,6 @@ bool emitMain; llvm::Function* mainFunc; - // expression l/r value handling - typedef std::vector ExpVec; - ExpVec exps; - IRExp* topexp(); - // basic block scopes std::vector scopes; IRScope& scope(); diff -r f7190d9eb70c -r 20446d22f832 gen/statements.cpp --- a/gen/statements.cpp Sat Jul 12 09:23:14 2008 +0200 +++ b/gen/statements.cpp Sat Jul 12 15:43:13 2008 +0200 @@ -64,9 +64,7 @@ DValue* rvar = new DVarValue(f->type->next, f->decl->ir.irFunc->retArg, true); - p->exps.push_back(IRExp(NULL,exp,rvar)); DValue* e = exp->toElem(p); - p->exps.pop_back(); if (!e->inPlace()) DtoAssign(rvar, e); diff -r f7190d9eb70c -r 20446d22f832 gen/toir.cpp --- a/gen/toir.cpp Sat Jul 12 09:23:14 2008 +0200 +++ b/gen/toir.cpp Sat Jul 12 15:43:13 2008 +0200 @@ -470,23 +470,9 @@ if (dtype->ty == Tarray) { LLConstant* clen = llvm::ConstantInt::get(DtoSize_t(),len,false); - if (!p->topexp() || p->topexp()->e2 != this) { - LLValue* tmpmem = new llvm::AllocaInst(DtoType(dtype),"tempstring",p->topallocapoint()); - DtoSetArray(tmpmem, clen, arrptr); - return new DVarValue(type, tmpmem, true); - } - else if (p->topexp()->e2 == this) { - DValue* arr = p->topexp()->v; - assert(arr); - if (arr->isSlice()) { - return new DSliceValue(type, clen, arrptr); - } - else { - DtoSetArray(arr->getRVal(), clen, arrptr); - return new DImValue(type, arr->getLVal(), true); - } - } - assert(0); + LLValue* tmpmem = new llvm::AllocaInst(DtoType(dtype),"tempstring",p->topallocapoint()); + DtoSetArray(tmpmem, clen, arrptr); + return new DVarValue(type, tmpmem, true); } else if (dtype->ty == Tsarray) { const LLType* dstType = getPtrToType(LLArrayType::get(ct, len)); @@ -577,14 +563,9 @@ Logger::print("AssignExp::toElem: %s | %s = %s\n", toChars(), e1->type->toChars(), e2->type ? e2->type->toChars() : 0); LOG_SCOPE; - p->exps.push_back(IRExp(e1,e2,NULL)); - DValue* l = e1->toElem(p); - p->topexp()->v = l; DValue* r = e2->toElem(p); - p->exps.pop_back(); - Logger::println("performing assignment"); DImValue* im = r->isIm(); @@ -592,8 +573,11 @@ Logger::println("assignment not inplace"); if (DArrayLenValue* al = l->isArrayLen()) { - DSliceValue* slice = DtoResizeDynArray(l->getType(), l, r); - DtoAssign(l, slice); + DLRValue* arrlenval = l->isLRValue(); + assert(arrlenval); + DVarValue arrval(arrlenval->getLType(), arrlenval->getLVal(), true); + DSliceValue* slice = DtoResizeDynArray(arrval.getType(), &arrval, r); + DtoAssign(&arrval, slice); } else { @@ -672,10 +656,8 @@ Logger::print("AddAssignExp::toElem: %s\n", toChars()); LOG_SCOPE; - p->exps.push_back(IRExp(e1,e2,NULL)); DValue* l = e1->toElem(p); DValue* r = e2->toElem(p); - p->exps.pop_back(); Type* t = DtoDType(type); @@ -692,16 +674,9 @@ } DtoAssign(l, res); - // used as lvalue :/ - if (p->topexp() && p->topexp()->e1 == this) - { - assert(!l->isLRValue()); - return l; - } - else - { - return res; - } + // might need to return l here if used as an lvalue + // but when can this ever happen? + return res; } ////////////////////////////////////////////////////////////////////////////////////////// @@ -1030,31 +1005,13 @@ LLFunctionType::param_iterator argiter = llfnty->param_begin(); int j = 0; - IRExp* topexp = p->topexp(); - - bool isInPlace = false; - // attrs llvm::PAListPtr palist; // hidden struct return arguments // TODO: use sret param attr if (retinptr) { - if (topexp && topexp->e2 == this) { - assert(topexp->v); - LLValue* tlv = topexp->v->getLVal(); - assert(isaStruct(tlv->getType()->getContainedType(0))); - llargs[j] = tlv; - isInPlace = true; - /*if (DtoIsPassedByRef(tf->next)) { - isInPlace = true; - } - else - assert(0);*/ - } - else { - llargs[j] = new llvm::AllocaInst(argiter->get()->getContainedType(0),"rettmp",p->topallocapoint()); - } + llargs[j] = new llvm::AllocaInst(argiter->get()->getContainedType(0),"rettmp",p->topallocapoint()); if (dfn && dfn->func && dfn->func->runTimeHack) { const LLType* rettype = getPtrToType(DtoType(type)); @@ -1288,7 +1245,7 @@ // param attrs call->setParamAttrs(palist); - return new DImValue(type, retllval, isInPlace); + return new DImValue(type, retllval, false); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -1302,20 +1259,15 @@ DValue* v = DtoCast(u, to); if (v->isSlice()) { - assert(!gIR->topexp() || gIR->topexp()->e1 != this); + // only valid as rvalue! return v; } - else if (DLRValue* lr = u->isLRValue()) - return new DLRValue(lr->getLType(), lr->getLVal(), to, v->getRVal()); - - else if (u->isVar() && u->isVar()->lval) + else if(u->isLVal()) return new DLRValue(e1->type, u->getLVal(), to, v->getRVal()); - else if (gIR->topexp() && gIR->topexp()->e1 == this) - return new DLRValue(e1->type, u->getLVal(), to, v->getRVal()); - - return v; + else + return v; } ////////////////////////////////////////////////////////////////////////////////////////// @@ -1365,17 +1317,12 @@ DValue* a = e1->toElem(p); - if (p->topexp() && p->topexp()->e1 == this) { - Logger::println("lval PtrExp"); - return new DVarValue(type, a->getRVal(), true); - } - // this should be deterministic but right now lvalue casts don't propagate lvalueness !?! LLValue* lv = a->getRVal(); LLValue* v = lv; if (DtoCanLoad(v)) v = DtoLoad(v); - return new DLRValue(e1->type, lv, type, v); + return new DLRValue(type, lv, type, v); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -2000,14 +1947,7 @@ DValue* u = e1->toElem(p); Logger::println("e1 = %s", e1->type->toChars()); - if (p->topexp() && p->topexp()->e1 == this) - { - return new DArrayLenValue(e1->type, u->getLVal()); - } - else - { - return new DImValue(type, DtoArrayLen(u)); - } + return new DArrayLenValue(e1->type, u->getLVal(), type, DtoArrayLen(u)); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -2152,11 +2092,8 @@ { \ Logger::print("%sAssignExp::toElem: %s | %s\n", #X, toChars(), type->toChars()); \ LOG_SCOPE; \ - p->exps.push_back(IRExp(e1,e2,NULL)); \ DValue* u = e1->toElem(p); \ - p->topexp()->v = u; \ DValue* v = e2->toElem(p); \ - p->exps.pop_back(); \ LLValue* uval = u->getRVal(); \ LLValue* vval = v->getRVal(); \ LLValue* tmp = llvm::BinaryOperator::create(llvm::Instruction::Y, uval, vval, "tmp", p->scopebb()); \ @@ -2189,11 +2126,8 @@ { Logger::print("ShrAssignExp::toElem: %s | %s\n", toChars(), type->toChars()); LOG_SCOPE; - p->exps.push_back(IRExp(e1,e2,NULL)); DValue* u = e1->toElem(p); - p->topexp()->v = u; DValue* v = e2->toElem(p); - p->exps.pop_back(); LLValue* uval = u->getRVal(); LLValue* vval = v->getRVal(); LLValue* tmp; @@ -2239,16 +2173,7 @@ const LLPointerType* int8ptrty = getPtrToType(LLType::Int8Ty); - LLValue* lval; - bool inplace = false; - if (p->topexp() && p->topexp()->e2 == this) { - assert(p->topexp()->v); - lval = p->topexp()->v->getLVal(); - inplace = true; - } - else { - lval = new llvm::AllocaInst(DtoType(type), "tmpdelegate", p->topallocapoint()); - } + LLValue* lval = new llvm::AllocaInst(DtoType(type), "tmpdelegate", p->topallocapoint()); DValue* u = e1->toElem(p); LLValue* uval; @@ -2300,7 +2225,7 @@ castfptr = DtoBitCast(castfptr, fptr->getType()->getContainedType(0)); DtoStore(castfptr, fptr); - return new DImValue(type, lval, inplace); + return new DImValue(type, lval); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -2517,18 +2442,8 @@ DtoForceDefineDsymbol(fd); - bool temp = false; - LLValue* lval = NULL; - if (p->topexp() && p->topexp()->e2 == this) { - assert(p->topexp()->v); - lval = p->topexp()->v->getLVal(); - } - else { - const LLType* dgty = DtoType(type); - Logger::cout() << "delegate without explicit storage:" << '\n' << *dgty << '\n'; - lval = new llvm::AllocaInst(dgty,"dgstorage",p->topallocapoint()); - temp = true; - } + const LLType* dgty = DtoType(type); + LLValue* lval = new llvm::AllocaInst(dgty,"dgstorage",p->topallocapoint()); LLValue* context = DtoGEPi(lval,0,0); const LLPointerType* pty = isaPointer(context->getType()->getContainedType(0)); @@ -2548,10 +2463,7 @@ LLValue* castfptr = DtoBitCast(fd->ir.irFunc->func, fptr->getType()->getContainedType(0)); DtoStore(castfptr, fptr); - if (temp) - return new DVarValue(type, lval, true); - else - return new DImValue(type, lval, true); + return new DVarValue(type, lval, true); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -2582,33 +2494,7 @@ // dst pointer LLValue* dstMem = 0; - - // rvalue of assignment - if (p->topexp() && p->topexp()->e2 == this) - { - DValue* topval = p->topexp()->v; - // slice assignment (copy) - if (DSliceValue* s = topval->isSlice()) - { - assert(s->ptr->getType()->getContainedType(0) == llStoType->getContainedType(0)); - dstMem = DtoBitCast(s->ptr, getPtrToType(llStoType)); - sliceInPlace = true; - // FIXME: insert bounds checks - } - // static array assignment - else if (topval->getType()->toBasetype()->ty == Tsarray) - { - dstMem = topval->getLVal(); - } - // otherwise we still need to alloca storage - } - - // alloca storage if not found already - if (!dstMem) - { - dstMem = new llvm::AllocaInst(llStoType, "arrayliteral", p->topallocapoint()); - } - Logger::cout() << "using dest mem: " << *dstMem << '\n'; + dstMem = new llvm::AllocaInst(llStoType, "arrayliteral", p->topallocapoint()); // store elements for (size_t i=0; itype, elemAddr, true); - p->exps.push_back(IRExp(NULL, expr, vv)); DValue* e = expr->toElem(p); - p->exps.pop_back(); DImValue* im = e->isIm(); if (!im || !im->inPlace()) { DtoAssign(vv, e); @@ -2629,7 +2513,7 @@ // return storage directly ? if (!dyn || (dyn && sliceInPlace)) - return new DImValue(type, dstMem, true); + return new DImValue(type, dstMem, false); // wrap in a slice return new DSliceValue(type, DtoConstSize_t(len), DtoGEPi(dstMem,0,0,"tmp")); } @@ -2664,25 +2548,11 @@ Logger::print("StructLiteralExp::toElem: %s | %s\n", toChars(), type->toChars()); LOG_SCOPE; - LLValue* sptr; const LLType* llt = DtoType(type); LLValue* mem = 0; - bool isinplace = true; - - // already has memory (r-value of assignment) - IRExp* topexp = p->topexp(); - if (topexp && topexp->e2 == this && !topexp->v->isSlice()) - { - assert(topexp->e2 == this); - sptr = topexp->v->getLVal(); - } - // temporary struct literal - else - { - sptr = new llvm::AllocaInst(llt,"tmpstructliteral",p->topallocapoint()); - isinplace = false; - } + + LLValue* sptr = new llvm::AllocaInst(llt,"tmpstructliteral",p->topallocapoint()); // num elements in literal @@ -2719,9 +2589,7 @@ LLValue* arrptr = DtoGEPi(sptr,0,j); DValue* darrptr = new DVarValue(vx->type, arrptr, true); - p->exps.push_back(IRExp(NULL,vx,darrptr)); DValue* ve = vx->toElem(p); - p->exps.pop_back(); if (!ve->inPlace()) DtoAssign(darrptr, ve); @@ -2729,7 +2597,7 @@ j++; } - return new DImValue(type, sptr, isinplace); + return new DImValue(type, sptr); } //////////////////////////////////////////////////////////////////////////////////////////