comparison gen/arrays.cpp @ 217:0806379a5eca trunk

[svn r233] Added: -oq command line option for writing fully qualified object names. Added: started support for x86 80bit floating point. Changed: aggregates passed by value now use the llvm 'byval' parameter attribute, also lays ground work for using other attributes. Changed: eliminated a lot more std::vectorS, these showed up pretty much at the top when profiling! Changed: performed other misc. cleanups. Changed: halt expression now call the new llvm trap intrinsic instead of an assert(0). Changed: dstress suite now passes -O0 by default, this only eliminates unreferenced globals, which speeds up linking quite a bit.
author lindquist
date Thu, 05 Jun 2008 06:38:36 +0200
parents 7816aafeea3c
children 9760f54af0b7
comparison
equal deleted inserted replaced
216:3d022aa016ae 217:0806379a5eca
182 assert(t == pt); 182 assert(t == pt);
183 } 183 }
184 184
185 Logger::cout() << "array: " << *ptr << " dim: " << *dim << " val: " << *val << '\n'; 185 Logger::cout() << "array: " << *ptr << " dim: " << *dim << " val: " << *val << '\n';
186 186
187 std::vector<LLValue*> args; 187 LLSmallVector<LLValue*, 4> args;
188 args.push_back(ptr); 188 args.push_back(ptr);
189 args.push_back(dim); 189 args.push_back(dim);
190 args.push_back(val); 190 args.push_back(val);
191 191
192 const char* funcname = NULL; 192 const char* funcname = NULL;
422 422
423 LLValue* sz2; 423 LLValue* sz2;
424 LLValue* srcarr = DtoBitCast(get_slice_ptr(src,sz2),arrty); 424 LLValue* srcarr = DtoBitCast(get_slice_ptr(src,sz2),arrty);
425 425
426 llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32(); 426 llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32();
427 std::vector<LLValue*> llargs; 427 LLSmallVector<LLValue*, 4> llargs(4);
428 llargs.resize(4);
429 llargs[0] = dstarr; 428 llargs[0] = dstarr;
430 llargs[1] = srcarr; 429 llargs[1] = srcarr;
431 llargs[2] = sz1; 430 llargs[2] = sz1;
432 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); 431 llargs[3] = DtoConstInt(0);
433 432
434 llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); 433 llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
435 } 434 }
436 435
437 void DtoArrayCopyToSlice(DSliceValue* dst, DValue* src) 436 void DtoArrayCopyToSlice(DSliceValue* dst, DValue* src)
442 LLValue* sz1; 441 LLValue* sz1;
443 LLValue* dstarr = DtoBitCast(get_slice_ptr(dst,sz1),arrty); 442 LLValue* dstarr = DtoBitCast(get_slice_ptr(dst,sz1),arrty);
444 LLValue* srcarr = DtoBitCast(DtoArrayPtr(src),arrty); 443 LLValue* srcarr = DtoBitCast(DtoArrayPtr(src),arrty);
445 444
446 llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32(); 445 llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32();
447 std::vector<LLValue*> llargs; 446 LLSmallVector<LLValue*, 4> llargs(4);
448 llargs.resize(4);
449 llargs[0] = dstarr; 447 llargs[0] = dstarr;
450 llargs[1] = srcarr; 448 llargs[1] = srcarr;
451 llargs[2] = sz1; 449 llargs[2] = sz1;
452 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); 450 llargs[3] = DtoConstInt(0);
453 451
454 llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); 452 llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
455 } 453 }
456 454
457 ////////////////////////////////////////////////////////////////////////////////////////// 455 //////////////////////////////////////////////////////////////////////////////////////////
465 const LLType* arrty = getPtrToType(llvm::Type::Int8Ty); 463 const LLType* arrty = getPtrToType(llvm::Type::Int8Ty);
466 LLValue* dstarr = DtoBitCast(dst,arrty); 464 LLValue* dstarr = DtoBitCast(dst,arrty);
467 LLValue* srcarr = DtoBitCast(src,arrty); 465 LLValue* srcarr = DtoBitCast(src,arrty);
468 466
469 llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32(); 467 llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32();
470 std::vector<LLValue*> llargs; 468 LLSmallVector<LLValue*,4> llargs(4);
471 llargs.resize(4);
472 llargs[0] = dstarr; 469 llargs[0] = dstarr;
473 llargs[1] = srcarr; 470 llargs[1] = srcarr;
474 llargs[2] = n; 471 llargs[2] = n;
475 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); 472 llargs[3] = DtoConstInt(0);
476 473
477 llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); 474 llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
478 } 475 }
479 476
480 ////////////////////////////////////////////////////////////////////////////////////////// 477 //////////////////////////////////////////////////////////////////////////////////////////
481 LLConstant* DtoConstSlice(LLConstant* dim, LLConstant* ptr) 478 LLConstant* DtoConstSlice(LLConstant* dim, LLConstant* ptr)
482 { 479 {
483 std::vector<const LLType*> types; 480 LLConstant* values[2] = { dim, ptr };
484 types.push_back(dim->getType()); 481 return llvm::ConstantStruct::get(values, 2);
485 types.push_back(ptr->getType());
486 const llvm::StructType* type = llvm::StructType::get(types);
487 std::vector<LLConstant*> values;
488 values.push_back(dim);
489 values.push_back(ptr);
490 return llvm::ConstantStruct::get(type,values);
491 } 482 }
492 483
493 ////////////////////////////////////////////////////////////////////////////////////////// 484 //////////////////////////////////////////////////////////////////////////////////////////
494 DSliceValue* DtoNewDynArray(Type* arrayType, DValue* dim, bool defaultInit) 485 DSliceValue* DtoNewDynArray(Type* arrayType, DValue* dim, bool defaultInit)
495 { 486 {
496 Logger::println("DtoNewDynArray : %s", arrayType->toChars()); 487 Logger::println("DtoNewDynArray : %s", arrayType->toChars());
497 LOG_SCOPE; 488 LOG_SCOPE;
498 489
490 // typeinfo arg
491 LLValue* arrayTypeInfo = DtoTypeInfoOf(arrayType);
492
493 // dim arg
494 assert(DtoType(dim->getType()) == DtoSize_t());
495 LLValue* arrayLen = dim->getRVal();
496
497 // get runtime function
499 bool zeroInit = arrayType->toBasetype()->nextOf()->isZeroInit(); 498 bool zeroInit = arrayType->toBasetype()->nextOf()->isZeroInit();
500 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, zeroInit ? "_d_newarrayT" : "_d_newarrayiT" ); 499 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, zeroInit ? "_d_newarrayT" : "_d_newarrayiT" );
501 500
502 LLSmallVector<LLValue*,2> args; 501 // call allocator
503 args.push_back(DtoTypeInfoOf(arrayType)); 502 LLValue* newptr = gIR->ir->CreateCall2(fn, arrayTypeInfo, arrayLen, ".gc_mem");
504 assert(DtoType(dim->getType()) == DtoSize_t()); 503
505 args.push_back(dim->getRVal()); 504 // cast to wanted type
506
507 LLValue* newptr = gIR->ir->CreateCall(fn, args.begin(), args.end(), ".gc_mem");
508 const LLType* dstType = DtoType(arrayType)->getContainedType(1); 505 const LLType* dstType = DtoType(arrayType)->getContainedType(1);
509 if (newptr->getType() != dstType) 506 if (newptr->getType() != dstType)
510 newptr = DtoBitCast(newptr, dstType, ".gc_mem"); 507 newptr = DtoBitCast(newptr, dstType, ".gc_mem");
511 508
512 Logger::cout() << "final ptr = " << *newptr << '\n'; 509 Logger::cout() << "final ptr = " << *newptr << '\n';
516 DValue* e = dty->defaultInit()->toElem(gIR); 513 DValue* e = dty->defaultInit()->toElem(gIR);
517 DtoArrayInit(newptr,dim,e->getRVal()); 514 DtoArrayInit(newptr,dim,e->getRVal());
518 } 515 }
519 #endif 516 #endif
520 517
521 return new DSliceValue(arrayType, args[1], newptr); 518 return new DSliceValue(arrayType, arrayLen, newptr);
522 } 519 }
523 520
524 ////////////////////////////////////////////////////////////////////////////////////////// 521 //////////////////////////////////////////////////////////////////////////////////////////
525 DSliceValue* DtoResizeDynArray(Type* arrayType, DValue* array, DValue* newdim) 522 DSliceValue* DtoResizeDynArray(Type* arrayType, DValue* array, DValue* newdim)
526 { 523 {
540 537
541 LLSmallVector<LLValue*,4> args; 538 LLSmallVector<LLValue*,4> args;
542 args.push_back(DtoTypeInfoOf(arrayType)); 539 args.push_back(DtoTypeInfoOf(arrayType));
543 args.push_back(newdim->getRVal()); 540 args.push_back(newdim->getRVal());
544 args.push_back(DtoArrayLen(array)); 541 args.push_back(DtoArrayLen(array));
542
545 LLValue* arrPtr = DtoArrayPtr(array); 543 LLValue* arrPtr = DtoArrayPtr(array);
546 Logger::cout() << "arrPtr = " << *arrPtr << '\n'; 544 Logger::cout() << "arrPtr = " << *arrPtr << '\n';
547 args.push_back(DtoBitCast(arrPtr, fn->getFunctionType()->getParamType(3), "tmp")); 545 args.push_back(DtoBitCast(arrPtr, fn->getFunctionType()->getParamType(3), "tmp"));
548 546
549 LLValue* newptr = gIR->ir->CreateCall(fn, args.begin(), args.end(), ".gc_mem"); 547 LLValue* newptr = gIR->ir->CreateCall(fn, args.begin(), args.end(), ".gc_mem");
732 Logger::println("casting to dynamic arrays"); 730 Logger::println("casting to dynamic arrays");
733 Type* l_ty = DtoDType(l->getType()); 731 Type* l_ty = DtoDType(l->getType());
734 Type* r_ty = DtoDType(r->getType()); 732 Type* r_ty = DtoDType(r->getType());
735 assert(l_ty->next == r_ty->next); 733 assert(l_ty->next == r_ty->next);
736 if ((l_ty->ty == Tsarray) || (r_ty->ty == Tsarray)) { 734 if ((l_ty->ty == Tsarray) || (r_ty->ty == Tsarray)) {
737 Type* a_ty = new Type(Tarray, l_ty->next); 735 Type* a_ty = l_ty->next->arrayOf();
738 if (l_ty->ty == Tsarray) 736 if (l_ty->ty == Tsarray)
739 l = DtoCastArray(l, a_ty); 737 l = DtoCastArray(l, a_ty);
740 if (r_ty->ty == Tsarray) 738 if (r_ty->ty == Tsarray)
741 r = DtoCastArray(r, a_ty); 739 r = DtoCastArray(r, a_ty);
742 } 740 }
772 else 770 else
773 rmem = r->getRVal(); 771 rmem = r->getRVal();
774 772
775 const LLType* pt = fn->getFunctionType()->getParamType(0); 773 const LLType* pt = fn->getFunctionType()->getParamType(0);
776 774
777 std::vector<LLValue*> args; 775 LLSmallVector<LLValue*, 3> args;
778 Logger::cout() << "bitcasting to " << *pt << '\n'; 776 Logger::cout() << "bitcasting to " << *pt << '\n';
779 Logger::cout() << *lmem << '\n'; 777 Logger::cout() << *lmem << '\n';
780 Logger::cout() << *rmem << '\n'; 778 Logger::cout() << *rmem << '\n';
781 args.push_back(DtoBitCast(lmem,pt)); 779 args.push_back(DtoBitCast(lmem,pt));
782 args.push_back(DtoBitCast(rmem,pt)); 780 args.push_back(DtoBitCast(rmem,pt));
797 } 795 }
798 796
799 ////////////////////////////////////////////////////////////////////////////////////////// 797 //////////////////////////////////////////////////////////////////////////////////////////
800 LLValue* DtoArrayEquals(TOK op, DValue* l, DValue* r) 798 LLValue* DtoArrayEquals(TOK op, DValue* l, DValue* r)
801 { 799 {
802 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_adEq");
803 assert(fn);
804
805 LLValue* res = DtoArrayEqCmp_impl("_adEq", l, r, true); 800 LLValue* res = DtoArrayEqCmp_impl("_adEq", l, r, true);
806 if (op == TOKnotequal) 801 if (op == TOKnotequal)
807 res = gIR->ir->CreateNot(res, "tmp"); 802 res = gIR->ir->CreateNot(res, "tmp");
808 803
809 return res; 804 return res;
881 size_t esz = getABITypeSize(elemty); 876 size_t esz = getABITypeSize(elemty);
882 size_t nsz = getABITypeSize(newelemty); 877 size_t nsz = getABITypeSize(newelemty);
883 if (esz == nsz) 878 if (esz == nsz)
884 return len; 879 return len;
885 880
886 std::vector<LLValue*> args; 881 LLSmallVector<LLValue*, 3> args;
887 args.push_back(len); 882 args.push_back(len);
888 args.push_back(llvm::ConstantInt::get(DtoSize_t(), esz, false)); 883 args.push_back(llvm::ConstantInt::get(DtoSize_t(), esz, false));
889 args.push_back(llvm::ConstantInt::get(DtoSize_t(), nsz, false)); 884 args.push_back(llvm::ConstantInt::get(DtoSize_t(), nsz, false));
890 885
891 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_array_cast_len"); 886 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_array_cast_len");