diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2016-06-21 23:42:48 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2016-06-21 23:42:48 +0000 |
commit | 21521891a2e3492f22455af6c1c1a903a723115c (patch) | |
tree | d87dc59fe74622378723f1d795f09c44aacc3789 /llvm/lib/Bitcode/Writer/ValueEnumerator.cpp | |
parent | bc1570848fd279aff53d37c2da0ade99079526b0 (diff) | |
download | llvm-21521891a2e3492f22455af6c1c1a903a723115c.zip llvm-21521891a2e3492f22455af6c1c1a903a723115c.tar.gz llvm-21521891a2e3492f22455af6c1c1a903a723115c.tar.bz2 |
IR: Allow metadata attachments on declarations, and fix lazy loaded metadata issue with globals.
This change is motivated by an upcoming change to the metadata representation
used for CFI. The indirect function call checker needs type information for
external function declarations in order to correctly generate jump table
entries for such declarations. We currently associate such type information
with declarations using a global metadata node, but I plan [1] to move all
such metadata to global object attachments.
In bitcode, metadata attachments for function declarations appear in the
global metadata block. This seems reasonable to me because I expect metadata
attachments on declarations to be uncommon. In the long term I'd also expect
this to be the case for CFI, because we'd want to use some specialized bitcode
format for this metadata that could be read as part of the ThinLTO thin-link
phase, which would mean that it would not appear in the global metadata block.
To solve the lazy loaded metadata issue I was seeing with D20147, I use the
same bitcode representation for metadata attachments for global variables as I
do for function declarations. Since there's a use case for metadata attachments
in the global metadata block, we might as well use that representation for
global variables as well, at least until we have a mechanism for lazy loading
global variables.
In the assembly format, the metadata attachments appear after the "declare"
keyword in order to avoid a parsing ambiguity.
[1] http://lists.llvm.org/pipermail/llvm-dev/2016-June/100462.html
Differential Revision: http://reviews.llvm.org/D21052
llvm-svn: 273336
Diffstat (limited to 'llvm/lib/Bitcode/Writer/ValueEnumerator.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Writer/ValueEnumerator.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp index 98eb7fa..398f7d7 100644 --- a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -348,7 +348,10 @@ ValueEnumerator::ValueEnumerator(const Module &M, MDs.clear(); GV.getAllMetadata(MDs); for (const auto &I : MDs) - EnumerateMetadata(&GV, I.second); + // FIXME: Pass GV to EnumerateMetadata and arrange for the bitcode writer + // to write metadata to the global variable's own metadata block + // (PR28134). + EnumerateMetadata(nullptr, I.second); } // Enumerate types used by function bodies and argument lists. @@ -360,7 +363,7 @@ ValueEnumerator::ValueEnumerator(const Module &M, MDs.clear(); F.getAllMetadata(MDs); for (const auto &I : MDs) - EnumerateMetadata(&F, I.second); + EnumerateMetadata(F.isDeclaration() ? nullptr : &F, I.second); for (const BasicBlock &BB : F) for (const Instruction &I : BB) { @@ -530,18 +533,17 @@ void ValueEnumerator::EnumerateNamedMDNode(const NamedMDNode *MD) { EnumerateMetadata(nullptr, MD->getOperand(i)); } -unsigned ValueEnumerator::getMetadataGlobalID(const GlobalObject *GO) const { - return GO ? getValueID(GO) + 1 : 0; +unsigned ValueEnumerator::getMetadataFunctionID(const Function *F) const { + return F ? getValueID(F) + 1 : 0; } -void ValueEnumerator::EnumerateMetadata(const GlobalObject *GO, - const Metadata *MD) { - EnumerateMetadata(getMetadataGlobalID(GO), MD); +void ValueEnumerator::EnumerateMetadata(const Function *F, const Metadata *MD) { + EnumerateMetadata(getMetadataFunctionID(F), MD); } void ValueEnumerator::EnumerateFunctionLocalMetadata( const Function &F, const LocalAsMetadata *Local) { - EnumerateFunctionLocalMetadata(getMetadataGlobalID(&F), Local); + EnumerateFunctionLocalMetadata(getMetadataFunctionID(&F), Local); } void ValueEnumerator::dropFunctionFromMetadata( |