aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineOperand.cpp
diff options
context:
space:
mode:
authorYongKang Zhu <yongzhu@fb.com>2022-09-13 16:08:17 -0700
committerHongtao Yu <hoy@fb.com>2022-09-13 16:12:41 -0700
commit5fa6b2435477c8d44fc827cda2f998591b1cf837 (patch)
tree450ec823ba9d6b8a9b95b577f28957f76c57a0d0 /llvm/lib/CodeGen/MachineOperand.cpp
parentb6965f7246bba1b399755f56d8ae34893e815198 (diff)
downloadllvm-5fa6b2435477c8d44fc827cda2f998591b1cf837.zip
llvm-5fa6b2435477c8d44fc827cda2f998591b1cf837.tar.gz
llvm-5fa6b2435477c8d44fc827cda2f998591b1cf837.tar.bz2
Address feedback in https://reviews.llvm.org/D133637
https://reviews.llvm.org/D133637 fixes the problem where we should hash raw content of register mask instead of the pointer to it. Fix the same issue in `llvm::hash_value()`. Remove the added API `MachineOperand::getRegMaskSize()` to avoid potential confusion. Add an assert to emphasize that we probably should hash a machine operand iff it has associated machine function, but keep the fallback logic in the original change. Reviewed By: MatzeB Differential Revision: https://reviews.llvm.org/D133747
Diffstat (limited to 'llvm/lib/CodeGen/MachineOperand.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineOperand.cpp34
1 files changed, 19 insertions, 15 deletions
diff --git a/llvm/lib/CodeGen/MachineOperand.cpp b/llvm/lib/CodeGen/MachineOperand.cpp
index 7a85eaf..393a4f7 100644
--- a/llvm/lib/CodeGen/MachineOperand.cpp
+++ b/llvm/lib/CodeGen/MachineOperand.cpp
@@ -18,6 +18,7 @@
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineJumpTableInfo.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
+#include "llvm/CodeGen/StableHashing.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/Config/llvm-config.h"
@@ -45,6 +46,7 @@ static const MachineFunction *getMFIfAvailable(const MachineOperand &MO) {
return MF;
return nullptr;
}
+
static MachineFunction *getMFIfAvailable(MachineOperand &MO) {
return const_cast<MachineFunction *>(
getMFIfAvailable(const_cast<const MachineOperand &>(MO)));
@@ -279,17 +281,6 @@ void MachineOperand::ChangeToRegister(Register Reg, bool isDef, bool isImp,
RegInfo->addRegOperandToUseList(this);
}
-/// getRegMaskSize - Return the size of regmask array if we are able to figure
-/// it out from this operand. Return zero otherwise.
-unsigned MachineOperand::getRegMaskSize() const {
- if (const MachineFunction *MF = getMFIfAvailable(*this)) {
- const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
- unsigned RegMaskSize = (TRI->getNumRegs() + 31) / 32;
- return RegMaskSize;
- }
- return 0;
-}
-
/// isIdenticalTo - Return true if this operand is identical to the specified
/// operand. Note that this should stay in sync with the hash_value overload
/// below.
@@ -333,8 +324,9 @@ bool MachineOperand::isIdenticalTo(const MachineOperand &Other) const {
if (RegMask == OtherRegMask)
return true;
- const unsigned RegMaskSize = getRegMaskSize();
- if (RegMaskSize != 0) {
+ if (const MachineFunction *MF = getMFIfAvailable(*this)) {
+ const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
+ unsigned RegMaskSize = MachineOperand::getRegMaskSize(TRI->getNumRegs());
// Deep compare of the two RegMasks
return std::equal(RegMask, RegMask + RegMaskSize, OtherRegMask);
}
@@ -390,8 +382,20 @@ hash_code llvm::hash_value(const MachineOperand &MO) {
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getBlockAddress(),
MO.getOffset());
case MachineOperand::MO_RegisterMask:
- case MachineOperand::MO_RegisterLiveOut:
- return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getRegMask());
+ case MachineOperand::MO_RegisterLiveOut: {
+ if (const MachineFunction *MF = getMFIfAvailable(MO)) {
+ const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
+ unsigned RegMaskSize = MachineOperand::getRegMaskSize(TRI->getNumRegs());
+ const uint32_t *RegMask = MO.getRegMask();
+ std::vector<stable_hash> RegMaskHashes(RegMask, RegMask + RegMaskSize);
+ return 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());
+ }
case MachineOperand::MO_Metadata:
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMetadata());
case MachineOperand::MO_MCSymbol: