31 #define DEBUG_TYPE "x86-pad-short-functions" 33 STATISTIC(NumBBsPadded,
"Number of basic blocks padded");
36 struct VisitedBBInfo {
44 VisitedBBInfo() : HasReturn(
false), Cycles(0) {}
45 VisitedBBInfo(
bool HasReturn,
unsigned int Cycles)
46 : HasReturn(HasReturn), Cycles(Cycles) {}
62 return "X86 Atom pad short functions";
67 unsigned int Cycles = 0);
70 unsigned int &Cycles);
74 unsigned int NOOPsToAdd);
92 return new PadShortFunc();
112 findReturns(&MF.
front());
114 bool MadeChange =
false;
117 unsigned int Cycles = 0;
121 I != ReturnBBs.end(); ++
I) {
129 "Basic block should contain at least a RET but is empty");
132 while (ReturnLoc->isDebugInstr())
134 assert(ReturnLoc->isReturn() && !ReturnLoc->isCall() &&
135 "Basic block does not end with RET");
150 bool hasReturn = cyclesUntilReturn(MBB, Cycles);
155 ReturnBBs[MBB] =
std::max(ReturnBBs[MBB], Cycles);
164 findReturns(*
I, Cycles);
173 unsigned int &Cycles) {
176 = VisitedBBs.find(MBB);
177 if (it != VisitedBBs.end()) {
178 VisitedBBInfo BBInfo = it->second;
179 Cycles += BBInfo.Cycles;
180 return BBInfo.HasReturn;
183 unsigned int CyclesToEnd = 0;
189 if (
MI.isReturn() && !
MI.isCall()) {
190 VisitedBBs[MBB] = VisitedBBInfo(
true, CyclesToEnd);
191 Cycles += CyclesToEnd;
195 CyclesToEnd += TSM.computeInstrLatency(&
MI);
198 VisitedBBs[MBB] = VisitedBBInfo(
false, CyclesToEnd);
199 Cycles += CyclesToEnd;
207 unsigned int NOOPsToAdd) {
209 unsigned IssueWidth = TSM.getIssueWidth();
211 for (
unsigned i = 0, e = IssueWidth * NOOPsToAdd; i != e; ++i)
212 BuildMI(*MBB, MBBI, DL, TSM.getInstrInfo()->
get(X86::NOOP));
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
This class represents lattice values for constants.
STATISTIC(NumFunctions, "Total number of functions")
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Provide an instruction scheduling machine model to CodeGen passes.
bool padShortFunctions() const
FunctionPass * createX86PadShortFunctions()
Return a pass that pads short functions with NOOPs.
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.
bool optForSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
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)
const Function & getFunction() const
Return the LLVM function that this machine code represents.
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.