ValueMapper: Roll RemapInstruction into Mapper, NFC
Add Mapper::remapInstruction, move the guts of llvm::RemapInstruction into it, and use the same Mapper for most of the calls to MapValue and MapMetadata. There should be no functionality change here. I left off the call to MapValue that wasn't passing in a Materializer argument (for basic blocks of PHINodes). It shouldn't change functionality either, but I'm suspicious enough to commit separately. llvm-svn: 265832
This commit is contained in:
parent
fe6583a0a6
commit
a574e7a7a4
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue