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) {}
58 const char *getPassName()
const override {
59 return "X86 Atom pad short functions";
64 unsigned int Cycles = 0);
67 unsigned int &Cycles);
71 unsigned int NOOPsToAdd);
90 return new PadShortFunc();
102 if (!STI->padShortFunctions())
105 TII = STI->getInstrInfo();
110 findReturns(MF.
begin());
112 bool MadeChange =
false;
115 unsigned int Cycles = 0;
119 I != ReturnBBs.end(); ++
I) {
126 assert(MBB->
size() > 0 &&
127 "Basic block should contain at least a RET but is empty");
130 while (ReturnLoc->isDebugValue())
132 assert(ReturnLoc->isReturn() && !ReturnLoc->isCall() &&
133 "Basic block does not end with RET");
135 addPadding(MBB, ReturnLoc,
Threshold - Cycles);
148 bool hasReturn = cyclesUntilReturn(MBB, Cycles);
153 ReturnBBs[MBB] = std::max(ReturnBBs[MBB], Cycles);
162 findReturns(*
I, Cycles);
171 unsigned int &Cycles) {
174 = VisitedBBs.
find(MBB);
175 if (it != VisitedBBs.
end()) {
176 VisitedBBInfo BBInfo = it->second;
177 Cycles += BBInfo.Cycles;
178 return BBInfo.HasReturn;
181 unsigned int CyclesToEnd = 0;
184 MBBI != MBB->
end(); ++MBBI) {
190 VisitedBBs[MBB] = VisitedBBInfo(
true, CyclesToEnd);
191 Cycles += CyclesToEnd;
195 CyclesToEnd +=
TII->getInstrLatency(STI->getInstrItineraryData(),
MI);
198 VisitedBBs[MBB] = VisitedBBInfo(
false, CyclesToEnd);
199 Cycles += CyclesToEnd;
207 unsigned int NOOPsToAdd) {
210 while (NOOPsToAdd-- > 0) {
STATISTIC(NumFunctions,"Total number of functions")
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
FunctionPass * createX86PadShortFunctions()
createX86PadShortFunctions - Return a pass that pads short functions with NOOPs.
std::vector< MachineBasicBlock * >::iterator succ_iterator
TargetInstrInfo - Interface to description of machine instruction set.
bundle_iterator< MachineInstr, instr_iterator > iterator
bool isReturn(QueryType Type=AnyInBundle) const
FunctionPass class - This class is used to implement most global optimizations.
MachineInstrBuilder BuildMI(MachineFunction &MF, DebugLoc DL, const MCInstrDesc &MCID)
BuildMI - Builder interface.
succ_iterator succ_begin()
Representation of each machine instruction.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
bool isCall(QueryType Type=AnyInBundle) const
iterator find(const KeyT &Val)
static int const Threshold
TODO: Write a new FunctionPass AliasAnalysis so that it can keep a cache.
Function must be optimized for size first.