[llvm] r265832 - ValueMapper: Roll RemapInstruction into Mapper, NFC

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 8 12:09:34 PDT 2016


Author: dexonsmith
Date: Fri Apr  8 14:09:34 2016
New Revision: 265832

URL: http://llvm.org/viewvc/llvm-project?rev=265832&view=rev
Log:
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.

Modified:
    llvm/trunk/include/llvm/Transforms/Utils/ValueMapper.h
    llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp

Modified: llvm/trunk/include/llvm/Transforms/Utils/ValueMapper.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/ValueMapper.h?rev=265832&r1=265831&r2=265832&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/ValueMapper.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/ValueMapper.h Fri Apr  8 14:09:34 2016
@@ -146,6 +146,14 @@ MDNode *MapMetadata(const MDNode *MD, Va
                     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,

Modified: llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp?rev=265832&r1=265831&r2=265832&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp Fri Apr  8 14:09:34 2016
@@ -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 *
                                           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
   // 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->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);
   }




More information about the llvm-commits mailing list