#include "X86.h"
#include "X86InstrBuilder.h"
#include "X86InstrInfo.h"
#include "X86Subtarget.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineConstantPool.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/MachineSSAUpdater.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/CodeGen/TargetSchedule.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/MC/MCSchedule.h"
#include "llvm/Pass.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <iterator>
#include <utility>
usingnamespacellvm;
#define PASS_KEY …
#define DEBUG_TYPE …
STATISTIC(NumCopiesEliminated, "Number of copies of EFLAGS eliminated");
STATISTIC(NumSetCCsInserted, "Number of setCC instructions inserted");
STATISTIC(NumTestsInserted, "Number of test instructions inserted");
STATISTIC(NumAddsInserted, "Number of adds instructions inserted");
STATISTIC(NumNFsConvertedTo, "Number of NF instructions converted to");
namespace {
CondRegArray;
class X86FlagsCopyLoweringPass : public MachineFunctionPass { … };
}
INITIALIZE_PASS_BEGIN(X86FlagsCopyLoweringPass, DEBUG_TYPE,
"X86 EFLAGS copy lowering", false, false)
INITIALIZE_PASS_END(X86FlagsCopyLoweringPass, DEBUG_TYPE,
"X86 EFLAGS copy lowering", false, false)
FunctionPass *llvm::createX86FlagsCopyLoweringPass() { … }
char X86FlagsCopyLoweringPass::ID = …;
void X86FlagsCopyLoweringPass::getAnalysisUsage(AnalysisUsage &AU) const { … }
static bool isArithmeticOp(unsigned Opc) { … }
static MachineBasicBlock &splitBlock(MachineBasicBlock &MBB,
MachineInstr &SplitI,
const X86InstrInfo &TII) { … }
enum EFLAGSClobber { … };
static EFLAGSClobber getClobberType(const MachineInstr &MI) { … }
bool X86FlagsCopyLoweringPass::runOnMachineFunction(MachineFunction &MF) { … }
CondRegArray X86FlagsCopyLoweringPass::collectCondsInRegs(
MachineBasicBlock &MBB, MachineBasicBlock::iterator TestPos) { … }
Register X86FlagsCopyLoweringPass::promoteCondToReg(
MachineBasicBlock &TestMBB, MachineBasicBlock::iterator TestPos,
const DebugLoc &TestLoc, X86::CondCode Cond) { … }
std::pair<unsigned, bool> X86FlagsCopyLoweringPass::getCondOrInverseInReg(
MachineBasicBlock &TestMBB, MachineBasicBlock::iterator TestPos,
const DebugLoc &TestLoc, X86::CondCode Cond, CondRegArray &CondRegs) { … }
void X86FlagsCopyLoweringPass::insertTest(MachineBasicBlock &MBB,
MachineBasicBlock::iterator Pos,
const DebugLoc &Loc, unsigned Reg) { … }
void X86FlagsCopyLoweringPass::rewriteSetCC(MachineBasicBlock &MBB,
MachineBasicBlock::iterator Pos,
const DebugLoc &Loc,
MachineInstr &MI,
CondRegArray &CondRegs) { … }
void X86FlagsCopyLoweringPass::rewriteArithmetic(
MachineBasicBlock &MBB, MachineBasicBlock::iterator Pos,
const DebugLoc &Loc, MachineInstr &MI, CondRegArray &CondRegs) { … }
static X86::CondCode getImplicitCondFromMI(unsigned Opc) { … }
static unsigned getOpcodeWithCC(unsigned Opc, X86::CondCode CC) { … }
void X86FlagsCopyLoweringPass::rewriteMI(MachineBasicBlock &MBB,
MachineBasicBlock::iterator Pos,
const DebugLoc &Loc, MachineInstr &MI,
CondRegArray &CondRegs) { … }