LLVM 20.0.0git
XtensaRegisterInfo.cpp
Go to the documentation of this file.
1//===- XtensaRegisterInfo.cpp - Xtensa Register 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 the TargetRegisterInfo class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "XtensaRegisterInfo.h"
14#include "XtensaInstrInfo.h"
15#include "XtensaSubtarget.h"
16#include "XtensaUtils.h"
21#include "llvm/Support/Debug.h"
24
25#define DEBUG_TYPE "xtensa-reg-info"
26
27#define GET_REGINFO_TARGET_DESC
28#include "XtensaGenRegisterInfo.inc"
29
30using namespace llvm;
31
33 : XtensaGenRegisterInfo(Xtensa::A0), Subtarget(STI) {}
34
35const uint16_t *
37 return CSR_Xtensa_SaveList;
38}
39
40const uint32_t *
42 CallingConv::ID) const {
43 return CSR_Xtensa_RegMask;
44}
45
47 BitVector Reserved(getNumRegs());
49
50 Reserved.set(Xtensa::A0);
51 if (TFI->hasFP(MF)) {
52 // Reserve frame pointer.
54 }
55
56 // Reserve stack pointer.
57 Reserved.set(Xtensa::SP);
58 return Reserved;
59}
60
62 int SPAdj, unsigned FIOperandNum,
63 RegScavenger *RS) const {
64 MachineInstr &MI = *II;
65 MachineFunction &MF = *MI.getParent()->getParent();
66 int FrameIndex = MI.getOperand(FIOperandNum).getIndex();
67 uint64_t StackSize = MF.getFrameInfo().getStackSize();
68 int64_t SPOffset = MF.getFrameInfo().getObjectOffset(FrameIndex);
70 const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
71 int MinCSFI = 0;
72 int MaxCSFI = -1;
73
74 if (CSI.size()) {
75 MinCSFI = CSI[0].getFrameIdx();
76 MaxCSFI = CSI[CSI.size() - 1].getFrameIdx();
77 }
78 // The following stack frame objects are always referenced relative to $sp:
79 // 1. Outgoing arguments.
80 // 2. Pointer to dynamically allocated stack space.
81 // 3. Locations for callee-saved registers.
82 // 4. Locations for eh data registers.
83 // Everything else is referenced relative to whatever register
84 // getFrameRegister() returns.
85 unsigned FrameReg;
86 if ((FrameIndex >= MinCSFI && FrameIndex <= MaxCSFI))
87 FrameReg = Xtensa::SP;
88 else
89 FrameReg = getFrameRegister(MF);
90
91 // Calculate final offset.
92 // - There is no need to change the offset if the frame object is one of the
93 // following: an outgoing argument, pointer to a dynamically allocated
94 // stack space or a $gp restore location,
95 // - If the frame object is any of the following, its offset must be adjusted
96 // by adding the size of the stack:
97 // incoming argument, callee-saved register location or local variable.
98 bool IsKill = false;
99 int64_t Offset =
100 SPOffset + (int64_t)StackSize + MI.getOperand(FIOperandNum + 1).getImm();
101
102 bool Valid = isValidAddrOffset(MI, Offset);
103
104 // If MI is not a debug value, make sure Offset fits in the 16-bit immediate
105 // field.
106 if (!MI.isDebugValue() && !Valid) {
107 MachineBasicBlock &MBB = *MI.getParent();
108 DebugLoc DL = II->getDebugLoc();
109 unsigned ADD = Xtensa::ADD;
110 unsigned Reg;
111 const XtensaInstrInfo &TII = *static_cast<const XtensaInstrInfo *>(
113
114 TII.loadImmediate(MBB, II, &Reg, Offset);
115 BuildMI(MBB, II, DL, TII.get(ADD), Reg)
116 .addReg(FrameReg)
117 .addReg(Reg, RegState::Kill);
118
119 FrameReg = Reg;
120 Offset = 0;
121 IsKill = true;
122 }
123
124 MI.getOperand(FIOperandNum).ChangeToRegister(FrameReg, false, false, IsKill);
125 MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset);
126
127 return false;
128}
129
132 return TFI->hasFP(MF) ? Xtensa::A15 : Xtensa::SP;
133}
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
uint64_t IntrinsicInst * II
A debug info location.
Definition: DebugLoc.h:33
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
Definition: MachineInstr.h:69
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
Information about stack frame layout on the target.
virtual bool hasFP(const MachineFunction &MF) const =0
hasFP - Return true if the specified function should have a dedicated frame pointer register.
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetInstrInfo * getInstrInfo() const
XtensaRegisterInfo(const XtensaSubtarget &STI)
const uint16_t * getCalleeSavedRegs(const MachineFunction *MF=0) const override
bool eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj, unsigned FIOperandNum, RegScavenger *RS=nullptr) const override
const uint32_t * getCallPreservedMask(const MachineFunction &MF, CallingConv::ID) const override
Register getFrameRegister(const MachineFunction &MF) const override
BitVector getReservedRegs(const MachineFunction &MF) const override
@ Kill
The last use of a register.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
bool isValidAddrOffset(int Scale, int64_t OffsetVal)
Definition: XtensaUtils.cpp:17