From 57765d53477910de18f8c5e7d2ce585a0f782935 Mon Sep 17 00:00:00 2001 From: Robert Lytton Date: Thu, 3 Jul 2014 09:30:33 +0000 Subject: Move the calling of emitTargetMD() later. Summary: Because a global created by GetOrCreateLLVMGlobal() is not finalised until later viz: extern char a[]; char f(){ return a[5];} char a[10]; Change MangledDeclNames to use a MapVector rather than a DenseMap so that the Metadata is output in order of original declaration, so to make deterministic and improve human readablity. Differential Revision: http://reviews.llvm.org/D4176 llvm-svn: 212263 --- clang/lib/CodeGen/CodeGenModule.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index e1ff948..2f840dd 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -393,6 +393,8 @@ void CodeGenModule::Release() { DebugInfo->finalize(); EmitVersionIdentMetadata(); + + EmitTargetMetadata(); } void CodeGenModule::UpdateCompletedType(const TagDecl *TD) { @@ -1534,8 +1536,6 @@ CodeGenModule::GetOrCreateLLVMFunction(StringRef MangledName, } } - getTargetCodeGenInfo().emitTargetMD(D, F, *this); - // Make sure the result is of the requested type. if (!IsIncompleteFunction) { assert(F->getType()->getElementType() == Ty); @@ -1685,8 +1685,6 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, if (AddrSpace != Ty->getAddressSpace()) return llvm::ConstantExpr::getAddrSpaceCast(GV, Ty); - getTargetCodeGenInfo().emitTargetMD(D, GV, *this); - return GV; } @@ -3340,6 +3338,14 @@ void CodeGenModule::EmitVersionIdentMetadata() { IdentMetadata->addOperand(llvm::MDNode::get(Ctx, IdentNode)); } +void CodeGenModule::EmitTargetMetadata() { + for (auto &I : MangledDeclNames) { + const Decl *D = I.first.getDecl()->getMostRecentDecl(); + llvm::GlobalValue *GV = GetGlobalValue(I.second); + getTargetCodeGenInfo().emitTargetMD(D, GV, *this); + } +} + void CodeGenModule::EmitCoverageFile() { if (!getCodeGenOpts().CoverageFile.empty()) { if (llvm::NamedMDNode *CUNode = TheModule.getNamedMetadata("llvm.dbg.cu")) { -- cgit v1.1