Skip to content

Commit 65c0120

Browse files
author
Michael Zolotukhin
committed
Revert "Assert that we have all use/users in the getters."
This reverts commit fdb838f. llvm-svn: 257751
1 parent 68befd7 commit 65c0120

File tree

7 files changed

+23
-96
lines changed

7 files changed

+23
-96
lines changed

llvm/include/llvm/IR/Module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,14 +439,14 @@ class Module {
439439
void setMaterializer(GVMaterializer *GVM);
440440
/// Retrieves the GVMaterializer, if any, for this Module.
441441
GVMaterializer *getMaterializer() const { return Materializer.get(); }
442-
bool isMaterialized() const { return !getMaterializer(); }
443442

444443
/// Make sure the GlobalValue is fully read. If the module is corrupt, this
445444
/// returns true and fills in the optional string with information about the
446445
/// problem. If successful, this returns false.
447446
std::error_code materialize(GlobalValue *GV);
448447

449448
/// Make sure all GlobalValues in this Module are fully read and clear the
449+
/// Materializer. If the module is corrupt, this DOES NOT clear the old
450450
/// Materializer.
451451
std::error_code materializeAll();
452452

llvm/include/llvm/IR/Value.h

Lines changed: 12 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -273,91 +273,38 @@ class Value {
273273
//----------------------------------------------------------------------
274274
// Methods for handling the chain of uses of this Value.
275275
//
276-
// Materializing a function can introduce new uses, so these methods come in
277-
// two variants:
278-
// The methods that start with materialized_ check the uses that are
279-
// currently known given which functions are materialized. Be very careful
280-
// when using them since you might not get all uses.
281-
// The methods that don't start with materialized_ assert that modules is
282-
// fully materialized.
283-
#ifdef NDEBUG
284-
void assertModuleIsMaterialized() const {}
285-
#else
286-
void assertModuleIsMaterialized() const;
287-
#endif
288-
289-
bool use_empty() const {
290-
assertModuleIsMaterialized();
291-
return UseList == nullptr;
292-
}
276+
bool use_empty() const { return UseList == nullptr; }
293277

294278
typedef use_iterator_impl<Use> use_iterator;
295279
typedef use_iterator_impl<const Use> const_use_iterator;
296-
use_iterator materialized_use_begin() { return use_iterator(UseList); }
297-
const_use_iterator materialized_use_begin() const {
298-
return const_use_iterator(UseList);
299-
}
300-
use_iterator use_begin() {
301-
assertModuleIsMaterialized();
302-
return materialized_use_begin();
303-
}
304-
const_use_iterator use_begin() const {
305-
assertModuleIsMaterialized();
306-
return materialized_use_begin();
307-
}
280+
use_iterator use_begin() { return use_iterator(UseList); }
281+
const_use_iterator use_begin() const { return const_use_iterator(UseList); }
308282
use_iterator use_end() { return use_iterator(); }
309283
const_use_iterator use_end() const { return const_use_iterator(); }
310-
iterator_range<use_iterator> materialized_uses() {
311-
return make_range(materialized_use_begin(), use_end());
312-
}
313-
iterator_range<const_use_iterator> materialized_uses() const {
314-
return make_range(materialized_use_begin(), use_end());
315-
}
316284
iterator_range<use_iterator> uses() {
317-
assertModuleIsMaterialized();
318-
return materialized_uses();
285+
return make_range(use_begin(), use_end());
319286
}
320287
iterator_range<const_use_iterator> uses() const {
321-
assertModuleIsMaterialized();
322-
return materialized_uses();
288+
return make_range(use_begin(), use_end());
323289
}
324290

325-
bool user_empty() const {
326-
assertModuleIsMaterialized();
327-
return UseList == nullptr;
328-
}
291+
bool user_empty() const { return UseList == nullptr; }
329292

330293
typedef user_iterator_impl<User> user_iterator;
331294
typedef user_iterator_impl<const User> const_user_iterator;
332-
user_iterator materialized_user_begin() { return user_iterator(UseList); }
333-
const_user_iterator materialized_user_begin() const {
334-
return const_user_iterator(UseList);
335-
}
336-
user_iterator user_begin() {
337-
assertModuleIsMaterialized();
338-
return materialized_user_begin();
339-
}
295+
user_iterator user_begin() { return user_iterator(UseList); }
340296
const_user_iterator user_begin() const {
341-
assertModuleIsMaterialized();
342-
return materialized_user_begin();
297+
return const_user_iterator(UseList);
343298
}
344299
user_iterator user_end() { return user_iterator(); }
345300
const_user_iterator user_end() const { return const_user_iterator(); }
346-
User *user_back() {
347-
assertModuleIsMaterialized();
348-
return *materialized_user_begin();
349-
}
350-
const User *user_back() const {
351-
assertModuleIsMaterialized();
352-
return *materialized_user_begin();
353-
}
301+
User *user_back() { return *user_begin(); }
302+
const User *user_back() const { return *user_begin(); }
354303
iterator_range<user_iterator> users() {
355-
assertModuleIsMaterialized();
356-
return make_range(materialized_user_begin(), user_end());
304+
return make_range(user_begin(), user_end());
357305
}
358306
iterator_range<const_user_iterator> users() const {
359-
assertModuleIsMaterialized();
360-
return make_range(materialized_user_begin(), user_end());
307+
return make_range(user_begin(), user_end());
361308
}
362309

363310
/// \brief Return true if there is exactly one user of this value.

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3022,7 +3022,7 @@ std::error_code BitcodeReader::parseUseLists() {
30223022
V = ValueList[ID];
30233023
unsigned NumUses = 0;
30243024
SmallDenseMap<const Use *, unsigned, 16> Order;
3025-
for (const Use &U : V->materialized_uses()) {
3025+
for (const Use &U : V->uses()) {
30263026
if (++NumUses > Record.size())
30273027
break;
30283028
Order[&U] = Record[NumUses - 1];
@@ -5267,8 +5267,7 @@ std::error_code BitcodeReader::materialize(GlobalValue *GV) {
52675267

52685268
// Upgrade any old intrinsic calls in the function.
52695269
for (auto &I : UpgradedIntrinsics) {
5270-
for (auto UI = I.first->materialized_user_begin(), UE = I.first->user_end();
5271-
UI != UE;) {
5270+
for (auto UI = I.first->user_begin(), UE = I.first->user_end(); UI != UE;) {
52725271
User *U = *UI;
52735272
++UI;
52745273
if (CallInst *CI = dyn_cast<CallInst>(U))

llvm/lib/IR/Module.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,10 @@ std::error_code Module::materialize(GlobalValue *GV) {
394394
std::error_code Module::materializeAll() {
395395
if (!Materializer)
396396
return std::error_code();
397-
std::unique_ptr<GVMaterializer> M = std::move(Materializer);
398-
return M->materializeModule();
397+
if (std::error_code EC = Materializer->materializeModule())
398+
return EC;
399+
Materializer.reset();
400+
return std::error_code();
399401
}
400402

401403
std::error_code Module::materializeMetadata() {

llvm/lib/IR/Value.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -314,16 +314,6 @@ void Value::takeName(Value *V) {
314314
}
315315

316316
#ifndef NDEBUG
317-
void Value::assertModuleIsMaterialized() const {
318-
const GlobalValue *GV = dyn_cast<GlobalValue>(this);
319-
if (!GV)
320-
return;
321-
const Module *M = GV->getParent();
322-
if (!M)
323-
return;
324-
assert(M->isMaterialized());
325-
}
326-
327317
static bool contains(SmallPtrSetImpl<ConstantExpr *> &Cache, ConstantExpr *Expr,
328318
Constant *C) {
329319
if (!Cache.insert(Expr).second)

llvm/lib/IR/Verifier.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,9 +1901,7 @@ void Verifier::visitFunction(const Function &F) {
19011901

19021902
// If this function is actually an intrinsic, verify that it is only used in
19031903
// direct call/invokes, never having its "address taken".
1904-
// Only do this if the module is materialized, otherwise we don't have all the
1905-
// uses.
1906-
if (F.getIntrinsicID() && F.getParent()->isMaterialized()) {
1904+
if (F.getIntrinsicID()) {
19071905
const User *U;
19081906
if (F.hasAddressTaken(&U))
19091907
Assert(0, "Invalid user of intrinsic instruction!", U);

llvm/tools/llvm-extract/llvm-extract.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,22 +242,13 @@ int main(int argc, char **argv) {
242242
}
243243
}
244244

245-
{
246-
std::vector<GlobalValue *> Gvs(GVs.begin(), GVs.end());
247-
legacy::PassManager Extract;
248-
Extract.add(createGVExtractionPass(Gvs, DeleteFn));
249-
Extract.run(*M);
250-
251-
// Now that we have all the GVs we want, mark the module as fully
252-
// materialized.
253-
// FIXME: should the GVExtractionPass handle this?
254-
M->materializeAll();
255-
}
256-
257245
// In addition to deleting all other functions, we also want to spiff it
258246
// up a little bit. Do this now.
259247
legacy::PassManager Passes;
260248

249+
std::vector<GlobalValue*> Gvs(GVs.begin(), GVs.end());
250+
251+
Passes.add(createGVExtractionPass(Gvs, DeleteFn));
261252
if (!DeleteFn)
262253
Passes.add(createGlobalDCEPass()); // Delete unreachable globals
263254
Passes.add(createStripDeadDebugInfoPass()); // Remove dead debug info

0 commit comments

Comments
 (0)