Skip to content

Commit e62452b

Browse files
committed
Revert "Double check that passes correctly set their Modified status"
This check fires during self-host. > The approach is simple: if a pass reports that it's not modifying a > Function/Module, compute a loose hash of that Function/Module and compare it > with the original one. If we report no change but there's a hash change, then we > have an error. > > This approach misses a lot of change but it's not super intrusive and can > detect most of the simple mistakes. > > Differential Revision: https://reviews.llvm.org/D80916 This reverts commit 3667d87.
1 parent 1a8e450 commit e62452b

File tree

2 files changed

+1
-88
lines changed

2 files changed

+1
-88
lines changed

llvm/lib/IR/LegacyPassManager.cpp

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,74 +1475,6 @@ void FPPassManager::dumpPassStructure(unsigned Offset) {
14751475
}
14761476
}
14771477

1478-
#ifdef EXPENSIVE_CHECKS
1479-
namespace {
1480-
namespace details {
1481-
1482-
// Basic hashing mechanism to detect structural change to the IR, used to verify
1483-
// pass return status consistency with actual change. Loosely copied from
1484-
// llvm/lib/Transforms/Utils/FunctionComparator.cpp
1485-
1486-
class StructuralHash {
1487-
uint64_t Hash = 0x6acaa36bef8325c5ULL;
1488-
1489-
void update(uint64_t V) { Hash = hashing::detail::hash_16_bytes(Hash, V); }
1490-
1491-
public:
1492-
StructuralHash() = default;
1493-
1494-
void update(Function &F) {
1495-
if (F.empty())
1496-
return;
1497-
1498-
update(F.isVarArg());
1499-
update(F.arg_size());
1500-
1501-
SmallVector<const BasicBlock *, 8> BBs;
1502-
SmallPtrSet<const BasicBlock *, 16> VisitedBBs;
1503-
1504-
BBs.push_back(&F.getEntryBlock());
1505-
VisitedBBs.insert(BBs[0]);
1506-
while (!BBs.empty()) {
1507-
const BasicBlock *BB = BBs.pop_back_val();
1508-
update(45798); // Block header
1509-
for (auto &Inst : *BB)
1510-
update(Inst.getOpcode());
1511-
1512-
const Instruction *Term = BB->getTerminator();
1513-
for (unsigned i = 0, e = Term->getNumSuccessors(); i != e; ++i) {
1514-
if (!VisitedBBs.insert(Term->getSuccessor(i)).second)
1515-
continue;
1516-
BBs.push_back(Term->getSuccessor(i));
1517-
}
1518-
}
1519-
}
1520-
1521-
void update(Module &M) {
1522-
for (Function &F : M)
1523-
update(F);
1524-
}
1525-
1526-
uint64_t getHash() const { return Hash; }
1527-
};
1528-
1529-
} // namespace details
1530-
1531-
uint64_t StructuralHash(Function &F) {
1532-
details::StructuralHash H;
1533-
H.update(F);
1534-
return H.getHash();
1535-
}
1536-
1537-
uint64_t StructuralHash(Module &M) {
1538-
details::StructuralHash H;
1539-
H.update(M);
1540-
return H.getHash();
1541-
}
1542-
1543-
} // end anonymous namespace
1544-
1545-
#endif
15461478

15471479
/// Execute all of the passes scheduled for execution by invoking
15481480
/// runOnFunction method. Keep track of whether any of the passes modifies
@@ -1581,16 +1513,7 @@ bool FPPassManager::runOnFunction(Function &F) {
15811513
{
15821514
PassManagerPrettyStackEntry X(FP, F);
15831515
TimeRegion PassTimer(getPassTimer(FP));
1584-
#ifdef EXPENSIVE_CHECKS
1585-
uint64_t RefHash = StructuralHash(F);
1586-
#endif
15871516
LocalChanged |= FP->runOnFunction(F);
1588-
1589-
#ifdef EXPENSIVE_CHECKS
1590-
assert((LocalChanged || (RefHash == StructuralHash(F))) &&
1591-
"Pass modifies its input and doesn't report it.");
1592-
#endif
1593-
15941517
if (EmitICRemark) {
15951518
unsigned NewSize = F.getInstructionCount();
15961519

@@ -1691,17 +1614,7 @@ MPPassManager::runOnModule(Module &M) {
16911614
PassManagerPrettyStackEntry X(MP, M);
16921615
TimeRegion PassTimer(getPassTimer(MP));
16931616

1694-
#ifdef EXPENSIVE_CHECKS
1695-
uint64_t RefHash = StructuralHash(M);
1696-
#endif
1697-
16981617
LocalChanged |= MP->runOnModule(M);
1699-
1700-
#ifdef EXPENSIVE_CHECKS
1701-
assert((LocalChanged || (RefHash == StructuralHash(M))) &&
1702-
"Pass modifies its input and doesn't report it.");
1703-
#endif
1704-
17051618
if (EmitICRemark) {
17061619
// Update the size of the module.
17071620
unsigned ModuleCount = M.getInstructionCount();

llvm/unittests/IR/LegacyPassManagerTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ namespace llvm {
680680
ASSERT_EQ(M->getFunctionList().size(), 4U);
681681
Function *F = M->getFunction("test2");
682682
Function *SF = splitSimpleFunction(*F);
683-
CallInst::Create(F, "", &*SF->getEntryBlock().getFirstInsertionPt());
683+
CallInst::Create(F, "", &SF->getEntryBlock());
684684
ASSERT_EQ(M->getFunctionList().size(), 5U);
685685
CGModifierPass *P = new CGModifierPass();
686686
legacy::PassManager Passes;

0 commit comments

Comments
 (0)