diff options
author | Robert Lytton <robert@xmos.com> | 2014-07-03 09:30:33 +0000 |
---|---|---|
committer | Robert Lytton <robert@xmos.com> | 2014-07-03 09:30:33 +0000 |
commit | 57765d53477910de18f8c5e7d2ce585a0f782935 (patch) | |
tree | dd49e005a177b84fd5bc0e17927d1c5402bd18a2 /clang/lib | |
parent | 5b88f78f7a342d1eee97acff4dcc4c0170464535 (diff) | |
download | bcm5719-llvm-57765d53477910de18f8c5e7d2ce585a0f782935.tar.gz bcm5719-llvm-57765d53477910de18f8c5e7d2ce585a0f782935.zip |
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
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 14 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.h | 7 |
2 files changed, 15 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index e1ff9485a80..2f840dd182e 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")) { diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index 88f5faf7093..c0bfb4c5e6b 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -349,8 +349,8 @@ class CodeGenModule : public CodeGenTypeCache { /// emitted when the translation unit is complete. CtorList GlobalDtors; - /// A map of canonical GlobalDecls to their mangled names. - llvm::DenseMap<GlobalDecl, StringRef> MangledDeclNames; + /// An ordered map of canonical GlobalDecls to their mangled names. + llvm::MapVector<GlobalDecl, StringRef> MangledDeclNames; llvm::StringMap<GlobalDecl, llvm::BumpPtrAllocator> Manglings; /// Global annotations. @@ -1146,6 +1146,9 @@ private: /// \brief Emit the Clang version as llvm.ident metadata. void EmitVersionIdentMetadata(); + /// Emits target specific Metadata for global declarations. + void EmitTargetMetadata(); + /// Emit the llvm.gcov metadata used to tell LLVM where to emit the .gcno and /// .gcda files in a way that persists in .bc files. void EmitCoverageFile(); |