mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-17 06:33:21 +00:00
Remove another outbreak of customized (and completely broken) hashing.
This one is particularly annoying because the hashing algorithm is highly specialized, with a strange "equivalence" definition that subsets the fields involved. Still, this looks at the exact same set of data as the old code, but without bitwise or-ing over parts of it and other mixing badness. No functionality changed here. I've left a substantial fixme about the fact that there is a cleaner and more principled way to do this, but it requires making the equality definition actual stable for particular types... git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152218 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d4d8b2a7f6
commit
fc22625eb0
@ -40,6 +40,7 @@
|
|||||||
#include "llvm/Support/MathExtras.h"
|
#include "llvm/Support/MathExtras.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/ADT/FoldingSet.h"
|
#include "llvm/ADT/FoldingSet.h"
|
||||||
|
#include "llvm/ADT/Hashing.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
@ -1843,49 +1844,52 @@ void MachineInstr::setPhysRegsDeadExcept(ArrayRef<unsigned> UsedRegs,
|
|||||||
|
|
||||||
unsigned
|
unsigned
|
||||||
MachineInstrExpressionTrait::getHashValue(const MachineInstr* const &MI) {
|
MachineInstrExpressionTrait::getHashValue(const MachineInstr* const &MI) {
|
||||||
unsigned Hash = MI->getOpcode() * 37;
|
// Build up a buffer of hash code components.
|
||||||
|
//
|
||||||
|
// FIXME: This is a total hack. We should have a hash_value overload for
|
||||||
|
// MachineOperand, but currently that doesn't work because there are many
|
||||||
|
// different ideas of "equality" and thus different sets of information that
|
||||||
|
// contribute to the hash code. This one happens to want to take a specific
|
||||||
|
// subset. It's not clear that this routine uses the correct set of
|
||||||
|
// information, it would be good to somehow ensure this function is
|
||||||
|
// MachineInstr::isIdenticalTo with the 'IgnoreVRegDefs' filter look at the
|
||||||
|
// same bits.
|
||||||
|
SmallVector<size_t, 8> HashComponents;
|
||||||
|
HashComponents.reserve(MI->getNumOperands() + 1);
|
||||||
|
HashComponents.push_back(MI->getOpcode());
|
||||||
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
|
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
|
||||||
const MachineOperand &MO = MI->getOperand(i);
|
const MachineOperand &MO = MI->getOperand(i);
|
||||||
uint64_t Key = (uint64_t)MO.getType() << 32;
|
|
||||||
switch (MO.getType()) {
|
switch (MO.getType()) {
|
||||||
default: break;
|
default: break;
|
||||||
case MachineOperand::MO_Register:
|
case MachineOperand::MO_Register:
|
||||||
if (MO.isDef() && TargetRegisterInfo::isVirtualRegister(MO.getReg()))
|
if (MO.isDef() && TargetRegisterInfo::isVirtualRegister(MO.getReg()))
|
||||||
continue; // Skip virtual register defs.
|
continue; // Skip virtual register defs.
|
||||||
Key |= MO.getReg();
|
HashComponents.push_back(hash_combine(MO.getType(), MO.getReg()));
|
||||||
break;
|
break;
|
||||||
case MachineOperand::MO_Immediate:
|
case MachineOperand::MO_Immediate:
|
||||||
Key |= MO.getImm();
|
HashComponents.push_back(hash_combine(MO.getType(), MO.getImm()));
|
||||||
break;
|
break;
|
||||||
case MachineOperand::MO_FrameIndex:
|
case MachineOperand::MO_FrameIndex:
|
||||||
case MachineOperand::MO_ConstantPoolIndex:
|
case MachineOperand::MO_ConstantPoolIndex:
|
||||||
case MachineOperand::MO_JumpTableIndex:
|
case MachineOperand::MO_JumpTableIndex:
|
||||||
Key |= MO.getIndex();
|
HashComponents.push_back(hash_combine(MO.getType(), MO.getIndex()));
|
||||||
break;
|
break;
|
||||||
case MachineOperand::MO_MachineBasicBlock:
|
case MachineOperand::MO_MachineBasicBlock:
|
||||||
Key |= DenseMapInfo<void*>::getHashValue(MO.getMBB());
|
HashComponents.push_back(hash_combine(MO.getType(), MO.getMBB()));
|
||||||
break;
|
break;
|
||||||
case MachineOperand::MO_GlobalAddress:
|
case MachineOperand::MO_GlobalAddress:
|
||||||
Key |= DenseMapInfo<void*>::getHashValue(MO.getGlobal());
|
HashComponents.push_back(hash_combine(MO.getType(), MO.getGlobal()));
|
||||||
break;
|
break;
|
||||||
case MachineOperand::MO_BlockAddress:
|
case MachineOperand::MO_BlockAddress:
|
||||||
Key |= DenseMapInfo<void*>::getHashValue(MO.getBlockAddress());
|
HashComponents.push_back(hash_combine(MO.getType(),
|
||||||
|
MO.getBlockAddress()));
|
||||||
break;
|
break;
|
||||||
case MachineOperand::MO_MCSymbol:
|
case MachineOperand::MO_MCSymbol:
|
||||||
Key |= DenseMapInfo<void*>::getHashValue(MO.getMCSymbol());
|
HashComponents.push_back(hash_combine(MO.getType(), MO.getMCSymbol()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Key += ~(Key << 32);
|
|
||||||
Key ^= (Key >> 22);
|
|
||||||
Key += ~(Key << 13);
|
|
||||||
Key ^= (Key >> 8);
|
|
||||||
Key += (Key << 3);
|
|
||||||
Key ^= (Key >> 15);
|
|
||||||
Key += ~(Key << 27);
|
|
||||||
Key ^= (Key >> 31);
|
|
||||||
Hash = (unsigned)Key + Hash * 37;
|
|
||||||
}
|
}
|
||||||
return Hash;
|
return hash_combine_range(HashComponents.begin(), HashComponents.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MachineInstr::emitError(StringRef Msg) const {
|
void MachineInstr::emitError(StringRef Msg) const {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user