LLVM  14.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"
14 #include "NVPTX.h"
15 #include "NVPTXRegisterInfo.h"
16 #include "NVPTXSubtarget.h"
17 #include "NVPTXTargetMachine.h"
24 
25 using namespace llvm;
26 
28  : TargetFrameLowering(TargetFrameLowering::StackGrowsUp, Align(8), 0) {}
29 
30 bool NVPTXFrameLowering::hasFP(const MachineFunction &MF) const { return true; }
31 
33  MachineBasicBlock &MBB) const {
34  if (MF.getFrameInfo().hasStackObjects()) {
35  assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported");
36  MachineInstr *MI = &MBB.front();
38 
39  // This instruction really occurs before first instruction
40  // in the BB, so giving it no debug location.
41  DebugLoc dl = DebugLoc();
42 
43  // Emits
44  // mov %SPL, %depot;
45  // cvta.local %SP, %SPL;
46  // for local address accesses in MF.
47  bool Is64Bit =
48  static_cast<const NVPTXTargetMachine &>(MF.getTarget()).is64Bit();
49  unsigned CvtaLocalOpcode =
50  (Is64Bit ? NVPTX::cvta_local_yes_64 : NVPTX::cvta_local_yes);
51  unsigned MovDepotOpcode =
52  (Is64Bit ? NVPTX::MOV_DEPOT_ADDR_64 : NVPTX::MOV_DEPOT_ADDR);
53  if (!MR.use_empty(NVPTX::VRFrame)) {
54  // If %SP is not used, do not bother emitting "cvta.local %SP, %SPL".
55  MI = BuildMI(MBB, MI, dl,
56  MF.getSubtarget().getInstrInfo()->get(CvtaLocalOpcode),
57  NVPTX::VRFrame)
58  .addReg(NVPTX::VRFrameLocal);
59  }
60  BuildMI(MBB, MI, dl, MF.getSubtarget().getInstrInfo()->get(MovDepotOpcode),
61  NVPTX::VRFrameLocal)
63  }
64 }
65 
68  Register &FrameReg) const {
69  const MachineFrameInfo &MFI = MF.getFrameInfo();
70  FrameReg = NVPTX::VRDepot;
71  return StackOffset::getFixed(MFI.getObjectOffset(FI) -
73 }
74 
76  MachineBasicBlock &MBB) const {}
77 
78 // This function eliminates ADJCALLSTACKDOWN,
79 // ADJCALLSTACKUP pseudo instructions
83  // Simply discard ADJCALLSTACKDOWN,
84  // ADJCALLSTACKUP instructions.
85  return MBB.erase(I);
86 }
87 
90  return {DwarfFrameBase::CFA, {0}};
91 }
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:103
llvm::MachineInstrBuilder::addImm
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Definition: MachineInstrBuilder.h:131
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::TargetFrameLowering
Information about stack frame layout on the target.
Definition: TargetFrameLowering.h:43
llvm::NVPTXFrameLowering::hasFP
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register.
Definition: NVPTXFrameLowering.cpp:30
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition: MachineRegisterInfo.h:52
llvm::TargetSubtargetInfo::getInstrInfo
virtual const TargetInstrInfo * getInstrInfo() const
Definition: TargetSubtargetInfo.h:92
is64Bit
static bool is64Bit(const char *name)
Definition: X86Disassembler.cpp:1023
llvm::NVPTXFrameLowering::getDwarfFrameBase
DwarfFrameBase getDwarfFrameBase(const MachineFunction &MF) const override
Return the frame base information to be encoded in the DWARF subprogram debug info.
Definition: NVPTXFrameLowering.cpp:89
llvm::MachineFunction::getFunctionNumber
unsigned getFunctionNumber() const
getFunctionNumber - Return a unique ID for the current function.
Definition: MachineFunction.h:601
llvm::StackOffset::getFixed
ScalarTy getFixed() const
Definition: TypeSize.h:149
TargetInstrInfo.h
llvm::TargetFrameLowering::DwarfFrameBase
Definition: TargetFrameLowering.h:56
llvm::NVPTXFrameLowering::eliminateCallFramePseudoInstr
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...
Definition: NVPTXFrameLowering.cpp:80
NVPTXRegisterInfo.h
llvm::NVPTXTargetMachine
NVPTXTargetMachine.
Definition: NVPTXTargetMachine.h:24
NVPTX.h
MachineRegisterInfo.h
llvm::MachineBasicBlock::erase
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
Definition: MachineBasicBlock.cpp:1299
llvm::MachineFrameInfo::hasStackObjects
bool hasStackObjects() const
Return true if there are any stack objects in this function.
Definition: MachineFrameInfo.h:348
llvm::NVPTXFrameLowering::emitEpilogue
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
Definition: NVPTXFrameLowering.cpp:75
llvm::MachineFunction::front
const MachineBasicBlock & front() const
Definition: MachineFunction.h:820
llvm::MachineFunction::getRegInfo
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Definition: MachineFunction.h:636
llvm::TargetFrameLowering::getOffsetOfLocalArea
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
Definition: TargetFrameLowering.h:140
llvm::TargetFrameLowering::DwarfFrameBase::CFA
@ CFA
Definition: TargetFrameLowering.h:59
llvm::MachineFrameInfo::getObjectOffset
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
Definition: MachineFrameInfo.h:494
llvm::NVPTXFrameLowering::emitPrologue
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
Definition: NVPTXFrameLowering.cpp:32
llvm::NVPTXFrameLowering::getFrameIndexReference
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...
Definition: NVPTXFrameLowering.cpp:67
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::MachineRegisterInfo::use_empty
bool use_empty(Register RegNo) const
use_empty - Return true if there are no instructions using the specified register.
Definition: MachineRegisterInfo.h:506
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:626
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
I
#define I(x, y, z)
Definition: MD5.cpp:59
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::MachineFunction::getFrameInfo
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Definition: MachineFunction.h:642
llvm::MachineInstrBuilder::addReg
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Definition: MachineInstrBuilder.h:97
llvm::MachineFunction
Definition: MachineFunction.h:230
MachineLocation.h
llvm::StackOffset
StackOffset is a class to represent an offset with 2 dimensions, named fixed and scalable,...
Definition: TypeSize.h:134
llvm::NVPTXFrameLowering::NVPTXFrameLowering
NVPTXFrameLowering()
Definition: NVPTXFrameLowering.cpp:27
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::MachineFunction::getTarget
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Definition: MachineFunction.h:622
MachineFrameInfo.h
NVPTXTargetMachine.h
llvm::MachineBasicBlock::front
MachineInstr & front()
Definition: MachineBasicBlock.h:247
llvm::MachineFrameInfo
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Definition: MachineFrameInfo.h:107
MachineInstrBuilder.h
llvm::BuildMI
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
Definition: MachineInstrBuilder.h:328
NVPTXSubtarget.h
NVPTXFrameLowering.h
llvm::MCInstrInfo::get
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
Definition: MCInstrInfo.h:62
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
MachineFunction.h
llvm::MachineInstrBundleIterator< MachineInstr >