summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Linker/LinkModules.cpp
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2015-12-17 17:14:09 +0000
committerTeresa Johnson <tejohnson@google.com>2015-12-17 17:14:09 +0000
commite5a619173274bf2a9033ea1c8b2346f1bee2766b (patch)
treedf1a23654ddaef760e878af89977d13945649896 /llvm/lib/Linker/LinkModules.cpp
parentcaaa3aa07c8fa129c8032597f2d0317637a1569a (diff)
downloadbcm5719-llvm-e5a619173274bf2a9033ea1c8b2346f1bee2766b.tar.gz
bcm5719-llvm-e5a619173274bf2a9033ea1c8b2346f1bee2766b.zip
[ThinLTO] Metadata linking for imported functions
Summary: Second patch split out from http://reviews.llvm.org/D14752. Maps metadata as a post-pass from each module when importing complete, suturing up final metadata to the temporary metadata left on the imported instructions. This entails saving the mapping from bitcode value id to temporary metadata in the importing pass, and from bitcode value id to final metadata during the metadata linking postpass. Depends on D14825. Reviewers: dexonsmith, joker.eph Subscribers: davidxl, llvm-commits, joker.eph Differential Revision: http://reviews.llvm.org/D14838 llvm-svn: 255909
Diffstat (limited to 'llvm/lib/Linker/LinkModules.cpp')
-rw-r--r--llvm/lib/Linker/LinkModules.cpp33
1 files changed, 28 insertions, 5 deletions
diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp
index 9c9c0ef321f..556251092a2 100644
--- a/llvm/lib/Linker/LinkModules.cpp
+++ b/llvm/lib/Linker/LinkModules.cpp
@@ -48,6 +48,11 @@ class ModuleLinker {
/// as part of a different backend compilation process.
bool HasExportedFunctions = false;
+ /// Association between metadata value id and temporary metadata that
+ /// remains unmapped after function importing. Saved during function
+ /// importing and consumed during the metadata linking postpass.
+ DenseMap<unsigned, MDNode *> *ValIDToTempMDMap;
+
/// Used as the callback for lazy linking.
/// The mover has just hit GV and we have to decide if it, and other members
/// of the same comdat, should be linked. Every member to be linked is passed
@@ -150,9 +155,10 @@ class ModuleLinker {
public:
ModuleLinker(IRMover &Mover, Module &SrcM, unsigned Flags,
const FunctionInfoIndex *Index = nullptr,
- DenseSet<const GlobalValue *> *FunctionsToImport = nullptr)
+ DenseSet<const GlobalValue *> *FunctionsToImport = nullptr,
+ DenseMap<unsigned, MDNode *> *ValIDToTempMDMap = nullptr)
: Mover(Mover), SrcM(SrcM), Flags(Flags), ImportIndex(Index),
- ImportFunction(FunctionsToImport) {
+ ImportFunction(FunctionsToImport), ValIDToTempMDMap(ValIDToTempMDMap) {
assert((ImportIndex || !ImportFunction) &&
"Expect a FunctionInfoIndex when importing");
// If we have a FunctionInfoIndex but no function to import,
@@ -161,6 +167,8 @@ public:
// may be exported to another backend compilation.
if (ImportIndex && !ImportFunction)
HasExportedFunctions = ImportIndex->hasExportedFunctions(SrcM);
+ assert((ValIDToTempMDMap || !ImportFunction) &&
+ "Function importing must provide a ValIDToTempMDMap");
}
bool run();
@@ -502,6 +510,7 @@ bool ModuleLinker::getComdatResult(const Comdat *SrcC,
bool ModuleLinker::shouldLinkFromSource(bool &LinkFromSrc,
const GlobalValue &Dest,
const GlobalValue &Src) {
+
// Should we unconditionally use the Src?
if (shouldOverrideFromSrc()) {
LinkFromSrc = true;
@@ -776,7 +785,8 @@ bool ModuleLinker::run() {
if (Mover.move(SrcM, ValuesToLink.getArrayRef(),
[this](GlobalValue &GV, IRMover::ValueAdder Add) {
addLazyFor(GV, Add);
- }))
+ },
+ ValIDToTempMDMap, false))
return true;
Module &DstM = Mover.getModule();
for (auto &P : Internalize) {
@@ -791,8 +801,10 @@ Linker::Linker(Module &M) : Mover(M) {}
bool Linker::linkInModule(std::unique_ptr<Module> Src, unsigned Flags,
const FunctionInfoIndex *Index,
- DenseSet<const GlobalValue *> *FunctionsToImport) {
- ModuleLinker TheLinker(Mover, *Src, Flags, Index, FunctionsToImport);
+ DenseSet<const GlobalValue *> *FunctionsToImport,
+ DenseMap<unsigned, MDNode *> *ValIDToTempMDMap) {
+ ModuleLinker TheLinker(Mover, *Src, Flags, Index, FunctionsToImport,
+ ValIDToTempMDMap);
return TheLinker.run();
}
@@ -801,6 +813,17 @@ bool Linker::linkInModuleForCAPI(Module &Src) {
return TheLinker.run();
}
+bool Linker::linkInMetadata(Module &Src,
+ DenseMap<unsigned, MDNode *> *ValIDToTempMDMap) {
+ SetVector<GlobalValue *> ValuesToLink;
+ if (Mover.move(
+ Src, ValuesToLink.getArrayRef(),
+ [this](GlobalValue &GV, IRMover::ValueAdder Add) { assert(false); },
+ ValIDToTempMDMap, true))
+ return true;
+ return false;
+}
+
//===----------------------------------------------------------------------===//
// LinkModules entrypoint.
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud