diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2009-11-18 14:59:57 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2009-11-18 14:59:57 +0000 |
commit | 741c13ecc20fb35b836ad690aeecd402f002d654 (patch) | |
tree | 60a1694bec5a44d15456acc880cb2f91619f66aa /lib/CodeGen/CodeGenFunction.cpp | |
parent | b3a51061b1b9c4add078237850649f7c9efb13ab (diff) | |
download | FreeBSD-src-741c13ecc20fb35b836ad690aeecd402f002d654.zip FreeBSD-src-741c13ecc20fb35b836ad690aeecd402f002d654.tar.gz |
Update clang to r89205.
Diffstat (limited to 'lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r-- | lib/CodeGen/CodeGenFunction.cpp | 127 |
1 files changed, 17 insertions, 110 deletions
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 4be3413..475c7bf 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -27,11 +27,7 @@ CodeGenFunction::CodeGenFunction(CodeGenModule &cgm) : BlockFunction(cgm, *this, Builder), CGM(cgm), Target(CGM.getContext().Target), Builder(cgm.getModule().getContext()), -#ifndef USEINDIRECTBRANCH - DebugInfo(0), IndirectGotoSwitch(0), -#else DebugInfo(0), IndirectBranch(0), -#endif SwitchInsn(0), CaseRangeBlock(0), InvokeDest(0), CXXThisDecl(0) { LLVMIntTy = ConvertType(getContext().IntTy); @@ -134,7 +130,6 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) { EmitFunctionEpilog(*CurFnInfo, ReturnValue); -#ifdef USEINDIRECTBRANCH // If someone did an indirect goto, emit the indirect goto block at the end of // the function. if (IndirectBranch) { @@ -142,13 +137,10 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) { Builder.ClearInsertionPoint(); } - -#endif // Remove the AllocaInsertPt instruction, which is just a convenience for us. llvm::Instruction *Ptr = AllocaInsertPt; AllocaInsertPt = 0; Ptr->eraseFromParent(); -#ifdef USEINDIRECTBRANCH // If someone took the address of a label but never did an indirect goto, we // made a zero entry PHI node, which is illegal, zap it now. @@ -159,8 +151,6 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) { PN->eraseFromParent(); } } - -#endif } void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, @@ -260,19 +250,21 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, // FIXME: Support CXXTryStmt here, too. if (const CompoundStmt *S = FD->getCompoundBody()) { StartFunction(GD, FD->getResultType(), Fn, Args, S->getLBracLoc()); - const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(FD); - llvm::BasicBlock *DtorEpilogue = 0; - if (DD) { - DtorEpilogue = createBasicBlock("dtor.epilogue"); - - PushCleanupBlock(DtorEpilogue); - } - - if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(FD)) + + if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(FD)) { EmitCtorPrologue(CD, GD.getCtorType()); - EmitStmt(S); + EmitStmt(S); + + // If any of the member initializers are temporaries bound to references + // make sure to emit their destructors. + EmitCleanupBlocks(0); + + } else if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(FD)) { + llvm::BasicBlock *DtorEpilogue = createBasicBlock("dtor.epilogue"); + PushCleanupBlock(DtorEpilogue); + + EmitStmt(S); - if (DD) { CleanupBlockInfo Info = PopCleanupBlock(); assert(Info.CleanupBlock == DtorEpilogue && "Block mismatch!"); @@ -283,7 +275,11 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, EmitBlock(Info.SwitchBlock); if (Info.EndBlock) EmitBlock(Info.EndBlock); + } else { + // Just a regular function, emit its body. + EmitStmt(S); } + FinishFunction(S->getRBracLoc()); } else if (FD->isImplicit()) { const CXXRecordDecl *ClassDecl = @@ -493,121 +489,32 @@ void CodeGenFunction::EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty) { TypeInfo.second/8)); } -#ifndef USEINDIRECTBRANCH -unsigned CodeGenFunction::GetIDForAddrOfLabel(const LabelStmt *L) { - // Use LabelIDs.size()+1 as the new ID if one hasn't been assigned. - unsigned &Entry = LabelIDs[L]; - if (Entry) return Entry; -#else - llvm::BlockAddress *CodeGenFunction::GetAddrOfLabel(const LabelStmt *L) { // Make sure that there is a block for the indirect goto. if (IndirectBranch == 0) GetIndirectGotoBlock(); -#endif -#ifndef USEINDIRECTBRANCH - Entry = LabelIDs.size(); -#else llvm::BasicBlock *BB = getBasicBlockForLabel(L); -#endif - -#ifndef USEINDIRECTBRANCH - // If this is the first "address taken" of a label and the indirect goto has - // already been seen, add this to it. - if (IndirectGotoSwitch) { - // If this is the first address-taken label, set it as the default dest. - if (Entry == 1) - IndirectGotoSwitch->setSuccessor(0, getBasicBlockForLabel(L)); - else { - // Otherwise add it to the switch as a new dest. - const llvm::IntegerType *Int32Ty = llvm::Type::getInt32Ty(VMContext); - IndirectGotoSwitch->addCase(llvm::ConstantInt::get(Int32Ty, Entry), - getBasicBlockForLabel(L)); - } - } - return Entry; -#else // Make sure the indirect branch includes all of the address-taken blocks. IndirectBranch->addDestination(BB); return llvm::BlockAddress::get(CurFn, BB); -#endif } llvm::BasicBlock *CodeGenFunction::GetIndirectGotoBlock() { -#ifndef USEINDIRECTBRANCH - // If we already made the switch stmt for indirect goto, return its block. - if (IndirectGotoSwitch) return IndirectGotoSwitch->getParent(); -#else // If we already made the indirect branch for indirect goto, return its block. if (IndirectBranch) return IndirectBranch->getParent(); -#endif -#ifndef USEINDIRECTBRANCH - EmitBlock(createBasicBlock("indirectgoto")); -#else CGBuilderTy TmpBuilder(createBasicBlock("indirectgoto")); -#endif -#ifndef USEINDIRECTBRANCH - const llvm::IntegerType *Int32Ty = llvm::Type::getInt32Ty(VMContext); -#else const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(VMContext); -#endif // Create the PHI node that indirect gotos will add entries to. -#ifndef USEINDIRECTBRANCH - llvm::Value *DestVal = Builder.CreatePHI(Int32Ty, "indirect.goto.dest"); -#else llvm::Value *DestVal = TmpBuilder.CreatePHI(Int8PtrTy, "indirect.goto.dest"); -#endif - -#ifndef USEINDIRECTBRANCH - // Create the switch instruction. For now, set the insert block to this block - // which will be fixed as labels are added. - IndirectGotoSwitch = Builder.CreateSwitch(DestVal, Builder.GetInsertBlock()); - - // Clear the insertion point to indicate we are in unreachable code. - Builder.ClearInsertionPoint(); - // If we already have labels created, add them. - if (!LabelIDs.empty()) { - // Invert LabelID's so that the order is determinstic. - std::vector<const LabelStmt*> AddrTakenLabelsByID; - AddrTakenLabelsByID.resize(LabelIDs.size()); - - for (std::map<const LabelStmt*,unsigned>::iterator - LI = LabelIDs.begin(), LE = LabelIDs.end(); LI != LE; ++LI) { - assert(LI->second-1 < AddrTakenLabelsByID.size() && - "Numbering inconsistent"); - AddrTakenLabelsByID[LI->second-1] = LI->first; - } - - // Set the default entry as the first block. - IndirectGotoSwitch->setSuccessor(0, - getBasicBlockForLabel(AddrTakenLabelsByID[0])); - - // FIXME: The iteration order of this is nondeterminstic! - for (unsigned i = 1, e = AddrTakenLabelsByID.size(); i != e; ++i) - IndirectGotoSwitch->addCase(llvm::ConstantInt::get(Int32Ty, i+1), - getBasicBlockForLabel(AddrTakenLabelsByID[i])); - } else { - // Otherwise, create a dead block and set it as the default dest. This will - // be removed by the optimizers after the indirect goto is set up. - llvm::BasicBlock *Dummy = createBasicBlock("indgoto.dummy"); - EmitBlock(Dummy); - IndirectGotoSwitch->setSuccessor(0, Dummy); - Builder.CreateUnreachable(); - Builder.ClearInsertionPoint(); - } - - return IndirectGotoSwitch->getParent(); -#else // Create the indirect branch instruction. IndirectBranch = TmpBuilder.CreateIndirectBr(DestVal); return IndirectBranch->getParent(); -#endif } llvm::Value *CodeGenFunction::GetVLASize(const VariableArrayType *VAT) { |