aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Bitcode
diff options
context:
space:
mode:
authorVictor Hernandez <vhernandez@apple.com>2010-01-13 19:37:33 +0000
committerVictor Hernandez <vhernandez@apple.com>2010-01-13 19:37:33 +0000
commit0c316416bdf6a915d084052e7e9c1ad943ff1353 (patch)
treee2d446caa6ac48719f5c73dabedb970d53087a90 /lib/Bitcode
parentab9cd107211604988c19d2d49eb4bfcd05df7995 (diff)
downloadexternal_llvm-0c316416bdf6a915d084052e7e9c1ad943ff1353.zip
external_llvm-0c316416bdf6a915d084052e7e9c1ad943ff1353.tar.gz
external_llvm-0c316416bdf6a915d084052e7e9c1ad943ff1353.tar.bz2
Write function-local metadata as a metadata subblock of a funciton block
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93339 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode')
-rw-r--r--lib/Bitcode/Writer/BitcodeWriter.cpp40
1 files changed, 36 insertions, 4 deletions
diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp
index 26c922a..a81b346 100644
--- a/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -499,11 +499,13 @@ static void WriteModuleMetadata(const ValueEnumerator &VE,
for (unsigned i = 0, e = Vals.size(); i != e; ++i) {
if (const MDNode *N = dyn_cast<MDNode>(Vals[i].first)) {
- if (!StartedMetadataBlock) {
- Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);
- StartedMetadataBlock = true;
+ if (!N->isFunctionLocal()) {
+ if (!StartedMetadataBlock) {
+ Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);
+ StartedMetadataBlock = true;
+ }
+ WriteMDNode(N, VE, Stream, Record);
}
- WriteMDNode(N, VE, Stream, Record);
} else if (const MDString *MDS = dyn_cast<MDString>(Vals[i].first)) {
if (!StartedMetadataBlock) {
Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);
@@ -552,6 +554,35 @@ static void WriteModuleMetadata(const ValueEnumerator &VE,
Stream.ExitBlock();
}
+static void WriteFunctionLocalMetadata(const ValueEnumerator &VE,
+ BitstreamWriter &Stream) {
+ bool StartedMetadataBlock = false;
+ SmallVector<uint64_t, 64> Record;
+ ValueEnumerator::ValueList Vals = VE.getMDValues();
+ ValueEnumerator::ValueList::iterator it = Vals.begin();
+ ValueEnumerator::ValueList::iterator end = Vals.end();
+
+ while (it != end) {
+ if (const MDNode *N = dyn_cast<MDNode>((*it).first)) {
+ if (N->isFunctionLocal()) {
+ if (!StartedMetadataBlock) {
+ Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);
+ StartedMetadataBlock = true;
+ }
+ WriteMDNode(N, VE, Stream, Record);
+ // Remove function-local MD, since it is used outside of function.
+ it = Vals.erase(it);
+ end = Vals.end();
+ continue;
+ }
+ }
+ ++it;
+ }
+
+ if (StartedMetadataBlock)
+ Stream.ExitBlock();
+}
+
static void WriteMetadataAttachment(const Function &F,
const ValueEnumerator &VE,
BitstreamWriter &Stream) {
@@ -1210,6 +1241,7 @@ static void WriteFunction(const Function &F, ValueEnumerator &VE,
// Emit names for all the instructions etc.
WriteValueSymbolTable(F.getValueSymbolTable(), VE, Stream);
+ WriteFunctionLocalMetadata(VE, Stream);
WriteMetadataAttachment(F, VE, Stream);
VE.purgeFunction();
Stream.ExitBlock();