Mercurial > projects > ldc
comparison gen/arrays.cpp @ 622:26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Commented some logging calls that could potentially write out many megabytes of type dumps.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Wed, 01 Oct 2008 18:32:31 +0200 |
parents | 83ca663ecc20 |
children | df196c8dea26 |
comparison
equal
deleted
inserted
replaced
619:722630261d62 | 622:26fce59fe80a |
---|---|
83 ptr = DtoGEPi(dst,0,1); | 83 ptr = DtoGEPi(dst,0,1); |
84 DtoStore(val, ptr); | 84 DtoStore(val, ptr); |
85 } | 85 } |
86 else | 86 else |
87 { | 87 { |
88 Logger::cout() << "array assignment type dont match: " << *dst->getType() << "\n\n" << *src->getType() << '\n'; | 88 if (Logger::enabled()) |
89 Logger::cout() << "array assignment type dont match: " << *dst->getType() << "\n\n" << *src->getType() << '\n'; | |
89 const LLArrayType* arrty = isaArray(src->getType()->getContainedType(0)); | 90 const LLArrayType* arrty = isaArray(src->getType()->getContainedType(0)); |
90 if (!arrty) | 91 if (!arrty) |
91 { | 92 { |
92 std::cout << "invalid: " << *src << '\n'; | 93 std::cout << "invalid: " << *src << '\n'; |
93 assert(0); | 94 assert(0); |
232 assert(0 && "unhandled array init"); | 233 assert(0 && "unhandled array init"); |
233 } | 234 } |
234 | 235 |
235 LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, funcname); | 236 LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, funcname); |
236 assert(fn); | 237 assert(fn); |
237 Logger::cout() << "calling array init function: " << *fn <<'\n'; | 238 if (Logger::enabled()) |
239 Logger::cout() << "calling array init function: " << *fn <<'\n'; | |
238 CallOrInvoke* call = gIR->CreateCallOrInvoke(fn, args.begin(), args.end()); | 240 CallOrInvoke* call = gIR->CreateCallOrInvoke(fn, args.begin(), args.end()); |
239 call->setCallingConv(llvm::CallingConv::C); | 241 call->setCallingConv(llvm::CallingConv::C); |
240 } | 242 } |
241 | 243 |
242 ////////////////////////////////////////////////////////////////////////////////////////// | 244 ////////////////////////////////////////////////////////////////////////////////////////// |
333 if (!v) | 335 if (!v) |
334 v = DtoConstInitializer(t->next, init); | 336 v = DtoConstInitializer(t->next, init); |
335 assert(v); | 337 assert(v); |
336 | 338 |
337 inits[i] = v; | 339 inits[i] = v; |
338 Logger::cout() << "llval: " << *v << '\n'; | 340 if (Logger::enabled()) |
341 Logger::cout() << "llval: " << *v << '\n'; | |
339 } | 342 } |
340 | 343 |
341 Logger::println("building constant array"); | 344 Logger::println("building constant array"); |
342 const LLArrayType* arrty = LLArrayType::get(elemty,tdim); | 345 const LLArrayType* arrty = LLArrayType::get(elemty,tdim); |
343 LLConstant* constarr = LLConstantArray::get(arrty, inits); | 346 LLConstant* constarr = LLConstantArray::get(arrty, inits); |
424 // cast to wanted type | 427 // cast to wanted type |
425 const LLType* dstType = DtoType(arrayType)->getContainedType(1); | 428 const LLType* dstType = DtoType(arrayType)->getContainedType(1); |
426 if (newptr->getType() != dstType) | 429 if (newptr->getType() != dstType) |
427 newptr = DtoBitCast(newptr, dstType, ".gc_mem"); | 430 newptr = DtoBitCast(newptr, dstType, ".gc_mem"); |
428 | 431 |
429 Logger::cout() << "final ptr = " << *newptr << '\n'; | 432 if (Logger::enabled()) |
433 Logger::cout() << "final ptr = " << *newptr << '\n'; | |
430 | 434 |
431 return new DSliceValue(arrayType, arrayLen, newptr); | 435 return new DSliceValue(arrayType, arrayLen, newptr); |
432 } | 436 } |
433 | 437 |
434 ////////////////////////////////////////////////////////////////////////////////////////// | 438 ////////////////////////////////////////////////////////////////////////////////////////// |
466 // cast to wanted type | 470 // cast to wanted type |
467 const LLType* dstType = DtoType(arrayType)->getContainedType(1); | 471 const LLType* dstType = DtoType(arrayType)->getContainedType(1); |
468 if (newptr->getType() != dstType) | 472 if (newptr->getType() != dstType) |
469 newptr = DtoBitCast(newptr, dstType, ".gc_mem"); | 473 newptr = DtoBitCast(newptr, dstType, ".gc_mem"); |
470 | 474 |
471 Logger::cout() << "final ptr = " << *newptr << '\n'; | 475 if (Logger::enabled()) |
476 Logger::cout() << "final ptr = " << *newptr << '\n'; | |
472 | 477 |
473 assert(firstDim); | 478 assert(firstDim); |
474 return new DSliceValue(arrayType, firstDim, newptr); | 479 return new DSliceValue(arrayType, firstDim, newptr); |
475 } | 480 } |
476 | 481 |
495 args.push_back(DtoTypeInfoOf(arrayType)); | 500 args.push_back(DtoTypeInfoOf(arrayType)); |
496 args.push_back(newdim->getRVal()); | 501 args.push_back(newdim->getRVal()); |
497 args.push_back(DtoArrayLen(array)); | 502 args.push_back(DtoArrayLen(array)); |
498 | 503 |
499 LLValue* arrPtr = DtoArrayPtr(array); | 504 LLValue* arrPtr = DtoArrayPtr(array); |
500 Logger::cout() << "arrPtr = " << *arrPtr << '\n'; | 505 if (Logger::enabled()) |
506 Logger::cout() << "arrPtr = " << *arrPtr << '\n'; | |
501 args.push_back(DtoBitCast(arrPtr, fn->getFunctionType()->getParamType(3), "tmp")); | 507 args.push_back(DtoBitCast(arrPtr, fn->getFunctionType()->getParamType(3), "tmp")); |
502 | 508 |
503 LLValue* newptr = gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), ".gc_mem")->get(); | 509 LLValue* newptr = gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), ".gc_mem")->get(); |
504 if (newptr->getType() != arrPtr->getType()) | 510 if (newptr->getType() != arrPtr->getType()) |
505 newptr = DtoBitCast(newptr, arrPtr->getType(), ".gc_mem"); | 511 newptr = DtoBitCast(newptr, arrPtr->getType(), ".gc_mem"); |
724 rmem = r->getRVal(); | 730 rmem = r->getRVal(); |
725 | 731 |
726 const LLType* pt = fn->getFunctionType()->getParamType(0); | 732 const LLType* pt = fn->getFunctionType()->getParamType(0); |
727 | 733 |
728 LLSmallVector<LLValue*, 3> args; | 734 LLSmallVector<LLValue*, 3> args; |
729 Logger::cout() << "bitcasting to " << *pt << '\n'; | 735 if (Logger::enabled()) |
730 Logger::cout() << *lmem << '\n'; | 736 { |
731 Logger::cout() << *rmem << '\n'; | 737 Logger::cout() << "bitcasting to " << *pt << '\n'; |
738 Logger::cout() << *lmem << '\n'; | |
739 Logger::cout() << *rmem << '\n'; | |
740 } | |
732 args.push_back(DtoBitCast(lmem,pt)); | 741 args.push_back(DtoBitCast(lmem,pt)); |
733 args.push_back(DtoBitCast(rmem,pt)); | 742 args.push_back(DtoBitCast(rmem,pt)); |
734 | 743 |
735 // pass array typeinfo ? | 744 // pass array typeinfo ? |
736 if (useti) { | 745 if (useti) { |
737 Type* t = l->getType(); | 746 Type* t = l->getType(); |
738 LLValue* tival = DtoTypeInfoOf(t); | 747 LLValue* tival = DtoTypeInfoOf(t); |
739 // DtoTypeInfoOf only does declare, not enough in this case :/ | 748 // DtoTypeInfoOf only does declare, not enough in this case :/ |
740 DtoForceConstInitDsymbol(t->vtinfo); | 749 DtoForceConstInitDsymbol(t->vtinfo); |
741 Logger::cout() << "typeinfo decl: " << *tival << '\n'; | 750 |
751 if (Logger::enabled()) | |
752 Logger::cout() << "typeinfo decl: " << *tival << '\n'; | |
742 | 753 |
743 pt = fn->getFunctionType()->getParamType(2); | 754 pt = fn->getFunctionType()->getParamType(2); |
744 args.push_back(DtoBitCast(tival, pt)); | 755 args.push_back(DtoBitCast(tival, pt)); |
745 } | 756 } |
746 | 757 |
955 | 966 |
956 LLValue* rval; | 967 LLValue* rval; |
957 LLValue* rval2; | 968 LLValue* rval2; |
958 bool isslice = false; | 969 bool isslice = false; |
959 | 970 |
960 Logger::cout() << "from array or sarray" << '\n'; | 971 if (Logger::enabled()) |
972 Logger::cout() << "from array or sarray" << '\n'; | |
973 | |
961 if (totype->ty == Tpointer) { | 974 if (totype->ty == Tpointer) { |
962 Logger::cout() << "to pointer" << '\n'; | 975 if (Logger::enabled()) |
976 Logger::cout() << "to pointer" << '\n'; | |
963 rval = DtoArrayPtr(u); | 977 rval = DtoArrayPtr(u); |
964 if (rval->getType() != tolltype) | 978 if (rval->getType() != tolltype) |
965 rval = gIR->ir->CreateBitCast(rval, tolltype, "tmp"); | 979 rval = gIR->ir->CreateBitCast(rval, tolltype, "tmp"); |
966 } | 980 } |
967 else if (totype->ty == Tarray) { | 981 else if (totype->ty == Tarray) { |
968 Logger::cout() << "to array" << '\n'; | 982 if (Logger::enabled()) |
983 Logger::cout() << "to array" << '\n'; | |
969 | 984 |
970 const LLType* ptrty = DtoArrayType(totype)->getContainedType(1); | 985 const LLType* ptrty = DtoArrayType(totype)->getContainedType(1); |
971 const LLType* ety = DtoTypeNotVoid(fromtype->next); | 986 const LLType* ety = DtoTypeNotVoid(fromtype->next); |
972 | 987 |
973 if (DSliceValue* usl = u->isSlice()) { | 988 if (DSliceValue* usl = u->isSlice()) { |
974 Logger::println("from slice"); | 989 if (Logger::enabled()) |
975 Logger::cout() << "from: " << *usl->ptr << " to: " << *ptrty << '\n'; | 990 { |
991 Logger::println("from slice"); | |
992 Logger::cout() << "from: " << *usl->ptr << " to: " << *ptrty << '\n'; | |
993 } | |
976 rval = DtoBitCast(usl->ptr, ptrty); | 994 rval = DtoBitCast(usl->ptr, ptrty); |
977 if (fromtype->next->size() == totype->next->size()) | 995 if (fromtype->next->size() == totype->next->size()) |
978 rval2 = DtoArrayLen(usl); | 996 rval2 = DtoArrayLen(usl); |
979 else | 997 else |
980 rval2 = DtoArrayCastLength(DtoArrayLen(usl), ety, ptrty->getContainedType(0)); | 998 rval2 = DtoArrayCastLength(DtoArrayLen(usl), ety, ptrty->getContainedType(0)); |
981 } | 999 } |
982 else { | 1000 else { |
983 LLValue* uval = u->getRVal(); | 1001 LLValue* uval = u->getRVal(); |
984 if (fromtype->ty == Tsarray) { | 1002 if (fromtype->ty == Tsarray) { |
985 Logger::cout() << "uvalTy = " << *uval->getType() << '\n'; | 1003 if (Logger::enabled()) |
1004 Logger::cout() << "uvalTy = " << *uval->getType() << '\n'; | |
986 assert(isaPointer(uval->getType())); | 1005 assert(isaPointer(uval->getType())); |
987 const LLArrayType* arrty = isaArray(uval->getType()->getContainedType(0)); | 1006 const LLArrayType* arrty = isaArray(uval->getType()->getContainedType(0)); |
988 | 1007 |
989 if(arrty->getNumElements()*fromtype->next->size() % totype->next->size() != 0) | 1008 if(arrty->getNumElements()*fromtype->next->size() % totype->next->size() != 0) |
990 { | 1009 { |
1010 } | 1029 } |
1011 } | 1030 } |
1012 isslice = true; | 1031 isslice = true; |
1013 } | 1032 } |
1014 else if (totype->ty == Tsarray) { | 1033 else if (totype->ty == Tsarray) { |
1015 Logger::cout() << "to sarray" << '\n'; | 1034 if (Logger::enabled()) |
1035 Logger::cout() << "to sarray" << '\n'; | |
1016 assert(0); | 1036 assert(0); |
1017 } | 1037 } |
1018 else { | 1038 else { |
1019 assert(0); | 1039 assert(0); |
1020 } | 1040 } |