Skip to content

Port Preserved[Module|Function]HashAnalysis to Analysis #116108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion llvm/include/llvm/Analysis/StructuralHash.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//=- StructuralHash.h - Structural Hash Printing --*- C++ -*-----------------=//
//=- StructuralHash.h - Structural Hash Printing and Analysis --*- C++ -*----=//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -10,9 +10,40 @@
#define LLVM_ANALYSIS_STRUCTURALHASH_H

#include "llvm/IR/PassManager.h"
#include "llvm/IR/StructuralHash.h"

namespace llvm {

struct PreservedFunctionHashAnalysis
: public AnalysisInfoMixin<PreservedFunctionHashAnalysis> {
static AnalysisKey Key;

struct FunctionHash {
uint64_t Hash;
};

using Result = FunctionHash;

Result run(Function &F, FunctionAnalysisManager &FAM) {
return Result{StructuralHash(F)};
}
};

struct PreservedModuleHashAnalysis
: public AnalysisInfoMixin<PreservedModuleHashAnalysis> {
static AnalysisKey Key;

struct ModuleHash {
uint64_t Hash;
};

using Result = ModuleHash;

Result run(Module &F, ModuleAnalysisManager &FAM) {
return Result{StructuralHash(F)};
}
};

enum class StructuralHashOptions {
None, /// Hash with opcode only.
Detailed, /// Hash with opcode and operands.
Expand Down
9 changes: 9 additions & 0 deletions llvm/lib/Analysis/StructuralHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
//
// This file defines the StructuralHashPrinterPass which is used to show
// the structural hash of all functions in a module and the module itself.
// This file defines the StructuralHashPrinterPass and the
// PreservedFunctionHashAnalysis and PreservedModuleHashAnalysis keys.
//
// The StructuralHashPrinterPass is used to show the structural hash of all
// functions in a module and the module itself.
//
//===----------------------------------------------------------------------===//

Expand All @@ -18,6 +23,10 @@

using namespace llvm;

AnalysisKey PreservedFunctionHashAnalysis::Key;

AnalysisKey PreservedModuleHashAnalysis::Key;

PreservedAnalyses StructuralHashPrinterPass::run(Module &M,
ModuleAnalysisManager &MAM) {
OS << "Module Hash: "
Expand Down
36 changes: 1 addition & 35 deletions llvm/lib/Passes/StandardInstrumentations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "llvm/Analysis/CallGraphSCCPass.h"
#include "llvm/Analysis/LazyCallGraph.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/StructuralHash.h"
#include "llvm/CodeGen/MIRPrinter.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
Expand All @@ -30,7 +31,6 @@
#include "llvm/IR/PassInstrumentation.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/PrintPasses.h"
#include "llvm/IR/StructuralHash.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/CrashRecoveryContext.h"
Expand Down Expand Up @@ -1303,40 +1303,6 @@ struct PreservedCFGCheckerAnalysis

AnalysisKey PreservedCFGCheckerAnalysis::Key;

struct PreservedFunctionHashAnalysis
: public AnalysisInfoMixin<PreservedFunctionHashAnalysis> {
static AnalysisKey Key;

struct FunctionHash {
uint64_t Hash;
};

using Result = FunctionHash;

Result run(Function &F, FunctionAnalysisManager &FAM) {
return Result{StructuralHash(F)};
}
};

AnalysisKey PreservedFunctionHashAnalysis::Key;

struct PreservedModuleHashAnalysis
: public AnalysisInfoMixin<PreservedModuleHashAnalysis> {
static AnalysisKey Key;

struct ModuleHash {
uint64_t Hash;
};

using Result = ModuleHash;

Result run(Module &F, ModuleAnalysisManager &FAM) {
return Result{StructuralHash(F)};
}
};

AnalysisKey PreservedModuleHashAnalysis::Key;

bool PreservedCFGCheckerInstrumentation::CFG::invalidate(
Function &F, const PreservedAnalyses &PA,
FunctionAnalysisManager::Invalidator &) {
Expand Down
Loading