Mercurial > projects > ldc
comparison gen/llvmhelpers.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 |
---|---|
414 // ASSIGNMENT HELPER (store this in that) | 414 // ASSIGNMENT HELPER (store this in that) |
415 ////////////////////////////////////////////////////////////////////////////////////////*/ | 415 ////////////////////////////////////////////////////////////////////////////////////////*/ |
416 | 416 |
417 void DtoAssign(Loc& loc, DValue* lhs, DValue* rhs) | 417 void DtoAssign(Loc& loc, DValue* lhs, DValue* rhs) |
418 { | 418 { |
419 Logger::cout() << "DtoAssign(...);\n"; | 419 Logger::println("DtoAssign(...);\n"); |
420 LOG_SCOPE; | 420 LOG_SCOPE; |
421 | 421 |
422 Type* t = lhs->getType()->toBasetype(); | 422 Type* t = lhs->getType()->toBasetype(); |
423 Type* t2 = rhs->getType()->toBasetype(); | 423 Type* t2 = rhs->getType()->toBasetype(); |
424 | 424 |
470 if (rhs->isNull()) | 470 if (rhs->isNull()) |
471 DtoAggrZeroInit(lhs->getLVal()); | 471 DtoAggrZeroInit(lhs->getLVal()); |
472 else { | 472 else { |
473 LLValue* l = lhs->getLVal(); | 473 LLValue* l = lhs->getLVal(); |
474 LLValue* r = rhs->getRVal(); | 474 LLValue* r = rhs->getRVal(); |
475 Logger::cout() << "assign\nlhs: " << *l << "rhs: " << *r << '\n'; | 475 if (Logger::enabled()) |
476 Logger::cout() << "assign\nlhs: " << *l << "rhs: " << *r << '\n'; | |
476 DtoAggrCopy(l, r); | 477 DtoAggrCopy(l, r); |
477 } | 478 } |
478 } | 479 } |
479 else if (t->ty == Tclass) { | 480 else if (t->ty == Tclass) { |
480 assert(t2->ty == Tclass); | 481 assert(t2->ty == Tclass); |
481 LLValue* l = lhs->getLVal(); | 482 LLValue* l = lhs->getLVal(); |
482 LLValue* r = rhs->getRVal(); | 483 LLValue* r = rhs->getRVal(); |
483 Logger::cout() << "l : " << *l << '\n'; | 484 if (Logger::enabled()) |
484 Logger::cout() << "r : " << *r << '\n'; | 485 { |
486 Logger::cout() << "l : " << *l << '\n'; | |
487 Logger::cout() << "r : " << *r << '\n'; | |
488 } | |
485 r = DtoBitCast(r, l->getType()->getContainedType(0)); | 489 r = DtoBitCast(r, l->getType()->getContainedType(0)); |
486 DtoStore(r, l); | 490 DtoStore(r, l); |
487 } | 491 } |
488 else if (t->iscomplex()) { | 492 else if (t->iscomplex()) { |
489 LLValue* dst; | 493 LLValue* dst; |
497 DtoStore(rhs->getRVal(), dst); | 501 DtoStore(rhs->getRVal(), dst); |
498 } | 502 } |
499 else { | 503 else { |
500 LLValue* l = lhs->getLVal(); | 504 LLValue* l = lhs->getLVal(); |
501 LLValue* r = rhs->getRVal(); | 505 LLValue* r = rhs->getRVal(); |
502 Logger::cout() << "assign\nlhs: " << *l << "rhs: " << *r << '\n'; | 506 if (Logger::enabled()) |
507 Logger::cout() << "assign\nlhs: " << *l << "rhs: " << *r << '\n'; | |
503 const LLType* lit = l->getType()->getContainedType(0); | 508 const LLType* lit = l->getType()->getContainedType(0); |
504 if (r->getType() != lit) { | 509 if (r->getType() != lit) { |
505 // handle lvalue cast assignments | 510 // handle lvalue cast assignments |
506 if (DLRValue* lr = lhs->isLRValue()) { | 511 if (DLRValue* lr = lhs->isLRValue()) { |
507 Logger::println("lvalue cast!"); | 512 Logger::println("lvalue cast!"); |
508 r = DtoCast(loc, rhs, lr->getLType())->getRVal(); | 513 r = DtoCast(loc, rhs, lr->getLType())->getRVal(); |
509 } | 514 } |
510 else { | 515 else { |
511 r = DtoCast(loc, rhs, lhs->getType())->getRVal(); | 516 r = DtoCast(loc, rhs, lhs->getType())->getRVal(); |
512 } | 517 } |
513 Logger::cout() << "really assign\nlhs: " << *l << "rhs: " << *r << '\n'; | 518 if (Logger::enabled()) |
519 Logger::cout() << "really assign\nlhs: " << *l << "rhs: " << *r << '\n'; | |
514 assert(r->getType() == l->getType()->getContainedType(0)); | 520 assert(r->getType() == l->getType()->getContainedType(0)); |
515 } | 521 } |
516 gIR->ir->CreateStore(r, l); | 522 gIR->ir->CreateStore(r, l); |
517 } | 523 } |
518 } | 524 } |
582 return new DImValue(_to, rval); | 588 return new DImValue(_to, rval); |
583 } | 589 } |
584 | 590 |
585 if (to->isintegral()) { | 591 if (to->isintegral()) { |
586 if (fromsz < tosz) { | 592 if (fromsz < tosz) { |
587 Logger::cout() << "cast to: " << *tolltype << '\n'; | 593 if (Logger::enabled()) |
594 Logger::cout() << "cast to: " << *tolltype << '\n'; | |
588 if (from->isunsigned() || from->ty == Tbool) { | 595 if (from->isunsigned() || from->ty == Tbool) { |
589 rval = new llvm::ZExtInst(rval, tolltype, "tmp", gIR->scopebb()); | 596 rval = new llvm::ZExtInst(rval, tolltype, "tmp", gIR->scopebb()); |
590 } else { | 597 } else { |
591 rval = new llvm::SExtInst(rval, tolltype, "tmp", gIR->scopebb()); | 598 rval = new llvm::SExtInst(rval, tolltype, "tmp", gIR->scopebb()); |
592 } | 599 } |
608 else { | 615 else { |
609 rval = new llvm::SIToFPInst(rval, tolltype, "tmp", gIR->scopebb()); | 616 rval = new llvm::SIToFPInst(rval, tolltype, "tmp", gIR->scopebb()); |
610 } | 617 } |
611 } | 618 } |
612 else if (to->ty == Tpointer) { | 619 else if (to->ty == Tpointer) { |
613 Logger::cout() << "cast pointer: " << *tolltype << '\n'; | 620 if (Logger::enabled()) |
621 Logger::cout() << "cast pointer: " << *tolltype << '\n'; | |
614 rval = gIR->ir->CreateIntToPtr(rval, tolltype, "tmp"); | 622 rval = gIR->ir->CreateIntToPtr(rval, tolltype, "tmp"); |
615 } | 623 } |
616 else { | 624 else { |
617 error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), _to->toChars()); | 625 error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), _to->toChars()); |
618 fatal(); | 626 fatal(); |
631 | 639 |
632 LLValue* rval; | 640 LLValue* rval; |
633 | 641 |
634 if (totype->ty == Tpointer || totype->ty == Tclass) { | 642 if (totype->ty == Tpointer || totype->ty == Tclass) { |
635 LLValue* src = val->getRVal(); | 643 LLValue* src = val->getRVal(); |
636 Logger::cout() << "src: " << *src << "to type: " << *tolltype << '\n'; | 644 if (Logger::enabled()) |
645 Logger::cout() << "src: " << *src << "to type: " << *tolltype << '\n'; | |
637 rval = DtoBitCast(src, tolltype); | 646 rval = DtoBitCast(src, tolltype); |
638 } | 647 } |
639 else if (totype->isintegral()) { | 648 else if (totype->isintegral()) { |
640 rval = new llvm::PtrToIntInst(val->getRVal(), tolltype, "tmp", gIR->scopebb()); | 649 rval = new llvm::PtrToIntInst(val->getRVal(), tolltype, "tmp", gIR->scopebb()); |
641 } | 650 } |
908 const LLType* _type = DtoType(vd->type); | 917 const LLType* _type = DtoType(vd->type); |
909 Type* t = vd->type->toBasetype(); | 918 Type* t = vd->type->toBasetype(); |
910 | 919 |
911 //Logger::cout() << "initializer: " << *_init << '\n'; | 920 //Logger::cout() << "initializer: " << *_init << '\n'; |
912 if (_type != _init->getType()) { | 921 if (_type != _init->getType()) { |
913 Logger::cout() << "got type '" << *_init->getType() << "' expected '" << *_type << "'\n"; | 922 if (Logger::enabled()) |
923 Logger::cout() << "got type '" << *_init->getType() << "' expected '" << *_type << "'\n"; | |
924 | |
914 // zero initalizer | 925 // zero initalizer |
915 if (_init->isNullValue()) | 926 if (_init->isNullValue()) |
916 _init = llvm::Constant::getNullValue(_type); | 927 _init = llvm::Constant::getNullValue(_type); |
917 // pointer to global constant (struct.init) | 928 // pointer to global constant (struct.init) |
918 else if (llvm::isa<llvm::GlobalVariable>(_init)) | 929 else if (llvm::isa<llvm::GlobalVariable>(_init)) |
928 else if (isaArray(_type)) | 939 else if (isaArray(_type)) |
929 { | 940 { |
930 _init = DtoConstStaticArray(_type, _init); | 941 _init = DtoConstStaticArray(_type, _init); |
931 } | 942 } |
932 else { | 943 else { |
933 Logger::cout() << "Unexpected initializer type: " << *_type << '\n'; | 944 if (Logger::enabled()) |
945 Logger::cout() << "Unexpected initializer type: " << *_type << '\n'; | |
934 //assert(0); | 946 //assert(0); |
935 } | 947 } |
936 } | 948 } |
937 | 949 |
938 bool istempl = false; | 950 bool istempl = false; |
948 assert(!_type->isAbstract()); | 960 assert(!_type->isAbstract()); |
949 | 961 |
950 llvm::GlobalVariable* gvar = llvm::cast<llvm::GlobalVariable>(vd->ir.irGlobal->value); | 962 llvm::GlobalVariable* gvar = llvm::cast<llvm::GlobalVariable>(vd->ir.irGlobal->value); |
951 if (!(vd->storage_class & STCextern) && (vd->getModule() == gIR->dmodule || istempl)) | 963 if (!(vd->storage_class & STCextern) && (vd->getModule() == gIR->dmodule || istempl)) |
952 { | 964 { |
953 Logger::println("setting initializer"); | 965 if (Logger::enabled()) |
954 Logger::cout() << "global: " << *gvar << '\n'; | 966 { |
955 Logger::cout() << "init: " << *_init << '\n'; | 967 Logger::println("setting initializer"); |
968 Logger::cout() << "global: " << *gvar << '\n'; | |
969 Logger::cout() << "init: " << *_init << '\n'; | |
970 } | |
956 gvar->setInitializer(_init); | 971 gvar->setInitializer(_init); |
957 // do debug info | 972 // do debug info |
958 if (global.params.symdebug) | 973 if (global.params.symdebug) |
959 { | 974 { |
960 LLGlobalVariable* gv = DtoDwarfGlobalVariable(gvar, vd); | 975 LLGlobalVariable* gv = DtoDwarfGlobalVariable(gvar, vd); |
1166 else | 1181 else |
1167 { | 1182 { |
1168 assert(vd->ir.irLocal->value); | 1183 assert(vd->ir.irLocal->value); |
1169 } | 1184 } |
1170 | 1185 |
1171 Logger::cout() << "llvm value for decl: " << *vd->ir.irLocal->value << '\n'; | 1186 if (Logger::enabled()) |
1187 Logger::cout() << "llvm value for decl: " << *vd->ir.irLocal->value << '\n'; | |
1172 DValue* ie = DtoInitializer(vd->ir.irLocal->value, vd->init); | 1188 DValue* ie = DtoInitializer(vd->ir.irLocal->value, vd->init); |
1173 } | 1189 } |
1174 | 1190 |
1175 return new DVarValue(vd->type, vd, vd->ir.getIrValue()); | 1191 return new DVarValue(vd->type, vd, vd->ir.getIrValue()); |
1176 } | 1192 } |
1290 | 1306 |
1291 LLConstant* _init = DtoConstInitializer(t, init); | 1307 LLConstant* _init = DtoConstInitializer(t, init); |
1292 assert(_init); | 1308 assert(_init); |
1293 if (_type != _init->getType()) | 1309 if (_type != _init->getType()) |
1294 { | 1310 { |
1295 Logger::cout() << "field init is: " << *_init << " type should be " << *_type << '\n'; | 1311 if (Logger::enabled()) |
1312 Logger::cout() << "field init is: " << *_init << " type should be " << *_type << '\n'; | |
1296 if (t->ty == Tsarray) | 1313 if (t->ty == Tsarray) |
1297 { | 1314 { |
1298 const LLArrayType* arrty = isaArray(_type); | 1315 const LLArrayType* arrty = isaArray(_type); |
1299 uint64_t n = arrty->getNumElements(); | 1316 uint64_t n = arrty->getNumElements(); |
1300 std::vector<LLConstant*> vals(n,_init); | 1317 std::vector<LLConstant*> vals(n,_init); |
1377 | 1394 |
1378 static LLConstant* expand_to_sarray(Type *base, Expression* exp) | 1395 static LLConstant* expand_to_sarray(Type *base, Expression* exp) |
1379 { | 1396 { |
1380 Logger::println("building type %s from expression (%s) of type %s", base->toChars(), exp->toChars(), exp->type->toChars()); | 1397 Logger::println("building type %s from expression (%s) of type %s", base->toChars(), exp->toChars(), exp->type->toChars()); |
1381 const LLType* dstTy = DtoType(base); | 1398 const LLType* dstTy = DtoType(base); |
1382 Logger::cout() << "final llvm type requested: " << *dstTy << '\n'; | 1399 if (Logger::enabled()) |
1400 Logger::cout() << "final llvm type requested: " << *dstTy << '\n'; | |
1383 | 1401 |
1384 LLConstant* val = exp->toConstElem(gIR); | 1402 LLConstant* val = exp->toConstElem(gIR); |
1385 | 1403 |
1386 Type* expbase = exp->type->toBasetype(); | 1404 Type* expbase = exp->type->toBasetype(); |
1387 Type* t = base; | 1405 Type* t = base; |
1508 } | 1526 } |
1509 // pointer/class | 1527 // pointer/class |
1510 else if (ty == Tpointer || ty == Tclass) { | 1528 else if (ty == Tpointer || ty == Tclass) { |
1511 LLValue* val = dval->getRVal(); | 1529 LLValue* val = dval->getRVal(); |
1512 LLValue* zero = LLConstant::getNullValue(val->getType()); | 1530 LLValue* zero = LLConstant::getNullValue(val->getType()); |
1513 Logger::cout() << "val: " << *val << '\n'; | 1531 if (Logger::enabled()) |
1514 Logger::cout() << "zero: " << *zero << '\n'; | 1532 { |
1533 Logger::cout() << "val: " << *val << '\n'; | |
1534 Logger::cout() << "zero: " << *zero << '\n'; | |
1535 } | |
1515 return gIR->ir->CreateICmpNE(val, zero, "tmp"); | 1536 return gIR->ir->CreateICmpNE(val, zero, "tmp"); |
1516 } | 1537 } |
1517 // dynamic array | 1538 // dynamic array |
1518 else if (ty == Tarray) | 1539 else if (ty == Tarray) |
1519 { | 1540 { |