summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bitcode/Writer/ValueEnumerator.h
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2016-04-02 15:22:57 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2016-04-02 15:22:57 +0000
commit520f8542fffc9bc1dae1f866782db867da2e6c39 (patch)
treec2fbe46c901c0034c5c02ca63b15ba92b5acff85 /llvm/lib/Bitcode/Writer/ValueEnumerator.h
parent0b76b723f425a999688625f3d9271eb26ef9ee2f (diff)
downloadbcm5719-llvm-520f8542fffc9bc1dae1f866782db867da2e6c39.tar.gz
bcm5719-llvm-520f8542fffc9bc1dae1f866782db867da2e6c39.zip
Bitcode: Try to emit metadata in function blocks
Whenever metadata is only referenced by a single function, emit the metadata just in that function block. This should improve lazy-loading by reducing the amount of metadata in the global block. For now, this should catch all DILocations, and anything else that happens to be referenced only by a single function. It's also a first step toward a couple of possible future directions (which this commit does *not* implement): 1. Some debug info metadata is only referenced from compile units and individual functions. If we can drop the link from the compile unit, this optimization will get more powerful. 2. Any uniqued metadata that isn't referenced globally can in theory be emitted in every function block that references it (trading off bitcode size and full-parse time vs. lazy-load time). Note: this assumes the new BitcodeReader error checking from r265223. The metadata stored in function blocks gets purged after parsing each function, which means unresolved forward references will get lost. Since all the global metadata should have already been resolved by the time we get to the function metadata blocks we just need to check for that case. (If for some reason we need to handle bitcode that fails the checks in r265223, the fix is to store about-to-be-dropped unresolved nodes in MetadataList::shrinkTo until they can be handled succesfully by a future call to MetadataList::tryToResolveCycles.) llvm-svn: 265226
Diffstat (limited to 'llvm/lib/Bitcode/Writer/ValueEnumerator.h')
-rw-r--r--llvm/lib/Bitcode/Writer/ValueEnumerator.h66
1 files changed, 59 insertions, 7 deletions
diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.h b/llvm/lib/Bitcode/Writer/ValueEnumerator.h
index 4c5c03d13e2..ade52a90060 100644
--- a/llvm/lib/Bitcode/Writer/ValueEnumerator.h
+++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.h
@@ -63,8 +63,42 @@ private:
ComdatSetType Comdats;
std::vector<const Metadata *> MDs;
- typedef DenseMap<const Metadata *, unsigned> MetadataMapType;
+ std::vector<const Metadata *> FunctionMDs;
+
+ /// Index of information about a piece of metadata.
+ struct MDIndex {
+ unsigned F = 0; ///< The ID of the function for this metadata, if any.
+ unsigned ID = 0; ///< The implicit ID of this metadata in bitcode.
+
+ MDIndex() = default;
+ explicit MDIndex(unsigned F) : F(F) {}
+
+ /// Check if this has a function tag, and it's different from NewF.
+ bool hasDifferentFunction(unsigned NewF) const { return F && F != NewF; }
+
+ /// Fetch the MD this references out of the given metadata array.
+ const Metadata *get(ArrayRef<const Metadata *> MDs) const {
+ assert(ID && "Expected non-zero ID");
+ assert(ID <= MDs.size() && "Expected valid ID");
+ return MDs[ID - 1];
+ }
+ };
+ typedef DenseMap<const Metadata *, MDIndex> MetadataMapType;
MetadataMapType MetadataMap;
+
+ /// Range of metadata IDs, as a half-open range.
+ struct MDRange {
+ unsigned First = 0;
+ unsigned Last = 0;
+
+ /// Number of strings in the prefix of the metadata range.
+ unsigned NumStrings = 0;
+
+ MDRange() = default;
+ explicit MDRange(unsigned First) : First(First) {}
+ };
+ SmallDenseMap<unsigned, MDRange, 1> FunctionMDInfo;
+
bool ShouldPreserveUseListOrder;
typedef DenseMap<AttributeSet, unsigned> AttributeGroupMapType;
@@ -116,7 +150,7 @@ public:
return ID - 1;
}
unsigned getMetadataOrNullID(const Metadata *MD) const {
- return MetadataMap.lookup(MD);
+ return MetadataMap.lookup(MD).ID;
}
unsigned numMDs() const { return MDs.size(); }
@@ -196,13 +230,31 @@ public:
private:
void OptimizeConstants(unsigned CstStart, unsigned CstEnd);
- // Reorder the reachable metadata. This is not just an optimization, but is
- // mandatory for emitting MDString correctly.
+ /// Reorder the reachable metadata.
+ ///
+ /// This is not just an optimization, but is mandatory for emitting MDString
+ /// correctly.
void organizeMetadata();
- void EnumerateMDNodeOperands(const MDNode *N);
- void EnumerateMetadata(const Metadata *MD);
- void EnumerateFunctionLocalMetadata(const LocalAsMetadata *Local);
+ /// Drop the function tag from the transitive operands of the given node.
+ void dropFunctionFromOps(const MDNode &N);
+
+ /// Incorporate the function metadata.
+ ///
+ /// This should be called before enumerating LocalAsMetadata for the
+ /// function.
+ void incorporateFunctionMetadata(const Function &F);
+
+ bool insertMetadata(unsigned F, const Metadata *MD);
+
+ unsigned getMetadataFunctionID(const Function *F) const;
+ void EnumerateMDNodeOperands(const Function *F, const MDNode *N);
+ void EnumerateMDNodeOperands(unsigned F, const MDNode *N);
+ void EnumerateMetadata(const Function *F, const Metadata *MD);
+ void EnumerateMetadata(unsigned F, const Metadata *MD);
+ void EnumerateFunctionLocalMetadata(const Function &F,
+ const LocalAsMetadata *Local);
+ void EnumerateFunctionLocalMetadata(unsigned F, const LocalAsMetadata *Local);
void EnumerateNamedMDNode(const NamedMDNode *NMD);
void EnumerateValue(const Value *V);
void EnumerateType(Type *T);
OpenPOWER on IntegriCloud