33 #define DEBUG_TYPE "x86-pad-short-functions" 35 STATISTIC(NumBBsPadded,
"Number of basic blocks padded");
38 struct VisitedBBInfo {
46 VisitedBBInfo() : HasReturn(
false), Cycles(0) {}
47 VisitedBBInfo(
bool HasReturn,
unsigned int Cycles)
48 : HasReturn(HasReturn), Cycles(Cycles) {}
70 return "X86 Atom pad short functions";
75 unsigned int Cycles = 0);
78 unsigned int &Cycles);
82 unsigned int NOOPsToAdd);
100 return new PadShortFunc();
118 &getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
119 auto *MBFI = (PSI && PSI->hasProfileSummary()) ?
120 &getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI() :
126 findReturns(&MF.
front());
128 bool MadeChange =
false;
132 I != ReturnBBs.end(); ++
I) {
134 unsigned Cycles =
I->second;
145 "Basic block should contain at least a RET but is empty");
148 while (ReturnLoc->isDebugInstr())
150 assert(ReturnLoc->isReturn() && !ReturnLoc->isCall() &&
151 "Basic block does not end with RET");
166 bool hasReturn = cyclesUntilReturn(MBB, Cycles);
171 ReturnBBs[MBB] =
std::max(ReturnBBs[MBB], Cycles);
180 findReturns(*
I, Cycles);
189 unsigned int &Cycles) {
192 = VisitedBBs.find(MBB);
193 if (it != VisitedBBs.end()) {
194 VisitedBBInfo BBInfo = it->second;
195 Cycles += BBInfo.Cycles;
196 return BBInfo.HasReturn;
199 unsigned int CyclesToEnd = 0;
205 if (
MI.isReturn() && !
MI.isCall()) {
206 VisitedBBs[MBB] = VisitedBBInfo(
true, CyclesToEnd);
207 Cycles += CyclesToEnd;
211 CyclesToEnd += TSM.computeInstrLatency(&
MI);
214 VisitedBBs[MBB] = VisitedBBInfo(
false, CyclesToEnd);
215 Cycles += CyclesToEnd;
223 unsigned int NOOPsToAdd) {
225 unsigned IssueWidth = TSM.getIssueWidth();
227 for (
unsigned i = 0,
e = IssueWidth * NOOPsToAdd; i !=
e; ++i)
228 BuildMI(*MBB, MBBI, DL, TSM.getInstrInfo()->
get(X86::NOOP));
This class represents lattice values for constants.
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
STATISTIC(NumFunctions, "Total number of functions")
AnalysisUsage & addRequired()
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Provide an instruction scheduling machine model to CodeGen passes.
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
bool padShortFunctions() const
FunctionPass * createX86PadShortFunctions()
Return a pass that pads short functions with NOOPs.
===- LazyMachineBlockFrequencyInfo.h - Lazy Block Frequency -*- C++ -*–===//
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
This is an alternative analysis pass to MachineBlockFrequencyInfo.
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
succ_iterator succ_begin()
const MachineBasicBlock & front() const
static bool hasReturn(const MachineBasicBlock &MBB)
Returns true if MBB contains an instruction that returns.
static void addPadding(BinaryStreamWriter &Writer)
Align max(MaybeAlign Lhs, Align Rhs)
const Function & getFunction() const
Return the LLVM function that this machine code represents.
bool shouldOptimizeForSize(const MachineFunction *MF, ProfileSummaryInfo *PSI, const MachineBlockFrequencyInfo *BFI, PGSOQueryType QueryType=PGSOQueryType::Other)
Returns true if machine function MF is suggested to be size-optimized based on the profile...
static cl::opt< unsigned > Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"), cl::init(100), cl::Hidden)
MachineFunctionProperties & set(Property P)
Representation of each machine instruction.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
std::vector< MachineBasicBlock * >::iterator succ_iterator
Properties which a MachineFunction may have at a given point in time.