Mercurial > projects > ldc
diff gen/nested.cpp @ 1210:3d4581761b4c
Add some alignment info where LLVM might otherwise be more pessimistic.
In particular, %.nest_arg is always aligned even though it's bitcast from i8*.
Pointers in vtables are also guaranteed to be stored at aligned addresses.
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Sun, 12 Apr 2009 21:56:43 +0200 |
parents | 8699c450a1a0 |
children | df2227fdc860 |
line wrap: on
line diff
--- a/gen/nested.cpp Sun Apr 12 20:23:00 2009 +0200 +++ b/gen/nested.cpp Sun Apr 12 21:56:43 2009 +0200 @@ -96,7 +96,7 @@ if (nestedCtx == NCArray) { LLValue* val = DtoBitCast(ctx, getPtrToType(getVoidPtrType())); val = DtoGEPi1(val, vd->ir.irLocal->nestedIndex); - val = DtoLoad(val); + val = DtoAlignedLoad(val); assert(vd->ir.irLocal->value); val = DtoBitCast(val, vd->ir.irLocal->value->getType(), vd->toChars()); return new DVarValue(astype, vd, val); @@ -107,10 +107,10 @@ LLValue* val = DtoBitCast(ctx, LLPointerType::getUnqual(parentfunc->ir.irFunc->framesType)); val = DtoGEPi(val, 0, vd->ir.irLocal->nestedDepth); - val = DtoLoad(val, (std::string(".frame.") + parentfunc->toChars()).c_str()); + val = DtoAlignedLoad(val, (std::string(".frame.") + parentfunc->toChars()).c_str()); val = DtoGEPi(val, 0, vd->ir.irLocal->nestedIndex, vd->toChars()); if (vd->ir.irLocal->byref) - val = DtoLoad(val); + val = DtoAlignedLoad(val); return new DVarValue(astype, vd, val); } else { @@ -137,7 +137,7 @@ assert(isaPointer(vd->ir.irLocal->value)); LLValue* val = DtoBitCast(vd->ir.irLocal->value, getVoidPtrType()); - DtoStore(val, gep); + DtoAlignedStore(val, gep); } else if (nestedCtx == NCHybrid) { assert(vd->ir.irLocal->value && "Nested variable without storage?"); @@ -147,10 +147,10 @@ FuncDeclaration *parentfunc = getParentFunc(vd); assert(parentfunc && "No parent function for nested variable?"); - LLValue* frame = DtoLoad(framep, (std::string(".frame.") + parentfunc->toChars()).c_str()); + LLValue* frame = DtoAlignedLoad(framep, (std::string(".frame.") + parentfunc->toChars()).c_str()); LLValue* slot = DtoGEPi(frame, 0, vd->ir.irLocal->nestedIndex); - DtoStore(vd->ir.irLocal->value, slot); + DtoAlignedStore(vd->ir.irLocal->value, slot); } else { // Already initialized in DtoCreateNestedContext } @@ -248,7 +248,8 @@ assert(cd->vthis); src = DtoLoad(DtoGEPi(thisval, 0,cd->vthis->ir.irField->index, ".vthis")); } - DtoMemCpy(nestedVars, src, DtoConstSize_t(nparelems*PTRSIZE)); + DtoMemCpy(nestedVars, src, DtoConstSize_t(nparelems*PTRSIZE), + getABITypeAlign(getVoidPtrType())); } // store in IrFunction @@ -267,7 +268,7 @@ Logger::println("nested param: %s", vd->toChars()); LLValue* gep = DtoGEPi(nestedVars, 0, idx); LLValue* val = DtoBitCast(vd->ir.irLocal->value, getVoidPtrType()); - DtoStore(val, gep); + DtoAlignedStore(val, gep); } else { @@ -367,13 +368,14 @@ } src = DtoBitCast(src, getVoidPtrType()); LLValue* dst = DtoBitCast(nestedVars, getVoidPtrType()); - DtoMemCpy(dst, src, DtoConstSize_t(depth * PTRSIZE)); + DtoMemCpy(dst, src, DtoConstSize_t(depth * PTRSIZE), + getABITypeAlign(getVoidPtrType())); } // Create frame for current function and append to frames list LLValue* frame = DtoAlloca(frameType, ".frame"); // store current frame in list - DtoStore(frame, DtoGEPi(nestedVars, 0, depth)); + DtoAlignedStore(frame, DtoGEPi(nestedVars, 0, depth)); // store context in IrFunction irfunction->nestedVar = nestedVars; @@ -386,7 +388,7 @@ LLValue* gep = DtoGEPi(frame, 0, vd->ir.irLocal->nestedIndex, vd->toChars()); if (vd->isParameter()) { Logger::println("nested param: %s", vd->toChars()); - DtoStore(vd->ir.irLocal->value, gep); + DtoAlignedStore(vd->ir.irLocal->value, gep); vd->ir.irLocal->byref = true; } else if (vd->isRef() || vd->isOut()) { // This slot is initialized in DtoNestedInit, to handle things like byref foreach variables