-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[llvm] Use hash_combine_range with ranges (NFC) #137530
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
Merged
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_hash_combine_range_llvm
Apr 27, 2025
Merged
[llvm] Use hash_combine_range with ranges (NFC) #137530
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_hash_combine_range_llvm
Apr 27, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-pgo Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/137530.diff 5 Files Affected:
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) {
|
@llvm/pr-subscribers-vectorizers Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/137530.diff 5 Files Affected:
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) {
|
nikic
approved these changes
Apr 27, 2025
jyli0116
pushed a commit
to jyli0116/llvm-project
that referenced
this pull request
Apr 28, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
Ankur-0429
pushed a commit
to Ankur-0429/llvm-project
that referenced
this pull request
May 9, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.