1 | //===- XtensaFrameLowering.cpp - Xtensa 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 Xtensa implementation of TargetFrameLowering class. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #include "XtensaFrameLowering.h" |
14 | #include "XtensaInstrInfo.h" |
15 | #include "XtensaSubtarget.h" |
16 | #include "llvm/CodeGen/MachineFrameInfo.h" |
17 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
18 | #include "llvm/CodeGen/MachineModuleInfo.h" |
19 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
20 | #include "llvm/CodeGen/RegisterScavenging.h" |
21 | #include "llvm/IR/Function.h" |
22 | |
23 | using namespace llvm; |
24 | |
25 | XtensaFrameLowering::XtensaFrameLowering() |
26 | : TargetFrameLowering(TargetFrameLowering::StackGrowsDown, Align(4), 0, |
27 | Align(4)) {} |
28 | |
29 | bool XtensaFrameLowering::hasFP(const MachineFunction &MF) const { |
30 | const MachineFrameInfo &MFI = MF.getFrameInfo(); |
31 | return MF.getTarget().Options.DisableFramePointerElim(MF) || |
32 | MFI.hasVarSizedObjects(); |
33 | } |
34 | |
35 | void XtensaFrameLowering::emitPrologue(MachineFunction &MF, |
36 | MachineBasicBlock &MBB) const {} |
37 | |
38 | void XtensaFrameLowering::emitEpilogue(MachineFunction &MF, |
39 | MachineBasicBlock &MBB) const {} |
40 | |
41 | // Eliminate ADJCALLSTACKDOWN, ADJCALLSTACKUP pseudo instructions |
42 | MachineBasicBlock::iterator XtensaFrameLowering::eliminateCallFramePseudoInstr( |
43 | MachineFunction &MF, MachineBasicBlock &MBB, |
44 | MachineBasicBlock::iterator I) const { |
45 | const XtensaInstrInfo &TII = |
46 | *static_cast<const XtensaInstrInfo *>(MF.getSubtarget().getInstrInfo()); |
47 | |
48 | if (!hasReservedCallFrame(MF)) { |
49 | int64_t Amount = I->getOperand(i: 0).getImm(); |
50 | |
51 | if (I->getOpcode() == Xtensa::ADJCALLSTACKDOWN) |
52 | Amount = -Amount; |
53 | |
54 | unsigned SP = Xtensa::SP; |
55 | TII.adjustStackPtr(SP, Amount, MBB, I); |
56 | } |
57 | |
58 | return MBB.erase(I); |
59 | } |
60 | |