From 99b53613ebe2c59d41030e987962c1ed101b2efe Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 21 Mar 2009 08:03:33 +0000 Subject: simplify some more code. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67439 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 59 +++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 27 deletions(-) (limited to 'lib/CodeGen/CodeGenModule.cpp') diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 91ab2b7b03..38b8d36ed5 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -535,11 +535,12 @@ bool CodeGenModule::MayDeferGeneration(const ValueDecl *Global) { if (FD->getAttr() || FD->getAttr()) return false; + // FIXME: What about inline, and/or extern inline? if (FD->getStorageClass() != FunctionDecl::Static) return false; } else { const VarDecl *VD = cast(Global); - assert(VD->isFileVarDecl() && "Invalid decl."); + assert(VD->isFileVarDecl() && "Invalid decl"); if (VD->getStorageClass() != VarDecl::Static) return false; @@ -594,42 +595,46 @@ void CodeGenModule::EmitGlobalDefinition(const ValueDecl *D) { QualType ASTTy = D->getType(); const llvm::Type *Ty = getTypes().ConvertTypeForMem(ASTTy); - const llvm::Type *PTy = llvm::PointerType::get(Ty, ASTTy.getAddressSpace()); // Lookup the entry, lazily creating it if necessary. llvm::GlobalValue *&Entry = GlobalDeclMap[getMangledName(D)]; - if (!Entry) { - llvm::GlobalVariable *GV = - new llvm::GlobalVariable(Ty, false, - llvm::GlobalValue::ExternalLinkage, - 0, getMangledName(D), &getModule(), - 0, ASTTy.getAddressSpace()); - Entry = GV; + if (Entry) { + const llvm::Type *PTy = llvm::PointerType::get(Ty, ASTTy.getAddressSpace()); + + // Make sure the result is of the correct type. + if (Entry->getType() != PTy) + return llvm::ConstantExpr::getBitCast(Entry, PTy); + return Entry; + } + + llvm::GlobalVariable *GV = + new llvm::GlobalVariable(Ty, false, + llvm::GlobalValue::ExternalLinkage, + 0, getMangledName(D), &getModule(), + 0, ASTTy.getAddressSpace()); - // Handle things which are present even on external declarations. + // Handle things which are present even on external declarations. - // FIXME: This code is overly simple and should be merged with - // other global handling. + // FIXME: This code is overly simple and should be merged with + // other global handling. - GV->setConstant(D->getType().isConstant(Context)); + GV->setConstant(D->getType().isConstant(Context)); - // FIXME: Merge with other attribute handling code. + // FIXME: Merge with other attribute handling code. - if (D->getStorageClass() == VarDecl::PrivateExtern) - setGlobalVisibility(GV, VisibilityAttr::HiddenVisibility); + if (D->getStorageClass() == VarDecl::PrivateExtern) + setGlobalVisibility(GV, VisibilityAttr::HiddenVisibility); - if (D->getAttr() || D->getAttr()) - GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage); + if (D->getAttr() || D->getAttr()) + GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage); - if (const AsmLabelAttr *ALA = D->getAttr()) { - // Prefaced with special LLVM marker to indicate that the name - // should not be munged. - GV->setName("\01" + ALA->getLabel()); - } + // FIXME: This should be handled by the mangler! + if (const AsmLabelAttr *ALA = D->getAttr()) { + // Prefaced with special LLVM marker to indicate that the name + // should not be munged. + GV->setName("\01" + ALA->getLabel()); } - - // Make sure the result is of the correct type. - return llvm::ConstantExpr::getBitCast(Entry, PTy); + return Entry = GV; } void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) { @@ -826,7 +831,7 @@ llvm::Constant *CodeGenModule::GetAddrOfFunction(const FunctionDecl *D) { // Lookup the entry, lazily creating it if necessary. llvm::GlobalValue *&Entry = GlobalDeclMap[getMangledName(D)]; if (!Entry) - Entry = EmitForwardFunctionDefinition(D, 0); + return Entry = EmitForwardFunctionDefinition(D, 0); if (Entry->getType() != PTy) return llvm::ConstantExpr::getBitCast(Entry, PTy); -- cgit v1.2.3-18-g5258