diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2015-06-18 20:00:03 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2015-06-18 20:00:03 +0000 |
commit | 8985b32e76f5e92d32705edb2cef58f9b747af38 (patch) | |
tree | 3b2bbd68e34810024751464d1dfe1cfe729b11d8 /llvm/lib/CodeGen | |
parent | c65d43e64926c9f868213f453bb4cdc3d4ab7879 (diff) | |
download | bcm5719-llvm-8985b32e76f5e92d32705edb2cef58f9b747af38.tar.gz bcm5719-llvm-8985b32e76f5e92d32705edb2cef58f9b747af38.zip |
[BranchFolding] Replace custom MachineInstr with MachineInstrExpressionTrait
While the hash functions are subtly different it shouldn't have an
impact. Instructions are checked with isIdenticalTo later.
llvm-svn: 240040
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/BranchFolding.cpp | 52 |
1 files changed, 6 insertions, 46 deletions
diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp index b8d9a1a29ed..a884833d471 100644 --- a/llvm/lib/CodeGen/BranchFolding.cpp +++ b/llvm/lib/CodeGen/BranchFolding.cpp @@ -264,54 +264,14 @@ bool BranchFolder::OptimizeFunction(MachineFunction &MF, // Tail Merging of Blocks //===----------------------------------------------------------------------===// -/// HashMachineInstr - Compute a hash value for MI and its operands. -static unsigned HashMachineInstr(const MachineInstr *MI) { - unsigned Hash = MI->getOpcode(); - for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { - const MachineOperand &Op = MI->getOperand(i); - - // Merge in bits from the operand if easy. - unsigned OperandHash = 0; - switch (Op.getType()) { - case MachineOperand::MO_Register: OperandHash = Op.getReg(); break; - case MachineOperand::MO_Immediate: OperandHash = Op.getImm(); break; - case MachineOperand::MO_MachineBasicBlock: - OperandHash = Op.getMBB()->getNumber(); - break; - case MachineOperand::MO_FrameIndex: - case MachineOperand::MO_ConstantPoolIndex: - case MachineOperand::MO_JumpTableIndex: - OperandHash = Op.getIndex(); - break; - case MachineOperand::MO_GlobalAddress: - case MachineOperand::MO_ExternalSymbol: - // Global address / external symbol are too hard, don't bother, but do - // pull in the offset. - OperandHash = Op.getOffset(); - break; - default: break; - } - - Hash += ((OperandHash << 3) | Op.getType()) << (i&31); - } - return Hash; -} - /// HashEndOfMBB - Hash the last instruction in the MBB. static unsigned HashEndOfMBB(const MachineBasicBlock *MBB) { - MachineBasicBlock::const_iterator I = MBB->end(); - if (I == MBB->begin()) - return 0; // Empty MBB. - - --I; - // Skip debug info so it will not affect codegen. - while (I->isDebugValue()) { - if (I==MBB->begin()) - return 0; // MBB empty except for debug info. - --I; - } - - return HashMachineInstr(I); + auto LastInst = MBB->getLastNonDebugInstr(); + if (LastInst == MBB->end()) + return 0; + // Hash the instruction and all operands. MachineInstrExpressionTrait ignores + // vreg defs when computing the hash but we're post-regalloc here. + return MachineInstrExpressionTrait::getHashValue(LastInst); } /// ComputeCommonTailLength - Given two machine basic blocks, compute the number |