Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 1 | //=======- NVPTXFrameLowering.cpp - NVPTX Frame Information ---*- C++ -*-=====// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 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" |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineFunction.h" |
| 20 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Justin Holewinski | 871ec93 | 2013-08-06 14:13:31 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
David Blaikie | 3f833ed | 2017-11-08 01:01:31 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/TargetInstrInfo.h" |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MachineLocation.h" |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 24 | |
| 25 | using namespace llvm; |
| 26 | |
Eric Christopher | 02389e3 | 2015-02-19 00:08:27 +0000 | [diff] [blame] | 27 | NVPTXFrameLowering::NVPTXFrameLowering() |
Guillaume Chatelet | 882c43d | 2019-10-17 07:49:39 +0000 | [diff] [blame^] | 28 | : TargetFrameLowering(TargetFrameLowering::StackGrowsUp, Align(8), 0) {} |
Eric Christopher | dd440f8 | 2014-06-27 02:05:24 +0000 | [diff] [blame] | 29 | |
Justin Holewinski | 0497ab1 | 2013-03-30 14:29:21 +0000 | [diff] [blame] | 30 | bool NVPTXFrameLowering::hasFP(const MachineFunction &MF) const { return true; } |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 31 | |
Quentin Colombet | 61b305e | 2015-05-05 17:38:16 +0000 | [diff] [blame] | 32 | void NVPTXFrameLowering::emitPrologue(MachineFunction &MF, |
| 33 | MachineBasicBlock &MBB) const { |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 34 | if (MF.getFrameInfo().hasStackObjects()) { |
Quentin Colombet | 61b305e | 2015-05-05 17:38:16 +0000 | [diff] [blame] | 35 | assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported"); |
Duncan P. N. Exon Smith | 68f499a | 2016-07-08 21:10:58 +0000 | [diff] [blame] | 36 | MachineInstr *MI = &MBB.front(); |
Jingyue Wu | 9c71150 | 2015-06-24 20:20:16 +0000 | [diff] [blame] | 37 | MachineRegisterInfo &MR = MF.getRegInfo(); |
| 38 | |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 39 | // This instruction really occurs before first instruction |
| 40 | // in the BB, so giving it no debug location. |
| 41 | DebugLoc dl = DebugLoc(); |
| 42 | |
Jingyue Wu | b374dc6 | 2015-06-30 21:28:31 +0000 | [diff] [blame] | 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); |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 59 | } |
Jingyue Wu | b374dc6 | 2015-06-30 21:28:31 +0000 | [diff] [blame] | 60 | BuildMI(MBB, MI, dl, MF.getSubtarget().getInstrInfo()->get(MovDepotOpcode), |
| 61 | NVPTX::VRFrameLocal) |
| 62 | .addImm(MF.getFunctionNumber()); |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | |
Alexey Bataev | 4dd7558 | 2018-07-26 16:29:52 +0000 | [diff] [blame] | 66 | int NVPTXFrameLowering::getFrameIndexReference(const MachineFunction &MF, |
| 67 | int FI, |
| 68 | unsigned &FrameReg) const { |
| 69 | const MachineFrameInfo &MFI = MF.getFrameInfo(); |
| 70 | FrameReg = NVPTX::VRDepot; |
| 71 | return MFI.getObjectOffset(FI) - getOffsetOfLocalArea(); |
| 72 | } |
| 73 | |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 74 | void NVPTXFrameLowering::emitEpilogue(MachineFunction &MF, |
Justin Holewinski | 0497ab1 | 2013-03-30 14:29:21 +0000 | [diff] [blame] | 75 | MachineBasicBlock &MBB) const {} |
Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 76 | |
| 77 | // This function eliminates ADJCALLSTACKDOWN, |
| 78 | // ADJCALLSTACKUP pseudo instructions |
Hans Wennborg | e1a2e90 | 2016-03-31 18:33:38 +0000 | [diff] [blame] | 79 | MachineBasicBlock::iterator NVPTXFrameLowering::eliminateCallFramePseudoInstr( |
Justin Holewinski | 0497ab1 | 2013-03-30 14:29:21 +0000 | [diff] [blame] | 80 | MachineFunction &MF, MachineBasicBlock &MBB, |
| 81 | MachineBasicBlock::iterator I) const { |
Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 82 | // Simply discard ADJCALLSTACKDOWN, |
| 83 | // ADJCALLSTACKUP instructions. |
Hans Wennborg | e1a2e90 | 2016-03-31 18:33:38 +0000 | [diff] [blame] | 84 | return MBB.erase(I); |
Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 85 | } |