summaryrefslogtreecommitdiff
path: root/include
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
commitd0f8afa9b6d5bc8697c56f1b909cfce0e30eec9e (patch)
tree48cd2005cdf733ae9b1b1d7ab933750cb3e04cd2 /include
parent55618d8f5c5498672bc044ccfc32dcd4f76f8456 (diff)
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255909 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/IR/GVMaterializer.h10
-rw-r--r--include/llvm/IR/Metadata.h5
-rw-r--r--include/llvm/IRReader/IRReader.h9
-rw-r--r--include/llvm/Linker/IRMover.h5
-rw-r--r--include/llvm/Linker/Linker.h13
-rw-r--r--include/llvm/Transforms/Utils/ValueMapper.h11
6 files changed, 45 insertions, 8 deletions
diff --git a/include/llvm/IR/GVMaterializer.h b/include/llvm/IR/GVMaterializer.h
index 1d6c9157f0b..992a8c8fc6f 100644
--- a/include/llvm/IR/GVMaterializer.h
+++ b/include/llvm/IR/GVMaterializer.h
@@ -18,12 +18,14 @@
#ifndef LLVM_IR_GVMATERIALIZER_H
#define LLVM_IR_GVMATERIALIZER_H
+#include "llvm/ADT/DenseMap.h"
#include <system_error>
#include <vector>
namespace llvm {
class Function;
class GlobalValue;
+class Metadata;
class Module;
class StructType;
@@ -56,6 +58,14 @@ public:
virtual std::error_code materializeMetadata() = 0;
virtual void setStripDebugInfo() = 0;
+ /// Client should define this interface if the mapping between metadata
+ /// values and value ids needs to be preserved, e.g. across materializer
+ /// instantiations. If OnlyTempMD is true, only those that have remained
+ /// temporary metadata are recorded in the map.
+ virtual void
+ saveMDValueList(DenseMap<const Metadata *, unsigned> &MDValueToValIDMap,
+ bool OnlyTempMD) {}
+
virtual std::vector<StructType *> getIdentifiedStructTypes() const = 0;
};
diff --git a/include/llvm/IR/Metadata.h b/include/llvm/IR/Metadata.h
index 84c82476c4f..2e9dc457bb0 100644
--- a/include/llvm/IR/Metadata.h
+++ b/include/llvm/IR/Metadata.h
@@ -832,10 +832,11 @@ public:
/// \brief Resolve cycles.
///
/// Once all forward declarations have been resolved, force cycles to be
- /// resolved.
+ /// resolved. If \p MDMaterialized is true, then any temporary metadata
+ /// is ignored, otherwise it asserts when encountering temporary metadata.
///
/// \pre No operands (or operands' operands, etc.) have \a isTemporary().
- void resolveCycles();
+ void resolveCycles(bool MDMaterialized = true);
/// \brief Replace a temporary node with a permanent one.
///
diff --git a/include/llvm/IRReader/IRReader.h b/include/llvm/IRReader/IRReader.h
index 2d9ace0b62a..523cd3d6df7 100644
--- a/include/llvm/IRReader/IRReader.h
+++ b/include/llvm/IRReader/IRReader.h
@@ -27,10 +27,11 @@ class LLVMContext;
/// If the given file holds a bitcode image, return a Module
/// for it which does lazy deserialization of function bodies. Otherwise,
/// attempt to parse it as LLVM Assembly and return a fully populated
-/// Module.
-std::unique_ptr<Module> getLazyIRFileModule(StringRef Filename,
- SMDiagnostic &Err,
- LLVMContext &Context);
+/// Module. The ShouldLazyLoadMetadata flag is passed down to the bitcode
+/// reader to optionally enable lazy metadata loading.
+std::unique_ptr<Module>
+getLazyIRFileModule(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context,
+ bool ShouldLazyLoadMetadata = false);
/// If the given MemoryBuffer holds a bitcode image, return a Module
/// for it. Otherwise, attempt to parse it as LLVM Assembly and return
diff --git a/include/llvm/Linker/IRMover.h b/include/llvm/Linker/IRMover.h
index 10e6d5c0f70..a964cc4b72c 100644
--- a/include/llvm/Linker/IRMover.h
+++ b/include/llvm/Linker/IRMover.h
@@ -16,6 +16,7 @@
namespace llvm {
class GlobalValue;
+class MDNode;
class Module;
class StructType;
class Type;
@@ -60,7 +61,9 @@ public:
/// Move in the provide values. The source is destroyed.
/// Returns true on error.
bool move(Module &Src, ArrayRef<GlobalValue *> ValuesToLink,
- std::function<void(GlobalValue &GV, ValueAdder Add)> AddLazyFor);
+ std::function<void(GlobalValue &GV, ValueAdder Add)> AddLazyFor,
+ DenseMap<unsigned, MDNode *> *ValIDToTempMDMap = nullptr,
+ bool IsMetadataLinkingPostpass = false);
Module &getModule() { return Composite; }
private:
diff --git a/include/llvm/Linker/Linker.h b/include/llvm/Linker/Linker.h
index eca0e9321a1..dde3f73883c 100644
--- a/include/llvm/Linker/Linker.h
+++ b/include/llvm/Linker/Linker.h
@@ -42,11 +42,14 @@ public:
/// For ThinLTO function importing/exporting the \p FunctionInfoIndex
/// is passed. If \p FunctionsToImport is provided, only the functions that
/// are part of the set will be imported from the source module.
+ /// The \p ValIDToTempMDMap is populated by the linker when function
+ /// importing is performed.
///
/// Returns true on error.
bool linkInModule(std::unique_ptr<Module> Src, unsigned Flags = Flags::None,
const FunctionInfoIndex *Index = nullptr,
- DenseSet<const GlobalValue *> *FunctionsToImport = nullptr);
+ DenseSet<const GlobalValue *> *FunctionsToImport = nullptr,
+ DenseMap<unsigned, MDNode *> *ValIDToTempMDMap = nullptr);
/// This exists to implement the deprecated LLVMLinkModules C api. Don't use
/// for anything else.
@@ -54,6 +57,14 @@ public:
static bool linkModules(Module &Dest, std::unique_ptr<Module> Src,
unsigned Flags = Flags::None);
+
+ /// \brief Link metadata from \p Src into the composite. The source is
+ /// destroyed.
+ ///
+ /// The \p ValIDToTempMDMap sound have been populated earlier during function
+ /// importing from \p Src.
+ bool linkInMetadata(Module &Src,
+ DenseMap<unsigned, MDNode *> *ValIDToTempMDMap);
};
/// Create a new module with exported local functions renamed and promoted
diff --git a/include/llvm/Transforms/Utils/ValueMapper.h b/include/llvm/Transforms/Utils/ValueMapper.h
index 5687bd21e99..7b1382854ba 100644
--- a/include/llvm/Transforms/Utils/ValueMapper.h
+++ b/include/llvm/Transforms/Utils/ValueMapper.h
@@ -55,6 +55,12 @@ namespace llvm {
/// It is called after the mapping is recorded, so it doesn't need to worry
/// about recursion.
virtual void materializeInitFor(GlobalValue *New, GlobalValue *Old);
+
+ /// If the client needs to handle temporary metadata it must implement
+ /// these methods.
+ virtual Metadata *mapTemporaryMetadata(Metadata *MD) { return nullptr; }
+ virtual void replaceTemporaryMetadata(const Metadata *OrigMD,
+ Metadata *NewMD) {}
};
/// RemapFlags - These are flags that the value mapping APIs allow.
@@ -78,6 +84,11 @@ namespace llvm {
/// Any global values not in value map are mapped to null instead of
/// mapping to self. Illegal if RF_IgnoreMissingEntries is also set.
RF_NullMapMissingGlobalValues = 8,
+
+ /// Set when there is still temporary metadata that must be handled,
+ /// such as when we are doing function importing and will materialize
+ /// and link metadata as a postpass.
+ RF_HaveUnmaterializedMetadata = 16,
};
static inline RemapFlags operator|(RemapFlags LHS, RemapFlags RHS) {