31using namespace sampleprof;
32using namespace sampleprofutil;
34#define DEBUG_TYPE "mirfs-discriminators"
41 cl::desc(
"New FS discriminators encoding (incompatible with the original "
48 "Add MIR Flow Sensitive Discriminators",
68 uint64_t Ret = updateHash(std::to_string(DIL->getLine()));
69 Ret ^= updateHash(BB.
getName());
70 Ret ^= updateHash(DIL->getScope()->getSubprogram()->getLinkageName());
71 for (DIL = DIL->getInlinedAt(); DIL; DIL = DIL->getInlinedAt()) {
72 Ret ^= updateHash(std::to_string(DIL->getLine()));
73 Ret ^= updateHash(DIL->getScope()->getSubprogram()->getLinkageName());
80 std::hash<uint64_t> Hasher;
81 return Seed ^ (Hasher(Val) + 0x9e3779b9 + (
Seed << 6) + (
Seed >> 2));
84 for (DIL = DIL->getInlinedAt(); DIL; DIL = DIL->getInlinedAt()) {
86 Ret = hashCombine(Ret,
xxh3_64bits(DIL->getSubprogramLinkageName()));
106 bool Changed =
false;
107 using LocationDiscriminator =
108 std::tuple<StringRef, unsigned, unsigned, uint64_t>;
111 using LocationDiscriminatorCurrPassMap =
114 LocationDiscriminatorBBMap LDBM;
115 LocationDiscriminatorCurrPassMap LDCM;
119 unsigned LowBitTemp = LowBit;
120 assert(LowBit > 0 &&
"LowBit in FSDiscriminator cannot be 0");
123 unsigned BitMaskBefore =
getN1Bits(LowBitTemp);
125 unsigned BitMaskNow =
getN1Bits(HighBit);
127 unsigned BitMaskThisPass = BitMaskNow ^ BitMaskBefore;
128 unsigned NumNewD = 0;
136 if (HasPseudoProbe) {
140 if (!
I.isPseudoProbe())
151 I.isPseudoProbe() ?
I.getOperand(1).getImm() : DIL->getLine();
157 if ((
Pass == FSDiscriminatorPass::Pass1) &&
I.isPseudoProbe()) {
167 auto &BBMap = LDBM[
LD];
168 auto R = BBMap.insert(&BB);
169 if (BBMap.size() == 1)
172 unsigned DiscriminatorCurrPass;
173 DiscriminatorCurrPass =
R.second ? ++LDCM[
LD] : LDCM[
LD];
174 DiscriminatorCurrPass = DiscriminatorCurrPass << LowBit;
177 DiscriminatorCurrPass &= BitMaskThisPass;
182 << DIL->getFilename() <<
":" << DIL->getLine() <<
":"
183 << DIL->getColumn() <<
":" << Discriminator <<
" "
188 I.setDebugLoc(NewDIL);
190 LLVM_DEBUG(
dbgs() << DIL->getFilename() <<
":" << DIL->getLine() <<
":"
191 << DIL->getColumn() <<
": add FS discriminator, from "
192 << Discriminator <<
" -> " << NewD <<
"\n");
199 LLVM_DEBUG(
dbgs() <<
"Num of FS Discriminators: " << NumNewD <<
"\n");
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
static uint64_t getCallStackHashV0(const MachineBasicBlock &BB, const MachineInstr &MI, const DILocation *DIL)
static uint64_t getCallStackHash(const DILocation *DIL)
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static ManagedStatic< cl::opt< uint64_t >, CreateSeed > Seed
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file provides the utility functions for the sampled PGO loader base implementation.
ArrayRef - 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.
Implements a dense probed hash-table based set.
FunctionPass class - This class is used to implement most global optimizations.
bool shouldEmitDebugInfoForProfiling() const
Returns true if we should emit debug info for profiling.
Module * getParent()
Get the module that this global value is contained inside of...
StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
Function & getFunction()
Return the LLVM function that this machine code represents.
Representation of each machine instruction.
NamedMDNode * getNamedMetadata(StringRef Name) const
Return the first NamedMDNode in the module with the specified name.
Pass interface - Implemented by all 'passes'.
StringRef - Represent a constant reference to a string, i.e.
StringRef getName() const
Return a constant reference to the value's name.
initializer< Ty > init(const Ty &Val)
uint64_t MD5Hash(const FunctionId &Obj)
void createFSDiscriminatorVariable(Module *M)
Create a global variable to flag FSDiscriminators are used.
This is an optimization pass for GlobalISel generic memory operations.
uint64_t xxh3_64bits(ArrayRef< uint8_t > data)
cl::opt< bool > EnableFSDiscriminator
FunctionPass * createMIRAddFSDiscriminatorsPass(sampleprof::FSDiscriminatorPass P)
Add Flow Sensitive Discriminators.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
cl::opt< bool > ImprovedFSDiscriminator("improved-fs-discriminator", cl::Hidden, cl::init(false), cl::desc("New FS discriminators encoding (incompatible with the original " "encoding)"))
static unsigned getN1Bits(int N)
constexpr const char * PseudoProbeDescMetadataName
char & MIRAddFSDiscriminatorsID
This pass adds flow sensitive discriminators.