Mercurial > projects > ldc
comparison gen/functions.cpp @ 205:9d44ec83acd1 trunk
[svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
Fixed: Implemented volatile statements. Uses the LLVM memory barrier intrinsic, closes #21 .
author | lindquist |
---|---|
date | Tue, 13 May 2008 17:58:11 +0200 |
parents | db9890b3fb64 |
children | 7816aafeea3c |
comparison
equal
deleted
inserted
replaced
204:11fe364b9a3e | 205:9d44ec83acd1 |
---|---|
360 | 360 |
361 // construct function | 361 // construct function |
362 const llvm::FunctionType* functype = DtoFunctionType(fdecl); | 362 const llvm::FunctionType* functype = DtoFunctionType(fdecl); |
363 llvm::Function* func = vafunc ? vafunc : gIR->module->getFunction(mangled_name); | 363 llvm::Function* func = vafunc ? vafunc : gIR->module->getFunction(mangled_name); |
364 if (!func) | 364 if (!func) |
365 func = new llvm::Function(functype, DtoLinkage(fdecl), mangled_name, gIR->module); | 365 func = llvm::Function::Create(functype, DtoLinkage(fdecl), mangled_name, gIR->module); |
366 else | 366 else |
367 assert(func->getFunctionType() == functype); | 367 assert(func->getFunctionType() == functype); |
368 | 368 |
369 // add func to IRFunc | 369 // add func to IRFunc |
370 fdecl->ir.irFunc->func = func; | 370 fdecl->ir.irFunc->func = func; |
487 gIR->functions.push_back(fd->ir.irFunc); | 487 gIR->functions.push_back(fd->ir.irFunc); |
488 | 488 |
489 if (fd->isMain()) | 489 if (fd->isMain()) |
490 gIR->emitMain = true; | 490 gIR->emitMain = true; |
491 | 491 |
492 llvm::BasicBlock* beginbb = new llvm::BasicBlock("entry",func); | 492 std::string entryname("entry_"); |
493 llvm::BasicBlock* endbb = new llvm::BasicBlock("endentry",func); | 493 entryname.append(fd->toPrettyChars()); |
494 | |
495 llvm::BasicBlock* beginbb = llvm::BasicBlock::Create(entryname,func); | |
496 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("endentry",func); | |
494 | 497 |
495 //assert(gIR->scopes.empty()); | 498 //assert(gIR->scopes.empty()); |
496 gIR->scopes.push_back(IRScope(beginbb, endbb)); | 499 gIR->scopes.push_back(IRScope(beginbb, endbb)); |
497 | 500 |
498 // create alloca point | 501 // create alloca point |
606 if (!fd->isMain()) { | 609 if (!fd->isMain()) { |
607 if (!gIR->scopereturned()) { | 610 if (!gIR->scopereturned()) { |
608 // pass the previous block into this block | 611 // pass the previous block into this block |
609 if (global.params.symdebug) DtoDwarfFuncEnd(fd); | 612 if (global.params.symdebug) DtoDwarfFuncEnd(fd); |
610 if (func->getReturnType() == llvm::Type::VoidTy) { | 613 if (func->getReturnType() == llvm::Type::VoidTy) { |
611 new llvm::ReturnInst(gIR->scopebb()); | 614 llvm::ReturnInst::Create(gIR->scopebb()); |
612 } | 615 } |
613 else { | 616 else { |
614 new llvm::ReturnInst(llvm::UndefValue::get(func->getReturnType()), gIR->scopebb()); | 617 llvm::ReturnInst::Create(llvm::UndefValue::get(func->getReturnType()), gIR->scopebb()); |
615 } | 618 } |
616 } | 619 } |
617 } | 620 } |
618 | 621 |
619 // erase alloca point | 622 // erase alloca point |
634 if (lastbb->getNumUses() == 0) | 637 if (lastbb->getNumUses() == 0) |
635 lastbb->eraseFromParent(); | 638 lastbb->eraseFromParent(); |
636 else { | 639 else { |
637 new llvm::UnreachableInst(lastbb); | 640 new llvm::UnreachableInst(lastbb); |
638 /*if (func->getReturnType() == llvm::Type::VoidTy) { | 641 /*if (func->getReturnType() == llvm::Type::VoidTy) { |
639 new llvm::ReturnInst(lastbb); | 642 llvm::ReturnInst::Create(lastbb); |
640 } | 643 } |
641 else { | 644 else { |
642 new llvm::ReturnInst(llvm::UndefValue::get(func->getReturnType()), lastbb); | 645 llvm::ReturnInst::Create(llvm::UndefValue::get(func->getReturnType()), lastbb); |
643 }*/ | 646 }*/ |
644 } | 647 } |
645 } | 648 } |
646 | 649 |
647 gIR->functions.pop_back(); | 650 gIR->functions.pop_back(); |
668 pvec.push_back((const llvm::Type*)getPtrToType(chPtrType)); | 671 pvec.push_back((const llvm::Type*)getPtrToType(chPtrType)); |
669 pvec.push_back((const llvm::Type*)getPtrToType(chPtrType)); | 672 pvec.push_back((const llvm::Type*)getPtrToType(chPtrType)); |
670 const llvm::Type* rettype = (const llvm::Type*)llvm::Type::Int32Ty; | 673 const llvm::Type* rettype = (const llvm::Type*)llvm::Type::Int32Ty; |
671 | 674 |
672 llvm::FunctionType* functype = llvm::FunctionType::get(rettype, pvec, false); | 675 llvm::FunctionType* functype = llvm::FunctionType::get(rettype, pvec, false); |
673 llvm::Function* func = new llvm::Function(functype,llvm::GlobalValue::ExternalLinkage,"main",ir.module); | 676 llvm::Function* func = llvm::Function::Create(functype,llvm::GlobalValue::ExternalLinkage,"main",ir.module); |
674 | 677 |
675 llvm::BasicBlock* bb = new llvm::BasicBlock("entry",func); | 678 llvm::BasicBlock* bb = llvm::BasicBlock::Create("entry",func); |
676 | 679 |
677 // call static ctors | 680 // call static ctors |
678 llvm::Function* fn = LLVM_D_GetRuntimeFunction(ir.module,"_moduleCtor"); | 681 llvm::Function* fn = LLVM_D_GetRuntimeFunction(ir.module,"_moduleCtor"); |
679 llvm::Instruction* apt = new llvm::CallInst(fn,"",bb); | 682 llvm::Instruction* apt = llvm::CallInst::Create(fn,"",bb); |
680 | 683 |
681 // run unit tests if -unittest is provided | 684 // run unit tests if -unittest is provided |
682 if (global.params.useUnitTests) { | 685 if (global.params.useUnitTests) { |
683 fn = LLVM_D_GetRuntimeFunction(ir.module,"_moduleUnitTests"); | 686 fn = LLVM_D_GetRuntimeFunction(ir.module,"_moduleUnitTests"); |
684 llvm::Instruction* apt = new llvm::CallInst(fn,"",bb); | 687 llvm::Instruction* apt = llvm::CallInst::Create(fn,"",bb); |
685 } | 688 } |
686 | 689 |
687 // call user main function | 690 // call user main function |
688 const llvm::FunctionType* mainty = ir.mainFunc->getFunctionType(); | 691 const llvm::FunctionType* mainty = ir.mainFunc->getFunctionType(); |
689 llvm::CallInst* call; | 692 llvm::CallInst* call; |
707 v = new llvm::ZExtInst(v, DtoSize_t(), "tmp", bb); | 710 v = new llvm::ZExtInst(v, DtoSize_t(), "tmp", bb); |
708 new llvm::StoreInst(v,ptr,bb); | 711 new llvm::StoreInst(v,ptr,bb); |
709 ptr = DtoGEPi(a,0,1,"tmp",bb); | 712 ptr = DtoGEPi(a,0,1,"tmp",bb); |
710 new llvm::StoreInst(arr,ptr,bb); | 713 new llvm::StoreInst(arr,ptr,bb); |
711 args.push_back(a); | 714 args.push_back(a); |
712 new llvm::CallInst(mfn, args.begin(), args.end(), "", bb); | 715 llvm::CallInst::Create(mfn, args.begin(), args.end(), "", bb); |
713 call = new llvm::CallInst(ir.mainFunc,a,"ret",bb); | 716 call = llvm::CallInst::Create(ir.mainFunc,a,"ret",bb); |
714 } | 717 } |
715 else | 718 else |
716 { | 719 { |
717 // main with no arguments | 720 // main with no arguments |
718 call = new llvm::CallInst(ir.mainFunc,"ret",bb); | 721 call = llvm::CallInst::Create(ir.mainFunc,"ret",bb); |
719 } | 722 } |
720 call->setCallingConv(ir.mainFunc->getCallingConv()); | 723 call->setCallingConv(ir.mainFunc->getCallingConv()); |
721 | 724 |
722 // call static dtors | 725 // call static dtors |
723 fn = LLVM_D_GetRuntimeFunction(ir.module,"_moduleDtor"); | 726 fn = LLVM_D_GetRuntimeFunction(ir.module,"_moduleDtor"); |
724 new llvm::CallInst(fn,"",bb); | 727 llvm::CallInst::Create(fn,"",bb); |
725 | 728 |
726 // return | 729 // return |
727 new llvm::ReturnInst(call,bb); | 730 llvm::ReturnInst::Create(call,bb); |
728 } | 731 } |
729 | 732 |
730 ////////////////////////////////////////////////////////////////////////////////////////// | 733 ////////////////////////////////////////////////////////////////////////////////////////// |
731 | 734 |
732 const llvm::FunctionType* DtoBaseFunctionType(FuncDeclaration* fdecl) | 735 const llvm::FunctionType* DtoBaseFunctionType(FuncDeclaration* fdecl) |