34#define DEBUG_TYPE "mirfs-discriminators"
40 cl::desc(
"New FS discriminators encoding (incompatible with the original "
45 "Add MIR Flow Sensitive Discriminators",
65 uint64_t Ret = updateHash(std::to_string(DIL->getLine()));
66 Ret ^= updateHash(BB.
getName());
67 Ret ^= updateHash(DIL->getScope()->getSubprogram()->getLinkageName());
68 for (DIL = DIL->getInlinedAt(); DIL; DIL = DIL->getInlinedAt()) {
69 Ret ^= updateHash(std::to_string(DIL->getLine()));
70 Ret ^= updateHash(DIL->getScope()->getSubprogram()->getLinkageName());
77 std::hash<uint64_t> Hasher;
78 return Seed ^ (Hasher(Val) + 0x9e3779b9 + (
Seed << 6) + (
Seed >> 2));
81 for (DIL = DIL->getInlinedAt(); DIL; DIL = DIL->getInlinedAt()) {
83 Ret = hashCombine(Ret,
xxh3_64bits(DIL->getSubprogramLinkageName()));
97 bool HasPseudoProbe = MF.getFunction().getParent()->getNamedMetadata(
100 if (!HasPseudoProbe && !MF.getFunction().shouldEmitDebugInfoForProfiling())
104 using LocationDiscriminator =
105 std::tuple<StringRef, unsigned, unsigned, uint64_t>;
106 using BBSet = DenseSet<const MachineBasicBlock *>;
107 using LocationDiscriminatorBBMap = DenseMap<LocationDiscriminator, BBSet>;
108 using LocationDiscriminatorCurrPassMap =
109 DenseMap<LocationDiscriminator, unsigned>;
111 LocationDiscriminatorBBMap LDBM;
112 LocationDiscriminatorCurrPassMap LDCM;
116 unsigned LowBitTemp = LowBit;
117 assert(LowBit > 0 &&
"LowBit in FSDiscriminator cannot be 0");
120 unsigned BitMaskBefore =
getN1Bits(LowBitTemp);
122 unsigned BitMaskNow =
getN1Bits(HighBit);
124 unsigned BitMaskThisPass = BitMaskNow ^ BitMaskBefore;
125 unsigned NumNewD = 0;
128 << MF.getFunction().getName() <<
" Highbit=" << HighBit
131 for (MachineBasicBlock &BB : MF) {
132 for (MachineInstr &
I : BB) {
133 if (HasPseudoProbe) {
137 if (!
I.isPseudoProbe())
142 const DILocation *DIL =
I.getDebugLoc().get();
148 I.isPseudoProbe() ?
I.getOperand(1).getImm() : DIL->getLine();
154 if ((Pass == FSDiscriminatorPass::Pass1) &&
I.isPseudoProbe()) {
164 auto &BBMap = LDBM[
LD];
165 auto R = BBMap.insert(&BB);
166 if (BBMap.size() == 1)
169 unsigned DiscriminatorCurrPass;
170 DiscriminatorCurrPass =
R.second ? ++LDCM[
LD] : LDCM[
LD];
171 DiscriminatorCurrPass = DiscriminatorCurrPass << LowBit;
174 DiscriminatorCurrPass &= BitMaskThisPass;
179 << DIL->getFilename() <<
":" << DIL->getLine() <<
":"
180 << DIL->getColumn() <<
":" << Discriminator <<
" "
185 I.setDebugLoc(NewDIL);
187 LLVM_DEBUG(
dbgs() << DIL->getFilename() <<
":" << DIL->getLine() <<
":"
188 << DIL->getColumn() <<
": add FS discriminator, from "
189 << Discriminator <<
" -> " << NewD <<
"\n");
196 LLVM_DEBUG(
dbgs() <<
"Num of FS Discriminators: " << NumNewD <<
"\n");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
Module.h This file contains the declarations for the Module class.
static uint64_t getCallStackHashV0(const MachineBasicBlock &BB, const MachineInstr &MI, const DILocation *DIL)
static uint64_t getCallStackHash(const DILocation *DIL)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static ManagedStatic< cl::opt< uint64_t >, CreateSeed > Seed
This file provides the utility functions for the sampled PGO loader base implementation.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
const DILocation * cloneWithDiscriminator(unsigned Discriminator) const
Returns a new DILocation with updated Discriminator.
FunctionPass class - This class is used to implement most global optimizations.
LLVM_ABI StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
Representation of each machine instruction.
Represent a constant reference to a string, i.e.
initializer< Ty > init(const Ty &Val)
uint64_t MD5Hash(const FunctionId &Obj)
LLVM_ABI void createFSDiscriminatorVariable(Module *M)
Create a global variable to flag FSDiscriminators are used.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI char & MIRAddFSDiscriminatorsID
This pass adds flow sensitive discriminators.
LLVM_ABI cl::opt< bool > ImprovedFSDiscriminator
uint64_t xxh3_64bits(ArrayRef< uint8_t > data)
Inline ArrayRef overloads of the xxhash entry points declared out-of-line in llvm/Support/xxhash....
LLVM_ABI cl::opt< bool > EnableFSDiscriminator
LLVM_ABI FunctionPass * createMIRAddFSDiscriminatorsPass(sampleprof::FSDiscriminatorPass P)
Add Flow Sensitive Discriminators.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static unsigned getN1Bits(int N)
constexpr const char * PseudoProbeDescMetadataName