25class StructuralHashImpl {
32 static constexpr stable_hash BlockHeaderHash = 45798;
33 static constexpr stable_hash FunctionHeaderHash = 0x62642d6b6b2d6b72;
34 static constexpr stable_hash GlobalHeaderHash = 23456;
41 std::unique_ptr<IndexInstrMap> IndexInstruction =
nullptr;
44 std::unique_ptr<IndexOperandHashMapType> IndexOperandHashMap =
nullptr;
58 StructuralHashImpl() =
delete;
59 explicit StructuralHashImpl(
bool DetailedHash,
61 : DetailedHash(DetailedHash), IgnoreOp(IgnoreOp) {
63 IndexInstruction = std::make_unique<IndexInstrMap>();
64 IndexOperandHashMap = std::make_unique<IndexOperandHashMapType>();
72 Hashes.
append(RawVals.begin(), RawVals.end());
77 return hashAPInt(
F.bitcastToAPInt());
82 return hashGlobalValue(&GVar);
87 if (
const auto *Seq = dyn_cast<ConstantDataSequential>(
C))
95 "__cfstring",
"__cstring",
"__objc_classrefs",
96 "__objc_methname",
"__objc_selrefs",
105 return hashGlobalValue(&GVar);
121 Type *Ty =
C->getType();
124 if (
C->isNullValue()) {
129 if (
auto *GVar = dyn_cast<GlobalVariable>(
C)) {
134 if (
auto *
G = dyn_cast<GlobalValue>(
C)) {
139 if (
const auto *Seq = dyn_cast<ConstantDataSequential>(
C)) {
140 if (Seq->isString()) {
146 switch (
C->getValueID()) {
147 case Value::ConstantIntVal: {
148 const APInt &
Int = cast<ConstantInt>(
C)->getValue();
152 case Value::ConstantFPVal: {
153 const APFloat &APF = cast<ConstantFP>(
C)->getValueAPF();
157 case Value::ConstantArrayVal:
158 case Value::ConstantStructVal:
159 case Value::ConstantVectorVal:
160 case Value::ConstantExprVal: {
161 for (
const auto &
Op :
C->operands()) {
162 auto H = hashConstant(cast<Constant>(
Op));
167 case Value::BlockAddressVal: {
173 case Value::DSOLocalEquivalentVal: {
174 const auto *Equiv = cast<DSOLocalEquivalent>(
C);
175 auto H = hashGlobalValue(Equiv->getGlobalValue());
189 return hashConstant(
C);
193 if (
Argument *Arg = dyn_cast<Argument>(V))
221 if (
const auto *ComparisonInstruction = dyn_cast<CmpInst>(&Inst))
222 Hashes.
emplace_back(ComparisonInstruction->getPredicate());
224 unsigned InstIdx = 0;
225 if (IndexInstruction) {
226 InstIdx = IndexInstruction->size();
227 IndexInstruction->try_emplace(InstIdx,
const_cast<Instruction *
>(&Inst));
231 auto OpndHash = hashOperand(
Op);
232 if (IgnoreOp && IgnoreOp(&Inst, OpndIdx)) {
233 assert(IndexOperandHashMap);
234 IndexOperandHashMap->try_emplace({InstIdx, OpndIdx}, OpndHash);
260 if (
F.isDeclaration())
277 VisitedBBs.
insert(BBs[0]);
278 while (!BBs.
empty()) {
282 for (
auto &Inst : *BB)
286 if (VisitedBBs.
insert(Succ).second)
309 void update(
const Module &M) {
316 uint64_t getHash()
const {
return Hash; }
318 std::unique_ptr<IndexInstrMap> getIndexInstrMap() {
319 return std::move(IndexInstruction);
322 std::unique_ptr<IndexOperandHashMapType> getIndexPairOpndHashMap() {
323 return std::move(IndexOperandHashMap);
330 StructuralHashImpl
H(DetailedHash);
336 return StructuralHashImpl::hashGlobalVariable(GVar);
340 StructuralHashImpl
H(DetailedHash);
348 StructuralHashImpl
H(
true, IgnoreOp);
351 H.getIndexPairOpndHashMap());
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Class for arbitrary precision integers.
This class represents an incoming formal argument to a Function.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM Basic Block Representation.
The address of a basic block.
Function * getFunction() const
This is an important base class in LLVM.
This class represents an Operation in the Expression.
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
StringRef getSection() const
Get the custom section of this global if it has one.
bool hasSection() const
Check if this global has a custom object file section.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Type * getValueType() const
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool hasInitializer() const
Definitions have initializers, declarations don't.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
A Module instance is used to store all the information related to an LLVM module.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
reference emplace_back(ArgTypes &&... Args)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
The instances of the Type class are immutable: once they are created, they are never changed.
TypeID getTypeID() const
Return the type id for the type.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
StringRef getName() const
Return a constant reference to the value's name.
@ C
The default llvm calling convention, compatible with C.
static constexpr StringLiteral SectionNames[SectionKindsNum]
This is an optimization pass for GlobalISel generic memory operations.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
FunctionHashInfo StructuralHashWithDifferences(const Function &F, IgnoreOperandFunc IgnoreOp)
Computes a structural hash of a given function, considering the structure and content of the function...
auto successors(const MachineBasicBlock *BB)
stable_hash stable_hash_name(StringRef Name)
stable_hash stable_hash_combine(ArrayRef< stable_hash > Buffer)
uint64_t stable_hash
An opaque object representing a stable hash code.
stable_hash StructuralHash(const Function &F, bool DetailedHash=false)
Returns a hash of the function F.
std::function< bool(const Instruction *, unsigned)> IgnoreOperandFunc
A function that takes an instruction and an operand index and returns true if the operand should be i...