[llvm] r265633 - ValueMapper: Allow RF_IgnoreMissingLocals and RF_NullMapMissingGlobalValues

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 6 18:22:46 PDT 2016


Author: dexonsmith
Date: Wed Apr  6 20:22:45 2016
New Revision: 265633

URL: http://llvm.org/viewvc/llvm-project?rev=265633&view=rev
Log:
ValueMapper: Allow RF_IgnoreMissingLocals and RF_NullMapMissingGlobalValues

Remove the assertion that disallowed the combination, since
RF_IgnoreMissingLocals should have no effect on globals.  As it happens,
RF_NullMapMissingGlobalValues asserted in MapValue(Constant*,...), so I
also changed a cast to a cast_or_null to get my test passing.

Modified:
    llvm/trunk/include/llvm/Transforms/Utils/ValueMapper.h
    llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp
    llvm/trunk/unittests/Transforms/Utils/ValueMapperTest.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=265633&r1=265632&r2=265633&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/ValueMapper.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/ValueMapper.h Wed Apr  6 20:22:45 2016
@@ -128,7 +128,8 @@ inline Constant *MapValue(const Constant
                           RemapFlags Flags = RF_None,
                           ValueMapTypeRemapper *TypeMapper = nullptr,
                           ValueMaterializer *Materializer = nullptr) {
-  return cast<Constant>(
+  // This can be null for RF_NullMapMissingGlobalValues.
+  return cast_or_null<Constant>(
       MapValue((const Value *)V, VM, Flags, TypeMapper, Materializer));
 }
 

Modified: llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp?rev=265633&r1=265632&r2=265633&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp Wed Apr  6 20:22:45 2016
@@ -276,14 +276,8 @@ Value *Mapper::mapValue(const Value *V)
   // Global values do not need to be seeded into the VM if they
   // are using the identity mapping.
   if (isa<GlobalValue>(V)) {
-    if (Flags & RF_NullMapMissingGlobalValues) {
-      // FIXME: Remove this assertion.  RF_IgnoreMissingLocals is unrelated to
-      // RF_NullMapMissingGlobalValues.
-      assert(!(Flags & RF_IgnoreMissingLocals) &&
-             "Illegal to specify both RF_NullMapMissingGlobalValues and "
-             "RF_IgnoreMissingLocals");
+    if (Flags & RF_NullMapMissingGlobalValues)
       return nullptr;
-    }
     return VM[V] = const_cast<Value*>(V);
   }
 

Modified: llvm/trunk/unittests/Transforms/Utils/ValueMapperTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Transforms/Utils/ValueMapperTest.cpp?rev=265633&r1=265632&r2=265633&view=diff
==============================================================================
--- llvm/trunk/unittests/Transforms/Utils/ValueMapperTest.cpp (original)
+++ llvm/trunk/unittests/Transforms/Utils/ValueMapperTest.cpp Wed Apr  6 20:22:45 2016
@@ -209,4 +209,16 @@ TEST(ValueMapperTest, MapValueLocalAsMet
   EXPECT_EQ(&A, MapValue(MAV, VM, RF_IgnoreMissingLocals));
 }
 
+TEST(ValueMapperTest, MapMetadataNullMapGlobalWithIgnoreMissingLocals) {
+  LLVMContext C;
+  FunctionType *FTy =
+      FunctionType::get(Type::getVoidTy(C), Type::getInt8Ty(C), false);
+  std::unique_ptr<Function> F(
+      Function::Create(FTy, GlobalValue::ExternalLinkage, "F"));
+
+  ValueToValueMapTy VM;
+  RemapFlags Flags = RF_IgnoreMissingLocals | RF_NullMapMissingGlobalValues;
+  EXPECT_EQ(nullptr, MapValue(F.get(), VM, Flags));
+}
+
 } // end namespace




More information about the llvm-commits mailing list