#include "MCTargetDesc/PPCMCTargetDesc.h"
#include "MCTargetDesc/PPCPredicates.h"
#include "PPC.h"
#include "PPCInstrBuilder.h"
#include "PPCInstrInfo.h"
#include "PPCMachineFunctionInfo.h"
#include "PPCTargetMachine.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/CodeGen/LiveVariables.h"
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachinePostDominators.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/InitializePasses.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/DebugCounter.h"
usingnamespacellvm;
#define DEBUG_TYPE …
STATISTIC(RemoveTOCSave, "Number of TOC saves removed");
STATISTIC(MultiTOCSaves,
"Number of functions with multiple TOC saves that must be kept");
STATISTIC(NumTOCSavesInPrologue, "Number of TOC saves placed in the prologue");
STATISTIC(NumEliminatedSExt, "Number of eliminated sign-extensions");
STATISTIC(NumEliminatedZExt, "Number of eliminated zero-extensions");
STATISTIC(NumOptADDLIs, "Number of optimized ADD instruction fed by LI");
STATISTIC(NumConvertedToImmediateForm,
"Number of instructions converted to their immediate form");
STATISTIC(NumFunctionsEnteredInMIPeephole,
"Number of functions entered in PPC MI Peepholes");
STATISTIC(NumFixedPointIterations,
"Number of fixed-point iterations converting reg-reg instructions "
"to reg-imm ones");
STATISTIC(NumRotatesCollapsed,
"Number of pairs of rotate left, clear left/right collapsed");
STATISTIC(NumEXTSWAndSLDICombined,
"Number of pairs of EXTSW and SLDI combined as EXTSWSLI");
STATISTIC(NumLoadImmZeroFoldedAndRemoved,
"Number of LI(8) reg, 0 that are folded to r0 and removed");
static cl::opt<bool>
FixedPointRegToImm("ppc-reg-to-imm-fixed-point", cl::Hidden, cl::init(true),
cl::desc("Iterate to a fixed point when attempting to "
"convert reg-reg instructions to reg-imm"));
static cl::opt<bool>
ConvertRegReg("ppc-convert-rr-to-ri", cl::Hidden, cl::init(true),
cl::desc("Convert eligible reg+reg instructions to reg+imm"));
static cl::opt<bool>
EnableSExtElimination("ppc-eliminate-signext",
cl::desc("enable elimination of sign-extensions"),
cl::init(true), cl::Hidden);
static cl::opt<bool>
EnableZExtElimination("ppc-eliminate-zeroext",
cl::desc("enable elimination of zero-extensions"),
cl::init(true), cl::Hidden);
static cl::opt<bool>
EnableTrapOptimization("ppc-opt-conditional-trap",
cl::desc("enable optimization of conditional traps"),
cl::init(false), cl::Hidden);
DEBUG_COUNTER(
PeepholeXToICounter, "ppc-xtoi-peephole",
"Controls whether PPC reg+reg to reg+imm peephole is performed on a MI");
DEBUG_COUNTER(PeepholePerOpCounter, "ppc-per-op-peephole",
"Controls whether PPC per opcode peephole is performed on a MI");
namespace {
struct PPCMIPeephole : public MachineFunctionPass { … };
#define addRegToUpdate(R) …
void PPCMIPeephole::addRegToUpdateWithLine(Register Reg, int Line) { … }
void PPCMIPeephole::initialize(MachineFunction &MFParm) { … }
static MachineInstr *getVRegDefOrNull(MachineOperand *Op,
MachineRegisterInfo *MRI) { … }
static unsigned getKnownLeadingZeroCount(const unsigned Reg,
const PPCInstrInfo *TII,
const MachineRegisterInfo *MRI) { … }
void PPCMIPeephole::UpdateTOCSaves(
std::map<MachineInstr *, bool> &TOCSaves, MachineInstr *MI) { … }
static bool collectUnprimedAccPHIs(MachineRegisterInfo *MRI,
MachineInstr *RootPHI,
SmallVectorImpl<MachineInstr *> &PHIs) { … }
void PPCMIPeephole::convertUnprimedAccPHIs(
const PPCInstrInfo *TII, MachineRegisterInfo *MRI,
SmallVectorImpl<MachineInstr *> &PHIs, Register Dst) { … }
bool PPCMIPeephole::simplifyCode() { … }
static bool isEqOrNe(MachineInstr *BI) { … }
static bool isSupportedCmpOp(unsigned opCode) { … }
static bool is64bitCmpOp(unsigned opCode) { … }
static bool isSignedCmpOp(unsigned opCode) { … }
static unsigned getSignedCmpOpCode(unsigned opCode) { … }
static unsigned getPredicateToDecImm(MachineInstr *BI, MachineInstr *CMPI) { … }
static unsigned getPredicateToIncImm(MachineInstr *BI, MachineInstr *CMPI) { … }
static unsigned getIncomingRegForBlock(MachineInstr *Phi,
MachineBasicBlock *MBB) { … }
static unsigned getSrcVReg(unsigned Reg, MachineBasicBlock *BB1,
MachineBasicBlock *BB2, MachineRegisterInfo *MRI) { … }
static bool eligibleForCompareElimination(MachineBasicBlock &MBB,
MachineBasicBlock *&PredMBB,
MachineBasicBlock *&MBBtoMoveCmp,
MachineRegisterInfo *MRI) { … }
bool PPCMIPeephole::eliminateRedundantTOCSaves(
std::map<MachineInstr *, bool> &TOCSaves) { … }
bool PPCMIPeephole::eliminateRedundantCompare() { … }
bool PPCMIPeephole::emitRLDICWhenLoweringJumpTables(MachineInstr &MI,
MachineInstr *&ToErase) { … }
bool PPCMIPeephole::combineSEXTAndSHL(MachineInstr &MI,
MachineInstr *&ToErase) { … }
}
INITIALIZE_PASS_BEGIN(PPCMIPeephole, DEBUG_TYPE,
"PowerPC MI Peephole Optimization", false, false)
INITIALIZE_PASS_DEPENDENCY(MachineBlockFrequencyInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(MachinePostDominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(LiveVariablesWrapperPass)
INITIALIZE_PASS_END(PPCMIPeephole, DEBUG_TYPE,
"PowerPC MI Peephole Optimization", false, false)
char PPCMIPeephole::ID = …;
FunctionPass*
llvm::createPPCMIPeepholePass() { … }