summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/Transforms/Utils/ValueMapper.h4
-rw-r--r--llvm/lib/Linker/LinkModules.cpp5
-rw-r--r--llvm/lib/Transforms/Utils/ValueMapper.cpp20
3 files changed, 22 insertions, 7 deletions
diff --git a/llvm/include/llvm/Transforms/Utils/ValueMapper.h b/llvm/include/llvm/Transforms/Utils/ValueMapper.h
index 6f4cd24c849..17ce4f4ab73 100644
--- a/llvm/include/llvm/Transforms/Utils/ValueMapper.h
+++ b/llvm/include/llvm/Transforms/Utils/ValueMapper.h
@@ -69,6 +69,10 @@ namespace llvm {
/// Instruct the remapper to move distinct metadata instead of duplicating
/// it when there are module-level changes.
RF_MoveDistinctMDs = 4,
+
+ /// 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,
};
static inline RemapFlags operator|(RemapFlags LHS, RemapFlags RHS) {
diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp
index ee41d25ed70..5419c22fbf7 100644
--- a/llvm/lib/Linker/LinkModules.cpp
+++ b/llvm/lib/Linker/LinkModules.cpp
@@ -1628,8 +1628,9 @@ void ModuleLinker::linkNamedMDNodes() {
NamedMDNode *DestNMD = DstM->getOrInsertNamedMetadata(NMD.getName());
// Add Src elements into Dest node.
for (const MDNode *op : NMD.operands())
- DestNMD->addOperand(MapMetadata(op, ValueMap, RF_MoveDistinctMDs,
- &TypeMap, &ValMaterializer));
+ DestNMD->addOperand(MapMetadata(
+ op, ValueMap, RF_MoveDistinctMDs | RF_NullMapMissingGlobalValues,
+ &TypeMap, &ValMaterializer));
}
}
diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp
index 414d4eaa68d..c8d13385b1d 100644
--- a/llvm/lib/Transforms/Utils/ValueMapper.cpp
+++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp
@@ -42,9 +42,16 @@ Value *llvm::MapValue(const Value *V, ValueToValueMapTy &VM, RemapFlags Flags,
// Global values do not need to be seeded into the VM if they
// are using the identity mapping.
- if (isa<GlobalValue>(V))
+ if (isa<GlobalValue>(V)) {
+ if (Flags & RF_NullMapMissingGlobalValues) {
+ assert(!(Flags & RF_IgnoreMissingEntries) &&
+ "Illegal to specify both RF_NullMapMissingGlobalValues and "
+ "RF_IgnoreMissingEntries");
+ return nullptr;
+ }
return VM[V] = const_cast<Value*>(V);
-
+ }
+
if (const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
// Inline asm may need *type* remapping.
FunctionType *NewTy = IA->getFunctionType();
@@ -74,7 +81,8 @@ Value *llvm::MapValue(const Value *V, ValueToValueMapTy &VM, RemapFlags Flags,
// correct. For now, just match behaviour from before the metadata/value
// split.
//
- // assert(MappedMD && "Referenced metadata value not in value map");
+ // assert((MappedMD || (Flags & RF_NullMapMissingGlobalValues)) &&
+ // "Referenced metadata value not in value map");
return VM[V] = MetadataAsValue::get(V->getContext(), MappedMD);
}
@@ -184,7 +192,8 @@ static Metadata *mapMetadataOp(Metadata *Op,
// correct. For now, just match behaviour from before the metadata/value
// split.
//
- // llvm_unreachable("Referenced metadata not in value map!");
+ // assert((Flags & RF_NullMapMissingGlobalValues) &&
+ // "Referenced metadata not in value map!");
return nullptr;
}
@@ -305,7 +314,8 @@ static Metadata *MapMetadataImpl(const Metadata *MD,
// correct. For now, just match behaviour from before the metadata/value
// split.
//
- // assert(MappedV && "Referenced metadata not in value map!");
+ // assert((MappedV || (Flags & RF_NullMapMissingGlobalValues)) &&
+ // "Referenced metadata not in value map!");
if (MappedV)
return mapToMetadata(VM, MD, ValueAsMetadata::get(MappedV));
return nullptr;
OpenPOWER on IntegriCloud