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) {
122 for (
auto &BB : MF) {
123 auto It = PrefetchHintsBySiteBBID.
find(*BB.getBBID());
124 if (It == PrefetchHintsBySiteBBID.
end())
126 const auto &BBHints = It->second;
127 unsigned NumCallsInBB = 0;
128 auto InstrIt = BB.begin();
129 for (
auto HintIt = BBHints.begin(); HintIt != BBHints.end();) {
130 auto NextInstrIt = InstrIt == BB.end() ? BB.end() : std::next(InstrIt);
133 while (HintIt != BBHints.end() &&
134 HintIt->SiteID.CallsiteIndex == NumCallsInBB) {
135 bool TargetFunctionDefined =
false;
137 TargetFunctionDefined = !TargetFunction->isDeclaration();
140 HintIt->TargetFunction, HintIt->TargetID.BBID,
141 HintIt->TargetID.CallsiteIndex);
143 TargetSymbolName, PtrTy);
145 TII->insertCodePrefetchInstr(BB, InstrIt, GV);
146 if (!TargetFunctionDefined && IsELF) {
157 MF.
getContext().getOrCreateSymbol(TargetSymbolName));
161 PrefetchInserted =
true;
164 if (InstrIt == BB.end())
166 if (InstrIt->isCall())
168 InstrIt = NextInstrIt;
171 return PrefetchInserted;
176 "BB Sections list not enabled!");
180 auto &ProfileReader =
181 getAnalysis<BasicBlockSectionsProfileReaderWrapperPass>();
183 MF, ProfileReader.getPrefetchTargetsForFunction(MF.
getName()));
185 MF, ProfileReader.getPrefetchHintsForFunction(MF.
getName()));
189void InsertCodePrefetch::getAnalysisUsage(AnalysisUsage &AU)
const {
191 AU.
addRequired<BasicBlockSectionsProfileReaderWrapperPass>();
196 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.
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...