[patch] Drop support for dematerializing
Rafael EspĂndola via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 15 16:14:46 PST 2015
Looks like it was only used on lib/Linker and the use was "dead" since
it was used on a function the IRMover had just moved.
Cheers,
Rafael
-------------- next part --------------
diff --git a/include/llvm/IR/GVMaterializer.h b/include/llvm/IR/GVMaterializer.h
index 1d6c915..4f08c03 100644
--- a/include/llvm/IR/GVMaterializer.h
+++ b/include/llvm/IR/GVMaterializer.h
@@ -34,21 +34,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 2f91726..4fa4e7d 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 2378b6d..a46ba80 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 d80e70d..3d05f91 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -219,9 +219,6 @@ class BitcodeReader : public GVMaterializer {
/// (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;
@@ -248,11 +245,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.
@@ -2928,9 +2923,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;
@@ -5244,32 +5236,6 @@ std::error_code BitcodeReader::materialize(GlobalValue *GV) {
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.");
diff --git a/lib/IR/Globals.cpp b/lib/IR/Globals.cpp
index c538c7b..6159f93 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 2acd9db..d174491 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 8a11a00..864661e 100644
--- a/lib/Linker/IRMover.cpp
+++ b/lib/Linker/IRMover.cpp
@@ -991,7 +991,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 055850d..420aca2 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<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, 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
More information about the llvm-commits
mailing list