Mercurial > projects > ldc
comparison gen/arrays.cpp @ 945:03d7c4aac654
SWITCHED TO LLVM 2.5 !
Applied patch from ticket #129 to compile against latest LLVM. Thanks Frits van Bommel.
Fixed implicit return by asm block at the end of a function on x86-32. Other architectures will produce an error at the moment. Adding support for new targets is fairly simple.
Fixed return calling convention for complex numbers, ST and ST(1) were switched around.
Added some testcases.
I've run a dstress test and there are no regressions. However, the runtime does not seem to compile with symbolic debug information. -O3 -release -inline works well and is what I used for the dstress run. Tango does not compile, a small workaround is needed in tango.io.digest.Digest.Digest.hexDigest. See ticket #206 .
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Sun, 08 Feb 2009 05:26:54 +0100 |
parents | 5e3bb0c3ea8b |
children | 8c73ff5f69e0 |
comparison
equal
deleted
inserted
replaced
944:eb310635d80e | 945:03d7c4aac654 |
---|---|
98 | 98 |
99 // lets first optimize all zero initializations down to a memset. | 99 // lets first optimize all zero initializations down to a memset. |
100 // this simplifies codegen later on as llvm null's have no address! | 100 // this simplifies codegen later on as llvm null's have no address! |
101 if (isaConstant(val) && isaConstant(val)->isNullValue()) | 101 if (isaConstant(val) && isaConstant(val)->isNullValue()) |
102 { | 102 { |
103 size_t X = getABITypeSize(val->getType()); | 103 size_t X = getTypePaddedSize(val->getType()); |
104 LLValue* nbytes = gIR->ir->CreateMul(dim, DtoConstSize_t(X), ".nbytes"); | 104 LLValue* nbytes = gIR->ir->CreateMul(dim, DtoConstSize_t(X), ".nbytes"); |
105 DtoMemSetZero(ptr, nbytes); | 105 DtoMemSetZero(ptr, nbytes); |
106 return; | 106 return; |
107 } | 107 } |
108 | 108 |
179 case Tsarray: | 179 case Tsarray: |
180 funcname = "_d_array_init_mem"; | 180 funcname = "_d_array_init_mem"; |
181 assert(arrayelemty == valuety && "ArrayInit doesn't work on elem-initialized static arrays"); | 181 assert(arrayelemty == valuety && "ArrayInit doesn't work on elem-initialized static arrays"); |
182 args[0] = DtoBitCast(args[0], getVoidPtrType()); | 182 args[0] = DtoBitCast(args[0], getVoidPtrType()); |
183 args[2] = DtoBitCast(args[2], getVoidPtrType()); | 183 args[2] = DtoBitCast(args[2], getVoidPtrType()); |
184 args.push_back(DtoConstSize_t(getABITypeSize(DtoType(arrayelemty)))); | 184 args.push_back(DtoConstSize_t(getTypePaddedSize(DtoType(arrayelemty)))); |
185 break; | 185 break; |
186 | 186 |
187 default: | 187 default: |
188 error("unhandled array init: %s = %s", array->getType()->toChars(), value->getType()->toChars()); | 188 error("unhandled array init: %s = %s", array->getType()->toChars(), value->getType()->toChars()); |
189 assert(0 && "unhandled array init"); | 189 assert(0 && "unhandled array init"); |
329 ////////////////////////////////////////////////////////////////////////////////////////// | 329 ////////////////////////////////////////////////////////////////////////////////////////// |
330 static LLValue* get_slice_ptr(DSliceValue* e, LLValue*& sz) | 330 static LLValue* get_slice_ptr(DSliceValue* e, LLValue*& sz) |
331 { | 331 { |
332 assert(e->len != 0); | 332 assert(e->len != 0); |
333 const LLType* t = e->ptr->getType()->getContainedType(0); | 333 const LLType* t = e->ptr->getType()->getContainedType(0); |
334 sz = gIR->ir->CreateMul(DtoConstSize_t(getABITypeSize(t)), e->len, "tmp"); | 334 sz = gIR->ir->CreateMul(DtoConstSize_t(getTypePaddedSize(t)), e->len, "tmp"); |
335 return e->ptr; | 335 return e->ptr; |
336 } | 336 } |
337 | 337 |
338 void DtoArrayCopySlices(DSliceValue* dst, DSliceValue* src) | 338 void DtoArrayCopySlices(DSliceValue* dst, DSliceValue* src) |
339 { | 339 { |
360 ////////////////////////////////////////////////////////////////////////////////////////// | 360 ////////////////////////////////////////////////////////////////////////////////////////// |
361 void DtoStaticArrayCopy(LLValue* dst, LLValue* src) | 361 void DtoStaticArrayCopy(LLValue* dst, LLValue* src) |
362 { | 362 { |
363 Logger::println("StaticArrayCopy"); | 363 Logger::println("StaticArrayCopy"); |
364 | 364 |
365 size_t n = getABITypeSize(dst->getType()->getContainedType(0)); | 365 size_t n = getTypePaddedSize(dst->getType()->getContainedType(0)); |
366 DtoMemCpy(dst, src, DtoConstSize_t(n)); | 366 DtoMemCpy(dst, src, DtoConstSize_t(n)); |
367 } | 367 } |
368 | 368 |
369 ////////////////////////////////////////////////////////////////////////////////////////// | 369 ////////////////////////////////////////////////////////////////////////////////////////// |
370 LLConstant* DtoConstSlice(LLConstant* dim, LLConstant* ptr) | 370 LLConstant* DtoConstSlice(LLConstant* dim, LLConstant* ptr) |
532 | 532 |
533 // advance ptr | 533 // advance ptr |
534 src1 = gIR->ir->CreateGEP(src1,len1,"tmp"); | 534 src1 = gIR->ir->CreateGEP(src1,len1,"tmp"); |
535 | 535 |
536 // memcpy | 536 // memcpy |
537 LLValue* elemSize = DtoConstSize_t(getABITypeSize(src2->getType()->getContainedType(0))); | 537 LLValue* elemSize = DtoConstSize_t(getTypePaddedSize(src2->getType()->getContainedType(0))); |
538 LLValue* bytelen = gIR->ir->CreateMul(len2, elemSize, "tmp"); | 538 LLValue* bytelen = gIR->ir->CreateMul(len2, elemSize, "tmp"); |
539 DtoMemCpy(src1,src2,bytelen); | 539 DtoMemCpy(src1,src2,bytelen); |
540 | 540 |
541 return slice; | 541 return slice; |
542 } | 542 } |
568 | 568 |
569 src1 = DtoArrayPtr(e1); | 569 src1 = DtoArrayPtr(e1); |
570 src2 = DtoArrayPtr(e2); | 570 src2 = DtoArrayPtr(e2); |
571 | 571 |
572 // first memcpy | 572 // first memcpy |
573 LLValue* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0))); | 573 LLValue* elemSize = DtoConstSize_t(getTypePaddedSize(src1->getType()->getContainedType(0))); |
574 LLValue* bytelen = gIR->ir->CreateMul(len1, elemSize, "tmp"); | 574 LLValue* bytelen = gIR->ir->CreateMul(len1, elemSize, "tmp"); |
575 DtoMemCpy(mem,src1,bytelen); | 575 DtoMemCpy(mem,src1,bytelen); |
576 | 576 |
577 // second memcpy | 577 // second memcpy |
578 mem = gIR->ir->CreateGEP(mem,len1,"tmp"); | 578 mem = gIR->ir->CreateGEP(mem,len1,"tmp"); |
611 | 611 |
612 src1 = DtoArrayPtr(e2); | 612 src1 = DtoArrayPtr(e2); |
613 | 613 |
614 mem = gIR->ir->CreateGEP(mem,DtoConstSize_t(1),"tmp"); | 614 mem = gIR->ir->CreateGEP(mem,DtoConstSize_t(1),"tmp"); |
615 | 615 |
616 LLValue* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0))); | 616 LLValue* elemSize = DtoConstSize_t(getTypePaddedSize(src1->getType()->getContainedType(0))); |
617 LLValue* bytelen = gIR->ir->CreateMul(len1, elemSize, "tmp"); | 617 LLValue* bytelen = gIR->ir->CreateMul(len1, elemSize, "tmp"); |
618 DtoMemCpy(mem,src1,bytelen); | 618 DtoMemCpy(mem,src1,bytelen); |
619 | 619 |
620 | 620 |
621 return slice; | 621 return slice; |
630 DSliceValue* slice = DtoNewDynArray(exp1->loc, type, lenval, false); | 630 DSliceValue* slice = DtoNewDynArray(exp1->loc, type, lenval, false); |
631 LLValue* mem = slice->ptr; | 631 LLValue* mem = slice->ptr; |
632 | 632 |
633 src1 = DtoArrayPtr(e1); | 633 src1 = DtoArrayPtr(e1); |
634 | 634 |
635 LLValue* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0))); | 635 LLValue* elemSize = DtoConstSize_t(getTypePaddedSize(src1->getType()->getContainedType(0))); |
636 LLValue* bytelen = gIR->ir->CreateMul(len1, elemSize, "tmp"); | 636 LLValue* bytelen = gIR->ir->CreateMul(len1, elemSize, "tmp"); |
637 DtoMemCpy(mem,src1,bytelen); | 637 DtoMemCpy(mem,src1,bytelen); |
638 | 638 |
639 mem = gIR->ir->CreateGEP(mem,len1,"tmp"); | 639 mem = gIR->ir->CreateGEP(mem,len1,"tmp"); |
640 DVarValue* memval = new DVarValue(e2->getType(), mem); | 640 DVarValue* memval = new DVarValue(e2->getType(), mem); |
767 | 767 |
768 assert(len); | 768 assert(len); |
769 assert(elemty); | 769 assert(elemty); |
770 assert(newelemty); | 770 assert(newelemty); |
771 | 771 |
772 size_t esz = getABITypeSize(elemty); | 772 size_t esz = getTypePaddedSize(elemty); |
773 size_t nsz = getABITypeSize(newelemty); | 773 size_t nsz = getTypePaddedSize(newelemty); |
774 if (esz == nsz) | 774 if (esz == nsz) |
775 return len; | 775 return len; |
776 | 776 |
777 LLSmallVector<LLValue*, 3> args; | 777 LLSmallVector<LLValue*, 3> args; |
778 args.push_back(len); | 778 args.push_back(len); |