@@ -201,8 +201,8 @@ void AVRFrameLowering::emitEpilogue(MachineFunction &MF,
201
201
202
202
// Restore the frame pointer by doing FP += <size>.
203
203
MachineInstr *MI = BuildMI (MBB, MBBI, DL, TII.get (Opcode), AVR::R29R28)
204
- .addReg (AVR::R29R28, RegState::Kill)
205
- .addImm (FrameSize);
204
+ .addReg (AVR::R29R28, RegState::Kill)
205
+ .addImm (FrameSize);
206
206
// The SREG implicit def is dead.
207
207
MI->getOperand (3 ).setIsDead ();
208
208
}
@@ -299,7 +299,7 @@ bool AVRFrameLowering::restoreCalleeSavedRegisters(
299
299
// / real instructions.
300
300
static void fixStackStores (MachineBasicBlock &MBB,
301
301
MachineBasicBlock::iterator StartMI,
302
- const TargetInstrInfo &TII, Register FP ) {
302
+ const TargetInstrInfo &TII) {
303
303
// Iterate through the BB until we hit a call instruction or we reach the end.
304
304
for (MachineInstr &MI :
305
305
llvm::make_early_inc_range (llvm::make_range (StartMI, MBB.end ()))) {
@@ -313,15 +313,15 @@ static void fixStackStores(MachineBasicBlock &MBB,
313
313
continue ;
314
314
315
315
assert (MI.getOperand (0 ).getReg () == AVR::SP &&
316
- " Invalid register, should be SP! " );
316
+ " SP is expected as base pointer " );
317
317
318
318
// Replace this instruction with a regular store. Use Y as the base
319
319
// pointer since it is guaranteed to contain a copy of SP.
320
320
unsigned STOpc =
321
321
(Opcode == AVR::STDWSPQRr) ? AVR::STDWPtrQRr : AVR::STDPtrQRr;
322
322
323
323
MI.setDesc (TII.get (STOpc));
324
- MI.getOperand (0 ).setReg (FP );
324
+ MI.getOperand (0 ).setReg (AVR::R31R30 );
325
325
}
326
326
}
327
327
@@ -331,69 +331,66 @@ MachineBasicBlock::iterator AVRFrameLowering::eliminateCallFramePseudoInstr(
331
331
const AVRSubtarget &STI = MF.getSubtarget <AVRSubtarget>();
332
332
const AVRInstrInfo &TII = *STI.getInstrInfo ();
333
333
334
- // There is nothing to insert when the call frame memory is allocated during
335
- // function entry. Delete the call frame pseudo and replace all pseudo stores
336
- // with real store instructions.
337
334
if (hasReservedCallFrame (MF)) {
338
- fixStackStores (MBB, MI, TII, AVR::R29R28);
339
335
return MBB.erase (MI);
340
336
}
341
337
342
338
DebugLoc DL = MI->getDebugLoc ();
343
339
unsigned int Opcode = MI->getOpcode ();
344
340
int Amount = TII.getFrameSize (*MI);
345
341
346
- // ADJCALLSTACKUP and ADJCALLSTACKDOWN are converted to adiw/subi
347
- // instructions to read and write the stack pointer in I/O space.
348
- if (Amount != 0 ) {
349
- assert (getStackAlign () == Align (1 ) && " Unsupported stack alignment" );
350
-
351
- if (Opcode == TII.getCallFrameSetupOpcode ()) {
352
- // Update the stack pointer.
353
- // In many cases this can be done far more efficiently by pushing the
354
- // relevant values directly to the stack. However, doing that correctly
355
- // (in the right order, possibly skipping some empty space for undef
356
- // values, etc) is tricky and thus left to be optimized in the future.
357
- BuildMI (MBB, MI, DL, TII.get (AVR::SPREAD), AVR::R31R30).addReg (AVR::SP);
358
-
359
- MachineInstr *New =
360
- BuildMI (MBB, MI, DL, TII.get (AVR::SUBIWRdK), AVR::R31R30)
361
- .addReg (AVR::R31R30, RegState::Kill)
362
- .addImm (Amount);
363
- New->getOperand (3 ).setIsDead ();
364
-
365
- BuildMI (MBB, MI, DL, TII.get (AVR::SPWRITE), AVR::SP).addReg (AVR::R31R30);
366
-
367
- // Make sure the remaining stack stores are converted to real store
368
- // instructions.
369
- fixStackStores (MBB, MI, TII, AVR::R31R30);
370
- } else {
371
- assert (Opcode == TII.getCallFrameDestroyOpcode ());
372
-
373
- // Note that small stack changes could be implemented more efficiently
374
- // with a few pop instructions instead of the 8-9 instructions now
375
- // required.
376
-
377
- // Select the best opcode to adjust SP based on the offset size.
378
- unsigned addOpcode;
379
- if (isUInt<6 >(Amount)) {
380
- addOpcode = AVR::ADIWRdK;
381
- } else {
382
- addOpcode = AVR::SUBIWRdK;
383
- Amount = -Amount;
384
- }
342
+ if (Amount == 0 ) {
343
+ return MBB.erase (MI);
344
+ }
345
+
346
+ assert (getStackAlign () == Align (1 ) && " Unsupported stack alignment" );
347
+
348
+ if (Opcode == TII.getCallFrameSetupOpcode ()) {
349
+ // Update the stack pointer.
350
+ // In many cases this can be done far more efficiently by pushing the
351
+ // relevant values directly to the stack. However, doing that correctly
352
+ // (in the right order, possibly skipping some empty space for undef
353
+ // values, etc) is tricky and thus left to be optimized in the future.
354
+ BuildMI (MBB, MI, DL, TII.get (AVR::SPREAD), AVR::R31R30).addReg (AVR::SP);
355
+
356
+ MachineInstr *New =
357
+ BuildMI (MBB, MI, DL, TII.get (AVR::SUBIWRdK), AVR::R31R30)
358
+ .addReg (AVR::R31R30, RegState::Kill)
359
+ .addImm (Amount);
360
+ New->getOperand (3 ).setIsDead ();
385
361
386
- // Build the instruction sequence.
387
- BuildMI (MBB, MI, DL, TII.get (AVR::SPREAD), AVR::R31R30).addReg (AVR::SP);
362
+ BuildMI (MBB, MI, DL, TII.get (AVR::SPWRITE), AVR::SP).addReg (AVR::R31R30);
388
363
389
- MachineInstr *New = BuildMI (MBB, MI, DL, TII.get (addOpcode), AVR::R31R30)
390
- .addReg (AVR::R31R30, RegState::Kill)
391
- .addImm (Amount);
392
- New->getOperand (3 ).setIsDead ();
364
+ // Make sure the remaining stack stores are converted to real store
365
+ // instructions.
366
+ fixStackStores (MBB, MI, TII);
367
+ } else {
368
+ assert (Opcode == TII.getCallFrameDestroyOpcode ());
393
369
394
- BuildMI (MBB, MI, DL, TII.get (AVR::SPWRITE), AVR::SP)
395
- .addReg (AVR::R31R30, RegState::Kill);
370
+ // Note that small stack changes could be implemented more efficiently
371
+ // with a few pop instructions instead of the 8-9 instructions now
372
+ // required.
373
+
374
+ // Select the best opcode to adjust SP based on the offset size.
375
+ unsigned AddOpcode;
376
+
377
+ if (isUInt<6 >(Amount)) {
378
+ AddOpcode = AVR::ADIWRdK;
379
+ } else {
380
+ AddOpcode = AVR::SUBIWRdK;
381
+ Amount = -Amount;
396
382
}
383
+
384
+ // Build the instruction sequence.
385
+ BuildMI (MBB, MI, DL, TII.get (AVR::SPREAD), AVR::R31R30).addReg (AVR::SP);
386
+
387
+ MachineInstr *New = BuildMI (MBB, MI, DL, TII.get (AddOpcode), AVR::R31R30)
388
+ .addReg (AVR::R31R30, RegState::Kill)
389
+ .addImm (Amount);
390
+ New->getOperand (3 ).setIsDead ();
391
+
392
+ BuildMI (MBB, MI, DL, TII.get (AVR::SPWRITE), AVR::SP)
393
+ .addReg (AVR::R31R30, RegState::Kill);
397
394
}
398
395
399
396
return MBB.erase (MI);
@@ -420,7 +417,7 @@ struct AVRFrameAnalyzer : public MachineFunctionPass {
420
417
421
418
bool runOnMachineFunction (MachineFunction &MF) override {
422
419
const MachineFrameInfo &MFI = MF.getFrameInfo ();
423
- AVRMachineFunctionInfo *FuncInfo = MF.getInfo <AVRMachineFunctionInfo>();
420
+ AVRMachineFunctionInfo *AFI = MF.getInfo <AVRMachineFunctionInfo>();
424
421
425
422
// If there are no fixed frame indexes during this stage it means there
426
423
// are allocas present in the function.
@@ -431,7 +428,7 @@ struct AVRFrameAnalyzer : public MachineFunctionPass {
431
428
for (unsigned i = 0 , e = MFI.getObjectIndexEnd (); i != e; ++i) {
432
429
// Variable sized objects have size 0.
433
430
if (MFI.getObjectSize (i)) {
434
- FuncInfo ->setHasAllocas (true );
431
+ AFI ->setHasAllocas (true );
435
432
break ;
436
433
}
437
434
}
@@ -460,7 +457,7 @@ struct AVRFrameAnalyzer : public MachineFunctionPass {
460
457
}
461
458
462
459
if (MFI.isFixedObjectIndex (MO.getIndex ())) {
463
- FuncInfo ->setHasStackArgs (true );
460
+ AFI ->setHasStackArgs (true );
464
461
return false ;
465
462
}
466
463
}
0 commit comments