Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 1 | //=======- NVPTXFrameLowering.cpp - NVPTX Frame Information ---*- C++ -*-=====// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains the NVPTX implementation of TargetFrameLowering class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "NVPTXFrameLowering.h" |
| 15 | #include "NVPTX.h" |
| 16 | #include "NVPTXRegisterInfo.h" |
| 17 | #include "NVPTXSubtarget.h" |
| 18 | #include "NVPTXTargetMachine.h" |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineFunction.h" |
| 21 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Justin Holewinski | 871ec93 | 2013-08-06 14:13:31 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MachineLocation.h" |
| 24 | #include "llvm/Target/TargetInstrInfo.h" |
| 25 | |
| 26 | using namespace llvm; |
| 27 | |
Eric Christopher | 02389e3 | 2015-02-19 00:08:27 +0000 | [diff] [blame] | 28 | NVPTXFrameLowering::NVPTXFrameLowering() |
| 29 | : TargetFrameLowering(TargetFrameLowering::StackGrowsUp, 8, 0) {} |
Eric Christopher | dd440f8 | 2014-06-27 02:05:24 +0000 | [diff] [blame] | 30 | |
Justin Holewinski | 0497ab1 | 2013-03-30 14:29:21 +0000 | [diff] [blame] | 31 | bool NVPTXFrameLowering::hasFP(const MachineFunction &MF) const { return true; } |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 32 | |
Quentin Colombet | 61b305e | 2015-05-05 17:38:16 +0000 | [diff] [blame] | 33 | void NVPTXFrameLowering::emitPrologue(MachineFunction &MF, |
| 34 | MachineBasicBlock &MBB) const { |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame^] | 35 | if (MF.getFrameInfo().hasStackObjects()) { |
Quentin Colombet | 61b305e | 2015-05-05 17:38:16 +0000 | [diff] [blame] | 36 | assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported"); |
Duncan P. N. Exon Smith | 68f499a | 2016-07-08 21:10:58 +0000 | [diff] [blame] | 37 | MachineInstr *MI = &MBB.front(); |
Jingyue Wu | 9c71150 | 2015-06-24 20:20:16 +0000 | [diff] [blame] | 38 | MachineRegisterInfo &MR = MF.getRegInfo(); |
| 39 | |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 40 | // This instruction really occurs before first instruction |
| 41 | // in the BB, so giving it no debug location. |
| 42 | DebugLoc dl = DebugLoc(); |
| 43 | |
Jingyue Wu | b374dc6 | 2015-06-30 21:28:31 +0000 | [diff] [blame] | 44 | // Emits |
| 45 | // mov %SPL, %depot; |
| 46 | // cvta.local %SP, %SPL; |
| 47 | // for local address accesses in MF. |
| 48 | bool Is64Bit = |
| 49 | static_cast<const NVPTXTargetMachine &>(MF.getTarget()).is64Bit(); |
| 50 | unsigned CvtaLocalOpcode = |
| 51 | (Is64Bit ? NVPTX::cvta_local_yes_64 : NVPTX::cvta_local_yes); |
| 52 | unsigned MovDepotOpcode = |
| 53 | (Is64Bit ? NVPTX::MOV_DEPOT_ADDR_64 : NVPTX::MOV_DEPOT_ADDR); |
| 54 | if (!MR.use_empty(NVPTX::VRFrame)) { |
| 55 | // If %SP is not used, do not bother emitting "cvta.local %SP, %SPL". |
| 56 | MI = BuildMI(MBB, MI, dl, |
| 57 | MF.getSubtarget().getInstrInfo()->get(CvtaLocalOpcode), |
| 58 | NVPTX::VRFrame) |
| 59 | .addReg(NVPTX::VRFrameLocal); |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 60 | } |
Jingyue Wu | b374dc6 | 2015-06-30 21:28:31 +0000 | [diff] [blame] | 61 | BuildMI(MBB, MI, dl, MF.getSubtarget().getInstrInfo()->get(MovDepotOpcode), |
| 62 | NVPTX::VRFrameLocal) |
| 63 | .addImm(MF.getFunctionNumber()); |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 64 | } |
| 65 | } |
| 66 | |
| 67 | void NVPTXFrameLowering::emitEpilogue(MachineFunction &MF, |
Justin Holewinski | 0497ab1 | 2013-03-30 14:29:21 +0000 | [diff] [blame] | 68 | MachineBasicBlock &MBB) const {} |
Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 69 | |
| 70 | // This function eliminates ADJCALLSTACKDOWN, |
| 71 | // ADJCALLSTACKUP pseudo instructions |
Hans Wennborg | e1a2e90 | 2016-03-31 18:33:38 +0000 | [diff] [blame] | 72 | MachineBasicBlock::iterator NVPTXFrameLowering::eliminateCallFramePseudoInstr( |
Justin Holewinski | 0497ab1 | 2013-03-30 14:29:21 +0000 | [diff] [blame] | 73 | MachineFunction &MF, MachineBasicBlock &MBB, |
| 74 | MachineBasicBlock::iterator I) const { |
Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 75 | // Simply discard ADJCALLSTACKDOWN, |
| 76 | // ADJCALLSTACKUP instructions. |
Hans Wennborg | e1a2e90 | 2016-03-31 18:33:38 +0000 | [diff] [blame] | 77 | return MBB.erase(I); |
Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 78 | } |