-
Notifications
You must be signed in to change notification settings - Fork 13.7k
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
Conversation
@llvm/pr-subscribers-llvm-analysis Author: Justin Fargnoli (justinfargnoli) ChangesThe new IRNormalizer Pass (#113780) must invalidate Full diff: https://github.com/llvm/llvm-project/pull/116108.diff 3 Files Affected:
diff --git a/llvm/include/llvm/Analysis/StructuralHash.h b/llvm/include/llvm/Analysis/StructuralHash.h
index 4c9f063bc7d2c8..9ab13e43a3aa9d 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<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.
diff --git a/llvm/lib/Analysis/StructuralHash.cpp b/llvm/lib/Analysis/StructuralHash.cpp
index 4f2e003148b606..d03251cf9a6f02 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 d4866a025c1b48..2d6aee0dab5f69 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<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 &) {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IRNormalizer needs to invalidate all analyses, not list specific ones to invalidate.
Effectively you're trying to suppress the error, by only invalidating exactly those analyses we use to detect missing analysis invalidation...
Thank you for the clarification @nikic! My original thought process was that However, it seems like the correct thought process is to be conservative and invalidate everything except CFG analyses because an analysis may depend on the syntactic structure of the IR. Am I on the right track here? To address you're feedback I've added cd500d2 to the |
The new IRNormalizer Pass (#113780) must invalidate
Preserved[Module|Function]HashAnalysis
. To invalidate the analyses, they must be made available to TransformUtils. TransformUtils depends on Analysis. Thus, portPreserved[Module|Function]HashAnalysis
to Analysis.