llvm-project/bolt/include/bolt/Core/HashUtilities.h
Shaw Young 131eb30584
[BOLT] Match blocks with calls as anchors (#96596)
Added another hash level – call hash – following opcode hash matching
for stale block matching. Call hash strings are the concatenation of the
lexicographically ordered names of each blocks’ called functions. This 
change bolsters block matching in cases where some instructions have
been removed or added but calls remain constant.

Test Plan: added match-functions-with-calls-as-anchors.test.
2024-07-10 15:46:47 -07:00

50 lines
1.6 KiB
C++

//===- bolt/Core/HashUtilities.h - Misc hash utilities --------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file contains functions for computing hash values over BinaryFunction
// and BinaryBasicBlock.
//
//===----------------------------------------------------------------------===//
#ifndef BOLT_CORE_HASH_UTILITIES_H
#define BOLT_CORE_HASH_UTILITIES_H
#include "bolt/Core/BinaryBasicBlock.h"
#include "bolt/Core/BinaryContext.h"
#include "bolt/Profile/ProfileYAMLMapping.h"
namespace llvm {
namespace bolt {
std::string hashInteger(uint64_t Value);
std::string hashSymbol(BinaryContext &BC, const MCSymbol &Symbol);
std::string hashExpr(BinaryContext &BC, const MCExpr &Expr);
std::string hashInstOperand(BinaryContext &BC, const MCOperand &Operand);
using OperandHashFuncTy = function_ref<typename std::string(const MCOperand &)>;
std::string hashBlock(BinaryContext &BC, const BinaryBasicBlock &BB,
OperandHashFuncTy OperandHashFunc);
std::string hashBlockLoose(BinaryContext &BC, const BinaryBasicBlock &BB);
std::string hashBlockCalls(BinaryContext &BC, const BinaryBasicBlock &BB);
std::string
hashBlockCalls(const DenseMap<uint32_t, yaml::bolt::BinaryFunctionProfile *>
&IdToYamlFunction,
const yaml::bolt::BinaryBasicBlockProfile &YamlBB);
} // namespace bolt
} // namespace llvm
#endif