26class StructuralHashImpl {
35 template <
typename T>
void hashArbitaryType(
const T &V) {
46 StructuralHashImpl() : Hash(4) {}
53 if (
ConstantInt *ConstInt = dyn_cast<ConstantInt>(Operand)) {
54 hashArbitaryType(ConstInt->getValue());
55 }
else if (
ConstantFP *ConstFP = dyn_cast<ConstantFP>(Operand)) {
56 hashArbitaryType(ConstFP->getValue());
57 }
else if (
Argument *Arg = dyn_cast<Argument>(Operand)) {
58 hash(Arg->getArgNo());
59 }
else if (
Function *Func = dyn_cast<Function>(Operand)) {
63 hashArbitaryType(
Func->getName());
67 void updateInstruction(
const Instruction &Inst,
bool DetailedHash) {
77 if (
const auto *ComparisonInstruction = dyn_cast<CmpInst>(&Inst))
78 hash(ComparisonInstruction->getPredicate());
100 void update(
const Function &
F,
bool DetailedHash) {
102 if (
F.isDeclaration())
105 hash(0x62642d6b6b2d6b72);
117 VisitedBBs.
insert(BBs[0]);
118 while (!BBs.
empty()) {
125 for (
auto &Inst : *BB)
126 updateInstruction(Inst, DetailedHash);
129 if (VisitedBBs.
insert(Succ).second)
144 void update(
const Module &M,
bool DetailedHash) {
148 update(
F, DetailedHash);
151 uint64_t getHash()
const {
return Hash; }
157 StructuralHashImpl
H;
158 H.update(
F, DetailedHash);
163 StructuralHashImpl
H;
164 H.update(M, DetailedHash);
static bool updateOperand(Instruction *Inst, unsigned Idx, Instruction *Mat)
Updates the operand at Idx in instruction Inst with the result of instruction Mat.
Module.h This file contains the declarations for the Module class.
This class represents an incoming formal argument to a Function.
LLVM Basic Block Representation.
ConstantFP - Floating Point Values [float, double].
This is the shared class of boolean and integer constants.
This class represents an Operation in the Expression.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Type * getValueType() const
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.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
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.
uint64_t hash_16_bytes(uint64_t low, uint64_t high)
NodeAddr< FuncNode * > Func
This is an optimization pass for GlobalISel generic memory operations.
auto successors(const MachineBasicBlock *BB)
IRHash StructuralHash(const Function &F, bool DetailedHash=false)
Returns a hash of the function F.
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.