28 #define DEBUG_TYPE "x86-discriminate-memops" 32 cl::desc(
"Generate unique debug info for each instruction with a memory " 33 "operand. Should be enabled for profile-drived cache prefetching, " 34 "both in the build of the binary being profiled, as well as in " 35 "the build of the binary consuming the profile."),
40 using Location = std::pair<StringRef, unsigned>;
43 return std::make_pair(Loc->getFilename(), Loc->getLine());
56 return "X86 Discriminate Memory Operands";
63 X86DiscriminateMemOps();
82 if (!FDI || !FDI->getUnit()->getDebugInfoForProfiling())
88 DILocation::get(FDI->
getContext(), FDI->getLine(), 0, FDI);
91 MemOpDiscriminators[diToLocation(ReferenceDI)] = 0;
97 for (
auto &MBB : MF) {
98 for (
auto &
MI : MBB) {
99 const auto &DI =
MI.getDebugLoc();
102 Location Loc = diToLocation(DI);
103 MemOpDiscriminators[Loc] =
104 std::max(MemOpDiscriminators[Loc], DI->getBaseDiscriminator());
113 bool Changed =
false;
114 for (
auto &MBB : MF) {
115 for (
auto &
MI : MBB) {
122 Location L = diToLocation(DI);
124 const std::pair<DenseSet<unsigned>::iterator,
bool> TryInsert =
126 if (!TryInsert.second) {
127 unsigned BF, DF, CI = 0;
128 DILocation::decodeDiscriminator(DI->getDiscriminator(), BF, DF, CI);
130 MemOpDiscriminators[L] + 1, DF, CI);
132 if (!EncodedDiscriminator) {
138 "for instruction with memory operand in: " 139 << DI->getFilename() <<
" Line: " << DI->getLine()
140 <<
" Column: " << DI->getColumn()
141 <<
". This is likely due to a large macro expansion. \n");
145 ++MemOpDiscriminators[L];
147 updateDebugInfo(&
MI, DI);
149 std::pair<DenseSet<unsigned>::iterator,
bool> MustInsert =
152 assert(MustInsert.second &&
"New discriminator shouldn't be present in set");
166 return new X86DiscriminateMemOps();
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
This class represents lattice values for constants.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
LLVMContext & getContext() const
initializer< Ty > init(const Ty &Val)
DISubprogram * getSubprogram() const
Get the attached subprogram.
std::pair< iterator, bool > insert(const ValueT &V)
FunctionPass class - This class is used to implement most global optimizations.
static cl::opt< bool > EnableDiscriminateMemops(DEBUG_TYPE, cl::init(false), cl::desc("Generate unique debug info for each instruction with a memory " "operand. Should be enabled for profile-drived cache prefetching, " "both in the build of the binary being profiled, as well as in " "the build of the binary consuming the profile."), cl::Hidden)
const Function & getFunction() const
Return the LLVM function that this machine code represents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void setDebugLoc(DebugLoc dl)
Replace current source information with new such.
Representation of each machine instruction.
unsigned getBaseDiscriminator() const
Returns the base discriminator stored in the discriminator.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const DILocation * cloneWithDiscriminator(unsigned Discriminator) const
Returns a new DILocation with updated Discriminator.
StringRef - Represent a constant reference to a string, i.e.
FunctionPass * createX86DiscriminateMemOpsPass()
This pass ensures instructions featuring a memory operand have distinctive <LineNumber, Discriminator> (with respect to eachother)
This file provides the interface for the sampled PGO loader pass.
int getMemoryOperandNo(uint64_t TSFlags)
getMemoryOperandNo - The function returns the MCInst operand # for the first field of the memory oper...