# HG changeset patch # User lindquist # Date 1191909073 -7200 # Node ID c0967c4b2a7473e73705847c7933b927f1619dae # Parent 3cfcb944304e17d3d9e6975c961dd2345ab8e345 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset. Resizing arrays did not allocate enough memory for types bigger than 1 byte. diff -r 3cfcb944304e -r c0967c4b2a74 dmd/Doxyfile --- a/dmd/Doxyfile Tue Oct 09 06:21:30 2007 +0200 +++ b/dmd/Doxyfile Tue Oct 09 07:51:13 2007 +0200 @@ -25,13 +25,13 @@ # The PROJECT_NAME tag is a single word (or a sequence of words surrounded # by quotes) that should identify the project. -PROJECT_NAME = DMDFE +PROJECT_NAME = DMD # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = 1.020 +PROJECT_NUMBER = 1.022 # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # base path where the generated documentation will be put. diff -r 3cfcb944304e -r c0967c4b2a74 gen/arrays.c --- a/gen/arrays.c Tue Oct 09 06:21:30 2007 +0200 +++ b/gen/arrays.c Tue Oct 09 07:51:13 2007 +0200 @@ -71,29 +71,18 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* LLVM_DtoNullArray(llvm::Value* v) +void LLVM_DtoNullArray(llvm::Value* v) { assert(gIR); - d_uns64 n = (global.params.is64bit) ? 16 : 8; - llvm::Type* i8p_ty = llvm::PointerType::get(llvm::Type::Int8Ty); - - llvm::Value* arr = new llvm::BitCastInst(v,i8p_ty,"tmp",gIR->scopebb()); + llvm::Value* len = LLVM_DtoGEPi(v,0,0,"tmp",gIR->scopebb()); + llvm::Value* zerolen = llvm::ConstantInt::get(len->getType()->getContainedType(0), 0, false); + new llvm::StoreInst(zerolen, len, gIR->scopebb()); - llvm::Function* fn = LLVM_DeclareMemSet32(); - std::vector llargs; - llargs.resize(4); - llargs[0] = arr; - llargs[1] = llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false); - llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false); - llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); - - //Logger::cout() << *fn << '|' << *fn->getType() << '\n'; - //Logger::cout() << "to null array call: " << *llargs[0] << '|' << *llargs[1] << '|' << *llargs[2] << '|' << *llargs[3] << '\n'; - - llvm::Value* ret = new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); - - return ret; + llvm::Value* ptr = LLVM_DtoGEPi(v,0,1,"tmp",gIR->scopebb()); + const llvm::PointerType* pty = llvm::cast(ptr->getType()->getContainedType(0)); + llvm::Value* nullptr = llvm::ConstantPointerNull::get(pty); + new llvm::StoreInst(nullptr, ptr, gIR->scopebb()); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -103,22 +92,15 @@ assert(gIR); if (dst->getType() == src->getType()) { - d_uns64 n = (global.params.is64bit) ? 16 : 8; - - llvm::Type* arrty = llvm::PointerType::get(llvm::Type::Int8Ty); - - llvm::Value* dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb()); - llvm::Value* srcarr = new llvm::BitCastInst(src,arrty,"tmp",gIR->scopebb()); + llvm::Value* ptr = LLVM_DtoGEPi(src,0,0,"tmp",gIR->scopebb()); + llvm::Value* val = new llvm::LoadInst(ptr,"tmp",gIR->scopebb()); + ptr = LLVM_DtoGEPi(dst,0,0,"tmp",gIR->scopebb()); + new llvm::StoreInst(val, ptr, gIR->scopebb()); - llvm::Function* fn = LLVM_DeclareMemCpy32(); - std::vector llargs; - llargs.resize(4); - llargs[0] = dstarr; - llargs[1] = srcarr; - llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false); - llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); - - new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); + ptr = LLVM_DtoGEPi(src,0,1,"tmp",gIR->scopebb()); + val = new llvm::LoadInst(ptr,"tmp",gIR->scopebb()); + ptr = LLVM_DtoGEPi(dst,0,1,"tmp",gIR->scopebb()); + new llvm::StoreInst(val, ptr, gIR->scopebb()); } else { @@ -347,7 +329,6 @@ return ret; } -////////////////////////////////////////////////////////////////////////////////////////// void LLVM_DtoArrayCopy(elem* dst, elem* src) { Logger::cout() << "Array copy ((((" << *src->mem << ")))) into ((((" << *dst->mem << "))))\n"; @@ -358,8 +339,9 @@ llvm::Type* arrty = llvm::PointerType::get(llvm::Type::Int8Ty); llvm::Value* sz1; + llvm::Value* dstarr = new llvm::BitCastInst(get_slice_ptr(dst,sz1),arrty,"tmp",gIR->scopebb()); + llvm::Value* sz2; - llvm::Value* dstarr = new llvm::BitCastInst(get_slice_ptr(dst,sz1),arrty,"tmp",gIR->scopebb()); llvm::Value* srcarr = new llvm::BitCastInst(get_slice_ptr(src,sz2),arrty,"tmp",gIR->scopebb()); llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32(); @@ -408,8 +390,14 @@ { llvm::Value* ptr = LLVM_DtoGEPi(arr, 0, 1, "tmp", gIR->scopebb()); llvm::Value* ptrld = new llvm::LoadInst(ptr,"tmp",gIR->scopebb()); - llvm::Value* newptr = LLVM_DtoRealloc(ptrld, sz); + + size_t isz = gTargetData->getTypeSize(ptrld->getType()->getContainedType(0)); + llvm::ConstantInt* n = llvm::ConstantInt::get(LLVM_DtoSize_t(), isz, false); + llvm::Value* bytesz = llvm::BinaryOperator::createMul(n,sz,"tmp",gIR->scopebb()); + + llvm::Value* newptr = LLVM_DtoRealloc(ptrld, bytesz); new llvm::StoreInst(newptr,ptr,gIR->scopebb()); + llvm::Value* len = LLVM_DtoGEPi(arr, 0, 0, "tmp", gIR->scopebb()); new llvm::StoreInst(sz,len,gIR->scopebb()); } diff -r 3cfcb944304e -r c0967c4b2a74 gen/arrays.h --- a/gen/arrays.h Tue Oct 09 06:21:30 2007 +0200 +++ b/gen/arrays.h Tue Oct 09 07:51:13 2007 +0200 @@ -11,7 +11,7 @@ void LLVM_DtoArrayInit(llvm::Value* l, llvm::Value* r); void LLVM_DtoArrayAssign(llvm::Value* l, llvm::Value* r); void LLVM_DtoSetArray(llvm::Value* arr, llvm::Value* dim, llvm::Value* ptr); -llvm::Value* LLVM_DtoNullArray(llvm::Value* v); +void LLVM_DtoNullArray(llvm::Value* v); void LLVM_DtoNewDynArray(llvm::Value* dst, llvm::Value* dim, const llvm::Type* ty); void LLVM_DtoResizeDynArray(llvm::Value* arr, llvm::Value* sz); diff -r 3cfcb944304e -r c0967c4b2a74 gen/toir.c --- a/gen/toir.c Tue Oct 09 06:21:30 2007 +0200 +++ b/gen/toir.c Tue Oct 09 07:51:13 2007 +0200 @@ -2158,21 +2158,10 @@ Logger::print("HaltExp::toElem: %s | %s\n", toChars(), type->toChars()); LOG_SCOPE; - std::vector llargs; - llargs.resize(3); - llargs[0] = llvm::ConstantInt::get(llvm::Type::Int1Ty, 0, false); - llargs[1] = llvm::ConstantInt::get(llvm::Type::Int32Ty, loc.linnum, false); - llargs[2] = llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty)); - - //Logger::cout() << *llargs[0] << '|' << *llargs[1] << '\n'; - - llvm::Function* fn = LLVM_D_GetRuntimeFunction(p->module, "_d_assert"); - assert(fn); - llvm::CallInst* call = new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", p->scopebb()); - call->setCallingConv(llvm::CallingConv::C); - + llvm::Value* loca = llvm::ConstantInt::get(llvm::Type::Int32Ty, loc.linnum, false); + LLVM_DtoAssert(llvm::ConstantInt::getFalse(), loca, NULL); + //new llvm::UnreachableInst(p->scopebb()); - return 0; } @@ -2348,6 +2337,26 @@ ////////////////////////////////////////////////////////////////////////////////////////// +elem* CatExp::toElem(IRState* p) +{ + Logger::print("CatExp::toElem: %s | %s\n", toChars(), type->toChars()); + LOG_SCOPE; + + assert(0 && "array concatenation is not yet implemented"); + + elem* lhs = e1->toElem(p); + elem* rhs = e2->toElem(p); + + // determine new size + + delete lhs; + delete rhs; + + return 0; +} + +////////////////////////////////////////////////////////////////////////////////////////// + #define STUB(x) elem *x::toElem(IRState * p) {error("Exp type "#x" not implemented: %s", toChars()); fatal(); return 0; } //STUB(IdentityExp); //STUB(CondExp); @@ -2374,7 +2383,7 @@ //STUB(MulAssignExp); //STUB(ModExp); //STUB(ModAssignExp); -STUB(CatExp); +//STUB(CatExp); STUB(CatAssignExp); //STUB(AddExp); //STUB(AddAssignExp); diff -r 3cfcb944304e -r c0967c4b2a74 test/arrays4.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/arrays4.d Tue Oct 09 07:51:13 2007 +0200 @@ -0,0 +1,7 @@ +module arrays4; + +void main() +{ + auto arr = new int[4]; + {auto arrcat = arr ~ arr;} +}