From f11617b0abb665433a65f40882ceaefda7bd8322 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 18 Dec 2015 19:57:26 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256019 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/GVMaterializer.h | 11 -------- include/llvm/IR/GlobalValue.h | 10 -------- include/llvm/IR/Module.h | 8 ------ lib/Bitcode/Reader/BitcodeReader.cpp | 34 ------------------------- lib/IR/Globals.cpp | 6 ----- lib/IR/Module.cpp | 11 -------- lib/Linker/IRMover.cpp | 1 - unittests/Bitcode/BitReaderTest.cpp | 38 ---------------------------- 8 files changed, 119 deletions(-) diff --git a/include/llvm/IR/GVMaterializer.h b/include/llvm/IR/GVMaterializer.h index 992a8c8fc6f..687f526e00e 100644 --- a/include/llvm/IR/GVMaterializer.h +++ b/include/llvm/IR/GVMaterializer.h @@ -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; diff --git a/include/llvm/IR/GlobalValue.h b/include/llvm/IR/GlobalValue.h index 2f9172648a2..4fa4e7daeab 100644 --- a/include/llvm/IR/GlobalValue.h +++ b/include/llvm/IR/GlobalValue.h @@ -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 diff --git a/include/llvm/IR/Module.h b/include/llvm/IR/Module.h index 2378b6d83d8..a46ba80bbf2 100644 --- a/include/llvm/IR/Module.h +++ b/include/llvm/IR/Module.h @@ -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(); diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index ff08f55d43f..d7fce0580c2 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -227,9 +227,6 @@ class BitcodeReader : public GVMaterializer { /// (e.g.) blockaddress forward references. bool WillMaterializeAllForwardRefs = false; - /// Functions that have block addresses taken. This is usually empty. - SmallPtrSet 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 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::parseConstants() { 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::materialize(GlobalValue *GV) { return materializeForwardReferencedFunctions(); } -bool BitcodeReader::isDematerializable(const GlobalValue *GV) const { - const Function *F = dyn_cast(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(F)); -} - -void BitcodeReader::dematerialize(GlobalValue *GV) { - Function *F = dyn_cast(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."); diff --git a/lib/IR/Globals.cpp b/lib/IR/Globals.cpp index c538c7baa1f..6159f93faf8 100644 --- a/lib/IR/Globals.cpp +++ b/lib/IR/Globals.cpp @@ -32,15 +32,9 @@ bool GlobalValue::isMaterializable() const { 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. diff --git a/lib/IR/Module.cpp b/lib/IR/Module.cpp index 2acd9db210d..d1744910869 100644 --- a/lib/IR/Module.cpp +++ b/lib/IR/Module.cpp @@ -384,12 +384,6 @@ void Module::setMaterializer(GVMaterializer *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(); @@ -397,11 +391,6 @@ std::error_code Module::materialize(GlobalValue *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(); diff --git a/lib/Linker/IRMover.cpp b/lib/Linker/IRMover.cpp index 718bfc998cb..6e344f81b5f 100644 --- a/lib/Linker/IRMover.cpp +++ b/lib/Linker/IRMover.cpp @@ -1163,7 +1163,6 @@ bool IRLinker::linkFunctionBody(Function &Dst, Function &Src) { for (Argument &Arg : Src.args()) ValueMap.erase(&Arg); - Src.dematerialize(); return false; } diff --git a/unittests/Bitcode/BitReaderTest.cpp b/unittests/Bitcode/BitReaderTest.cpp index 055850da505..420aca2443b 100644 --- a/unittests/Bitcode/BitReaderTest.cpp +++ b/unittests/Bitcode/BitReaderTest.cpp @@ -140,30 +140,6 @@ TEST(BitReaderTest, MateralizeForwardRefWithStream) { EXPECT_FALSE(M->getFunction("func")->empty()); } -TEST(BitReaderTest, DematerializeFunctionPreservesLinkageType) { - SmallString<1024> Mem; - - LLVMContext Context; - std::unique_ptr 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, MaterializeFunctionsForBlockAddr) { // PR11677 " 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, MaterializeFunctionsForBlockAddrInFunctionBefore) { 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, MaterializeFunctionsForBlockAddrInFunctionAfter) { 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 -- 2.34.1