#include "MCTargetDesc/X86BaseInfo.h"
#include "X86.h"
#include "X86InstrInfo.h"
#include "X86Subtarget.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/ProfileSummaryInfo.h"
#include "llvm/CodeGen/LazyMachineBlockFrequencyInfo.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/MachineRegisterInfo.h"
#include "llvm/CodeGen/MachineSizeOpts.h"
#include "llvm/CodeGen/TargetOpcodes.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/Function.h"
#include "llvm/MC/MCInstrDesc.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <cstdint>
#include <iterator>
usingnamespacellvm;
#define DEBUG_TYPE …
static cl::opt<bool>
DisableX86LEAOpt("disable-x86-lea-opt", cl::Hidden,
cl::desc("X86: Disable LEA optimizations."),
cl::init(false));
STATISTIC(NumSubstLEAs, "Number of LEA instruction substitutions");
STATISTIC(NumRedundantLEAs, "Number of redundant LEA instructions removed");
static inline bool isIdenticalOp(const MachineOperand &MO1,
const MachineOperand &MO2);
static bool isSimilarDispOp(const MachineOperand &MO1,
const MachineOperand &MO2);
static inline bool isLEA(const MachineInstr &MI);
namespace {
class MemOpKey { … };
}
namespace llvm {
template <> struct DenseMapInfo<MemOpKey> { … };
}
static inline MemOpKey getMemOpKey(const MachineInstr &MI, unsigned N) { … }
static inline bool isIdenticalOp(const MachineOperand &MO1,
const MachineOperand &MO2) { … }
#ifndef NDEBUG
static bool isValidDispOp(const MachineOperand &MO) {
return MO.isImm() || MO.isCPI() || MO.isJTI() || MO.isSymbol() ||
MO.isGlobal() || MO.isBlockAddress() || MO.isMCSymbol() || MO.isMBB();
}
#endif
static bool isSimilarDispOp(const MachineOperand &MO1,
const MachineOperand &MO2) { … }
static inline bool isLEA(const MachineInstr &MI) { … }
namespace {
class X86OptimizeLEAPass : public MachineFunctionPass { … };
}
char X86OptimizeLEAPass::ID = …;
FunctionPass *llvm::createX86OptimizeLEAs() { … }
INITIALIZE_PASS(…)
int X86OptimizeLEAPass::calcInstrDist(const MachineInstr &First,
const MachineInstr &Last) { … }
bool X86OptimizeLEAPass::chooseBestLEA(
const SmallVectorImpl<MachineInstr *> &List, const MachineInstr &MI,
MachineInstr *&BestLEA, int64_t &AddrDispShift, int &Dist) { … }
int64_t X86OptimizeLEAPass::getAddrDispShift(const MachineInstr &MI1,
unsigned N1,
const MachineInstr &MI2,
unsigned N2) const { … }
bool X86OptimizeLEAPass::isReplaceable(const MachineInstr &First,
const MachineInstr &Last,
int64_t &AddrDispShift) const { … }
void X86OptimizeLEAPass::findLEAs(const MachineBasicBlock &MBB,
MemOpMap &LEAs) { … }
bool X86OptimizeLEAPass::removeRedundantAddrCalc(MemOpMap &LEAs) { … }
MachineInstr *X86OptimizeLEAPass::replaceDebugValue(MachineInstr &MI,
unsigned OldReg,
unsigned NewReg,
int64_t AddrDispShift) { … }
bool X86OptimizeLEAPass::removeRedundantLEAs(MemOpMap &LEAs) { … }
bool X86OptimizeLEAPass::runOnMachineFunction(MachineFunction &MF) { … }