29 #define DEBUG_TYPE "x86-fixup-LEAs"
31 STATISTIC(NumLEAs,
"Number of LEA instructions created");
35 enum RegUsageState { RU_NotUsed, RU_Write, RU_Read };
42 const char *getPassName()
const override {
return "X86 LEA Fixup"; }
115 MFI->insert(MBBI, NewMI);
120 case X86::ADD64ri32_DB:
121 case X86::ADD64ri8_DB:
124 case X86::ADD32ri_DB:
125 case X86::ADD32ri8_DB:
128 case X86::ADD16ri_DB:
129 case X86::ADD16ri8_DB:
137 case X86::ADD16rr_DB:
145 return TII->convertToThreeAddress(MFI, MBBI,
nullptr);
158 DEBUG(
dbgs() <<
"Start X86FixupLEAs\n";);
161 processBasicBlock(Func,
I);
167 FixupLEAPass::RegUsageState
169 RegUsageState RegUsage = RU_NotUsed;
189 if (I == MFI->begin()) {
190 if (MFI->isPredecessor(MFI)) {
203 int InstrDistance = 1;
205 static const int INSTR_DISTANCE_THRESHOLD = 5;
210 while (Found && I != CurInst) {
211 if (CurInst->isCall() || CurInst->isInlineAsm())
213 if (InstrDistance > INSTR_DISTANCE_THRESHOLD)
215 if (usesRegister(p, CurInst) == RU_Write) {
218 InstrDistance +=
TII->getInstrLatency(
219 MF->getSubtarget().getInstrItineraryData(), CurInst);
232 if (AddrOffset >= 0) {
236 seekLEAFixup(p, I, MFI);
240 seekLEAFixup(q, I, MFI);
253 DEBUG(
dbgs() <<
"FixLEA: Candidate to replace:"; MBI->dump(););
268 if (opcode != X86::LEA16r && opcode != X86::LEA32r && opcode != X86::LEA64r &&
269 opcode != X86::LEA64_32r)
272 !
TII->isSafeToClobberEFLAGS(*MFI, I))
277 if ((SrcR1 == 0 || SrcR1 != DstR) && (SrcR2 == 0 || SrcR2 != DstR))
281 int addrr_opcode, addri_opcode;
285 addrr_opcode = X86::ADD16rr;
286 addri_opcode = X86::ADD16ri;
289 addrr_opcode = X86::ADD32rr;
290 addri_opcode = X86::ADD32ri;
294 addrr_opcode = X86::ADD64rr;
295 addri_opcode = X86::ADD64ri32;
298 DEBUG(
dbgs() <<
"FixLEA: Candidate to replace:"; I->dump(););
299 DEBUG(
dbgs() <<
"FixLEA: Replaced by: ";);
303 if (SrcR1 != 0 && SrcR2 != 0) {
310 MFI->insert(I, NewMI);
311 DEBUG(NewMI->dump(););
320 MFI->insert(I, NewMI);
321 DEBUG(NewMI->dump(););
334 processInstructionForSLM(I, MFI);
STATISTIC(NumFunctions,"Total number of functions")
const X86InstrInfo * getInstrInfo() const override
Describe properties that are true of each instruction in the target description file.
static bool getPreviousInstr(MachineBasicBlock::iterator &I, MachineFunction::iterator MFI)
getPreviousInstr - Given a reference to an instruction in a basic block, return a reference to the pr...
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
int getOperandBias(const MCInstrDesc &Desc)
getOperandBias - compute any additional adjustment needed to the offset to the start of the memory op...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
addImm - Add a new immediate operand.
unsigned getNumOperands() const
Access to explicit operands of the instruction.
static bool processInstruction(Loop &L, Instruction &Inst, DominatorTree &DT, const SmallVectorImpl< BasicBlock * > &ExitBlocks, PredIteratorCache &PredCache, LoopInfo *LI)
Given an instruction in the loop, check to see if it has any uses that are outside the current loop...
FunctionPass * createX86FixupLEAs()
createX86FixupLEAs - Return a a pass that selectively replaces certain instructions (like add...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bundle_iterator< MachineInstr, instr_iterator > iterator
const MachineOperand & getOperand(unsigned i) const
FunctionPass class - This class is used to implement most global optimizations.
MachineInstrBuilder BuildMI(MachineFunction &MF, DebugLoc DL, const MCInstrDesc &MCID)
BuildMI - Builder interface.
MachineOperand class - Representation of each machine instruction operand.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
Representation of each machine instruction.
unsigned getReg() const
getReg - Returns the register number.
int getMemoryOperandNo(uint64_t TSFlags, unsigned Opcode)
getMemoryOperandNo - The function returns the MCInst operand # for the first field of the memory oper...
const MachineInstrBuilder & addOperand(const MachineOperand &MO) const
BasicBlockListType::iterator iterator
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
addReg - Add a new virtual register operand...