[llvm] r256019 - Drop support for dematerializing.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 18 11:57:26 PST 2015


Author: rafael
Date: Fri Dec 18 13:57:26 2015
New Revision: 256019

URL: http://llvm.org/viewvc/llvm-project?rev=256019&view=rev
Log:
Drop support for dematerializing.

It was only used on lib/Linker and the use was "dead" since it was used on a
function the IRMover had just moved.

Modified:
    llvm/trunk/include/llvm/IR/GVMaterializer.h
    llvm/trunk/include/llvm/IR/GlobalValue.h
    llvm/trunk/include/llvm/IR/Module.h
    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
    llvm/trunk/lib/IR/Globals.cpp
    llvm/trunk/lib/IR/Module.cpp
    llvm/trunk/lib/Linker/IRMover.cpp
    llvm/trunk/unittests/Bitcode/BitReaderTest.cpp

Modified: llvm/trunk/include/llvm/IR/GVMaterializer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/GVMaterializer.h?rev=256019&r1=256018&r2=256019&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/GVMaterializer.h (original)
+++ llvm/trunk/include/llvm/IR/GVMaterializer.h Fri Dec 18 13:57:26 2015
@@ -36,21 +36,10 @@ protected:
 public:
   virtual ~GVMaterializer();
 
-  /// True if GV has been materialized and can be dematerialized back to
-  /// whatever backing store this GVMaterializer uses.
-  virtual bool isDematerializable(const GlobalValue *GV) const = 0;
-
   /// Make sure the given GlobalValue is fully read.
   ///
   virtual std::error_code materialize(GlobalValue *GV) = 0;
 
-  /// If the given GlobalValue is read in, and if the GVMaterializer supports
-  /// it, release the memory for the GV, and set it up to be materialized
-  /// lazily. If the Materializer doesn't support this capability, this method
-  /// is a noop.
-  ///
-  virtual void dematerialize(GlobalValue *) {}
-
   /// Make sure the entire Module has been completely read.
   ///
   virtual std::error_code materializeModule(Module *M) = 0;

Modified: llvm/trunk/include/llvm/IR/GlobalValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/GlobalValue.h?rev=256019&r1=256018&r2=256019&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/GlobalValue.h (original)
+++ llvm/trunk/include/llvm/IR/GlobalValue.h Fri Dec 18 13:57:26 2015
@@ -322,21 +322,11 @@ public:
   /// function has been read in yet or not.
   bool isMaterializable() const;
 
-  /// Returns true if this function was loaded from a GVMaterializer that's
-  /// still attached to its Module and that knows how to dematerialize the
-  /// function.
-  bool isDematerializable() const;
-
   /// Make sure this GlobalValue is fully read. If the module is corrupt, this
   /// returns true and fills in the optional string with information about the
   /// problem.  If successful, this returns false.
   std::error_code materialize();
 
-  /// If this GlobalValue is read in, and if the GVMaterializer supports it,
-  /// release the memory for the function, and set it up to be materialized
-  /// lazily. If !isDematerializable(), this method is a noop.
-  void dematerialize();
-
 /// @}
 
   /// Return true if the primary definition of this global value is outside of

Modified: llvm/trunk/include/llvm/IR/Module.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Module.h?rev=256019&r1=256018&r2=256019&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Module.h (original)
+++ llvm/trunk/include/llvm/IR/Module.h Fri Dec 18 13:57:26 2015
@@ -440,18 +440,10 @@ public:
   /// Retrieves the GVMaterializer, if any, for this Module.
   GVMaterializer *getMaterializer() const { return Materializer.get(); }
 
-  /// Returns true if this GV was loaded from this Module's GVMaterializer and
-  /// the GVMaterializer knows how to dematerialize the GV.
-  bool isDematerializable(const GlobalValue *GV) const;
-
   /// Make sure the GlobalValue is fully read. If the module is corrupt, this
   /// returns true and fills in the optional string with information about the
   /// problem. If successful, this returns false.
   std::error_code materialize(GlobalValue *GV);
-  /// If the GlobalValue is read in, and if the GVMaterializer supports it,
-  /// release the memory for the function, and set it up to be materialized
-  /// lazily. If !isDematerializable(), this method is a no-op.
-  void dematerialize(GlobalValue *GV);
 
   /// Make sure all GlobalValues in this Module are fully read.
   std::error_code materializeAll();

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=256019&r1=256018&r2=256019&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Fri Dec 18 13:57:26 2015
@@ -227,9 +227,6 @@ class BitcodeReader : public GVMateriali
   /// (e.g.) blockaddress forward references.
   bool WillMaterializeAllForwardRefs = false;
 
-  /// Functions that have block addresses taken.  This is usually empty.
-  SmallPtrSet<const Function *, 4> BlockAddressesTaken;
-
   /// True if any Metadata block has been materialized.
   bool IsMetadataMaterialized = false;
 
@@ -256,11 +253,9 @@ public:
 
   void releaseBuffer();
 
-  bool isDematerializable(const GlobalValue *GV) const override;
   std::error_code materialize(GlobalValue *GV) override;
   std::error_code materializeModule(Module *M) override;
   std::vector<StructType *> getIdentifiedStructTypes() const override;
-  void dematerialize(GlobalValue *GV) override;
 
   /// \brief Main interface to parsing a bitcode buffer.
   /// \returns true if an error occurred.
@@ -2951,9 +2946,6 @@ std::error_code BitcodeReader::parseCons
       if (!Fn)
         return error("Invalid record");
 
-      // Don't let Fn get dematerialized.
-      BlockAddressesTaken.insert(Fn);
-
       // If the function is already parsed we can insert the block address right
       // away.
       BasicBlock *BB;
@@ -5291,32 +5283,6 @@ std::error_code BitcodeReader::materiali
   return materializeForwardReferencedFunctions();
 }
 
-bool BitcodeReader::isDematerializable(const GlobalValue *GV) const {
-  const Function *F = dyn_cast<Function>(GV);
-  if (!F || F->isDeclaration())
-    return false;
-
-  // Dematerializing F would leave dangling references that wouldn't be
-  // reconnected on re-materialization.
-  if (BlockAddressesTaken.count(F))
-    return false;
-
-  return DeferredFunctionInfo.count(const_cast<Function*>(F));
-}
-
-void BitcodeReader::dematerialize(GlobalValue *GV) {
-  Function *F = dyn_cast<Function>(GV);
-  // If this function isn't dematerializable, this is a noop.
-  if (!F || !isDematerializable(F))
-    return;
-
-  assert(DeferredFunctionInfo.count(F) && "No info to read function later?");
-
-  // Just forget the function body, we can remat it later.
-  F->dropAllReferences();
-  F->setIsMaterializable(true);
-}
-
 std::error_code BitcodeReader::materializeModule(Module *M) {
   assert(M == TheModule &&
          "Can only Materialize the Module this BitcodeReader is attached to.");

Modified: llvm/trunk/lib/IR/Globals.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Globals.cpp?rev=256019&r1=256018&r2=256019&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Globals.cpp (original)
+++ llvm/trunk/lib/IR/Globals.cpp Fri Dec 18 13:57:26 2015
@@ -32,15 +32,9 @@ bool GlobalValue::isMaterializable() con
     return F->isMaterializable();
   return false;
 }
-bool GlobalValue::isDematerializable() const {
-  return getParent() && getParent()->isDematerializable(this);
-}
 std::error_code GlobalValue::materialize() {
   return getParent()->materialize(this);
 }
-void GlobalValue::dematerialize() {
-  getParent()->dematerialize(this);
-}
 
 /// Override destroyConstantImpl to make sure it doesn't get called on
 /// GlobalValue's because they shouldn't be treated like other constants.

Modified: llvm/trunk/lib/IR/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Module.cpp?rev=256019&r1=256018&r2=256019&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Module.cpp (original)
+++ llvm/trunk/lib/IR/Module.cpp Fri Dec 18 13:57:26 2015
@@ -384,12 +384,6 @@ void Module::setMaterializer(GVMateriali
   Materializer.reset(GVM);
 }
 
-bool Module::isDematerializable(const GlobalValue *GV) const {
-  if (Materializer)
-    return Materializer->isDematerializable(GV);
-  return false;
-}
-
 std::error_code Module::materialize(GlobalValue *GV) {
   if (!Materializer)
     return std::error_code();
@@ -397,11 +391,6 @@ std::error_code Module::materialize(Glob
   return Materializer->materialize(GV);
 }
 
-void Module::dematerialize(GlobalValue *GV) {
-  if (Materializer)
-    return Materializer->dematerialize(GV);
-}
-
 std::error_code Module::materializeAll() {
   if (!Materializer)
     return std::error_code();

Modified: llvm/trunk/lib/Linker/IRMover.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/IRMover.cpp?rev=256019&r1=256018&r2=256019&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/IRMover.cpp (original)
+++ llvm/trunk/lib/Linker/IRMover.cpp Fri Dec 18 13:57:26 2015
@@ -1163,7 +1163,6 @@ bool IRLinker::linkFunctionBody(Function
   for (Argument &Arg : Src.args())
     ValueMap.erase(&Arg);
 
-  Src.dematerialize();
   return false;
 }
 

Modified: llvm/trunk/unittests/Bitcode/BitReaderTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Bitcode/BitReaderTest.cpp?rev=256019&r1=256018&r2=256019&view=diff
==============================================================================
--- llvm/trunk/unittests/Bitcode/BitReaderTest.cpp (original)
+++ llvm/trunk/unittests/Bitcode/BitReaderTest.cpp Fri Dec 18 13:57:26 2015
@@ -140,30 +140,6 @@ TEST(BitReaderTest, MateralizeForwardRef
   EXPECT_FALSE(M->getFunction("func")->empty());
 }
 
-TEST(BitReaderTest, DematerializeFunctionPreservesLinkageType) {
-  SmallString<1024> Mem;
-
-  LLVMContext Context;
-  std::unique_ptr<Module> M = getLazyModuleFromAssembly(
-      Context, Mem, "define internal i32 @func() {\n"
-                      "ret i32 0\n"
-                    "}\n");
-
-  EXPECT_FALSE(verifyModule(*M, &dbgs()));
-
-  M->getFunction("func")->materialize();
-  EXPECT_FALSE(M->getFunction("func")->empty());
-  EXPECT_TRUE(M->getFunction("func")->getLinkage() ==
-              GlobalValue::InternalLinkage);
-
-  // Check that the linkage type is preserved after dematerialization.
-  M->getFunction("func")->dematerialize();
-  EXPECT_TRUE(M->getFunction("func")->empty());
-  EXPECT_TRUE(M->getFunction("func")->getLinkage() ==
-              GlobalValue::InternalLinkage);
-  EXPECT_FALSE(verifyModule(*M, &dbgs()));
-}
-
 // Tests that lazy evaluation can parse functions out of order.
 TEST(BitReaderTest, MaterializeFunctionsOutOfOrder) {
   SmallString<1024> Mem;
@@ -240,10 +216,6 @@ TEST(BitReaderTest, MaterializeFunctions
                     "  unreachable\n"
                     "}\n");
   EXPECT_FALSE(verifyModule(*M, &dbgs()));
-
-  // Try (and fail) to dematerialize @func.
-  M->getFunction("func")->dematerialize();
-  EXPECT_FALSE(M->getFunction("func")->empty());
 }
 
 TEST(BitReaderTest, MaterializeFunctionsForBlockAddrInFunctionBefore) {
@@ -271,11 +243,6 @@ TEST(BitReaderTest, MaterializeFunctions
   EXPECT_FALSE(M->getFunction("func")->empty());
   EXPECT_TRUE(M->getFunction("other")->empty());
   EXPECT_FALSE(verifyModule(*M, &dbgs()));
-
-  // Try (and fail) to dematerialize @func.
-  M->getFunction("func")->dematerialize();
-  EXPECT_FALSE(M->getFunction("func")->empty());
-  EXPECT_FALSE(verifyModule(*M, &dbgs()));
 }
 
 TEST(BitReaderTest, MaterializeFunctionsForBlockAddrInFunctionAfter) {
@@ -303,11 +270,6 @@ TEST(BitReaderTest, MaterializeFunctions
   EXPECT_FALSE(M->getFunction("func")->empty());
   EXPECT_TRUE(M->getFunction("other")->empty());
   EXPECT_FALSE(verifyModule(*M, &dbgs()));
-
-  // Try (and fail) to dematerialize @func.
-  M->getFunction("func")->dematerialize();
-  EXPECT_FALSE(M->getFunction("func")->empty());
-  EXPECT_FALSE(verifyModule(*M, &dbgs()));
 }
 
 } // end namespace




More information about the llvm-commits mailing list