//===-------- X86PadShortFunction.cpp - pad short functions -----------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file defines the pass which will pad short functions to prevent // a stall if a function returns before the return address is ready. This // is needed for some Intel Atom processors. // //===----------------------------------------------------------------------===// #include "X86.h" #include "X86InstrInfo.h" #include "X86Subtarget.h" #include "llvm/ADT/Statistic.h" #include "llvm/Analysis/ProfileSummaryInfo.h" #include "llvm/CodeGen/LazyMachineBlockFrequencyInfo.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/MachineSizeOpts.h" #include "llvm/CodeGen/Passes.h" #include "llvm/CodeGen/TargetSchedule.h" #include "llvm/IR/Function.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" usingnamespacellvm; #define DEBUG_TYPE … STATISTIC(NumBBsPadded, "Number of basic blocks padded"); namespace { struct VisitedBBInfo { … }; struct PadShortFunc : public MachineFunctionPass { … }; char PadShortFunc::ID = …; } FunctionPass *llvm::createX86PadShortFunctions() { … } /// runOnMachineFunction - Loop over all of the basic blocks, inserting /// NOOP instructions before early exits. bool PadShortFunc::runOnMachineFunction(MachineFunction &MF) { … } /// findReturn - Starting at MBB, follow control flow and add all /// basic blocks that contain a return to ReturnBBs. void PadShortFunc::findReturns(MachineBasicBlock *MBB, unsigned int Cycles) { … } /// cyclesUntilReturn - return true if the MBB has a return instruction, /// and return false otherwise. /// Cycles will be incremented by the number of cycles taken to reach the /// return or the end of the BB, whichever occurs first. bool PadShortFunc::cyclesUntilReturn(MachineBasicBlock *MBB, unsigned int &Cycles) { … } /// addPadding - Add the given number of NOOP instructions to the function /// just prior to the return at MBBI void PadShortFunc::addPadding(MachineBasicBlock *MBB, MachineBasicBlock::iterator &MBBI, unsigned int NOOPsToAdd) { … }