[llvm-branch-commits] [llvm] [StructuralHash] Support Differences (PR #112638)
Ellis Hoag via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Oct 18 14:05:49 PDT 2024
================
@@ -47,24 +60,140 @@ class StructuralHashImpl {
public:
StructuralHashImpl() = delete;
- explicit StructuralHashImpl(bool DetailedHash) : DetailedHash(DetailedHash) {}
+ explicit StructuralHashImpl(bool DetailedHash,
+ IgnoreOperandFunc IgnoreOp = nullptr)
+ : DetailedHash(DetailedHash), IgnoreOp(IgnoreOp) {
+ if (IgnoreOp) {
+ IndexInstruction = std::make_unique<IndexInstrMap>();
+ IndexOperandHashMap = std::make_unique<IndexOperandHashMapType>();
+ }
+ }
- stable_hash hashConstant(Constant *C) {
+ stable_hash hashAPInt(const APInt &I) {
SmallVector<stable_hash> Hashes;
- // TODO: hashArbitaryType() is not stable.
- if (ConstantInt *ConstInt = dyn_cast<ConstantInt>(C)) {
- Hashes.emplace_back(hashArbitaryType(ConstInt->getValue()));
- } else if (ConstantFP *ConstFP = dyn_cast<ConstantFP>(C)) {
- Hashes.emplace_back(hashArbitaryType(ConstFP->getValue()));
- } else if (Function *Func = dyn_cast<Function>(C))
- // Hashing the name will be deterministic as LLVM's hashing infrastructure
- // has explicit support for hashing strings and will not simply hash
- // the pointer.
- Hashes.emplace_back(hashArbitaryType(Func->getName()));
+ Hashes.emplace_back(I.getBitWidth());
+ for (unsigned J = 0; J < I.getNumWords(); ++J)
+ Hashes.emplace_back((I.getRawData())[J]);
----------------
ellishg wrote:
I also wonder what the difference is between `getNumWords()` and `getActiveWords()`.
```suggestion
for (unsigned Byte : ArrayRef(I.getRawData(), I.getNumWords()))
Hashes.emplace_back(Byte);
```
Actually, I wonder if this will work since `ArrayRef` can become a `SmallVector`. Or maybe I'm just being too fancy :)
```
Hashes.append(ArrayRef(I.getRawData(), I.getNumWords()));
```
https://github.com/llvm/llvm-project/pull/112638
More information about the llvm-branch-commits
mailing list