1//===-- AVRFrameLowering.cpp - AVR Frame Information ----------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the AVR implementation of TargetFrameLowering class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "AVRFrameLowering.h"
14
15#include "AVR.h"
16#include "AVRInstrInfo.h"
17#include "AVRMachineFunctionInfo.h"
18#include "AVRTargetMachine.h"
19#include "MCTargetDesc/AVRMCTargetDesc.h"
20
21#include "llvm/CodeGen/MachineFrameInfo.h"
22#include "llvm/CodeGen/MachineFunction.h"
23#include "llvm/CodeGen/MachineFunctionAnalysisManager.h"
24#include "llvm/CodeGen/MachineFunctionPass.h"
25#include "llvm/CodeGen/MachineInstrBuilder.h"
26#include "llvm/CodeGen/MachinePassManager.h"
27#include "llvm/CodeGen/MachineRegisterInfo.h"
28#include "llvm/CodeGen/TargetFrameLowering.h"
29#include "llvm/CodeGen/TargetRegisterInfo.h"
30#include "llvm/IR/Analysis.h"
31#include "llvm/Pass.h"
32#include "llvm/Support/ErrorHandling.h"
33
34using namespace llvm;
35
36namespace llvm {
37
38AVRFrameLowering::AVRFrameLowering()
39 : TargetFrameLowering(TargetFrameLowering::StackGrowsDown, Align(1), -2) {}
40
41bool AVRFrameLowering::canSimplifyCallFramePseudos(
42 const MachineFunction &MF) const {
43 // Always simplify call frame pseudo instructions, even when
44 // hasReservedCallFrame is false.
45 return true;
46}
47
48bool AVRFrameLowering::hasReservedCallFrame(const MachineFunction &MF) const {
49 // Reserve call frame memory in function prologue under the following
50 // conditions:
51 // - Y pointer is reserved to be the frame pointer.
52 // - The function does not contain variable sized objects.
53
54 const MachineFrameInfo &MFI = MF.getFrameInfo();
55 return hasFP(MF) && !MFI.hasVarSizedObjects();
56}
57
58void AVRFrameLowering::emitPrologue(MachineFunction &MF,
59 MachineBasicBlock &MBB) const {
60 MachineBasicBlock::iterator MBBI = MBB.begin();
61 DebugLoc DL = (MBBI != MBB.end()) ? MBBI->getDebugLoc() : DebugLoc();
62 const AVRSubtarget &STI = MF.getSubtarget<AVRSubtarget>();
63 const AVRInstrInfo &TII = *STI.getInstrInfo();
64 const AVRMachineFunctionInfo *AFI = MF.getInfo<AVRMachineFunctionInfo>();
65 const MachineRegisterInfo &MRI = MF.getRegInfo();
66 bool HasFP = hasFP(MF);
67
68 // Interrupt handlers re-enable interrupts in function entry.
69 if (AFI->isInterruptHandler()) {
70 BuildMI(BB&: MBB, I: MBBI, MIMD: DL, MCID: TII.get(Opcode: AVR::BSETs))
71 .addImm(Val: 0x07)
72 .setMIFlag(MachineInstr::FrameSetup);
73 }
74
75 // Emit special prologue code to save R1, R0 and SREG in interrupt/signal
76 // handlers before saving any other registers.
77 if (AFI->isInterruptOrSignalHandler()) {
78 BuildMI(BB&: MBB, I: MBBI, MIMD: DL, MCID: TII.get(Opcode: AVR::PUSHRr))
79 .addReg(RegNo: STI.getTmpRegister(), Flags: RegState::Kill)
80 .setMIFlag(MachineInstr::FrameSetup);
81
82 BuildMI(BB&: MBB, I: MBBI, MIMD: DL, MCID: TII.get(Opcode: AVR::INRdA), DestReg: STI.getTmpRegister())
83 .addImm(Val: STI.getIORegSREG())
84 .setMIFlag(MachineInstr::FrameSetup);
85 BuildMI(BB&: MBB, I: MBBI, MIMD: DL, MCID: TII.get(Opcode: AVR::PUSHRr))
86 .addReg(RegNo: STI.getTmpRegister(), Flags: RegState::Kill)
87 .setMIFlag(MachineInstr::FrameSetup);
88 if (!MRI.reg_empty(RegNo: STI.getZeroRegister())) {
89 BuildMI(BB&: MBB, I: MBBI, MIMD: DL, MCID: TII.get(Opcode: AVR::PUSHRr))
90 .addReg(RegNo: STI.getZeroRegister(), Flags: RegState::Kill)
91 .setMIFlag(MachineInstr::FrameSetup);
92 BuildMI(BB&: MBB, I: MBBI, MIMD: DL, MCID: TII.get(Opcode: AVR::EORRdRr))
93 .addReg(RegNo: STI.getZeroRegister(), Flags: RegState::Define)
94 .addReg(RegNo: STI.getZeroRegister(), Flags: RegState::Kill)
95 .addReg(RegNo: STI.getZeroRegister(), Flags: RegState::Kill)
96 .setMIFlag(MachineInstr::FrameSetup);
97 }
98 }
99
100 // Early exit if the frame pointer is not needed in this function.
101 if (!HasFP) {
102 return;
103 }
104
105 const MachineFrameInfo &MFI = MF.getFrameInfo();
106 unsigned FrameSize = MFI.getStackSize() - AFI->getCalleeSavedFrameSize();
107
108 // Skip the callee-saved push instructions.
109 while (
110 (MBBI != MBB.end()) && MBBI->getFlag(Flag: MachineInstr::FrameSetup) &&
111 (MBBI->getOpcode() == AVR::PUSHRr || MBBI->getOpcode() == AVR::PUSHWRr)) {
112 ++MBBI;
113 }
114
115 // Update Y with the new base value.
116 BuildMI(BB&: MBB, I: MBBI, MIMD: DL, MCID: TII.get(Opcode: AVR::SPREAD), DestReg: AVR::R29R28)
117 .addReg(RegNo: AVR::SP)
118 .setMIFlag(MachineInstr::FrameSetup);
119
120 // Mark the FramePtr as live-in in every block except the entry.
121 for (MachineBasicBlock &MBBJ : llvm::drop_begin(RangeOrContainer&: MF)) {
122 MBBJ.addLiveIn(PhysReg: AVR::R29R28);
123 }
124
125 if (!FrameSize) {
126 return;
127 }
128
129 // Reserve the necessary frame memory by doing FP -= <size>.
130 unsigned Opcode = (isUInt<6>(x: FrameSize) && STI.hasADDSUBIW()) ? AVR::SBIWRdK
131 : AVR::SUBIWRdK;
132
133 MachineInstr *MI = BuildMI(BB&: MBB, I: MBBI, MIMD: DL, MCID: TII.get(Opcode), DestReg: AVR::R29R28)
134 .addReg(RegNo: AVR::R29R28, Flags: RegState::Kill)
135 .addImm(Val: FrameSize)
136 .setMIFlag(MachineInstr::FrameSetup);
137 // The SREG implicit def is dead.
138 MI->getOperand(i: 3).setIsDead();
139
140 // Write back R29R28 to SP and temporarily disable interrupts.
141 BuildMI(BB&: MBB, I: MBBI, MIMD: DL, MCID: TII.get(Opcode: AVR::SPWRITE), DestReg: AVR::SP)
142 .addReg(RegNo: AVR::R29R28)
143 .setMIFlag(MachineInstr::FrameSetup);
144}
145
146static void restoreStatusRegister(MachineFunction &MF, MachineBasicBlock &MBB) {
147 const AVRMachineFunctionInfo *AFI = MF.getInfo<AVRMachineFunctionInfo>();
148 const MachineRegisterInfo &MRI = MF.getRegInfo();
149
150 MachineBasicBlock::iterator MBBI = MBB.getLastNonDebugInstr();
151
152 DebugLoc DL = MBBI->getDebugLoc();
153 const AVRSubtarget &STI = MF.getSubtarget<AVRSubtarget>();
154 const AVRInstrInfo &TII = *STI.getInstrInfo();
155
156 // Emit special epilogue code to restore R1, R0 and SREG in interrupt/signal
157 // handlers at the very end of the function, just before reti.
158 if (AFI->isInterruptOrSignalHandler()) {
159 if (!MRI.reg_empty(RegNo: STI.getZeroRegister())) {
160 BuildMI(BB&: MBB, I: MBBI, MIMD: DL, MCID: TII.get(Opcode: AVR::POPRd), DestReg: STI.getZeroRegister());
161 }
162 BuildMI(BB&: MBB, I: MBBI, MIMD: DL, MCID: TII.get(Opcode: AVR::POPRd), DestReg: STI.getTmpRegister());
163 BuildMI(BB&: MBB, I: MBBI, MIMD: DL, MCID: TII.get(Opcode: AVR::OUTARr))
164 .addImm(Val: STI.getIORegSREG())
165 .addReg(RegNo: STI.getTmpRegister(), Flags: RegState::Kill);
166 BuildMI(BB&: MBB, I: MBBI, MIMD: DL, MCID: TII.get(Opcode: AVR::POPRd), DestReg: STI.getTmpRegister());
167 }
168}
169
170void AVRFrameLowering::emitEpilogue(MachineFunction &MF,
171 MachineBasicBlock &MBB) const {
172 const AVRMachineFunctionInfo *AFI = MF.getInfo<AVRMachineFunctionInfo>();
173
174 // Early exit if the frame pointer is not needed in this function except for
175 // signal/interrupt handlers where special code generation is required.
176 if (!hasFP(MF) && !AFI->isInterruptOrSignalHandler()) {
177 return;
178 }
179
180 MachineBasicBlock::iterator MBBI = MBB.getLastNonDebugInstr();
181 assert(MBBI->getDesc().isReturn() &&
182 "Can only insert epilog into returning blocks");
183
184 DebugLoc DL = MBBI->getDebugLoc();
185 const MachineFrameInfo &MFI = MF.getFrameInfo();
186 unsigned FrameSize = MFI.getStackSize() - AFI->getCalleeSavedFrameSize();
187 const AVRSubtarget &STI = MF.getSubtarget<AVRSubtarget>();
188 const AVRInstrInfo &TII = *STI.getInstrInfo();
189
190 // Early exit if there is no need to restore the frame pointer.
191 if (!FrameSize && !MF.getFrameInfo().hasVarSizedObjects()) {
192 restoreStatusRegister(MF, MBB);
193 return;
194 }
195
196 // Skip the callee-saved pop instructions.
197 while (MBBI != MBB.begin()) {
198 MachineBasicBlock::iterator PI = std::prev(x: MBBI);
199 int Opc = PI->getOpcode();
200
201 if (Opc != AVR::POPRd && Opc != AVR::POPWRd && !PI->isTerminator()) {
202 break;
203 }
204
205 --MBBI;
206 }
207
208 if (FrameSize) {
209 // Restore the frame pointer by doing FP += <size>.
210 BuildMI(BB&: MBB, I: MBBI, MIMD: DL, MCID: TII.get(Opcode: AVR::ADIWRdKP), DestReg: AVR::R29R28)
211 .addReg(RegNo: AVR::R29R28, Flags: RegState::Kill)
212 .addImm(Val: FrameSize)
213 .setOperandDead(3); // implicit-def $sreg
214 }
215
216 // Write back R29R28 to SP and temporarily disable interrupts.
217 BuildMI(BB&: MBB, I: MBBI, MIMD: DL, MCID: TII.get(Opcode: AVR::SPWRITE), DestReg: AVR::SP)
218 .addReg(RegNo: AVR::R29R28, Flags: RegState::Kill);
219
220 restoreStatusRegister(MF, MBB);
221}
222
223StackOffset AVRFrameLowering::getFrameIndexReference(const MachineFunction &MF,
224 int FI,
225 Register &FrameReg) const {
226 int64_t Offset;
227 const MachineFrameInfo &MFI = MF.getFrameInfo();
228
229 switch (MFI.getStackID(ObjectIdx: FI)) {
230 case TargetStackID::Default:
231 Offset = MFI.getObjectOffset(ObjectIdx: FI) + MFI.getOffsetAdjustment() +
232 MFI.getStackSize() - getOffsetOfLocalArea() + 1;
233
234 assert(Offset > 0);
235 break;
236
237 case TargetStackID::AvrAlign:
238 Offset = MFI.getObjectOffset(ObjectIdx: FI);
239 assert(Offset >= 0);
240 break;
241
242 default:
243 llvm_unreachable("Unsupported stack!");
244 }
245
246 // Frame indices are addressed relative to the frame register (see
247 // AVRRegisterInfo::eliminateFrameIndex); callers such as the DWARF
248 // debug info emitter rely on it being reported back here.
249 FrameReg = MF.getSubtarget().getRegisterInfo()->getFrameRegister(MF);
250
251 return StackOffset::getFixed(Fixed: Offset);
252}
253
254// Return true if the specified function should have a dedicated frame
255// pointer register. This is true if the function meets any of the following
256// conditions:
257// - a register has been spilled
258// - has allocas
259// - input arguments are passed using the stack
260// - has variable sized objects
261// - the frame address is taken (llvm.frameaddress)
262// - the return address is taken (llvm.returnaddress)
263//
264// Notice that strictly this is not a frame pointer because it contains SP after
265// frame allocation instead of having the original SP in function entry.
266bool AVRFrameLowering::hasFPImpl(const MachineFunction &MF) const {
267 const MachineFrameInfo &MFI = MF.getFrameInfo();
268 const AVRMachineFunctionInfo *FuncInfo = MF.getInfo<AVRMachineFunctionInfo>();
269
270 // Note that reading the return address requires a frame index, and that frame
271 // indexes are always referenced through Y (see
272 // AVRRegisterInfo::eliminateFrameIndex).
273 return (FuncInfo->getHasSpills() || FuncInfo->getHasAllocas() ||
274 FuncInfo->getHasStackArgs() || MFI.hasVarSizedObjects() ||
275 MFI.isFrameAddressTaken() || MFI.isReturnAddressTaken());
276}
277
278bool AVRFrameLowering::spillCalleeSavedRegisters(
279 MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
280 ArrayRef<CalleeSavedInfo> CSI, const TargetRegisterInfo *TRI) const {
281 if (CSI.empty()) {
282 return false;
283 }
284
285 unsigned CalleeFrameSize = 0;
286 DebugLoc DL = MBB.findDebugLoc(MBBI: MI);
287 MachineFunction &MF = *MBB.getParent();
288 const AVRSubtarget &STI = MF.getSubtarget<AVRSubtarget>();
289 const TargetInstrInfo &TII = *STI.getInstrInfo();
290 AVRMachineFunctionInfo *AVRFI = MF.getInfo<AVRMachineFunctionInfo>();
291
292 for (const CalleeSavedInfo &I : llvm::reverse(C&: CSI)) {
293 MCRegister Reg = I.getReg();
294 bool IsNotLiveIn = !MBB.isLiveIn(Reg);
295
296 // Check if Reg is a sub register of a 16-bit livein register, and then
297 // add it to the livein list.
298 if (IsNotLiveIn)
299 for (const auto &LiveIn : MBB.liveins())
300 if (STI.getRegisterInfo()->isSubRegister(RegA: LiveIn.PhysReg, RegB: Reg)) {
301 IsNotLiveIn = false;
302 MBB.addLiveIn(PhysReg: Reg);
303 break;
304 }
305
306 assert(TRI->getRegSizeInBits(*TRI->getMinimalPhysRegClass(Reg)) == 8 &&
307 "Invalid register size");
308
309 // Add the callee-saved register as live-in only if it is not already a
310 // live-in register, this usually happens with arguments that are passed
311 // through callee-saved registers.
312 if (IsNotLiveIn) {
313 MBB.addLiveIn(PhysReg: Reg);
314 }
315
316 // Do not kill the register when it is an input argument.
317 BuildMI(BB&: MBB, I: MI, MIMD: DL, MCID: TII.get(Opcode: AVR::PUSHRr))
318 .addReg(RegNo: Reg, Flags: getKillRegState(B: IsNotLiveIn))
319 .setMIFlag(MachineInstr::FrameSetup);
320 ++CalleeFrameSize;
321 }
322
323 AVRFI->setCalleeSavedFrameSize(CalleeFrameSize);
324
325 return true;
326}
327
328bool AVRFrameLowering::restoreCalleeSavedRegisters(
329 MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
330 MutableArrayRef<CalleeSavedInfo> CSI, const TargetRegisterInfo *TRI) const {
331 if (CSI.empty()) {
332 return false;
333 }
334
335 DebugLoc DL = MBB.findDebugLoc(MBBI: MI);
336 const MachineFunction &MF = *MBB.getParent();
337 const AVRSubtarget &STI = MF.getSubtarget<AVRSubtarget>();
338 const TargetInstrInfo &TII = *STI.getInstrInfo();
339
340 for (const CalleeSavedInfo &CCSI : CSI) {
341 MCRegister Reg = CCSI.getReg();
342
343 assert(TRI->getRegSizeInBits(*TRI->getMinimalPhysRegClass(Reg)) == 8 &&
344 "Invalid register size");
345
346 BuildMI(BB&: MBB, I: MI, MIMD: DL, MCID: TII.get(Opcode: AVR::POPRd), DestReg: Reg);
347 }
348
349 return true;
350}
351
352/// Replace pseudo store instructions that pass arguments through the stack with
353/// real instructions.
354static void fixStackStores(MachineBasicBlock &MBB,
355 MachineBasicBlock::iterator StartMI,
356 const TargetInstrInfo &TII) {
357 // Iterate through the BB until we hit a call instruction or we reach the end.
358 for (MachineInstr &MI :
359 llvm::make_early_inc_range(Range: llvm::make_range(x: StartMI, y: MBB.end()))) {
360 if (MI.isCall())
361 break;
362
363 unsigned Opcode = MI.getOpcode();
364
365 // Only care of pseudo store instructions where SP is the base pointer.
366 if (Opcode != AVR::STDSPQRr && Opcode != AVR::STDWSPQRr)
367 continue;
368
369 assert(MI.getOperand(0).getReg() == AVR::SP &&
370 "SP is expected as base pointer");
371
372 // Replace this instruction with a regular store. Use Y as the base
373 // pointer since it is guaranteed to contain a copy of SP.
374 unsigned STOpc =
375 (Opcode == AVR::STDWSPQRr) ? AVR::STDWPtrQRr : AVR::STDPtrQRr;
376
377 MI.setDesc(TII.get(Opcode: STOpc));
378 MI.getOperand(i: 0).setReg(AVR::R31R30);
379 }
380}
381
382MachineBasicBlock::iterator AVRFrameLowering::eliminateCallFramePseudoInstr(
383 MachineFunction &MF, MachineBasicBlock &MBB,
384 MachineBasicBlock::iterator MI) const {
385 const AVRSubtarget &STI = MF.getSubtarget<AVRSubtarget>();
386 const AVRInstrInfo &TII = *STI.getInstrInfo();
387
388 if (hasReservedCallFrame(MF)) {
389 return MBB.erase(I: MI);
390 }
391
392 DebugLoc DL = MI->getDebugLoc();
393 unsigned int Opcode = MI->getOpcode();
394 int Amount = TII.getFrameSize(I: *MI);
395
396 if (Amount == 0) {
397 return MBB.erase(I: MI);
398 }
399
400 assert(getStackAlign() == Align(1) && "Unsupported stack alignment");
401
402 if (Opcode == TII.getCallFrameSetupOpcode()) {
403 // Update the stack pointer.
404 // In many cases this can be done far more efficiently by pushing the
405 // relevant values directly to the stack. However, doing that correctly
406 // (in the right order, possibly skipping some empty space for undef
407 // values, etc) is tricky and thus left to be optimized in the future.
408 BuildMI(BB&: MBB, I: MI, MIMD: DL, MCID: TII.get(Opcode: AVR::SPREAD), DestReg: AVR::R31R30).addReg(RegNo: AVR::SP);
409
410 MachineInstr *New =
411 BuildMI(BB&: MBB, I: MI, MIMD: DL, MCID: TII.get(Opcode: AVR::SUBIWRdK), DestReg: AVR::R31R30)
412 .addReg(RegNo: AVR::R31R30, Flags: RegState::Kill)
413 .addImm(Val: Amount);
414 New->getOperand(i: 3).setIsDead();
415
416 BuildMI(BB&: MBB, I: MI, MIMD: DL, MCID: TII.get(Opcode: AVR::SPWRITE), DestReg: AVR::SP).addReg(RegNo: AVR::R31R30);
417
418 // Make sure the remaining stack stores are converted to real store
419 // instructions.
420 fixStackStores(MBB, StartMI: MI, TII);
421 } else {
422 assert(Opcode == TII.getCallFrameDestroyOpcode());
423
424 // Note that small stack changes could be implemented more efficiently
425 // with a few pop instructions instead of the 8-9 instructions now
426 // required.
427
428 BuildMI(BB&: MBB, I: MI, MIMD: DL, MCID: TII.get(Opcode: AVR::SPREAD), DestReg: AVR::R31R30).addReg(RegNo: AVR::SP);
429
430 BuildMI(BB&: MBB, I: MI, MIMD: DL, MCID: TII.get(Opcode: AVR::ADIWRdKP), DestReg: AVR::R31R30)
431 .addReg(RegNo: AVR::R31R30, Flags: RegState::Kill)
432 .addImm(Val: Amount)
433 .setOperandDead(3); // implicit-def $sreg
434
435 BuildMI(BB&: MBB, I: MI, MIMD: DL, MCID: TII.get(Opcode: AVR::SPWRITE), DestReg: AVR::SP)
436 .addReg(RegNo: AVR::R31R30, Flags: RegState::Kill);
437 }
438
439 return MBB.erase(I: MI);
440}
441
442void AVRFrameLowering::determineCalleeSaves(MachineFunction &MF,
443 BitVector &SavedRegs,
444 RegScavenger *RS) const {
445 TargetFrameLowering::determineCalleeSaves(MF, SavedRegs, RS);
446
447 // If we have a frame pointer, the Y register needs to be saved as well.
448 if (hasFP(MF)) {
449 SavedRegs.set(AVR::R29);
450 SavedRegs.set(AVR::R28);
451 }
452}
453
454} // end of namespace llvm
455
456namespace {
457/// The frame analyzer pass.
458///
459/// Scans the function for allocas and used arguments
460/// that are passed through the stack.
461struct AVRFrameAnalyzerLegacy : public MachineFunctionPass {
462 static char ID;
463 AVRFrameAnalyzerLegacy() : MachineFunctionPass(ID) {}
464
465 bool runOnMachineFunction(MachineFunction &MF) override;
466
467 StringRef getPassName() const override { return "AVR Frame Analyzer"; }
468
469 void getAnalysisUsage(AnalysisUsage &AU) const override {
470 AU.setPreservesAll();
471 MachineFunctionPass::getAnalysisUsage(AU);
472 }
473};
474
475} // namespace
476
477char AVRFrameAnalyzerLegacy::ID = 0;
478
479/// Creates instance of the frame analyzer pass.
480FunctionPass *llvm::createAVRFrameAnalyzerLegacyPass() {
481 return new AVRFrameAnalyzerLegacy();
482}
483
484static bool runFrameAnalyzer(MachineFunction &MF) {
485 const MachineFrameInfo &MFI = MF.getFrameInfo();
486 AVRMachineFunctionInfo *AFI = MF.getInfo<AVRMachineFunctionInfo>();
487
488 // If there are no fixed frame indexes during this stage it means there
489 // are allocas present in the function.
490 if (MFI.getNumObjects() != MFI.getNumFixedObjects()) {
491 // Check for the type of allocas present in the function. We only care
492 // about fixed size allocas so do not give false positives if only
493 // variable sized allocas are present.
494 for (unsigned i = 0, e = MFI.getObjectIndexEnd(); i != e; ++i) {
495 if (!MFI.isVariableSizedObjectIndex(ObjectIdx: i) && !MFI.isDeadObjectIndex(ObjectIdx: i)) {
496 AFI->setHasAllocas(true);
497 break;
498 }
499 }
500 }
501
502 // If there are fixed frame indexes present, scan the function to see if
503 // they are really being used.
504 if (MFI.getNumFixedObjects() == 0) {
505 return false;
506 }
507
508 // Ok fixed frame indexes present, now scan the function to see if they
509 // are really being used, otherwise we can ignore them.
510 for (const MachineBasicBlock &BB : MF) {
511 for (const MachineInstr &MI : BB) {
512 int Opcode = MI.getOpcode();
513
514 if ((Opcode != AVR::LDDRdPtrQ) && (Opcode != AVR::LDDWRdPtrQ) &&
515 (Opcode != AVR::STDPtrQRr) && (Opcode != AVR::STDWPtrQRr) &&
516 (Opcode != AVR::FRMIDX)) {
517 continue;
518 }
519
520 for (const MachineOperand &MO : MI.operands()) {
521 if (!MO.isFI()) {
522 continue;
523 }
524
525 if (MFI.isFixedObjectIndex(ObjectIdx: MO.getIndex())) {
526 AFI->setHasStackArgs(true);
527 return false;
528 }
529 }
530 }
531 }
532
533 return false;
534}
535
536bool AVRFrameAnalyzerLegacy::runOnMachineFunction(MachineFunction &MF) {
537 return runFrameAnalyzer(MF);
538}
539
540PreservedAnalyses
541AVRFrameAnalyzerPass::run(MachineFunction &MF,
542 MachineFunctionAnalysisManager &MFAM) {
543 runFrameAnalyzer(MF);
544 return PreservedAnalyses::all();
545}
546