35using namespace sampleprof;
39 cl::desc(
"Path to the prefetch hints profile. See also "
40 "-x86-discriminate-memops"),
50 unsigned InstructionID;
55 Prefetches &prefetches)
const;
59 X86InsertPrefetch(
const std::string &PrefetchHintsFilename);
61 return "X86 Insert Cache Prefetches";
66 std::unique_ptr<SampleProfileReader> Reader;
75 if (
const auto &Loc =
MI.getDebugLoc())
78 Loc->getBaseDiscriminator());
79 return std::error_code();
87 return (BaseReg == 0 ||
88 X86MCRegisterClasses[X86::GR64RegClassID].
contains(BaseReg) ||
89 X86MCRegisterClasses[X86::GR32RegClassID].
contains(BaseReg)) &&
91 X86MCRegisterClasses[X86::GR64RegClassID].contains(IndexReg) ||
92 X86MCRegisterClasses[X86::GR32RegClassID].contains(IndexReg));
101char X86InsertPrefetch::ID = 0;
103X86InsertPrefetch::X86InsertPrefetch(
const std::string &PrefetchHintsFilename)
109bool X86InsertPrefetch::findPrefetchInfo(
const FunctionSamples *TopSamples,
111 Prefetches &Prefetches)
const {
112 assert(Prefetches.empty() &&
113 "Expected caller passed empty PrefetchInfo vector.");
119 static constexpr std::pair<StringLiteral, unsigned> HintTypes[] = {
120 {
"_nta_", X86::PREFETCHNTA},
121 {
"_t0_", X86::PREFETCHT0},
122 {
"_t1_", X86::PREFETCHT1},
123 {
"_t2_", X86::PREFETCHT2},
125 static const char *SerializedPrefetchPrefix =
"__prefetch";
127 auto T = getPrefetchHints(TopSamples,
MI);
130 int16_t max_index = -1;
133 for (
const auto &S_V : *
T) {
135 if (
Name.consume_front(SerializedPrefetchPrefix)) {
136 int64_t
D =
static_cast<int64_t
>(S_V.second);
138 for (
const auto &HintType : HintTypes) {
139 if (
Name.consume_front(HintType.first)) {
140 IID = HintType.second;
147 Name.consumeInteger(10, index);
149 if (index >= Prefetches.size())
150 Prefetches.resize(index + 1);
151 Prefetches[index] = {IID,
D};
152 max_index = std::max(max_index,
static_cast<int16_t
>(index));
155 assert(max_index + 1 >= 0 &&
156 "Possible overflow: max_index + 1 should be positive.");
157 assert(
static_cast<size_t>(max_index + 1) == Prefetches.size() &&
158 "The number of prefetch hints received should match the number of "
159 "PrefetchInfo objects returned");
160 return !Prefetches.empty();
163bool X86InsertPrefetch::doInitialization(
Module &M) {
172 if (std::error_code EC = ReaderOrErr.
getError()) {
173 std::string Msg =
"Could not open profile: " +
EC.message();
175 DiagnosticSeverity::DS_Warning));
178 Reader = std::move(ReaderOrErr.
get());
183void X86InsertPrefetch::getAnalysisUsage(
AnalysisUsage &AU)
const {
195 bool Changed =
false;
199 for (
auto &
MBB : MF) {
208 int MemOpOffset =
Offset + Bias;
210 if (!IsMemOpCompatibleWithPrefetch(*Current, MemOpOffset))
213 if (!findPrefetchInfo(Samples, *Current, Prefetches))
216 "The Prefetches vector should contain at least a value if "
217 "findPrefetchInfo returned true.");
218 for (
auto &PrefInfo : Prefetches) {
219 unsigned PFetchInstrID = PrefInfo.InstructionID;
220 int64_t Delta = PrefInfo.Delta;
223 MF.CreateMachineInstr(
Desc, Current->getDebugLoc(),
true);
229 "Unexpected change in X86 operand offset order.");
239 .addImm(Current->getOperand(MemOpOffset +
X86::AddrDisp).getImm() +
244 if (!Current->memoperands_empty()) {
246 MIB.addMemOperand(MF.getMachineMemOperand(
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
const HexagonInstrInfo * TII
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file provides the interface for the sampled PGO loader pass.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Defines the virtual file system interface vfs::FileSystem.
static cl::opt< std::string > PrefetchHintsFile("prefetch-hints-file", cl::desc("Path to the prefetch hints profile. See also " "-x86-discriminate-memops"), cl::Hidden)
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
This class represents an Operation in the Expression.
Diagnostic information for the sample profiler.
Represents either an error or a value T.
std::error_code getError() const
FunctionPass class - This class is used to implement most global optimizations.
This is an important class for using LLVM in a threaded context.
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
Describe properties that are true of each instruction in the target description file.
instr_iterator instr_begin()
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
instr_iterator instr_end()
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
bool doInitialization(Module &) override
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
Representation of each machine instruction.
A description of a memory reference used in the backend.
LocationSize getSize() const
Return the size in bytes of the memory reference.
int64_t getOffset() const
For normal values, this is a byte offset added to the base address.
A Module instance is used to store all the information related to an LLVM module.
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Wrapper class representing virtual and physical registers.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
TargetInstrInfo - Interface to description of machine instruction set.
virtual const TargetInstrInfo * getInstrInfo() const
Representation of the samples collected for a function.
const FunctionSamples * findFunctionSamples(const DILocation *DIL, SampleProfileReaderItaniumRemapper *Remapper=nullptr, const HashKeyMap< std::unordered_map, FunctionId, FunctionId > *FuncNameToProfNameMap=nullptr) const
Get the FunctionSamples of the inline instance where DIL originates from.
static unsigned getOffset(const DILocation *DIL)
Returns the line offset to the start line of the subprogram.
static bool UseMD5
Whether the profile uses MD5 to represent string.
static ErrorOr< std::unique_ptr< SampleProfileReader > > create(StringRef Filename, LLVMContext &C, vfs::FileSystem &FS, FSDiscriminatorPass P=FSDiscriminatorPass::Base, StringRef RemapFilename="")
Create a sample profile reader appropriate to the file format.
std::unordered_map< FunctionId, uint64_t > CallTargetMap
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
int getMemoryOperandNo(uint64_t TSFlags)
unsigned getOperandBias(const MCInstrDesc &Desc)
Compute whether all of the def operands are repeated in the uses and therefore should be skipped.
IntrusiveRefCntPtr< FileSystem > getRealFileSystem()
Gets an vfs::FileSystem for the 'real' file system, as seen by the operating system.
This is an optimization pass for GlobalISel generic memory operations.
FunctionPass * createX86InsertPrefetchPass()
This pass applies profiling information to insert cache prefetches.
Description of the encoding of one expression Op.