41#define DEBUG_TYPE "insert-code-prefetch"
62 StringRef getPassName()
const override {
63 return "Code Prefetch Inserter Pass";
66 void getAnalysisUsage(AnalysisUsage &AU)
const override;
69 bool runOnMachineFunction(MachineFunction &MF)
override;
78char InsertCodePrefetch::ID = 0;
87 if (PrefetchTargets.empty())
92 for (
const auto &
Target : PrefetchTargets)
93 PrefetchTargetsByBBID[
Target.BBID].push_back(
Target.CallsiteIndex);
95 for (
auto &[K, V] : PrefetchTargetsByBBID) {
99 MF.setPrefetchTargets(PrefetchTargetsByBBID);
106 bool PrefetchInserted =
false;
110 for (
const auto &
H : PrefetchHints)
111 PrefetchHintsBySiteBBID[
H.SiteID.BBID].push_back(
H);
114 for (
auto &[SiteBBID, Hints] : PrefetchHintsBySiteBBID) {
123 for (
auto &BB : MF) {
124 auto It = PrefetchHintsBySiteBBID.
find(*BB.getBBID());
125 if (It == PrefetchHintsBySiteBBID.
end())
127 const auto &BBHints = It->second;
128 unsigned NumCallsInBB = 0;
129 auto InstrIt = BB.begin();
130 for (
auto HintIt = BBHints.begin(); HintIt != BBHints.end();) {
131 auto NextInstrIt = InstrIt == BB.end() ? BB.end() : std::next(InstrIt);
134 while (HintIt != BBHints.end() &&
135 HintIt->SiteID.CallsiteIndex == NumCallsInBB) {
136 bool TargetFunctionDefined =
false;
138 TargetFunctionDefined = !TargetFunction->isDeclaration();
141 HintIt->TargetFunction, HintIt->TargetID.BBID,
142 HintIt->TargetID.CallsiteIndex);
144 TargetSymbolName, PtrTy);
146 TII->insertCodePrefetchInstr(BB, InstrIt, GV);
147 if (!TargetFunctionDefined && IsELF) {
158 MF.
getContext().getOrCreateSymbol(TargetSymbolName));
162 PrefetchInserted =
true;
165 if (InstrIt == BB.end())
167 if (InstrIt->isCall())
169 InstrIt = NextInstrIt;
172 return PrefetchInserted;
177 "BB Sections list not enabled!");
181 auto &ProfileReader =
182 getAnalysis<BasicBlockSectionsProfileReaderWrapperPass>();
184 MF, ProfileReader.getPrefetchTargetsForFunction(MF.
getName()));
186 MF, ProfileReader.getPrefetchHintsForFunction(MF.
getName()));
190void InsertCodePrefetch::getAnalysisUsage(AnalysisUsage &AU)
const {
192 AU.
addRequired<BasicBlockSectionsProfileReaderWrapperPass>();
197 return new InsertCodePrefetch();
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the DenseMap class.
const HexagonInstrInfo * TII
static bool insertPrefetchHints(MachineFunction &MF, const SmallVector< PrefetchHint > &PrefetchHints)
Code prefetch static false bool setPrefetchTargets(MachineFunction &MF, const SmallVector< CallsiteID > &PrefetchTargets)
This file contains common utilities for code prefetch insertion.
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file defines the SmallVector class.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
iterator find(const_arg_type_t< KeyT > Val)
const Function & getFunction() const
Module * getParent()
Get the module that this global value is contained inside of...
void setBinding(unsigned Binding) const
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MCContext & getContext() const
Function & getFunction()
Return the LLVM function that this machine code represents.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Representation of each machine instruction.
LLVM_ABI void setPostInstrSymbol(MachineFunction &MF, MCSymbol *Symbol)
Set a symbol that will be emitted just after the instruction itself.
A Module instance is used to store all the information related to an LLVM module.
LLVMContext & getContext() const
Get the global data context.
GlobalVariable * getOrInsertGlobal(StringRef Name, Type *Ty, function_ref< GlobalVariable *()> CreateGlobalCallback)
Look up the specified global in the module symbol table.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
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.
const Triple & getTargetTriple() const
llvm::BasicBlockSection getBBSectionsType() const
If basic blocks should be emitted into their own section, corresponding to -fbasic-block-sections.
virtual const TargetInstrInfo * getInstrInfo() const
Target - Wrapper for Target specific information.
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
void stable_sort(R &&Range)
std::string utostr(uint64_t X, bool isNeg=false)
auto unique(Range &&R, Predicate P)
void sort(IteratorTy Start, IteratorTy End)
SmallString< 128 > getPrefetchTargetSymbolName(StringRef FunctionName, const UniqueBBID &BBID, unsigned CallsiteIndex)
bool hasInstrProfHashMismatch(MachineFunction &MF)
This checks if the source of this function has drifted since this binary was profiled previously.
LLVM_ABI MachineFunctionPass * createInsertCodePrefetchPass()
createInsertCodePrefetchPass - This pass enables inserting code prefetch hints based on the basic blo...