Go to the documentation of this file.
33 #define DEBUG_TYPE "x86-pad-short-functions"
35 STATISTIC(NumBBsPadded,
"Number of basic blocks padded");
38 struct VisitedBBInfo {
40 bool HasReturn =
false;
44 unsigned int Cycles = 0;
46 VisitedBBInfo() =
default;
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);
84 const unsigned int Threshold = 4;
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;
131 for (
const auto &ReturnBB : ReturnBBs) {
133 unsigned Cycles = ReturnBB.second;
140 if (Cycles < Threshold) {
144 "Basic block should contain at least a RET but is empty");
147 while (ReturnLoc->isDebugInstr())
149 assert(ReturnLoc->isReturn() && !ReturnLoc->isCall() &&
150 "Basic block does not end with RET");
166 if (Cycles >= Threshold)
177 findReturns(Succ, Cycles);
185 unsigned int &Cycles) {
188 = VisitedBBs.find(
MBB);
189 if (
it != VisitedBBs.end()) {
190 VisitedBBInfo BBInfo =
it->second;
191 Cycles += BBInfo.Cycles;
192 return BBInfo.HasReturn;
195 unsigned int CyclesToEnd = 0;
201 if (
MI.isReturn() && !
MI.isCall()) {
202 VisitedBBs[
MBB] = VisitedBBInfo(
true, CyclesToEnd);
203 Cycles += CyclesToEnd;
207 CyclesToEnd += TSM.computeInstrLatency(&
MI);
210 VisitedBBs[
MBB] = VisitedBBInfo(
false, CyclesToEnd);
211 Cycles += CyclesToEnd;
219 unsigned int NOOPsToAdd) {
221 unsigned IssueWidth = TSM.getIssueWidth();
223 for (
unsigned i = 0,
e = IssueWidth * NOOPsToAdd;
i !=
e; ++
i)
FunctionPass * createX86PadShortFunctions()
Return a pass that pads short functions with NOOPs.
This is an optimization pass for GlobalISel generic memory operations.
into xmm2 addss xmm2 xmm1 xmm3 addss xmm3 movaps xmm0 unpcklps xmm0 ret seems silly when it could just be one addps Expand libm rounding functions main should enable SSE DAZ mode and other fast SSE modes Think about doing i64 math in SSE regs on x86 This testcase should have no SSE instructions in it
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Properties which a MachineFunction may have at a given point in time.
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const MachineBasicBlock & front() const
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.
Represent the analysis usage information of a pass.
MachineFunctionProperties & set(Property P)
STATISTIC(NumFunctions, "Total number of functions")
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
===- LazyMachineBlockFrequencyInfo.h - Lazy Block Frequency -*- C++ -*–===//
static void addPadding(BinaryStreamWriter &Writer)
Provide an instruction scheduling machine model to CodeGen passes.
Representation of each machine instruction.
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This is an alternative analysis pass to MachineBlockFrequencyInfo.
iterator_range< succ_iterator > successors()
StringRef - Represent a constant reference to a string, i.e.
MachineBasicBlock MachineBasicBlock::iterator MBBI
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
static bool hasReturn(const MachineBasicBlock &MBB)
Returns true if MBB contains an instruction that returns.
Function & getFunction()
Return the LLVM function that this machine code represents.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
FunctionPass class - This class is used to implement most global optimizations.
AnalysisUsage & addRequired()