[llvm] [llvm] Use hash_combine_range with ranges (NFC) (PR #137530)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 27 10:03:03 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/137530
None
>From 1d99818ec232387731b04879fe3d56b55c025030 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 20 Apr 2025 16:38:37 -0700
Subject: [PATCH] [llvm] Use hash_combine_range with ranges (NFC)
---
.../llvm/Transforms/Scalar/GVNExpression.h | 2 +-
.../ProfileData/Coverage/CoverageMapping.cpp | 3 +--
llvm/lib/Transforms/Scalar/EarlyCSE.cpp | 27 ++++++++-----------
llvm/lib/Transforms/Utils/Local.cpp | 6 ++---
.../Transforms/Vectorize/LoopVectorize.cpp | 4 +--
5 files changed, 18 insertions(+), 24 deletions(-)
diff --git a/llvm/include/llvm/Transforms/Scalar/GVNExpression.h b/llvm/include/llvm/Transforms/Scalar/GVNExpression.h
index 71437953640c9..50cd6ceb9fc0d 100644
--- a/llvm/include/llvm/Transforms/Scalar/GVNExpression.h
+++ b/llvm/include/llvm/Transforms/Scalar/GVNExpression.h
@@ -221,7 +221,7 @@ class BasicExpression : public Expression {
hash_code getHashValue() const override {
return hash_combine(this->Expression::getHashValue(), ValueType,
- hash_combine_range(op_begin(), op_end()));
+ hash_combine_range(operands()));
}
// Debugging support
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index c39585681911a..d3fe218c19a14 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -933,8 +933,7 @@ Error CoverageMapping::loadFunctionRecord(
}
// Don't create records for (filenames, function) pairs we've already seen.
- auto FilenamesHash = hash_combine_range(Record.Filenames.begin(),
- Record.Filenames.end());
+ auto FilenamesHash = hash_combine_range(Record.Filenames);
if (!RecordProvenance[FilenamesHash].insert(hash_value(OrigFuncName)).second)
return Error::success();
diff --git a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
index 3a0ae6b01a114..1e378369166c0 100644
--- a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
+++ b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
@@ -223,13 +223,11 @@ static unsigned hashCallInst(CallInst *CI) {
// Don't CSE convergent calls in different basic blocks, because they
// implicitly depend on the set of threads that is currently executing.
if (CI->isConvergent()) {
- return hash_combine(
- CI->getOpcode(), CI->getParent(),
- hash_combine_range(CI->value_op_begin(), CI->value_op_end()));
+ return hash_combine(CI->getOpcode(), CI->getParent(),
+ hash_combine_range(CI->operand_values()));
}
- return hash_combine(
- CI->getOpcode(),
- hash_combine_range(CI->value_op_begin(), CI->value_op_end()));
+ return hash_combine(CI->getOpcode(),
+ hash_combine_range(CI->operand_values()));
}
static unsigned getHashValueImpl(SimpleValue Val) {
@@ -302,12 +300,11 @@ static unsigned getHashValueImpl(SimpleValue Val) {
if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(Inst))
return hash_combine(EVI->getOpcode(), EVI->getOperand(0),
- hash_combine_range(EVI->idx_begin(), EVI->idx_end()));
+ hash_combine_range(EVI->indices()));
if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(Inst))
return hash_combine(IVI->getOpcode(), IVI->getOperand(0),
- IVI->getOperand(1),
- hash_combine_range(IVI->idx_begin(), IVI->idx_end()));
+ IVI->getOperand(1), hash_combine_range(IVI->indices()));
assert((isa<CallInst>(Inst) || isa<ExtractElementInst>(Inst) ||
isa<InsertElementInst>(Inst) || isa<ShuffleVectorInst>(Inst) ||
@@ -322,7 +319,7 @@ static unsigned getHashValueImpl(SimpleValue Val) {
std::swap(LHS, RHS);
return hash_combine(
II->getOpcode(), LHS, RHS,
- hash_combine_range(II->value_op_begin() + 2, II->value_op_end()));
+ hash_combine_range(drop_begin(II->operand_values(), 2)));
}
// gc.relocate is 'special' call: its second and third operands are
@@ -338,9 +335,8 @@ static unsigned getHashValueImpl(SimpleValue Val) {
return hashCallInst(CI);
// Mix in the opcode.
- return hash_combine(
- Inst->getOpcode(),
- hash_combine_range(Inst->value_op_begin(), Inst->value_op_end()));
+ return hash_combine(Inst->getOpcode(),
+ hash_combine_range(Inst->operand_values()));
}
unsigned DenseMapInfo<SimpleValue>::getHashValue(SimpleValue Val) {
@@ -608,9 +604,8 @@ unsigned DenseMapInfo<GEPValue>::getHashValue(const GEPValue &Val) {
if (Val.ConstantOffset.has_value())
return hash_combine(GEP->getOpcode(), GEP->getPointerOperand(),
Val.ConstantOffset.value());
- return hash_combine(
- GEP->getOpcode(),
- hash_combine_range(GEP->value_op_begin(), GEP->value_op_end()));
+ return hash_combine(GEP->getOpcode(),
+ hash_combine_range(GEP->operand_values()));
}
bool DenseMapInfo<GEPValue>::isEqual(const GEPValue &LHS, const GEPValue &RHS) {
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index f914d596f0bf0..414011259fcf1 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -1445,9 +1445,9 @@ EliminateDuplicatePHINodesSetBasedImpl(BasicBlock *BB,
// Compute a hash value on the operands. Instcombine will likely have
// sorted them, which helps expose duplicates, but we have to check all
// the operands to be safe in case instcombine hasn't run.
- return static_cast<unsigned>(hash_combine(
- hash_combine_range(PN->value_op_begin(), PN->value_op_end()),
- hash_combine_range(PN->block_begin(), PN->block_end())));
+ return static_cast<unsigned>(
+ hash_combine(hash_combine_range(PN->operand_values()),
+ hash_combine_range(PN->blocks())));
}
static unsigned getHashValue(PHINode *PN) {
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 6b5b50a26c199..724ea028bc54a 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -2741,8 +2741,8 @@ struct CSEDenseMapInfo {
static unsigned getHashValue(const Instruction *I) {
assert(canHandle(I) && "Unknown instruction!");
- return hash_combine(I->getOpcode(), hash_combine_range(I->value_op_begin(),
- I->value_op_end()));
+ return hash_combine(I->getOpcode(),
+ hash_combine_range(I->operand_values()));
}
static bool isEqual(const Instruction *LHS, const Instruction *RHS) {
More information about the llvm-commits
mailing list