27 #define DEBUG_TYPE "x86-discriminate-memops" 31 cl::desc(
"Generate unique debug info for each instruction with a memory " 32 "operand. Should be enabled for profile-drived cache prefetching, " 33 "both in the build of the binary being profiled, as well as in " 34 "the build of the binary consuming the profile."),
38 "x86-bypass-prefetch-instructions",
cl::init(
true),
39 cl::desc(
"When discriminating instructions with memory operands, ignore " 40 "prefetch instructions. This ensures the other memory operand " 41 "instructions have the same identifiers after inserting " 42 "prefetches, allowing for successive insertions."),
47 using Location = std::pair<StringRef, unsigned>;
50 return std::make_pair(Loc->getFilename(), Loc->getLine());
63 return "X86 Discriminate Memory Operands";
70 X86DiscriminateMemOps();
73 bool IsPrefetchOpcode(
unsigned Opcode) {
74 return Opcode == X86::PREFETCHNTA || Opcode == X86::PREFETCHT0 ||
75 Opcode == X86::PREFETCHT1 || Opcode == X86::PREFETCHT2;
93 if (!FDI || !FDI->getUnit()->getDebugInfoForProfiling())
99 DILocation::get(FDI->
getContext(), FDI->getLine(), 0, FDI);
100 assert(ReferenceDI &&
"ReferenceDI should not be nullptr");
102 MemOpDiscriminators[diToLocation(ReferenceDI)] = 0;
108 for (
auto &MBB : MF) {
109 for (
auto &
MI : MBB) {
110 const auto &DI =
MI.getDebugLoc();
115 Location Loc = diToLocation(DI);
116 MemOpDiscriminators[Loc] =
117 std::max(MemOpDiscriminators[Loc], DI->getBaseDiscriminator());
126 bool Changed =
false;
127 for (
auto &MBB : MF) {
128 for (
auto &
MI : MBB) {
138 Location L = diToLocation(DI);
140 const std::pair<DenseSet<unsigned>::iterator,
bool> TryInsert =
142 if (!TryInsert.second || !HasDebug) {
143 unsigned BF,
DF, CI = 0;
144 DILocation::decodeDiscriminator(DI->getDiscriminator(), BF,
DF, CI);
146 MemOpDiscriminators[L] + 1, DF, CI);
148 if (!EncodedDiscriminator) {
154 "for instruction with memory operand in: " 155 << DI->getFilename() <<
" Line: " << DI->getLine()
156 <<
" Column: " << DI->getColumn()
157 <<
". This is likely due to a large macro expansion. \n");
161 ++MemOpDiscriminators[L];
163 assert(DI &&
"DI should not be nullptr");
164 updateDebugInfo(&
MI, DI);
166 std::pair<DenseSet<unsigned>::iterator,
bool> MustInsert =
169 assert(MustInsert.second &&
"New discriminator shouldn't be present in set");
183 return new X86DiscriminateMemOps();
This class represents lattice values for constants.
static cl::opt< bool > BypassPrefetchInstructions("x86-bypass-prefetch-instructions", cl::init(true), cl::desc("When discriminating instructions with memory operands, ignore " "prefetch instructions. This ensures the other memory operand " "instructions have the same identifiers after inserting " "prefetches, allowing for successive insertions."), cl::Hidden)
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 RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
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)
Align max(MaybeAlign Lhs, Align Rhs)
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)
The function returns the MCInst operand # for the first field of the memory operand.