Skip to content

Commit ef6a751

Browse files
Port PreservedFunctionHashAnalysis and PreservedModuleHashAnalysis to Analysis
1 parent 3cac781 commit ef6a751

File tree

3 files changed

+42
-39
lines changed

3 files changed

+42
-39
lines changed

llvm/include/llvm/Analysis/StructuralHash.h

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//=- StructuralHash.h - Structural Hash Printing --*- C++ -*-----------------=//
1+
//=- StructuralHash.h - Structural Hash Printing and Analysis --*- C++ -*-----=//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -10,9 +10,40 @@
1010
#define LLVM_ANALYSIS_STRUCTURALHASH_H
1111

1212
#include "llvm/IR/PassManager.h"
13+
#include "llvm/IR/StructuralHash.h"
1314

1415
namespace llvm {
1516

17+
struct PreservedFunctionHashAnalysis
18+
: public AnalysisInfoMixin<PreservedFunctionHashAnalysis> {
19+
static AnalysisKey Key;
20+
21+
struct FunctionHash {
22+
uint64_t Hash;
23+
};
24+
25+
using Result = FunctionHash;
26+
27+
Result run(Function &F, FunctionAnalysisManager &FAM) {
28+
return Result{StructuralHash(F)};
29+
}
30+
};
31+
32+
struct PreservedModuleHashAnalysis
33+
: public AnalysisInfoMixin<PreservedModuleHashAnalysis> {
34+
static AnalysisKey Key;
35+
36+
struct ModuleHash {
37+
uint64_t Hash;
38+
};
39+
40+
using Result = ModuleHash;
41+
42+
Result run(Module &F, ModuleAnalysisManager &FAM) {
43+
return Result{StructuralHash(F)};
44+
}
45+
};
46+
1647
enum class StructuralHashOptions {
1748
None, /// Hash with opcode only.
1849
Detailed, /// Hash with opcode and operands.

llvm/lib/Analysis/StructuralHash.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,24 @@
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// This file defines the StructuralHashPrinterPass which is used to show
10-
// the structural hash of all functions in a module and the module itself.
9+
// This file defines the StructuralHashPrinterPass and the
10+
// PreservedFunctionHashAnalysis and PreservedModuleHashAnalysis keys.
11+
//
12+
// The StructuralHashPrinterPass is used to show the structural hash of all
13+
// functions in a module and the module itself.
1114
//
1215
//===----------------------------------------------------------------------===//
1316

1417
#include "llvm/Analysis/StructuralHash.h"
1518
#include "llvm/IR/Module.h"
16-
#include "llvm/IR/StructuralHash.h"
1719
#include "llvm/Support/Format.h"
1820

1921
using namespace llvm;
2022

23+
AnalysisKey PreservedFunctionHashAnalysis::Key;
24+
25+
AnalysisKey PreservedModuleHashAnalysis::Key;
26+
2127
PreservedAnalyses StructuralHashPrinterPass::run(Module &M,
2228
ModuleAnalysisManager &MAM) {
2329
OS << "Module Hash: "

llvm/lib/Passes/StandardInstrumentations.cpp

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/Analysis/CallGraphSCCPass.h"
1919
#include "llvm/Analysis/LazyCallGraph.h"
2020
#include "llvm/Analysis/LoopInfo.h"
21+
#include "llvm/Analysis/StructuralHash.h"
2122
#include "llvm/CodeGen/MIRPrinter.h"
2223
#include "llvm/CodeGen/MachineFunction.h"
2324
#include "llvm/CodeGen/MachineModuleInfo.h"
@@ -30,7 +31,6 @@
3031
#include "llvm/IR/PassInstrumentation.h"
3132
#include "llvm/IR/PassManager.h"
3233
#include "llvm/IR/PrintPasses.h"
33-
#include "llvm/IR/StructuralHash.h"
3434
#include "llvm/IR/Verifier.h"
3535
#include "llvm/Support/CommandLine.h"
3636
#include "llvm/Support/CrashRecoveryContext.h"
@@ -1303,40 +1303,6 @@ struct PreservedCFGCheckerAnalysis
13031303

13041304
AnalysisKey PreservedCFGCheckerAnalysis::Key;
13051305

1306-
struct PreservedFunctionHashAnalysis
1307-
: public AnalysisInfoMixin<PreservedFunctionHashAnalysis> {
1308-
static AnalysisKey Key;
1309-
1310-
struct FunctionHash {
1311-
uint64_t Hash;
1312-
};
1313-
1314-
using Result = FunctionHash;
1315-
1316-
Result run(Function &F, FunctionAnalysisManager &FAM) {
1317-
return Result{StructuralHash(F)};
1318-
}
1319-
};
1320-
1321-
AnalysisKey PreservedFunctionHashAnalysis::Key;
1322-
1323-
struct PreservedModuleHashAnalysis
1324-
: public AnalysisInfoMixin<PreservedModuleHashAnalysis> {
1325-
static AnalysisKey Key;
1326-
1327-
struct ModuleHash {
1328-
uint64_t Hash;
1329-
};
1330-
1331-
using Result = ModuleHash;
1332-
1333-
Result run(Module &F, ModuleAnalysisManager &FAM) {
1334-
return Result{StructuralHash(F)};
1335-
}
1336-
};
1337-
1338-
AnalysisKey PreservedModuleHashAnalysis::Key;
1339-
13401306
bool PreservedCFGCheckerInstrumentation::CFG::invalidate(
13411307
Function &F, const PreservedAnalyses &PA,
13421308
FunctionAnalysisManager::Invalidator &) {

0 commit comments

Comments
 (0)