LLVM 24.0.0git
NVPTXFrameLowering.cpp
Go to the documentation of this file.
1//=======- NVPTXFrameLowering.cpp - NVPTX Frame Information ---*- C++ -*-=====//
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 NVPTX implementation of TargetFrameLowering class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "NVPTXFrameLowering.h"
15#include "NVPTX.h"
16#include "NVPTXRegisterInfo.h"
17#include "NVPTXSubtarget.h"
23
24using namespace llvm;
25
28
30 return true;
31}
32
34 MachineBasicBlock &MBB) const {
35 if (MF.getFrameInfo().hasStackObjects()) {
36 assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported");
39
40 const NVPTXRegisterInfo *NRI =
41 MF.getSubtarget<NVPTXSubtarget>().getRegisterInfo();
42
43 // This instruction really occurs before first instruction
44 // in the BB, so giving it no debug location.
45 DebugLoc dl = DebugLoc();
46
47 // Emits the %SPL depot move and, when %SP is used, cvta.local.
48 // Mixed-width targets widen %SPL before cvta.local.
49 const Register FrameReg = NRI->getFrameRegister(MF);
50 const Register FrameLocalReg = NRI->getFrameLocalRegister(MF);
51 const bool Is64Bit = FrameReg == NVPTX::VRFrame64;
52 const bool IsLocal64 = FrameLocalReg == NVPTX::VRFrameLocal64;
53 unsigned CvtaLocalOpcode =
54 (Is64Bit ? NVPTX::cvta_local_64 : NVPTX::cvta_local_32);
55 unsigned MovDepotOpcode =
56 (IsLocal64 ? NVPTX::MOV_DEPOT_ADDR_64 : NVPTX::MOV_DEPOT_ADDR);
57 if (!MR.use_empty(FrameReg)) {
58 // If %SP is not used, do not bother emitting "cvta.local %SP, %SPL".
59 MBBI = BuildMI(MBB, MBBI, dl,
60 MF.getSubtarget().getInstrInfo()->get(CvtaLocalOpcode),
61 FrameReg)
62 .addReg(Is64Bit == IsLocal64 ? FrameLocalReg : FrameReg);
63 if (Is64Bit && !IsLocal64) {
64 // Widen %SPL before converting it to a generic pointer.
65 MBBI =
66 BuildMI(MBB, MBBI, dl,
67 MF.getSubtarget().getInstrInfo()->get(NVPTX::CVT_u64_u32),
68 FrameReg)
69 .addReg(FrameLocalReg)
71 }
72 }
73 if (!MR.use_empty(FrameLocalReg)) {
74 BuildMI(MBB, MBBI, dl,
75 MF.getSubtarget().getInstrInfo()->get(MovDepotOpcode),
76 FrameLocalReg)
78 }
79 }
80}
81
84 Register &FrameReg) const {
85 const MachineFrameInfo &MFI = MF.getFrameInfo();
86 FrameReg = NVPTX::VRDepot;
89}
90
93
94// This function eliminates ADJCALLSTACKDOWN,
95// ADJCALLSTACKUP pseudo instructions
99 // Simply discard ADJCALLSTACKDOWN,
100 // ADJCALLSTACKUP instructions.
101 return MBB.erase(I);
102}
103
106 DwarfFrameBase FrameBase;
107 FrameBase.Kind = DwarfFrameBase::CFA;
108 FrameBase.Location.Offset = 0;
109 return FrameBase;
110}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator MBBI
#define I(x, y, z)
Definition MD5.cpp:57
A debug info location.
Definition DebugLoc.h:126
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
Definition MCInstrInfo.h:89
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
bool hasStackObjects() const
Return true if there are any stack objects in this function.
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
unsigned getFunctionNumber() const
getFunctionNumber - Return a unique ID for the current function.
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.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const MachineBasicBlock & front() const
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
bool use_empty(Register RegNo) const
use_empty - Return true if there are no instructions using the specified register.
DwarfFrameBase getDwarfFrameBase(const MachineFunction &MF) const override
Return the frame base information to be encoded in the DWARF subprogram debug info.
bool hasFPImpl(const MachineFunction &MF) const override
MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const override
getFrameIndexReference - This method should return the base register and offset used to reference a f...
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
Register getFrameLocalRegister(const MachineFunction &MF) const
Register getFrameRegister(const MachineFunction &MF) const override
Wrapper class representing virtual and physical registers.
Definition Register.h:20
StackOffset holds a fixed and a scalable offset in bytes.
Definition TypeSize.h:30
int64_t getFixed() const
Returns the fixed component of the stack.
Definition TypeSize.h:46
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
TargetFrameLowering(StackDirection D, Align StackAl, int LAO, Align TransAl=Align(1), bool StackReal=true)
virtual const TargetInstrInfo * getInstrInfo() const
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
union llvm::TargetFrameLowering::DwarfFrameBase::@004076321055032247336074224075335064105264310375 Location
enum llvm::TargetFrameLowering::DwarfFrameBase::FrameBaseKind Kind