Go to the documentation of this file.
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-driven 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."),
39 "x86-bypass-prefetch-instructions",
cl::init(
true),
40 cl::desc(
"When discriminating instructions with memory operands, ignore "
41 "prefetch instructions. This ensures the other memory operand "
42 "instructions have the same identifiers after inserting "
43 "prefetches, allowing for successive insertions."),
48 using Location = std::pair<StringRef, unsigned>;
51 return std::make_pair(Loc->getFilename(), Loc->getLine());
64 return "X86 Discriminate Memory Operands";
71 X86DiscriminateMemOps();
74 bool IsPrefetchOpcode(
unsigned Opcode) {
75 return Opcode == X86::PREFETCHNTA || Opcode == X86::PREFETCHT0 ||
76 Opcode == X86::PREFETCHT1 || Opcode == X86::PREFETCHT2;
94 if (!FDI || !FDI->getUnit()->getDebugInfoForProfiling())
101 assert(ReferenceDI &&
"ReferenceDI should not be nullptr");
103 MemOpDiscriminators[diToLocation(ReferenceDI)] = 0;
109 for (
auto &
MBB : MF) {
110 for (
auto &
MI :
MBB) {
111 const auto &DI =
MI.getDebugLoc();
117 MemOpDiscriminators[Loc] =
118 std::max(MemOpDiscriminators[Loc], DI->getBaseDiscriminator());
127 bool Changed =
false;
128 for (
auto &
MBB : MF) {
129 for (
auto &
MI :
MBB) {
141 const std::pair<DenseSet<unsigned>::iterator,
bool> TryInsert =
143 if (!TryInsert.second || !HasDebug) {
144 unsigned BF,
DF, CI = 0;
145 DILocation::decodeDiscriminator(DI->getDiscriminator(), BF,
DF, CI);
147 MemOpDiscriminators[L] + 1,
DF, CI);
149 if (!EncodedDiscriminator) {
155 "for instruction with memory operand in: "
156 << DI->getFilename() <<
" Line: " << DI->getLine()
157 <<
" Column: " << DI->getColumn()
158 <<
". This is likely due to a large macro expansion. \n");
162 ++MemOpDiscriminators[L];
164 assert(DI &&
"DI should not be nullptr");
165 updateDebugInfo(&
MI, DI);
167 std::pair<DenseSet<unsigned>::iterator,
bool> MustInsert =
170 assert(MustInsert.second &&
"New discriminator shouldn't be present in set");
184 return new X86DiscriminateMemOps();
This is an optimization pass for GlobalISel generic memory operations.
int getMemoryOperandNo(uint64_t TSFlags)
The function returns the MCInst operand # for the first field of the memory operand.
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-driven 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)
DISubprogram * getSubprogram() const
Get the attached subprogram.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const DILocation * cloneWithDiscriminator(unsigned Discriminator) const
Returns a new DILocation with updated Discriminator.
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
std::pair< iterator, bool > insert(const ValueT &V)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
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)
FunctionPass * createX86DiscriminateMemOpsPass()
This pass ensures instructions featuring a memory operand have distinctive <LineNumber,...
Representation of each machine instruction.
initializer< Ty > init(const Ty &Val)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
LLVMContext & getContext() const
Function & getFunction()
Return the LLVM function that this machine code represents.
Should compile to something r4 addze r3 instead we get
unsigned getBaseDiscriminator() const
Returns the base discriminator stored in the discriminator.
FunctionPass class - This class is used to implement most global optimizations.