31using namespace sampleprof;
32using namespace sampleprofutil;
34#define DEBUG_TYPE "mirfs-discriminators"
40 cl::desc(
"New FS discriminators encoding (incompatible with the original "
46 "Add MIR Flow Sensitive Discriminators",
66 uint64_t Ret = updateHash(std::to_string(DIL->getLine()));
67 Ret ^= updateHash(BB.
getName());
68 Ret ^= updateHash(DIL->getScope()->getSubprogram()->getLinkageName());
69 for (DIL = DIL->getInlinedAt(); DIL; DIL = DIL->getInlinedAt()) {
70 Ret ^= updateHash(std::to_string(DIL->getLine()));
71 Ret ^= updateHash(DIL->getScope()->getSubprogram()->getLinkageName());
78 std::hash<uint64_t> Hasher;
79 return Seed ^ (Hasher(Val) + 0x9e3779b9 + (
Seed << 6) + (
Seed >> 2));
82 for (DIL = DIL->getInlinedAt(); DIL; DIL = DIL->getInlinedAt()) {
84 Ret = hashCombine(Ret,
xxHash64(DIL->getSubprogramLinkageName()));
104 bool Changed =
false;
105 using LocationDiscriminator =
106 std::tuple<StringRef, unsigned, unsigned, uint64_t>;
109 using LocationDiscriminatorCurrPassMap =
112 LocationDiscriminatorBBMap LDBM;
113 LocationDiscriminatorCurrPassMap LDCM;
117 unsigned LowBitTemp = LowBit;
118 assert(LowBit > 0 &&
"LowBit in FSDiscriminator cannot be 0");
121 unsigned BitMaskBefore =
getN1Bits(LowBitTemp);
123 unsigned BitMaskNow =
getN1Bits(HighBit);
125 unsigned BitMaskThisPass = BitMaskNow ^ BitMaskBefore;
126 unsigned NumNewD = 0;
134 if (HasPseudoProbe) {
138 if (!
I.isPseudoProbe())
149 I.isPseudoProbe() ?
I.getOperand(1).getImm() : DIL->getLine();
155 if ((
Pass == FSDiscriminatorPass::Pass1) &&
I.isPseudoProbe()) {
165 auto &BBMap = LDBM[
LD];
166 auto R = BBMap.insert(&BB);
167 if (BBMap.size() == 1)
170 unsigned DiscriminatorCurrPass;
171 DiscriminatorCurrPass =
R.second ? ++LDCM[
LD] : LDCM[
LD];
172 DiscriminatorCurrPass = DiscriminatorCurrPass << LowBit;
175 DiscriminatorCurrPass &= BitMaskThisPass;
180 << DIL->getFilename() <<
":" << DIL->getLine() <<
":"
181 << DIL->getColumn() <<
":" << Discriminator <<
" "
186 I.setDebugLoc(NewDIL);
188 LLVM_DEBUG(
dbgs() << DIL->getFilename() <<
":" << DIL->getLine() <<
":"
189 << DIL->getColumn() <<
": add FS discriminator, from "
190 << Discriminator <<
" -> " << NewD <<
"\n");
197 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)
cl::opt< bool > ImprovedFSDiscriminator("improved-fs-discriminator", cl::Hidden, cl::init(false), cl::desc("New FS discriminators encoding (incompatible with the original " "encoding)"))
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(const Twine &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)
void createFSDiscriminatorVariable(Module *M)
Create a global variable to flag FSDiscriminators are used.
This is an optimization pass for GlobalISel generic memory operations.
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.
static unsigned getN1Bits(int N)
uint64_t MD5Hash(StringRef Str)
Helper to compute and return lower 64 bits of the given string's MD5 hash.
uint64_t xxHash64(llvm::StringRef Data)
constexpr const char * PseudoProbeDescMetadataName
char & MIRAddFSDiscriminatorsID
This pass adds flow sensitive discriminators.