diff options
Diffstat (limited to 'bolt/lib/Core/BinaryFunction.cpp')
-rw-r--r-- | bolt/lib/Core/BinaryFunction.cpp | 35 |
1 files changed, 10 insertions, 25 deletions
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp index 89ba3627cdd7..47c6b7eddaf8 100644 --- a/bolt/lib/Core/BinaryFunction.cpp +++ b/bolt/lib/Core/BinaryFunction.cpp @@ -14,6 +14,7 @@ #include "bolt/Core/BinaryBasicBlock.h" #include "bolt/Core/BinaryDomTree.h" #include "bolt/Core/DynoStats.h" +#include "bolt/Core/HashUtilities.h" #include "bolt/Core/MCPlusBuilder.h" #include "bolt/Utils/NameResolver.h" #include "bolt/Utils/NameShortener.h" @@ -3604,34 +3605,18 @@ size_t BinaryFunction::computeHash(bool UseDFS, // The hash is computed by creating a string of all instruction opcodes and // possibly their operands and then hashing that string with std::hash. std::string HashString; - for (const BinaryBasicBlock *BB : Order) { - for (const MCInst &Inst : *BB) { - unsigned Opcode = Inst.getOpcode(); - - if (BC.MIB->isPseudo(Inst)) - continue; + for (const BinaryBasicBlock *BB : Order) + HashString.append(hashBlock(BC, *BB, OperandHashFunc)); - // Ignore unconditional jumps since we check CFG consistency by processing - // basic blocks in order and do not rely on branches to be in-sync with - // CFG. Note that we still use condition code of conditional jumps. - if (BC.MIB->isUnconditionalBranch(Inst)) - continue; - - if (Opcode == 0) - HashString.push_back(0); - - while (Opcode) { - uint8_t LSB = Opcode & 0xff; - HashString.push_back(LSB); - Opcode = Opcode >> 8; - } + return Hash = std::hash<std::string>{}(HashString); +} - for (const MCOperand &Op : MCPlus::primeOperands(Inst)) - HashString.append(OperandHashFunc(Op)); - } +void BinaryFunction::computeBlockHashes() const { + for (const BinaryBasicBlock *BB : BasicBlocks) { + std::string Hash = + hashBlock(BC, *BB, [](const MCOperand &Op) { return std::string(); }); + BB->setHash(std::hash<std::string>{}(Hash)); } - - return Hash = std::hash<std::string>{}(HashString); } void BinaryFunction::insertBasicBlocks( |