Path: blob/main/contrib/llvm-project/llvm/lib/Target/NVPTX/NVPTXFrameLowering.cpp
35271 views
//=======- NVPTXFrameLowering.cpp - NVPTX Frame Information ---*- C++ -*-=====//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file contains the NVPTX implementation of TargetFrameLowering class.9//10//===----------------------------------------------------------------------===//1112#include "NVPTXFrameLowering.h"13#include "NVPTX.h"14#include "NVPTXRegisterInfo.h"15#include "NVPTXSubtarget.h"16#include "NVPTXTargetMachine.h"17#include "llvm/CodeGen/MachineFrameInfo.h"18#include "llvm/CodeGen/MachineFunction.h"19#include "llvm/CodeGen/MachineInstrBuilder.h"20#include "llvm/CodeGen/MachineRegisterInfo.h"21#include "llvm/CodeGen/TargetInstrInfo.h"22#include "llvm/MC/MachineLocation.h"2324using namespace llvm;2526NVPTXFrameLowering::NVPTXFrameLowering()27: TargetFrameLowering(TargetFrameLowering::StackGrowsUp, Align(8), 0) {}2829bool NVPTXFrameLowering::hasFP(const MachineFunction &MF) const { return true; }3031void NVPTXFrameLowering::emitPrologue(MachineFunction &MF,32MachineBasicBlock &MBB) const {33if (MF.getFrameInfo().hasStackObjects()) {34assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported");35MachineBasicBlock::iterator MBBI = MBB.begin();36MachineRegisterInfo &MR = MF.getRegInfo();3738const NVPTXRegisterInfo *NRI =39MF.getSubtarget<NVPTXSubtarget>().getRegisterInfo();4041// This instruction really occurs before first instruction42// in the BB, so giving it no debug location.43DebugLoc dl = DebugLoc();4445// Emits46// mov %SPL, %depot;47// cvta.local %SP, %SPL;48// for local address accesses in MF.49bool Is64Bit =50static_cast<const NVPTXTargetMachine &>(MF.getTarget()).is64Bit();51unsigned CvtaLocalOpcode =52(Is64Bit ? NVPTX::cvta_local_64 : NVPTX::cvta_local);53unsigned MovDepotOpcode =54(Is64Bit ? NVPTX::MOV_DEPOT_ADDR_64 : NVPTX::MOV_DEPOT_ADDR);55if (!MR.use_empty(NRI->getFrameRegister(MF))) {56// If %SP is not used, do not bother emitting "cvta.local %SP, %SPL".57MBBI = BuildMI(MBB, MBBI, dl,58MF.getSubtarget().getInstrInfo()->get(CvtaLocalOpcode),59NRI->getFrameRegister(MF))60.addReg(NRI->getFrameLocalRegister(MF));61}62if (!MR.use_empty(NRI->getFrameLocalRegister(MF))) {63BuildMI(MBB, MBBI, dl,64MF.getSubtarget().getInstrInfo()->get(MovDepotOpcode),65NRI->getFrameLocalRegister(MF))66.addImm(MF.getFunctionNumber());67}68}69}7071StackOffset72NVPTXFrameLowering::getFrameIndexReference(const MachineFunction &MF, int FI,73Register &FrameReg) const {74const MachineFrameInfo &MFI = MF.getFrameInfo();75FrameReg = NVPTX::VRDepot;76return StackOffset::getFixed(MFI.getObjectOffset(FI) -77getOffsetOfLocalArea());78}7980void NVPTXFrameLowering::emitEpilogue(MachineFunction &MF,81MachineBasicBlock &MBB) const {}8283// This function eliminates ADJCALLSTACKDOWN,84// ADJCALLSTACKUP pseudo instructions85MachineBasicBlock::iterator NVPTXFrameLowering::eliminateCallFramePseudoInstr(86MachineFunction &MF, MachineBasicBlock &MBB,87MachineBasicBlock::iterator I) const {88// Simply discard ADJCALLSTACKDOWN,89// ADJCALLSTACKUP instructions.90return MBB.erase(I);91}9293TargetFrameLowering::DwarfFrameBase94NVPTXFrameLowering::getDwarfFrameBase(const MachineFunction &MF) const {95DwarfFrameBase FrameBase;96FrameBase.Kind = DwarfFrameBase::CFA;97FrameBase.Location.Offset = 0;98return FrameBase;99}100101102