Skip to content

Commit

Permalink
[NFC] Use stable_hash_combine instead of hash_combine (llvm#105619)
Browse files Browse the repository at this point in the history
I found the current stable hash is not deterministic across multiple
runs on a specific platform. This is because it uses `hash_combine`
instead of `stable_hash_combine`.

(cherry picked from commit c9b6339)
  • Loading branch information
kyulee-com authored and adrian-prantl committed Oct 21, 2024
1 parent e57d2a5 commit e00e654
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions llvm/lib/CodeGen/MachineStableHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ stable_hash llvm::stableHashValue(const MachineOperand &MO) {
case MachineOperand::MO_Register:
if (MO.getReg().isVirtual()) {
const MachineRegisterInfo &MRI = MO.getParent()->getMF()->getRegInfo();
SmallVector<unsigned> DefOpcodes;
SmallVector<stable_hash> DefOpcodes;
for (auto &Def : MRI.def_instructions(MO.getReg()))
DefOpcodes.push_back(Def.getOpcode());
return hash_combine_range(DefOpcodes.begin(), DefOpcodes.end());
return stable_hash_combine_range(DefOpcodes.begin(), DefOpcodes.end());
}

// Register operands don't have target flags.
Expand All @@ -80,7 +80,7 @@ stable_hash llvm::stableHashValue(const MachineOperand &MO) {
: MO.getFPImm()->getValueAPF().bitcastToAPInt();
auto ValHash =
stable_hash_combine_array(Val.getRawData(), Val.getNumWords());
return hash_combine(MO.getType(), MO.getTargetFlags(), ValHash);
return stable_hash_combine(MO.getType(), MO.getTargetFlags(), ValHash);
}

case MachineOperand::MO_MachineBasicBlock:
Expand Down Expand Up @@ -112,8 +112,8 @@ stable_hash llvm::stableHashValue(const MachineOperand &MO) {
MO.getIndex());

case MachineOperand::MO_ExternalSymbol:
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getOffset(),
xxh3_64bits(MO.getSymbolName()));
return stable_hash_combine(MO.getType(), MO.getTargetFlags(),
MO.getOffset(), xxh3_64bits(MO.getSymbolName()));

case MachineOperand::MO_RegisterMask:
case MachineOperand::MO_RegisterLiveOut: {
Expand All @@ -126,15 +126,16 @@ stable_hash llvm::stableHashValue(const MachineOperand &MO) {
const uint32_t *RegMask = MO.getRegMask();
std::vector<llvm::stable_hash> RegMaskHashes(RegMask,
RegMask + RegMaskSize);
return hash_combine(MO.getType(), MO.getTargetFlags(),
stable_hash_combine_array(RegMaskHashes.data(),
RegMaskHashes.size()));
return stable_hash_combine(
MO.getType(), MO.getTargetFlags(),
stable_hash_combine_array(RegMaskHashes.data(),
RegMaskHashes.size()));
}
}
}

assert(0 && "MachineOperand not associated with any MachineFunction");
return hash_combine(MO.getType(), MO.getTargetFlags());
return stable_hash_combine(MO.getType(), MO.getTargetFlags());
}

case MachineOperand::MO_ShuffleMask: {
Expand All @@ -144,14 +145,15 @@ stable_hash llvm::stableHashValue(const MachineOperand &MO) {
MO.getShuffleMask(), std::back_inserter(ShuffleMaskHashes),
[](int S) -> llvm::stable_hash { return llvm::stable_hash(S); });

return hash_combine(MO.getType(), MO.getTargetFlags(),
stable_hash_combine_array(ShuffleMaskHashes.data(),
ShuffleMaskHashes.size()));
return stable_hash_combine(
MO.getType(), MO.getTargetFlags(),
stable_hash_combine_array(ShuffleMaskHashes.data(),
ShuffleMaskHashes.size()));
}
case MachineOperand::MO_MCSymbol: {
auto SymbolName = MO.getMCSymbol()->getName();
return hash_combine(MO.getType(), MO.getTargetFlags(),
xxh3_64bits(SymbolName));
return stable_hash_combine(MO.getType(), MO.getTargetFlags(),
xxh3_64bits(SymbolName));
}
case MachineOperand::MO_CFIIndex:
return stable_hash_combine(MO.getType(), MO.getTargetFlags(),
Expand Down

0 comments on commit e00e654

Please sign in to comment.