diff --git a/llvm/include/llvm/Analysis/StructuralHash.h b/llvm/include/llvm/Analysis/StructuralHash.h index 4c9f063bc7d2c..9ab13e43a3aa9 100644 --- a/llvm/include/llvm/Analysis/StructuralHash.h +++ b/llvm/include/llvm/Analysis/StructuralHash.h @@ -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. @@ -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 { + 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 { + 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. diff --git a/llvm/lib/Analysis/StructuralHash.cpp b/llvm/lib/Analysis/StructuralHash.cpp index 4f2e003148b60..d03251cf9a6f0 100644 --- a/llvm/lib/Analysis/StructuralHash.cpp +++ b/llvm/lib/Analysis/StructuralHash.cpp @@ -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. // //===----------------------------------------------------------------------===// @@ -18,6 +23,10 @@ using namespace llvm; +AnalysisKey PreservedFunctionHashAnalysis::Key; + +AnalysisKey PreservedModuleHashAnalysis::Key; + PreservedAnalyses StructuralHashPrinterPass::run(Module &M, ModuleAnalysisManager &MAM) { OS << "Module Hash: " diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp index d4866a025c1b4..2d6aee0dab5f6 100644 --- a/llvm/lib/Passes/StandardInstrumentations.cpp +++ b/llvm/lib/Passes/StandardInstrumentations.cpp @@ -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" @@ -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" @@ -1303,40 +1303,6 @@ struct PreservedCFGCheckerAnalysis AnalysisKey PreservedCFGCheckerAnalysis::Key; -struct PreservedFunctionHashAnalysis - : public AnalysisInfoMixin { - 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 { - 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 &) {