llvm.org GIT mirror llvm / f11617b
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 Rafael Espindola 3 years ago
8 changed file(s) with 0 addition(s) and 119 deletion(s). Raw diff Collapse all Expand all
3535 public:
3636 virtual ~GVMaterializer();
3737
38 /// True if GV has been materialized and can be dematerialized back to
39 /// whatever backing store this GVMaterializer uses.
40 virtual bool isDematerializable(const GlobalValue *GV) const = 0;
41
4238 /// Make sure the given GlobalValue is fully read.
4339 ///
4440 virtual std::error_code materialize(GlobalValue *GV) = 0;
45
46 /// If the given GlobalValue is read in, and if the GVMaterializer supports
47 /// it, release the memory for the GV, and set it up to be materialized
48 /// lazily. If the Materializer doesn't support this capability, this method
49 /// is a noop.
50 ///
51 virtual void dematerialize(GlobalValue *) {}
5241
5342 /// Make sure the entire Module has been completely read.
5443 ///
321321 /// function has been read in yet or not.
322322 bool isMaterializable() const;
323323
324 /// Returns true if this function was loaded from a GVMaterializer that's
325 /// still attached to its Module and that knows how to dematerialize the
326 /// function.
327 bool isDematerializable() const;
328
329324 /// Make sure this GlobalValue is fully read. If the module is corrupt, this
330325 /// returns true and fills in the optional string with information about the
331326 /// problem. If successful, this returns false.
332327 std::error_code materialize();
333
334 /// If this GlobalValue is read in, and if the GVMaterializer supports it,
335 /// release the memory for the function, and set it up to be materialized
336 /// lazily. If !isDematerializable(), this method is a noop.
337 void dematerialize();
338328
339329 /// @}
340330
439439 /// Retrieves the GVMaterializer, if any, for this Module.
440440 GVMaterializer *getMaterializer() const { return Materializer.get(); }
441441
442 /// Returns true if this GV was loaded from this Module's GVMaterializer and
443 /// the GVMaterializer knows how to dematerialize the GV.
444 bool isDematerializable(const GlobalValue *GV) const;
445
446442 /// Make sure the GlobalValue is fully read. If the module is corrupt, this
447443 /// returns true and fills in the optional string with information about the
448444 /// problem. If successful, this returns false.
449445 std::error_code materialize(GlobalValue *GV);
450 /// If the GlobalValue is read in, and if the GVMaterializer supports it,
451 /// release the memory for the function, and set it up to be materialized
452 /// lazily. If !isDematerializable(), this method is a no-op.
453 void dematerialize(GlobalValue *GV);
454446
455447 /// Make sure all GlobalValues in this Module are fully read.
456448 std::error_code materializeAll();
226226 /// (e.g.) blockaddress forward references.
227227 bool WillMaterializeAllForwardRefs = false;
228228
229 /// Functions that have block addresses taken. This is usually empty.
230 SmallPtrSet BlockAddressesTaken;
231
232229 /// True if any Metadata block has been materialized.
233230 bool IsMetadataMaterialized = false;
234231
255252
256253 void releaseBuffer();
257254
258 bool isDematerializable(const GlobalValue *GV) const override;
259255 std::error_code materialize(GlobalValue *GV) override;
260256 std::error_code materializeModule(Module *M) override;
261257 std::vector getIdentifiedStructTypes() const override;
262 void dematerialize(GlobalValue *GV) override;
263258
264259 /// \brief Main interface to parsing a bitcode buffer.
265260 /// \returns true if an error occurred.
29502945 if (!Fn)
29512946 return error("Invalid record");
29522947
2953 // Don't let Fn get dematerialized.
2954 BlockAddressesTaken.insert(Fn);
2955
29562948 // If the function is already parsed we can insert the block address right
29572949 // away.
29582950 BasicBlock *BB;
52905282 return materializeForwardReferencedFunctions();
52915283 }
52925284
5293 bool BitcodeReader::isDematerializable(const GlobalValue *GV) const {
5294 const Function *F = dyn_cast(GV);
5295 if (!F || F->isDeclaration())
5296 return false;
5297
5298 // Dematerializing F would leave dangling references that wouldn't be
5299 // reconnected on re-materialization.
5300 if (BlockAddressesTaken.count(F))
5301 return false;
5302
5303 return DeferredFunctionInfo.count(const_cast(F));
5304 }
5305
5306 void BitcodeReader::dematerialize(GlobalValue *GV) {
5307 Function *F = dyn_cast(GV);
5308 // If this function isn't dematerializable, this is a noop.
5309 if (!F || !isDematerializable(F))
5310 return;
5311
5312 assert(DeferredFunctionInfo.count(F) && "No info to read function later?");
5313
5314 // Just forget the function body, we can remat it later.
5315 F->dropAllReferences();
5316 F->setIsMaterializable(true);
5317 }
5318
53195285 std::error_code BitcodeReader::materializeModule(Module *M) {
53205286 assert(M == TheModule &&
53215287 "Can only Materialize the Module this BitcodeReader is attached to.");
3131 return F->isMaterializable();
3232 return false;
3333 }
34 bool GlobalValue::isDematerializable() const {
35 return getParent() && getParent()->isDematerializable(this);
36 }
3734 std::error_code GlobalValue::materialize() {
3835 return getParent()->materialize(this);
39 }
40 void GlobalValue::dematerialize() {
41 getParent()->dematerialize(this);
4236 }
4337
4438 /// Override destroyConstantImpl to make sure it doesn't get called on
383383 Materializer.reset(GVM);
384384 }
385385
386 bool Module::isDematerializable(const GlobalValue *GV) const {
387 if (Materializer)
388 return Materializer->isDematerializable(GV);
389 return false;
390 }
391
392386 std::error_code Module::materialize(GlobalValue *GV) {
393387 if (!Materializer)
394388 return std::error_code();
395389
396390 return Materializer->materialize(GV);
397 }
398
399 void Module::dematerialize(GlobalValue *GV) {
400 if (Materializer)
401 return Materializer->dematerialize(GV);
402391 }
403392
404393 std::error_code Module::materializeAll() {
11621162 for (Argument &Arg : Src.args())
11631163 ValueMap.erase(&Arg);
11641164
1165 Src.dematerialize();
11661165 return false;
11671166 }
11681167
139139 EXPECT_FALSE(M->getFunction("func")->empty());
140140 }
141141
142 TEST(BitReaderTest, DematerializeFunctionPreservesLinkageType) {
143 SmallString<1024> Mem;
144
145 LLVMContext Context;
146 std::unique_ptr M = getLazyModuleFromAssembly(
147 Context, Mem, "define internal i32 @func() {\n"
148 "ret i32 0\n"
149 "}\n");
150
151 EXPECT_FALSE(verifyModule(*M, &dbgs()));
152
153 M->getFunction("func")->materialize();
154 EXPECT_FALSE(M->getFunction("func")->empty());
155 EXPECT_TRUE(M->getFunction("func")->getLinkage() ==
156 GlobalValue::InternalLinkage);
157
158 // Check that the linkage type is preserved after dematerialization.
159 M->getFunction("func")->dematerialize();
160 EXPECT_TRUE(M->getFunction("func")->empty());
161 EXPECT_TRUE(M->getFunction("func")->getLinkage() ==
162 GlobalValue::InternalLinkage);
163 EXPECT_FALSE(verifyModule(*M, &dbgs()));
164 }
165
166142 // Tests that lazy evaluation can parse functions out of order.
167143 TEST(BitReaderTest, MaterializeFunctionsOutOfOrder) {
168144 SmallString<1024> Mem;
239215 " unreachable\n"
240216 "}\n");
241217 EXPECT_FALSE(verifyModule(*M, &dbgs()));
242
243 // Try (and fail) to dematerialize @func.
244 M->getFunction("func")->dematerialize();
245 EXPECT_FALSE(M->getFunction("func")->empty());
246218 }
247219
248220 TEST(BitReaderTest, MaterializeFunctionsForBlockAddrInFunctionBefore) {
270242 EXPECT_FALSE(M->getFunction("func")->empty());
271243 EXPECT_TRUE(M->getFunction("other")->empty());
272244 EXPECT_FALSE(verifyModule(*M, &dbgs()));
273
274 // Try (and fail) to dematerialize @func.
275 M->getFunction("func")->dematerialize();
276 EXPECT_FALSE(M->getFunction("func")->empty());
277 EXPECT_FALSE(verifyModule(*M, &dbgs()));
278245 }
279246
280247 TEST(BitReaderTest, MaterializeFunctionsForBlockAddrInFunctionAfter) {
302269 EXPECT_FALSE(M->getFunction("func")->empty());
303270 EXPECT_TRUE(M->getFunction("other")->empty());
304271 EXPECT_FALSE(verifyModule(*M, &dbgs()));
305
306 // Try (and fail) to dematerialize @func.
307 M->getFunction("func")->dematerialize();
308 EXPECT_FALSE(M->getFunction("func")->empty());
309 EXPECT_FALSE(verifyModule(*M, &dbgs()));
310272 }
311273
312274 } // end namespace