blob: 5af91de5a114785ae4733bd4969c406a22cc00ae [file] [log] [blame]
Preston Gurd8b7ab4b2013-04-25 20:29:37 +00001//===-- X86FixupLEAs.cpp - use or replace LEA instructions -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Sanjay Patel63604412014-07-16 20:18:49 +000010// This file defines the pass that finds instructions that can be
11// re-written as LEA instructions in order to reduce pipeline delays.
Michael Kuperstein12982a82015-11-11 11:44:31 +000012// When optimizing for size it replaces suitable LEAs with INC or DEC.
Preston Gurd8b7ab4b2013-04-25 20:29:37 +000013//
14//===----------------------------------------------------------------------===//
15
Preston Gurd8b7ab4b2013-04-25 20:29:37 +000016#include "X86.h"
17#include "X86InstrInfo.h"
18#include "X86Subtarget.h"
19#include "llvm/ADT/Statistic.h"
20#include "llvm/CodeGen/LiveVariables.h"
21#include "llvm/CodeGen/MachineFunctionPass.h"
22#include "llvm/CodeGen/MachineInstrBuilder.h"
23#include "llvm/CodeGen/MachineRegisterInfo.h"
24#include "llvm/CodeGen/Passes.h"
25#include "llvm/Support/Debug.h"
26#include "llvm/Support/raw_ostream.h"
27#include "llvm/Target/TargetInstrInfo.h"
28using namespace llvm;
29
Chandler Carruth84e68b22014-04-22 02:41:26 +000030#define DEBUG_TYPE "x86-fixup-LEAs"
31
Preston Gurd8b7ab4b2013-04-25 20:29:37 +000032STATISTIC(NumLEAs, "Number of LEA instructions created");
33
34namespace {
Eric Christopher31b81ce2014-06-03 21:01:35 +000035class FixupLEAPass : public MachineFunctionPass {
36 enum RegUsageState { RU_NotUsed, RU_Write, RU_Read };
37 static char ID;
38 /// \brief Loop over all of the instructions in the basic block
39 /// replacing applicable instructions with LEA instructions,
40 /// where appropriate.
41 bool processBasicBlock(MachineFunction &MF, MachineFunction::iterator MFI);
Preston Gurd8b7ab4b2013-04-25 20:29:37 +000042
Sanjay Patel63604412014-07-16 20:18:49 +000043 const char *getPassName() const override { return "X86 LEA Fixup"; }
Preston Gurd128920d2013-04-25 21:31:33 +000044
Eric Christopher31b81ce2014-06-03 21:01:35 +000045 /// \brief Given a machine register, look for the instruction
46 /// which writes it in the current basic block. If found,
47 /// try to replace it with an equivalent LEA instruction.
Eric Christopher572e03a2015-06-19 01:53:21 +000048 /// If replacement succeeds, then also process the newly created
Eric Christopher31b81ce2014-06-03 21:01:35 +000049 /// instruction.
50 void seekLEAFixup(MachineOperand &p, MachineBasicBlock::iterator &I,
51 MachineFunction::iterator MFI);
Preston Gurd128920d2013-04-25 21:31:33 +000052
Eric Christopher31b81ce2014-06-03 21:01:35 +000053 /// \brief Given a memory access or LEA instruction
54 /// whose address mode uses a base and/or index register, look for
55 /// an opportunity to replace the instruction which sets the base or index
56 /// register with an equivalent LEA instruction.
57 void processInstruction(MachineBasicBlock::iterator &I,
58 MachineFunction::iterator MFI);
Preston Gurd128920d2013-04-25 21:31:33 +000059
Eric Christopher31b81ce2014-06-03 21:01:35 +000060 /// \brief Given a LEA instruction which is unprofitable
61 /// on Silvermont try to replace it with an equivalent ADD instruction
62 void processInstructionForSLM(MachineBasicBlock::iterator &I,
63 MachineFunction::iterator MFI);
Alexey Volkov6226de62014-05-20 08:55:50 +000064
Michael Kuperstein12982a82015-11-11 11:44:31 +000065 /// \brief Look for LEAs that add 1 to reg or subtract 1 from reg
66 /// and convert them to INC or DEC respectively.
67 bool fixupIncDec(MachineBasicBlock::iterator &I,
68 MachineFunction::iterator MFI) const;
69
Eric Christopher31b81ce2014-06-03 21:01:35 +000070 /// \brief Determine if an instruction references a machine register
71 /// and, if so, whether it reads or writes the register.
72 RegUsageState usesRegister(MachineOperand &p, MachineBasicBlock::iterator I);
Preston Gurd128920d2013-04-25 21:31:33 +000073
Eric Christopher31b81ce2014-06-03 21:01:35 +000074 /// \brief Step backwards through a basic block, looking
75 /// for an instruction which writes a register within
76 /// a maximum of INSTR_DISTANCE_THRESHOLD instruction latency cycles.
77 MachineBasicBlock::iterator searchBackwards(MachineOperand &p,
78 MachineBasicBlock::iterator &I,
79 MachineFunction::iterator MFI);
Preston Gurd128920d2013-04-25 21:31:33 +000080
Eric Christopher31b81ce2014-06-03 21:01:35 +000081 /// \brief if an instruction can be converted to an
82 /// equivalent LEA, insert the new instruction into the basic block
83 /// and return a pointer to it. Otherwise, return zero.
84 MachineInstr *postRAConvertToLEA(MachineFunction::iterator &MFI,
85 MachineBasicBlock::iterator &MBBI) const;
Preston Gurd8b7ab4b2013-04-25 20:29:37 +000086
Eric Christopher31b81ce2014-06-03 21:01:35 +000087public:
88 FixupLEAPass() : MachineFunctionPass(ID) {}
Preston Gurd8b7ab4b2013-04-25 20:29:37 +000089
Eric Christopher31b81ce2014-06-03 21:01:35 +000090 /// \brief Loop over all of the basic blocks,
91 /// replacing instructions by equivalent LEA instructions
92 /// if needed and when possible.
93 bool runOnMachineFunction(MachineFunction &MF) override;
Preston Gurd8b7ab4b2013-04-25 20:29:37 +000094
Derek Schuff1dbf7a52016-04-04 17:09:25 +000095 // This pass runs after regalloc and doesn't support VReg operands.
96 MachineFunctionProperties getRequiredProperties() const override {
97 return MachineFunctionProperties().set(
98 MachineFunctionProperties::Property::AllVRegsAllocated);
99 }
100
Eric Christopher31b81ce2014-06-03 21:01:35 +0000101private:
102 MachineFunction *MF;
Eric Christopher31b81ce2014-06-03 21:01:35 +0000103 const X86InstrInfo *TII; // Machine instruction info.
Michael Kuperstein12982a82015-11-11 11:44:31 +0000104 bool OptIncDec;
105 bool OptLEA;
Eric Christopher31b81ce2014-06-03 21:01:35 +0000106};
107char FixupLEAPass::ID = 0;
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000108}
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000109
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000110MachineInstr *
111FixupLEAPass::postRAConvertToLEA(MachineFunction::iterator &MFI,
Preston Gurd128920d2013-04-25 21:31:33 +0000112 MachineBasicBlock::iterator &MBBI) const {
Eric Christopher31b81ce2014-06-03 21:01:35 +0000113 MachineInstr *MI = MBBI;
114 MachineInstr *NewMI;
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000115 switch (MI->getOpcode()) {
Alexey Volkov6226de62014-05-20 08:55:50 +0000116 case X86::MOV32rr:
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000117 case X86::MOV64rr: {
Eric Christopher31b81ce2014-06-03 21:01:35 +0000118 const MachineOperand &Src = MI->getOperand(1);
119 const MachineOperand &Dest = MI->getOperand(0);
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000120 NewMI = BuildMI(*MF, MI->getDebugLoc(),
Eric Christopher31b81ce2014-06-03 21:01:35 +0000121 TII->get(MI->getOpcode() == X86::MOV32rr ? X86::LEA32r
122 : X86::LEA64r))
123 .addOperand(Dest)
124 .addOperand(Src)
125 .addImm(1)
126 .addReg(0)
127 .addImm(0)
128 .addReg(0);
129 MFI->insert(MBBI, NewMI); // Insert the new inst
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000130 return NewMI;
131 }
132 case X86::ADD64ri32:
133 case X86::ADD64ri8:
134 case X86::ADD64ri32_DB:
135 case X86::ADD64ri8_DB:
136 case X86::ADD32ri:
137 case X86::ADD32ri8:
138 case X86::ADD32ri_DB:
139 case X86::ADD32ri8_DB:
140 case X86::ADD16ri:
141 case X86::ADD16ri8:
142 case X86::ADD16ri_DB:
143 case X86::ADD16ri8_DB:
144 if (!MI->getOperand(2).isImm()) {
145 // convertToThreeAddress will call getImm()
146 // which requires isImm() to be true
Craig Topper062a2ba2014-04-25 05:30:21 +0000147 return nullptr;
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000148 }
Preston Gurdf03a6e72013-09-30 23:51:22 +0000149 break;
Preston Gurdf0b62882013-09-30 23:18:42 +0000150 case X86::ADD16rr:
151 case X86::ADD16rr_DB:
152 if (MI->getOperand(1).getReg() != MI->getOperand(2).getReg()) {
153 // if src1 != src2, then convertToThreeAddress will
154 // need to create a Virtual register, which we cannot do
155 // after register allocation.
Craig Topper062a2ba2014-04-25 05:30:21 +0000156 return nullptr;
Preston Gurdf0b62882013-09-30 23:18:42 +0000157 }
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000158 }
Craig Topper062a2ba2014-04-25 05:30:21 +0000159 return TII->convertToThreeAddress(MFI, MBBI, nullptr);
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000160}
161
Eric Christopher31b81ce2014-06-03 21:01:35 +0000162FunctionPass *llvm::createX86FixupLEAs() { return new FixupLEAPass(); }
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000163
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000164bool FixupLEAPass::runOnMachineFunction(MachineFunction &Func) {
Andrew Kaylor2bee5ef2016-04-26 21:44:24 +0000165 if (skipFunction(*Func.getFunction()))
166 return false;
167
Eric Christopherdd240fd2014-06-03 21:01:39 +0000168 MF = &Func;
Eric Christopher4369c9b2015-02-20 08:01:52 +0000169 const X86Subtarget &ST = Func.getSubtarget<X86Subtarget>();
Michael Kuperstein12982a82015-11-11 11:44:31 +0000170 OptIncDec = !ST.slowIncDec() || Func.getFunction()->optForMinSize();
171 OptLEA = ST.LEAusesAG() || ST.slowLEA();
172
173 if (!OptLEA && !OptIncDec)
Eric Christopher0d5c99e2014-05-22 01:46:02 +0000174 return false;
175
Eric Christopherd361ff82015-02-05 19:27:01 +0000176 TII = ST.getInstrInfo();
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000177
178 DEBUG(dbgs() << "Start X86FixupLEAs\n";);
179 // Process all basic blocks.
180 for (MachineFunction::iterator I = Func.begin(), E = Func.end(); I != E; ++I)
181 processBasicBlock(Func, I);
182 DEBUG(dbgs() << "End X86FixupLEAs\n";);
183
184 return true;
185}
186
Eric Christopher31b81ce2014-06-03 21:01:35 +0000187FixupLEAPass::RegUsageState
188FixupLEAPass::usesRegister(MachineOperand &p, MachineBasicBlock::iterator I) {
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000189 RegUsageState RegUsage = RU_NotUsed;
Eric Christopher31b81ce2014-06-03 21:01:35 +0000190 MachineInstr *MI = I;
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000191
192 for (unsigned int i = 0; i < MI->getNumOperands(); ++i) {
Eric Christopher31b81ce2014-06-03 21:01:35 +0000193 MachineOperand &opnd = MI->getOperand(i);
194 if (opnd.isReg() && opnd.getReg() == p.getReg()) {
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000195 if (opnd.isDef())
196 return RU_Write;
197 RegUsage = RU_Read;
198 }
199 }
200 return RegUsage;
201}
202
203/// getPreviousInstr - Given a reference to an instruction in a basic
204/// block, return a reference to the previous instruction in the block,
205/// wrapping around to the last instruction of the block if the block
206/// branches to itself.
Eric Christopher31b81ce2014-06-03 21:01:35 +0000207static inline bool getPreviousInstr(MachineBasicBlock::iterator &I,
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000208 MachineFunction::iterator MFI) {
209 if (I == MFI->begin()) {
Duncan P. N. Exon Smithd77de642015-10-19 21:48:29 +0000210 if (MFI->isPredecessor(&*MFI)) {
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000211 I = --MFI->end();
212 return true;
Eric Christopher31b81ce2014-06-03 21:01:35 +0000213 } else
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000214 return false;
215 }
216 --I;
217 return true;
218}
219
Eric Christopher31b81ce2014-06-03 21:01:35 +0000220MachineBasicBlock::iterator
221FixupLEAPass::searchBackwards(MachineOperand &p, MachineBasicBlock::iterator &I,
222 MachineFunction::iterator MFI) {
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000223 int InstrDistance = 1;
224 MachineBasicBlock::iterator CurInst;
225 static const int INSTR_DISTANCE_THRESHOLD = 5;
226
227 CurInst = I;
228 bool Found;
229 Found = getPreviousInstr(CurInst, MFI);
Eric Christopher31b81ce2014-06-03 21:01:35 +0000230 while (Found && I != CurInst) {
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000231 if (CurInst->isCall() || CurInst->isInlineAsm())
232 break;
233 if (InstrDistance > INSTR_DISTANCE_THRESHOLD)
234 break; // too far back to make a difference
Eric Christopher31b81ce2014-06-03 21:01:35 +0000235 if (usesRegister(p, CurInst) == RU_Write) {
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000236 return CurInst;
237 }
Eric Christopherd9134482014-08-04 21:25:23 +0000238 InstrDistance += TII->getInstrLatency(
Eric Christopherd361ff82015-02-05 19:27:01 +0000239 MF->getSubtarget().getInstrItineraryData(), CurInst);
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000240 Found = getPreviousInstr(CurInst, MFI);
241 }
Craig Topper062a2ba2014-04-25 05:30:21 +0000242 return nullptr;
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000243}
244
Michael Kuperstein12982a82015-11-11 11:44:31 +0000245static inline bool isLEA(const int opcode) {
246 return opcode == X86::LEA16r || opcode == X86::LEA32r ||
247 opcode == X86::LEA64r || opcode == X86::LEA64_32r;
248}
249
250/// isLEASimpleIncOrDec - Does this LEA have one these forms:
251/// lea %reg, 1(%reg)
252/// lea %reg, -1(%reg)
253static inline bool isLEASimpleIncOrDec(MachineInstr *LEA) {
254 unsigned SrcReg = LEA->getOperand(1 + X86::AddrBaseReg).getReg();
255 unsigned DstReg = LEA->getOperand(0).getReg();
256 unsigned AddrDispOp = 1 + X86::AddrDisp;
257 return SrcReg == DstReg &&
258 LEA->getOperand(1 + X86::AddrIndexReg).getReg() == 0 &&
259 LEA->getOperand(1 + X86::AddrSegmentReg).getReg() == 0 &&
260 LEA->getOperand(AddrDispOp).isImm() &&
261 (LEA->getOperand(AddrDispOp).getImm() == 1 ||
262 LEA->getOperand(AddrDispOp).getImm() == -1);
263}
264
265bool FixupLEAPass::fixupIncDec(MachineBasicBlock::iterator &I,
266 MachineFunction::iterator MFI) const {
267 MachineInstr *MI = I;
268 int Opcode = MI->getOpcode();
269 if (!isLEA(Opcode))
270 return false;
271
272 if (isLEASimpleIncOrDec(MI) && TII->isSafeToClobberEFLAGS(*MFI, I)) {
273 int NewOpcode;
274 bool isINC = MI->getOperand(4).getImm() == 1;
275 switch (Opcode) {
276 case X86::LEA16r:
277 NewOpcode = isINC ? X86::INC16r : X86::DEC16r;
278 break;
279 case X86::LEA32r:
280 case X86::LEA64_32r:
281 NewOpcode = isINC ? X86::INC32r : X86::DEC32r;
282 break;
283 case X86::LEA64r:
284 NewOpcode = isINC ? X86::INC64r : X86::DEC64r;
285 break;
286 }
287
288 MachineInstr *NewMI =
289 BuildMI(*MFI, I, MI->getDebugLoc(), TII->get(NewOpcode))
290 .addOperand(MI->getOperand(0))
291 .addOperand(MI->getOperand(1));
292 MFI->erase(I);
293 I = static_cast<MachineBasicBlock::iterator>(NewMI);
294 return true;
295 }
296 return false;
297}
298
Eric Christopher31b81ce2014-06-03 21:01:35 +0000299void FixupLEAPass::processInstruction(MachineBasicBlock::iterator &I,
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000300 MachineFunction::iterator MFI) {
301 // Process a load, store, or LEA instruction.
302 MachineInstr *MI = I;
303 int opcode = MI->getOpcode();
Eric Christopher31b81ce2014-06-03 21:01:35 +0000304 const MCInstrDesc &Desc = MI->getDesc();
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000305 int AddrOffset = X86II::getMemoryOperandNo(Desc.TSFlags, opcode);
306 if (AddrOffset >= 0) {
307 AddrOffset += X86II::getOperandBias(Desc);
Eric Christopher31b81ce2014-06-03 21:01:35 +0000308 MachineOperand &p = MI->getOperand(AddrOffset + X86::AddrBaseReg);
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000309 if (p.isReg() && p.getReg() != X86::ESP) {
310 seekLEAFixup(p, I, MFI);
311 }
Eric Christopher31b81ce2014-06-03 21:01:35 +0000312 MachineOperand &q = MI->getOperand(AddrOffset + X86::AddrIndexReg);
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000313 if (q.isReg() && q.getReg() != X86::ESP) {
314 seekLEAFixup(q, I, MFI);
315 }
316 }
317}
318
Eric Christopher31b81ce2014-06-03 21:01:35 +0000319void FixupLEAPass::seekLEAFixup(MachineOperand &p,
320 MachineBasicBlock::iterator &I,
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000321 MachineFunction::iterator MFI) {
322 MachineBasicBlock::iterator MBI = searchBackwards(p, I, MFI);
323 if (MBI) {
Eric Christopher31b81ce2014-06-03 21:01:35 +0000324 MachineInstr *NewMI = postRAConvertToLEA(MFI, MBI);
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000325 if (NewMI) {
326 ++NumLEAs;
Alexey Volkov6226de62014-05-20 08:55:50 +0000327 DEBUG(dbgs() << "FixLEA: Candidate to replace:"; MBI->dump(););
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000328 // now to replace with an equivalent LEA...
Alexey Volkov6226de62014-05-20 08:55:50 +0000329 DEBUG(dbgs() << "FixLEA: Replaced by: "; NewMI->dump(););
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000330 MFI->erase(MBI);
331 MachineBasicBlock::iterator J =
Eric Christopher31b81ce2014-06-03 21:01:35 +0000332 static_cast<MachineBasicBlock::iterator>(NewMI);
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000333 processInstruction(J, MFI);
334 }
335 }
336}
337
Alexey Volkov6226de62014-05-20 08:55:50 +0000338void FixupLEAPass::processInstructionForSLM(MachineBasicBlock::iterator &I,
339 MachineFunction::iterator MFI) {
340 MachineInstr *MI = I;
341 const int opcode = MI->getOpcode();
Michael Kuperstein12982a82015-11-11 11:44:31 +0000342 if (!isLEA(opcode))
Alexey Volkov6226de62014-05-20 08:55:50 +0000343 return;
344 if (MI->getOperand(5).getReg() != 0 || !MI->getOperand(4).isImm() ||
345 !TII->isSafeToClobberEFLAGS(*MFI, I))
346 return;
347 const unsigned DstR = MI->getOperand(0).getReg();
348 const unsigned SrcR1 = MI->getOperand(1).getReg();
349 const unsigned SrcR2 = MI->getOperand(3).getReg();
350 if ((SrcR1 == 0 || SrcR1 != DstR) && (SrcR2 == 0 || SrcR2 != DstR))
351 return;
352 if (MI->getOperand(2).getImm() > 1)
353 return;
354 int addrr_opcode, addri_opcode;
355 switch (opcode) {
Michael Kuperstein12982a82015-11-11 11:44:31 +0000356 default:
357 llvm_unreachable("Unexpected LEA instruction");
Alexey Volkov6226de62014-05-20 08:55:50 +0000358 case X86::LEA16r:
359 addrr_opcode = X86::ADD16rr;
360 addri_opcode = X86::ADD16ri;
361 break;
362 case X86::LEA32r:
363 addrr_opcode = X86::ADD32rr;
364 addri_opcode = X86::ADD32ri;
365 break;
366 case X86::LEA64_32r:
367 case X86::LEA64r:
368 addrr_opcode = X86::ADD64rr;
369 addri_opcode = X86::ADD64ri32;
370 break;
Alexey Volkov6226de62014-05-20 08:55:50 +0000371 }
372 DEBUG(dbgs() << "FixLEA: Candidate to replace:"; I->dump(););
373 DEBUG(dbgs() << "FixLEA: Replaced by: ";);
Craig Topper66f09ad2014-06-08 22:29:17 +0000374 MachineInstr *NewMI = nullptr;
Alexey Volkov6226de62014-05-20 08:55:50 +0000375 const MachineOperand &Dst = MI->getOperand(0);
376 // Make ADD instruction for two registers writing to LEA's destination
377 if (SrcR1 != 0 && SrcR2 != 0) {
378 const MachineOperand &Src1 = MI->getOperand(SrcR1 == DstR ? 1 : 3);
379 const MachineOperand &Src2 = MI->getOperand(SrcR1 == DstR ? 3 : 1);
380 NewMI = BuildMI(*MF, MI->getDebugLoc(), TII->get(addrr_opcode))
381 .addOperand(Dst)
382 .addOperand(Src1)
383 .addOperand(Src2);
384 MFI->insert(I, NewMI);
385 DEBUG(NewMI->dump(););
386 }
387 // Make ADD instruction for immediate
388 if (MI->getOperand(4).getImm() != 0) {
389 const MachineOperand &SrcR = MI->getOperand(SrcR1 == DstR ? 1 : 3);
390 NewMI = BuildMI(*MF, MI->getDebugLoc(), TII->get(addri_opcode))
391 .addOperand(Dst)
392 .addOperand(SrcR)
393 .addImm(MI->getOperand(4).getImm());
394 MFI->insert(I, NewMI);
395 DEBUG(NewMI->dump(););
396 }
397 if (NewMI) {
398 MFI->erase(I);
399 I = static_cast<MachineBasicBlock::iterator>(NewMI);
400 }
401}
402
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000403bool FixupLEAPass::processBasicBlock(MachineFunction &MF,
404 MachineFunction::iterator MFI) {
405
Alexey Volkov6226de62014-05-20 08:55:50 +0000406 for (MachineBasicBlock::iterator I = MFI->begin(); I != MFI->end(); ++I) {
Michael Kuperstein12982a82015-11-11 11:44:31 +0000407 if (OptIncDec)
408 if (fixupIncDec(I, MFI))
409 continue;
410
411 if (OptLEA) {
412 if (MF.getSubtarget<X86Subtarget>().isSLM())
413 processInstructionForSLM(I, MFI);
414 else
415 processInstruction(I, MFI);
416 }
Alexey Volkov6226de62014-05-20 08:55:50 +0000417 }
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000418 return false;
419}