[llvm] [IR] Introduce hash_value for FMF, GEPNoWrapFlags (PR #151946)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 4 04:29:14 PDT 2025
https://github.com/artagnon created https://github.com/llvm/llvm-project/pull/151946
This patch is motivated by wanting to do CSE at the VPlan-level: as VPlan stores FMF and GEPNoWrapFlags among other things in its recipes, de-duplicating them for common-subexpression-elimination would require hashing the VPlan recipes along with their embedded information.
>From c8aa7a3444b52059fa590166b41c733d6c8eba9c Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <ramkumar.ramachandra at codasip.com>
Date: Mon, 4 Aug 2025 12:24:03 +0100
Subject: [PATCH] [IR] Introduce hash_value for FMF, GEPNoWrapFlags
This patch is motivated by wanting to do CSE at the VPlan-level: as
VPlan stores FMF and GEPNoWrapFlags among other things in its recipes,
de-duplicating them for common-subexpression-elimination would require
hashing the VPlan recipes along with their embedded information.
---
llvm/include/llvm/IR/FMF.h | 7 +++++++
llvm/include/llvm/IR/GEPNoWrapFlags.h | 7 +++++++
2 files changed, 14 insertions(+)
diff --git a/llvm/include/llvm/IR/FMF.h b/llvm/include/llvm/IR/FMF.h
index 8bd591250a38a..da4d9f564bd5d 100644
--- a/llvm/include/llvm/IR/FMF.h
+++ b/llvm/include/llvm/IR/FMF.h
@@ -13,6 +13,7 @@
#ifndef LLVM_IR_FMF_H
#define LLVM_IR_FMF_H
+#include "llvm/ADT/Hashing.h"
#include "llvm/Support/Compiler.h"
namespace llvm {
@@ -121,6 +122,9 @@ class FastMathFlags {
const unsigned ValueMask = NoNaNs | NoInfs | NoSignedZeros;
return FastMathFlags(ValueMask & (LHS.Flags | RHS.Flags));
}
+
+ // Hashing.
+ friend hash_code hash_value(const FastMathFlags &FMF);
};
inline FastMathFlags operator|(FastMathFlags LHS, FastMathFlags RHS) {
@@ -138,6 +142,9 @@ inline raw_ostream &operator<<(raw_ostream &O, FastMathFlags FMF) {
return O;
}
+inline hash_code hash_value(const FastMathFlags &FMF) {
+ return hash_value(FMF.Flags);
+}
} // end namespace llvm
#endif // LLVM_IR_FMF_H
diff --git a/llvm/include/llvm/IR/GEPNoWrapFlags.h b/llvm/include/llvm/IR/GEPNoWrapFlags.h
index 4e6ab0d88bfcf..35974b323d1e1 100644
--- a/llvm/include/llvm/IR/GEPNoWrapFlags.h
+++ b/llvm/include/llvm/IR/GEPNoWrapFlags.h
@@ -13,6 +13,7 @@
#ifndef LLVM_IR_GEPNOWRAPFLAGS_H
#define LLVM_IR_GEPNOWRAPFLAGS_H
+#include "llvm/ADT/Hashing.h"
#include <assert.h>
namespace llvm {
@@ -101,8 +102,14 @@ class GEPNoWrapFlags {
Flags |= Other.Flags;
return *this;
}
+
+ // Hashing.
+ friend hash_code hash_value(const GEPNoWrapFlags &NW);
};
+inline hash_code hash_value(const GEPNoWrapFlags &NW) {
+ return hash_value(NW.Flags);
+}
} // end namespace llvm
#endif // LLVM_IR_GEPNOWRAPFLAGS_H
More information about the llvm-commits
mailing list