#include "SystemZ.h"
#include "SystemZInstrInfo.h"
#include "SystemZTargetMachine.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/CodeGen/LiveRegUnits.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/MC/MCInstrDesc.h"
#include <cassert>
#include <cstdint>
usingnamespacellvm;
#define DEBUG_TYPE …
STATISTIC(BranchOnCounts, "Number of branch-on-count instructions");
STATISTIC(LoadAndTraps, "Number of load-and-trap instructions");
STATISTIC(EliminatedComparisons, "Number of eliminated comparisons");
STATISTIC(FusedComparisons, "Number of fused compare-and-branch instructions");
namespace {
struct Reference { … };
class SystemZElimCompare : public MachineFunctionPass { … };
char SystemZElimCompare::ID = …;
}
INITIALIZE_PASS(…)
static bool preservesValueOf(MachineInstr &MI, unsigned Reg) { … }
static bool resultTests(MachineInstr &MI, unsigned Reg) { … }
Reference SystemZElimCompare::getRegReferences(MachineInstr &MI, unsigned Reg) { … }
static bool isLoadAndTestAsCmp(MachineInstr &MI) { … }
static unsigned getCompareSourceReg(MachineInstr &Compare) { … }
bool SystemZElimCompare::convertToBRCT(
MachineInstr &MI, MachineInstr &Compare,
SmallVectorImpl<MachineInstr *> &CCUsers) { … }
bool SystemZElimCompare::convertToLoadAndTrap(
MachineInstr &MI, MachineInstr &Compare,
SmallVectorImpl<MachineInstr *> &CCUsers) { … }
bool SystemZElimCompare::convertToLoadAndTest(
MachineInstr &MI, MachineInstr &Compare,
SmallVectorImpl<MachineInstr *> &CCUsers) { … }
bool SystemZElimCompare::convertToLogical(
MachineInstr &MI, MachineInstr &Compare,
SmallVectorImpl<MachineInstr *> &CCUsers) { … }
#ifndef NDEBUG
static bool isAddWithImmediate(unsigned Opcode) {
switch(Opcode) {
case SystemZ::AHI:
case SystemZ::AHIK:
case SystemZ::AGHI:
case SystemZ::AGHIK:
case SystemZ::AFI:
case SystemZ::AIH:
case SystemZ::AGFI:
return true;
default: break;
}
return false;
}
#endif
bool SystemZElimCompare::adjustCCMasksForInstr(
MachineInstr &MI, MachineInstr &Compare,
SmallVectorImpl<MachineInstr *> &CCUsers,
unsigned ConvOpc) { … }
static bool isCompareZero(MachineInstr &Compare) { … }
bool SystemZElimCompare::optimizeCompareZero(
MachineInstr &Compare, SmallVectorImpl<MachineInstr *> &CCUsers) { … }
bool SystemZElimCompare::fuseCompareOperations(
MachineInstr &Compare, SmallVectorImpl<MachineInstr *> &CCUsers) { … }
bool SystemZElimCompare::processBlock(MachineBasicBlock &MBB) { … }
bool SystemZElimCompare::runOnMachineFunction(MachineFunction &F) { … }
FunctionPass *llvm::createSystemZElimComparePass(SystemZTargetMachine &TM) { … }