summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/Transforms/Utils/ValueMapper.h8
-rw-r--r--llvm/lib/Transforms/Utils/ValueMapper.cpp19
2 files changed, 19 insertions, 8 deletions
diff --git a/llvm/include/llvm/Transforms/Utils/ValueMapper.h b/llvm/include/llvm/Transforms/Utils/ValueMapper.h
index e4dedfe699c..710bf8f839b 100644
--- a/llvm/include/llvm/Transforms/Utils/ValueMapper.h
+++ b/llvm/include/llvm/Transforms/Utils/ValueMapper.h
@@ -146,6 +146,14 @@ MDNode *MapMetadata(const MDNode *MD, ValueToValueMapTy &VM,
ValueMapTypeRemapper *TypeMapper = nullptr,
ValueMaterializer *Materializer = nullptr);
+/// Convert the instruction operands from referencing the current values into
+/// those specified by VM.
+///
+/// If \a RF_IgnoreMissingLocals is set and an operand can't be found via \a
+/// MapValue(), use the old value. Otherwise assert that this doesn't happen.
+///
+/// Note that \a MapValue() only returns \c nullptr for SSA values missing from
+/// \c VM.
void RemapInstruction(Instruction *I, ValueToValueMapTy &VM,
RemapFlags Flags = RF_None,
ValueMapTypeRemapper *TypeMapper = nullptr,
diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp
index 472c2cab26d..ffd3a274cde 100644
--- a/llvm/lib/Transforms/Utils/ValueMapper.cpp
+++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp
@@ -79,6 +79,7 @@ public:
~Mapper();
Value *mapValue(const Value *V);
+ void remapInstruction(Instruction *I);
/// Map metadata.
///
@@ -735,15 +736,16 @@ MDNode *llvm::MapMetadata(const MDNode *MD, ValueToValueMapTy &VM,
Flags, TypeMapper, Materializer));
}
-/// RemapInstruction - Convert the instruction operands from referencing the
-/// current values into those specified by VMap.
-///
-void llvm::RemapInstruction(Instruction *I, ValueToValueMapTy &VMap,
+void llvm::RemapInstruction(Instruction *I, ValueToValueMapTy &VM,
RemapFlags Flags, ValueMapTypeRemapper *TypeMapper,
- ValueMaterializer *Materializer){
+ ValueMaterializer *Materializer) {
+ Mapper(VM, Flags, TypeMapper, Materializer).remapInstruction(I);
+}
+
+void Mapper::remapInstruction(Instruction *I) {
// Remap operands.
for (User::op_iterator op = I->op_begin(), E = I->op_end(); op != E; ++op) {
- Value *V = MapValue(*op, VMap, Flags, TypeMapper, Materializer);
+ Value *V = mapValue(*op);
// If we aren't ignoring missing entries, assert that something happened.
if (V)
*op = V;
@@ -755,7 +757,8 @@ void llvm::RemapInstruction(Instruction *I, ValueToValueMapTy &VMap,
// Remap phi nodes' incoming blocks.
if (PHINode *PN = dyn_cast<PHINode>(I)) {
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
- Value *V = MapValue(PN->getIncomingBlock(i), VMap, Flags);
+ // FIXME: Use Mapper::mapValue (but note the missing Materializer flag).
+ Value *V = MapValue(PN->getIncomingBlock(i), VM, Flags);
// If we aren't ignoring missing entries, assert that something happened.
if (V)
PN->setIncomingBlock(i, cast<BasicBlock>(V));
@@ -770,7 +773,7 @@ void llvm::RemapInstruction(Instruction *I, ValueToValueMapTy &VMap,
I->getAllMetadata(MDs);
for (const auto &MI : MDs) {
MDNode *Old = MI.second;
- MDNode *New = MapMetadata(Old, VMap, Flags, TypeMapper, Materializer);
+ MDNode *New = cast_or_null<MDNode>(mapMetadata(Old));
if (New != Old)
I->setMetadata(MI.first, New);
}
OpenPOWER on IntegriCloud