IR: RF_IgnoreMissingValues => RF_IgnoreMissingLocals, NFC
Clarify what this RemapFlag actually means.
- Change the flag name to match its intended behaviour.
- Clearly document that it's not supposed to affect globals.
- Add a host of FIXMEs to indicate how to fix the behaviour to match
the intent of the flag.
RF_IgnoreMissingLocals should only affect the behaviour of
RemapInstruction for function-local operands; namely, for operands of
type Argument, Instruction, and BasicBlock. Currently, it is *only*
passed into RemapInstruction calls (and the transitive MapValue calls
that it makes).
When I split Metadata from Value I didn't understand the flag, and I
used it in a bunch of places for "global" metadata.
This commit doesn't have any functionality change, but prepares to
cleanup MapMetadata and MapValue.
llvm-svn: 265628
GitOrigin-RevId: da68cbc4ad104a98182d44bb66aa08048f2cc061
diff --git a/lib/Transforms/Utils/ValueMapper.cpp b/lib/Transforms/Utils/ValueMapper.cpp
index 0c2954f..25c90b17 100644
--- a/lib/Transforms/Utils/ValueMapper.cpp
+++ b/lib/Transforms/Utils/ValueMapper.cpp
@@ -274,9 +274,11 @@
// are using the identity mapping.
if (isa<GlobalValue>(V)) {
if (Flags & RF_NullMapMissingGlobalValues) {
- assert(!(Flags & RF_IgnoreMissingEntries) &&
+ // FIXME: Remove this assertion. RF_IgnoreMissingLocals is unrelated to
+ // RF_NullMapMissingGlobalValues.
+ assert(!(Flags & RF_IgnoreMissingLocals) &&
"Illegal to specify both RF_NullMapMissingGlobalValues and "
- "RF_IgnoreMissingEntries");
+ "RF_IgnoreMissingLocals");
return nullptr;
}
return VM[V] = const_cast<Value*>(V);
@@ -303,8 +305,11 @@
if (!isa<LocalAsMetadata>(MD) && (Flags & RF_NoModuleLevelChanges))
return VM[V] = const_cast<Value *>(V);
+ // FIXME: be consistent with function-local values for LocalAsMetadata by
+ // returning nullptr when LocalAsMetadata is missing. Adding a mapping is
+ // expensive.
auto *MappedMD = mapMetadata(MD);
- if (MD == MappedMD || (!MappedMD && (Flags & RF_IgnoreMissingEntries)))
+ if (MD == MappedMD || (!MappedMD && (Flags & RF_IgnoreMissingLocals)))
return VM[V] = const_cast<Value *>(V);
return VM[V] = MetadataAsValue::get(V->getContext(), MappedMD);
@@ -628,14 +633,17 @@
if ((Flags & RF_NoModuleLevelChanges))
return mapToSelf(MD);
+ // FIXME: Assert that this is not LocalAsMetadata. It should be handled
+ // elsewhere.
if (const auto *VMD = dyn_cast<ValueAsMetadata>(MD)) {
// Disallow recursion into metadata mapping through mapValue.
VM.disableMapMetadata();
Value *MappedV = mapValue(VMD->getValue());
VM.enableMapMetadata();
+ // FIXME: Always use "ignore" behaviour. There should only be globals here.
if (VMD->getValue() == MappedV ||
- (!MappedV && (Flags & RF_IgnoreMissingEntries)))
+ (!MappedV && (Flags & RF_IgnoreMissingLocals)))
return mapToSelf(MD);
return mapToMetadata(MD, MappedV ? ValueAsMetadata::get(MappedV) : nullptr);
@@ -658,6 +666,8 @@
}
Metadata *Mapper::mapMetadata(const Metadata *MD) {
+ // FIXME: First check for and deal with LocalAsMetadata, so that
+ // mapSimpleMetadata() doesn't need to deal with it.
if (Optional<Metadata *> NewMD = mapSimpleMetadata(MD))
return *NewMD;
@@ -703,7 +713,7 @@
if (V)
*op = V;
else
- assert((Flags & RF_IgnoreMissingEntries) &&
+ assert((Flags & RF_IgnoreMissingLocals) &&
"Referenced value not in value map!");
}
@@ -715,7 +725,7 @@
if (V)
PN->setIncomingBlock(i, cast<BasicBlock>(V));
else
- assert((Flags & RF_IgnoreMissingEntries) &&
+ assert((Flags & RF_IgnoreMissingLocals) &&
"Referenced block not in value map!");
}
}