diff options
| author | Roman Divacky <rdivacky@FreeBSD.org> | 2010-03-06 09:22:29 +0000 | 
|---|---|---|
| committer | Roman Divacky <rdivacky@FreeBSD.org> | 2010-03-06 09:22:29 +0000 | 
| commit | f5a3459adfde823bc7617f8ecfdd9fbc5a1ffadf (patch) | |
| tree | 542734eaa7870f95912cbaebccb87dbec0c20b4f /lib/CodeGen/MachineInstr.cpp | |
| parent | 67a71b3184ce20a901e874d0ee25e01397dd87ef (diff) | |
Notes
Diffstat (limited to 'lib/CodeGen/MachineInstr.cpp')
| -rw-r--r-- | lib/CodeGen/MachineInstr.cpp | 86 | 
1 files changed, 69 insertions, 17 deletions
| diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp index cba93f14a0bb..e23670d1d1d2 100644 --- a/lib/CodeGen/MachineInstr.cpp +++ b/lib/CodeGen/MachineInstr.cpp @@ -704,24 +704,31 @@ void MachineInstr::addMemOperand(MachineFunction &MF,  bool MachineInstr::isIdenticalTo(const MachineInstr *Other,                                   MICheckType Check) const { -    if (Other->getOpcode() != getOpcode() || -        Other->getNumOperands() != getNumOperands()) +  // If opcodes or number of operands are not the same then the two +  // instructions are obviously not identical. +  if (Other->getOpcode() != getOpcode() || +      Other->getNumOperands() != getNumOperands()) +    return false; + +  // Check operands to make sure they match. +  for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { +    const MachineOperand &MO = getOperand(i); +    const MachineOperand &OMO = Other->getOperand(i); +    // Clients may or may not want to ignore defs when testing for equality. +    // For example, machine CSE pass only cares about finding common +    // subexpressions, so it's safe to ignore virtual register defs. +    if (Check != CheckDefs && MO.isReg() && MO.isDef()) { +      if (Check == IgnoreDefs) +        continue; +      // Check == IgnoreVRegDefs +      if (TargetRegisterInfo::isPhysicalRegister(MO.getReg()) || +          TargetRegisterInfo::isPhysicalRegister(OMO.getReg())) +        if (MO.getReg() != OMO.getReg()) +          return false; +    } else if (!MO.isIdenticalTo(OMO))        return false; -    for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { -      const MachineOperand &MO = getOperand(i); -      const MachineOperand &OMO = Other->getOperand(i); -      if (Check != CheckDefs && MO.isReg() && MO.isDef()) { -        if (Check == IgnoreDefs) -          continue; -        // Check == IgnoreVRegDefs -        if (TargetRegisterInfo::isPhysicalRegister(MO.getReg()) || -            TargetRegisterInfo::isPhysicalRegister(OMO.getReg())) -          if (MO.getReg() != OMO.getReg()) -            return false; -      } else if (!MO.isIdenticalTo(OMO)) -        return false; -    } -    return true; +  } +  return true;  }  /// removeFromParent - This method unlinks 'this' from the containing basic @@ -1348,3 +1355,48 @@ void MachineInstr::addRegisterDefined(unsigned IncomingReg,                                           true  /*IsDef*/,                                           true  /*IsImp*/));  } + +unsigned +MachineInstrExpressionTrait::getHashValue(const MachineInstr* const &MI) { +  unsigned Hash = MI->getOpcode() * 37; +  for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { +    const MachineOperand &MO = MI->getOperand(i); +    uint64_t Key = (uint64_t)MO.getType() << 32; +    switch (MO.getType()) { +      default: break; +      case MachineOperand::MO_Register: +        if (MO.isDef() && MO.getReg() && +            TargetRegisterInfo::isVirtualRegister(MO.getReg())) +          continue;  // Skip virtual register defs. +        Key |= MO.getReg(); +        break; +      case MachineOperand::MO_Immediate: +        Key |= MO.getImm(); +        break; +      case MachineOperand::MO_FrameIndex: +      case MachineOperand::MO_ConstantPoolIndex: +      case MachineOperand::MO_JumpTableIndex: +        Key |= MO.getIndex(); +        break; +      case MachineOperand::MO_MachineBasicBlock: +        Key |= DenseMapInfo<void*>::getHashValue(MO.getMBB()); +        break; +      case MachineOperand::MO_GlobalAddress: +        Key |= DenseMapInfo<void*>::getHashValue(MO.getGlobal()); +        break; +      case MachineOperand::MO_BlockAddress: +        Key |= DenseMapInfo<void*>::getHashValue(MO.getBlockAddress()); +        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; +} | 
