mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[X86] Making X86OptimizeLEAs pass public. NFC
Reviewers: wxiao3, LuoYuanke, andrew.w.kaylor, craig.topper, annita.zhang, liutianle, pengfei, xiangzhangllvm, RKSimon, spatel, andreadb Reviewed By: RKSimon Subscribers: andreadb, hiraditya, llvm-commits Tags: #llvm Patch by Gen Pei (gpei) Differential Revision: https://reviews.llvm.org/D65933 llvm-svn: 369612
This commit is contained in:
parent
2adef2024e
commit
d62f33b212
@ -142,8 +142,8 @@ void initializeX86DomainReassignmentPass(PassRegistry &);
|
||||
void initializeX86ExecutionDomainFixPass(PassRegistry &);
|
||||
void initializeX86ExpandPseudoPass(PassRegistry &);
|
||||
void initializeX86FlagsCopyLoweringPassPass(PassRegistry &);
|
||||
void initializeX86OptimizeLEAPassPass(PassRegistry &);
|
||||
void initializeX86SpeculativeLoadHardeningPassPass(PassRegistry &);
|
||||
|
||||
} // End llvm namespace
|
||||
|
||||
#endif
|
||||
|
@ -234,9 +234,9 @@ static inline bool isLEA(const MachineInstr &MI) {
|
||||
|
||||
namespace {
|
||||
|
||||
class OptimizeLEAPass : public MachineFunctionPass {
|
||||
class X86OptimizeLEAPass : public MachineFunctionPass {
|
||||
public:
|
||||
OptimizeLEAPass() : MachineFunctionPass(ID) {}
|
||||
X86OptimizeLEAPass() : MachineFunctionPass(ID) {}
|
||||
|
||||
StringRef getPassName() const override { return "X86 LEA Optimize"; }
|
||||
|
||||
@ -245,6 +245,8 @@ public:
|
||||
/// been calculated by LEA. Also, remove redundant LEAs.
|
||||
bool runOnMachineFunction(MachineFunction &MF) override;
|
||||
|
||||
static char ID;
|
||||
|
||||
private:
|
||||
using MemOpMap = DenseMap<MemOpKey, SmallVector<MachineInstr *, 16>>;
|
||||
|
||||
@ -295,18 +297,18 @@ private:
|
||||
MachineRegisterInfo *MRI;
|
||||
const X86InstrInfo *TII;
|
||||
const X86RegisterInfo *TRI;
|
||||
|
||||
static char ID;
|
||||
};
|
||||
|
||||
} // end anonymous namespace
|
||||
|
||||
char OptimizeLEAPass::ID = 0;
|
||||
char X86OptimizeLEAPass::ID = 0;
|
||||
|
||||
FunctionPass *llvm::createX86OptimizeLEAs() { return new OptimizeLEAPass(); }
|
||||
FunctionPass *llvm::createX86OptimizeLEAs() { return new X86OptimizeLEAPass(); }
|
||||
INITIALIZE_PASS(X86OptimizeLEAPass, DEBUG_TYPE, "X86 optimize LEA pass", false,
|
||||
false)
|
||||
|
||||
int OptimizeLEAPass::calcInstrDist(const MachineInstr &First,
|
||||
const MachineInstr &Last) {
|
||||
int X86OptimizeLEAPass::calcInstrDist(const MachineInstr &First,
|
||||
const MachineInstr &Last) {
|
||||
// Both instructions must be in the same basic block and they must be
|
||||
// presented in InstrPos.
|
||||
assert(Last.getParent() == First.getParent() &&
|
||||
@ -327,10 +329,9 @@ int OptimizeLEAPass::calcInstrDist(const MachineInstr &First,
|
||||
// 3) Displacement of the new memory operand should fit in 1 byte if possible.
|
||||
// 4) The LEA should be as close to MI as possible, and prior to it if
|
||||
// possible.
|
||||
bool OptimizeLEAPass::chooseBestLEA(const SmallVectorImpl<MachineInstr *> &List,
|
||||
const MachineInstr &MI,
|
||||
MachineInstr *&BestLEA,
|
||||
int64_t &AddrDispShift, int &Dist) {
|
||||
bool X86OptimizeLEAPass::chooseBestLEA(
|
||||
const SmallVectorImpl<MachineInstr *> &List, const MachineInstr &MI,
|
||||
MachineInstr *&BestLEA, int64_t &AddrDispShift, int &Dist) {
|
||||
const MachineFunction *MF = MI.getParent()->getParent();
|
||||
const MCInstrDesc &Desc = MI.getDesc();
|
||||
int MemOpNo = X86II::getMemoryOperandNo(Desc.TSFlags) +
|
||||
@ -386,9 +387,10 @@ bool OptimizeLEAPass::chooseBestLEA(const SmallVectorImpl<MachineInstr *> &List,
|
||||
// Get the difference between the addresses' displacements of the two
|
||||
// instructions \p MI1 and \p MI2. The numbers of the first memory operands are
|
||||
// passed through \p N1 and \p N2.
|
||||
int64_t OptimizeLEAPass::getAddrDispShift(const MachineInstr &MI1, unsigned N1,
|
||||
const MachineInstr &MI2,
|
||||
unsigned N2) const {
|
||||
int64_t X86OptimizeLEAPass::getAddrDispShift(const MachineInstr &MI1,
|
||||
unsigned N1,
|
||||
const MachineInstr &MI2,
|
||||
unsigned N2) const {
|
||||
const MachineOperand &Op1 = MI1.getOperand(N1 + X86::AddrDisp);
|
||||
const MachineOperand &Op2 = MI2.getOperand(N2 + X86::AddrDisp);
|
||||
|
||||
@ -410,9 +412,9 @@ int64_t OptimizeLEAPass::getAddrDispShift(const MachineInstr &MI1, unsigned N1,
|
||||
// 2) Def registers of LEAs belong to the same class.
|
||||
// 3) All uses of the Last LEA def register are replaceable, thus the
|
||||
// register is used only as address base.
|
||||
bool OptimizeLEAPass::isReplaceable(const MachineInstr &First,
|
||||
const MachineInstr &Last,
|
||||
int64_t &AddrDispShift) const {
|
||||
bool X86OptimizeLEAPass::isReplaceable(const MachineInstr &First,
|
||||
const MachineInstr &Last,
|
||||
int64_t &AddrDispShift) const {
|
||||
assert(isLEA(First) && isLEA(Last) &&
|
||||
"The function works only with LEA instructions");
|
||||
|
||||
@ -466,7 +468,8 @@ bool OptimizeLEAPass::isReplaceable(const MachineInstr &First,
|
||||
return true;
|
||||
}
|
||||
|
||||
void OptimizeLEAPass::findLEAs(const MachineBasicBlock &MBB, MemOpMap &LEAs) {
|
||||
void X86OptimizeLEAPass::findLEAs(const MachineBasicBlock &MBB,
|
||||
MemOpMap &LEAs) {
|
||||
unsigned Pos = 0;
|
||||
for (auto &MI : MBB) {
|
||||
// Assign the position number to the instruction. Note that we are going to
|
||||
@ -484,7 +487,7 @@ void OptimizeLEAPass::findLEAs(const MachineBasicBlock &MBB, MemOpMap &LEAs) {
|
||||
// Try to find load and store instructions which recalculate addresses already
|
||||
// calculated by some LEA and replace their memory operands with its def
|
||||
// register.
|
||||
bool OptimizeLEAPass::removeRedundantAddrCalc(MemOpMap &LEAs) {
|
||||
bool X86OptimizeLEAPass::removeRedundantAddrCalc(MemOpMap &LEAs) {
|
||||
bool Changed = false;
|
||||
|
||||
assert(!LEAs.empty());
|
||||
@ -563,9 +566,9 @@ bool OptimizeLEAPass::removeRedundantAddrCalc(MemOpMap &LEAs) {
|
||||
return Changed;
|
||||
}
|
||||
|
||||
MachineInstr *OptimizeLEAPass::replaceDebugValue(MachineInstr &MI,
|
||||
unsigned VReg,
|
||||
int64_t AddrDispShift) {
|
||||
MachineInstr *X86OptimizeLEAPass::replaceDebugValue(MachineInstr &MI,
|
||||
unsigned VReg,
|
||||
int64_t AddrDispShift) {
|
||||
DIExpression *Expr = const_cast<DIExpression *>(MI.getDebugExpression());
|
||||
if (AddrDispShift != 0)
|
||||
Expr = DIExpression::prepend(Expr, DIExpression::StackValue, AddrDispShift);
|
||||
@ -582,7 +585,7 @@ MachineInstr *OptimizeLEAPass::replaceDebugValue(MachineInstr &MI,
|
||||
}
|
||||
|
||||
// Try to find similar LEAs in the list and replace one with another.
|
||||
bool OptimizeLEAPass::removeRedundantLEAs(MemOpMap &LEAs) {
|
||||
bool X86OptimizeLEAPass::removeRedundantLEAs(MemOpMap &LEAs) {
|
||||
bool Changed = false;
|
||||
|
||||
// Loop over all entries in the table.
|
||||
@ -669,7 +672,7 @@ bool OptimizeLEAPass::removeRedundantLEAs(MemOpMap &LEAs) {
|
||||
return Changed;
|
||||
}
|
||||
|
||||
bool OptimizeLEAPass::runOnMachineFunction(MachineFunction &MF) {
|
||||
bool X86OptimizeLEAPass::runOnMachineFunction(MachineFunction &MF) {
|
||||
bool Changed = false;
|
||||
|
||||
if (DisableX86LEAOpt || skipFunction(MF.getFunction()))
|
||||
|
@ -81,6 +81,7 @@ extern "C" void LLVMInitializeX86Target() {
|
||||
initializeX86SpeculativeLoadHardeningPassPass(PR);
|
||||
initializeX86FlagsCopyLoweringPassPass(PR);
|
||||
initializeX86CondBrFoldingPassPass(PR);
|
||||
initializeX86OptimizeLEAPassPass(PR);
|
||||
}
|
||||
|
||||
static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user