Skip to content

Commit a3a4591

Browse files
committed
[LegacyPassManager] Move structural hashing into Pass classes. NFC.
Move structural hashing into virtual methods on Pass. This will allow MachineFunctionPass to override the method to add hashing of the MachineFunction. Differential Revision: https://reviews.llvm.org/D120123
1 parent 0b6df40 commit a3a4591

File tree

6 files changed

+30
-23
lines changed

6 files changed

+30
-23
lines changed

llvm/include/llvm/Pass.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,16 @@ class Pass {
228228
template <typename AnalysisType>
229229
AnalysisType &getAnalysisID(AnalysisID PI, Function &F,
230230
bool *Changed = nullptr);
231+
232+
#ifdef EXPENSIVE_CHECKS
233+
/// Hash a module in order to detect when a module (or more specific) pass has
234+
/// modified it.
235+
uint64_t structuralHash(Module &M) const;
236+
237+
/// Hash a function in order to detect when a function (or more specific) pass
238+
/// has modified it.
239+
virtual uint64_t structuralHash(Function &F) const;
240+
#endif
231241
};
232242

233243
//===----------------------------------------------------------------------===//

llvm/lib/Analysis/CallGraphSCCPass.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
#include "llvm/IR/OptBisect.h"
2929
#include "llvm/IR/PassTimingInfo.h"
3030
#include "llvm/IR/PrintPasses.h"
31-
#ifdef EXPENSIVE_CHECKS
32-
#include "llvm/IR/StructuralHash.h"
33-
#endif
3431
#include "llvm/Pass.h"
3532
#include "llvm/Support/CommandLine.h"
3633
#include "llvm/Support/Debug.h"
@@ -472,7 +469,7 @@ bool CGPassManager::RunAllPassesOnSCC(CallGraphSCC &CurSCC, CallGraph &CG,
472469
initializeAnalysisImpl(P);
473470

474471
#ifdef EXPENSIVE_CHECKS
475-
uint64_t RefHash = StructuralHash(CG.getModule());
472+
uint64_t RefHash = P->structuralHash(CG.getModule());
476473
#endif
477474

478475
// Actually run this pass on the current SCC.
@@ -482,7 +479,7 @@ bool CGPassManager::RunAllPassesOnSCC(CallGraphSCC &CurSCC, CallGraph &CG,
482479
Changed |= LocalChanged;
483480

484481
#ifdef EXPENSIVE_CHECKS
485-
if (!LocalChanged && (RefHash != StructuralHash(CG.getModule()))) {
482+
if (!LocalChanged && (RefHash != P->structuralHash(CG.getModule()))) {
486483
llvm::errs() << "Pass modifies its input and doesn't report it: "
487484
<< P->getPassName() << "\n";
488485
llvm_unreachable("Pass modifies its input and doesn't report it");

llvm/lib/Analysis/LoopPass.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
#include "llvm/IR/OptBisect.h"
2020
#include "llvm/IR/PassTimingInfo.h"
2121
#include "llvm/IR/PrintPasses.h"
22-
#ifdef EXPENSIVE_CHECKS
23-
#include "llvm/IR/StructuralHash.h"
24-
#endif
2522
#include "llvm/InitializePasses.h"
2623
#include "llvm/Support/Debug.h"
2724
#include "llvm/Support/TimeProfiler.h"
@@ -193,12 +190,12 @@ bool LPPassManager::runOnFunction(Function &F) {
193190
PassManagerPrettyStackEntry X(P, *CurrentLoop->getHeader());
194191
TimeRegion PassTimer(getPassTimer(P));
195192
#ifdef EXPENSIVE_CHECKS
196-
uint64_t RefHash = StructuralHash(F);
193+
uint64_t RefHash = P->structuralHash(F);
197194
#endif
198195
LocalChanged = P->runOnLoop(CurrentLoop, *this);
199196

200197
#ifdef EXPENSIVE_CHECKS
201-
if (!LocalChanged && (RefHash != StructuralHash(F))) {
198+
if (!LocalChanged && (RefHash != P->structuralHash(F))) {
202199
llvm::errs() << "Pass modifies its input and doesn't report it: "
203200
<< P->getPassName() << "\n";
204201
llvm_unreachable("Pass modifies its input and doesn't report it");

llvm/lib/Analysis/RegionPass.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
#include "llvm/IR/OptBisect.h"
1919
#include "llvm/IR/PassTimingInfo.h"
2020
#include "llvm/IR/PrintPasses.h"
21-
#ifdef EXPENSIVE_CHECKS
22-
#include "llvm/IR/StructuralHash.h"
23-
#endif
2421
#include "llvm/Support/Debug.h"
2522
#include "llvm/Support/Timer.h"
2623
#include "llvm/Support/raw_ostream.h"
@@ -98,12 +95,12 @@ bool RGPassManager::runOnFunction(Function &F) {
9895

9996
TimeRegion PassTimer(getPassTimer(P));
10097
#ifdef EXPENSIVE_CHECKS
101-
uint64_t RefHash = StructuralHash(F);
98+
uint64_t RefHash = P->structuralHash(F);
10299
#endif
103100
LocalChanged = P->runOnRegion(CurrentRegion, *this);
104101

105102
#ifdef EXPENSIVE_CHECKS
106-
if (!LocalChanged && (RefHash != StructuralHash(F))) {
103+
if (!LocalChanged && (RefHash != P->structuralHash(F))) {
107104
llvm::errs() << "Pass modifies its input and doesn't report it: "
108105
<< P->getPassName() << "\n";
109106
llvm_unreachable("Pass modifies its input and doesn't report it");

llvm/lib/IR/LegacyPassManager.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929
#include "llvm/Support/raw_ostream.h"
3030
#include <algorithm>
3131

32-
#ifdef EXPENSIVE_CHECKS
33-
#include "llvm/IR/StructuralHash.h"
34-
#endif
35-
3632
using namespace llvm;
3733

3834
// See PassManagers.h for Pass Manager infrastructure overview.
@@ -1429,12 +1425,12 @@ bool FPPassManager::runOnFunction(Function &F) {
14291425
PassManagerPrettyStackEntry X(FP, F);
14301426
TimeRegion PassTimer(getPassTimer(FP));
14311427
#ifdef EXPENSIVE_CHECKS
1432-
uint64_t RefHash = StructuralHash(F);
1428+
uint64_t RefHash = FP->structuralHash(F);
14331429
#endif
14341430
LocalChanged |= FP->runOnFunction(F);
14351431

14361432
#if defined(EXPENSIVE_CHECKS) && !defined(NDEBUG)
1437-
if (!LocalChanged && (RefHash != StructuralHash(F))) {
1433+
if (!LocalChanged && (RefHash != FP->structuralHash(F))) {
14381434
llvm::errs() << "Pass modifies its input and doesn't report it: "
14391435
<< FP->getPassName() << "\n";
14401436
llvm_unreachable("Pass modifies its input and doesn't report it");
@@ -1543,13 +1539,13 @@ MPPassManager::runOnModule(Module &M) {
15431539
TimeRegion PassTimer(getPassTimer(MP));
15441540

15451541
#ifdef EXPENSIVE_CHECKS
1546-
uint64_t RefHash = StructuralHash(M);
1542+
uint64_t RefHash = MP->structuralHash(M);
15471543
#endif
15481544

15491545
LocalChanged |= MP->runOnModule(M);
15501546

15511547
#ifdef EXPENSIVE_CHECKS
1552-
assert((LocalChanged || (RefHash == StructuralHash(M))) &&
1548+
assert((LocalChanged || (RefHash == MP->structuralHash(M))) &&
15531549
"Pass modifies its input and doesn't report it.");
15541550
#endif
15551551

llvm/lib/IR/Pass.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#include "llvm/Support/raw_ostream.h"
2828
#include <cassert>
2929

30+
#ifdef EXPENSIVE_CHECKS
31+
#include "llvm/IR/StructuralHash.h"
32+
#endif
33+
3034
using namespace llvm;
3135

3236
#define DEBUG_TYPE "ir"
@@ -133,6 +137,12 @@ LLVM_DUMP_METHOD void Pass::dump() const {
133137
}
134138
#endif
135139

140+
#ifdef EXPENSIVE_CHECKS
141+
uint64_t Pass::structuralHash(Module &M) const { return StructuralHash(M); }
142+
143+
uint64_t Pass::structuralHash(Function &F) const { return StructuralHash(F); }
144+
#endif
145+
136146
//===----------------------------------------------------------------------===//
137147
// ImmutablePass Implementation
138148
//

0 commit comments

Comments
 (0)