Drop support for dematerializing.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 18 Dec 2015 19:57:26 +0000 (19:57 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 18 Dec 2015 19:57:26 +0000 (19:57 +0000)
It was only used on lib/Linker and the use was "dead" since it was used on a
function the IRMover had just moved.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256019 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 992a8c8fc6f15bb5495a0253d8088eab9a74361d..687f526e00e508ed349074eea29c334093713ce5 100644 (file)
@@ -36,21 +36,10 @@ protected:
 public:
   virtual ~GVMaterializer();
 
 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;
 
   /// 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;
   /// Make sure the entire Module has been completely read.
   ///
   virtual std::error_code materializeModule(Module *M) = 0;
index 2f9172648a26a6d3f9cec216b7ef5be03b1c662e..4fa4e7daeab0e5634586290baa8f521818ea8f53 100644 (file)
@@ -322,21 +322,11 @@ public:
   /// function has been read in yet or not.
   bool isMaterializable() const;
 
   /// 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();
 
   /// 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
 /// @}
 
   /// Return true if the primary definition of this global value is outside of
index 2378b6d83d877372a983fd73bfada3c45d3fa43f..a46ba80bbf2f46d0a9f0963b006f8756d2365688 100644 (file)
@@ -440,18 +440,10 @@ public:
   /// Retrieves the GVMaterializer, if any, for this Module.
   GVMaterializer *getMaterializer() const { return Materializer.get(); }
 
   /// 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);
   /// 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();
 
   /// Make sure all GlobalValues in this Module are fully read.
   std::error_code materializeAll();
index ff08f55d43f144a0c017df60b6cfcfcf43b0ed2b..d7fce0580c2ecd40ea790bd611b5fe8a298b8a1b 100644 (file)
@@ -227,9 +227,6 @@ class BitcodeReader : public GVMaterializer {
   /// (e.g.) blockaddress forward references.
   bool WillMaterializeAllForwardRefs = false;
 
   /// (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;
 
   /// True if any Metadata block has been materialized.
   bool IsMetadataMaterialized = false;
 
@@ -256,11 +253,9 @@ public:
 
   void releaseBuffer();
 
 
   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;
   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.
 
   /// \brief Main interface to parsing a bitcode buffer.
   /// \returns true if an error occurred.
@@ -2951,9 +2946,6 @@ std::error_code BitcodeReader::parseConstants() {
       if (!Fn)
         return error("Invalid record");
 
       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;
       // If the function is already parsed we can insert the block address right
       // away.
       BasicBlock *BB;
@@ -5291,32 +5283,6 @@ std::error_code BitcodeReader::materialize(GlobalValue *GV) {
   return materializeForwardReferencedFunctions();
 }
 
   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.");
 std::error_code BitcodeReader::materializeModule(Module *M) {
   assert(M == TheModule &&
          "Can only Materialize the Module this BitcodeReader is attached to.");
index c538c7baa1feba5928ecc86a0176a5253ea3a216..6159f93faf89bdb368cf31f5b81b556f1456883c 100644 (file)
@@ -32,15 +32,9 @@ bool GlobalValue::isMaterializable() const {
     return F->isMaterializable();
   return false;
 }
     return F->isMaterializable();
   return false;
 }
-bool GlobalValue::isDematerializable() const {
-  return getParent() && getParent()->isDematerializable(this);
-}
 std::error_code GlobalValue::materialize() {
   return getParent()->materialize(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.
 
 /// Override destroyConstantImpl to make sure it doesn't get called on
 /// GlobalValue's because they shouldn't be treated like other constants.
index 2acd9db210db52e43fc49249b3daa666f324d7e5..d17449108690617adc3ecb3f42fabef1c6640e4b 100644 (file)
@@ -384,12 +384,6 @@ void Module::setMaterializer(GVMaterializer *GVM) {
   Materializer.reset(GVM);
 }
 
   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();
 std::error_code Module::materialize(GlobalValue *GV) {
   if (!Materializer)
     return std::error_code();
@@ -397,11 +391,6 @@ std::error_code Module::materialize(GlobalValue *GV) {
   return Materializer->materialize(GV);
 }
 
   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();
 std::error_code Module::materializeAll() {
   if (!Materializer)
     return std::error_code();
index 718bfc998cb98b4061fdb37f41dc56c94b0c4a3f..6e344f81b5fdfc9d7dc6fce17eeabb5c20df0d20 100644 (file)
@@ -1163,7 +1163,6 @@ bool IRLinker::linkFunctionBody(Function &Dst, Function &Src) {
   for (Argument &Arg : Src.args())
     ValueMap.erase(&Arg);
 
   for (Argument &Arg : Src.args())
     ValueMap.erase(&Arg);
 
-  Src.dematerialize();
   return false;
 }
 
   return false;
 }
 
index 055850da505ac4c5ea7bb486b67f27ab2bb8b733..420aca2443bb420eeb9f690e0f3d351e0e03bdf9 100644 (file)
@@ -140,30 +140,6 @@ TEST(BitReaderTest, MateralizeForwardRefWithStream) {
   EXPECT_FALSE(M->getFunction("func")->empty());
 }
 
   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;
 // Tests that lazy evaluation can parse functions out of order.
 TEST(BitReaderTest, MaterializeFunctionsOutOfOrder) {
   SmallString<1024> Mem;
@@ -240,10 +216,6 @@ TEST(BitReaderTest, MaterializeFunctionsForBlockAddr) { // PR11677
                     "  unreachable\n"
                     "}\n");
   EXPECT_FALSE(verifyModule(*M, &dbgs()));
                     "  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) {
 }
 
 TEST(BitReaderTest, MaterializeFunctionsForBlockAddrInFunctionBefore) {
@@ -271,11 +243,6 @@ TEST(BitReaderTest, MaterializeFunctionsForBlockAddrInFunctionBefore) {
   EXPECT_FALSE(M->getFunction("func")->empty());
   EXPECT_TRUE(M->getFunction("other")->empty());
   EXPECT_FALSE(verifyModule(*M, &dbgs()));
   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) {
 }
 
 TEST(BitReaderTest, MaterializeFunctionsForBlockAddrInFunctionAfter) {
@@ -303,11 +270,6 @@ TEST(BitReaderTest, MaterializeFunctionsForBlockAddrInFunctionAfter) {
   EXPECT_FALSE(M->getFunction("func")->empty());
   EXPECT_TRUE(M->getFunction("other")->empty());
   EXPECT_FALSE(verifyModule(*M, &dbgs()));
   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
 }
 
 } // end namespace