18 #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) {}
56 virtual const char *getPassName()
const {
57 return "X86 Atom pad short functions";
62 unsigned int Cycles = 0);
65 unsigned int &Cycles);
69 unsigned int NOOPsToAdd);
88 return new PadShortFunc();
103 TII =
TM->getInstrInfo();
108 findReturns(MF.
begin());
110 bool MadeChange =
false;
113 unsigned int Cycles = 0;
117 I != ReturnBBs.end(); ++
I) {
124 assert(MBB->
size() > 0 &&
125 "Basic block should contain at least a RET but is empty");
128 while (ReturnLoc->isDebugValue())
130 assert(ReturnLoc->isReturn() && !ReturnLoc->isCall() &&
131 "Basic block does not end with RET");
133 addPadding(MBB, ReturnLoc,
Threshold - Cycles);
146 bool hasReturn = cyclesUntilReturn(MBB, Cycles);
151 ReturnBBs[MBB] = std::max(ReturnBBs[MBB], Cycles);
160 findReturns(*
I, Cycles);
169 unsigned int &Cycles) {
172 = VisitedBBs.
find(MBB);
173 if (it != VisitedBBs.
end()) {
174 VisitedBBInfo BBInfo = it->second;
175 Cycles += BBInfo.Cycles;
176 return BBInfo.HasReturn;
179 unsigned int CyclesToEnd = 0;
182 MBBI != MBB->
end(); ++MBBI) {
188 VisitedBBs[MBB] = VisitedBBInfo(
true, CyclesToEnd);
189 Cycles += CyclesToEnd;
193 CyclesToEnd +=
TII->getInstrLatency(
TM->getInstrItineraryData(),
MI);
196 VisitedBBs[MBB] = VisitedBBInfo(
false, CyclesToEnd);
197 Cycles += CyclesToEnd;
205 unsigned int NOOPsToAdd) {
208 while (NOOPsToAdd-- > 0) {
const Function * getFunction() const
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
const HexagonInstrInfo * TII
FunctionPass * createX86PadShortFunctions()
std::vector< MachineBasicBlock * >::iterator succ_iterator
ID
LLVM Calling Convention Representation.
bundle_iterator< MachineInstr, instr_iterator > iterator
bool isReturn(QueryType Type=AnyInBundle) const
MachineInstrBuilder BuildMI(MachineFunction &MF, DebugLoc DL, const MCInstrDesc &MCID)
succ_iterator succ_begin()
AttributeSet getAttributes() const
Return the attribute list for this Function.
bool isCall(QueryType Type=AnyInBundle) const
STATISTIC(NumBBsPadded,"Number of basic blocks padded")
const TargetMachine & getTarget() const
static int const Threshold
iterator find(const KeyT &Val)
Function must be optimized for size first.