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" |
| 19 | #include "llvm/ADT/BitVector.h" |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineFunction.h" |
| 22 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Justin Holewinski | 871ec93 | 2013-08-06 14:13:31 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 24 | #include "llvm/MC/MachineLocation.h" |
| 25 | #include "llvm/Target/TargetInstrInfo.h" |
| 26 | |
| 27 | using namespace llvm; |
| 28 | |
Eric Christopher | 02389e3 | 2015-02-19 00:08:27 +0000 | [diff] [blame] | 29 | NVPTXFrameLowering::NVPTXFrameLowering() |
| 30 | : TargetFrameLowering(TargetFrameLowering::StackGrowsUp, 8, 0) {} |
Eric Christopher | dd440f8 | 2014-06-27 02:05:24 +0000 | [diff] [blame] | 31 | |
Justin Holewinski | 0497ab1 | 2013-03-30 14:29:21 +0000 | [diff] [blame] | 32 | bool NVPTXFrameLowering::hasFP(const MachineFunction &MF) const { return true; } |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 33 | |
Quentin Colombet | 61b305e | 2015-05-05 17:38:16 +0000 | [diff] [blame] | 34 | void NVPTXFrameLowering::emitPrologue(MachineFunction &MF, |
| 35 | MachineBasicBlock &MBB) const { |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 36 | if (MF.getFrameInfo()->hasStackObjects()) { |
Quentin Colombet | 61b305e | 2015-05-05 17:38:16 +0000 | [diff] [blame] | 37 | assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported"); |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 38 | // Insert "mov.u32 %SP, %Depot" |
Jingyue Wu | 9c71150 | 2015-06-24 20:20:16 +0000 | [diff] [blame^] | 39 | MachineInstr *MI = MBB.begin(); |
| 40 | MachineRegisterInfo &MR = MF.getRegInfo(); |
| 41 | |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 42 | // This instruction really occurs before first instruction |
| 43 | // in the BB, so giving it no debug location. |
| 44 | DebugLoc dl = DebugLoc(); |
| 45 | |
Justin Holewinski | 871ec93 | 2013-08-06 14:13:31 +0000 | [diff] [blame] | 46 | // mov %SPL, %depot; |
| 47 | // cvta.local %SP, %SPL; |
Eric Christopher | 02389e3 | 2015-02-19 00:08:27 +0000 | [diff] [blame] | 48 | if (static_cast<const NVPTXTargetMachine &>(MF.getTarget()).is64Bit()) { |
Jingyue Wu | 9c71150 | 2015-06-24 20:20:16 +0000 | [diff] [blame^] | 49 | // Check if %SP is actually used |
| 50 | if (MR.hasOneNonDBGUse(NVPTX::VRFrame)) { |
| 51 | MI = BuildMI(MBB, MI, dl, MF.getSubtarget().getInstrInfo()->get( |
| 52 | NVPTX::cvta_local_yes_64), |
| 53 | NVPTX::VRFrame) |
| 54 | .addReg(NVPTX::VRFrameLocal); |
| 55 | } |
| 56 | |
Eric Christopher | f0dad26 | 2014-06-27 02:05:22 +0000 | [diff] [blame] | 57 | BuildMI(MBB, MI, dl, |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 58 | MF.getSubtarget().getInstrInfo()->get(NVPTX::MOV_DEPOT_ADDR_64), |
Jingyue Wu | 9c71150 | 2015-06-24 20:20:16 +0000 | [diff] [blame^] | 59 | NVPTX::VRFrameLocal) |
| 60 | .addImm(MF.getFunctionNumber()); |
Justin Holewinski | 0497ab1 | 2013-03-30 14:29:21 +0000 | [diff] [blame] | 61 | } else { |
Jingyue Wu | 9c71150 | 2015-06-24 20:20:16 +0000 | [diff] [blame^] | 62 | // Check if %SP is actually used |
| 63 | if (MR.hasOneNonDBGUse(NVPTX::VRFrame)) { |
| 64 | MI = BuildMI(MBB, MI, dl, MF.getSubtarget().getInstrInfo()->get( |
| 65 | NVPTX::cvta_local_yes), |
| 66 | NVPTX::VRFrame) |
| 67 | .addReg(NVPTX::VRFrameLocal); |
| 68 | } |
Eric Christopher | f0dad26 | 2014-06-27 02:05:22 +0000 | [diff] [blame] | 69 | BuildMI(MBB, MI, dl, |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 70 | MF.getSubtarget().getInstrInfo()->get(NVPTX::MOV_DEPOT_ADDR), |
Jingyue Wu | 9c71150 | 2015-06-24 20:20:16 +0000 | [diff] [blame^] | 71 | NVPTX::VRFrameLocal) |
| 72 | .addImm(MF.getFunctionNumber()); |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | void NVPTXFrameLowering::emitEpilogue(MachineFunction &MF, |
Justin Holewinski | 0497ab1 | 2013-03-30 14:29:21 +0000 | [diff] [blame] | 78 | MachineBasicBlock &MBB) const {} |
Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 79 | |
| 80 | // This function eliminates ADJCALLSTACKDOWN, |
| 81 | // ADJCALLSTACKUP pseudo instructions |
Justin Holewinski | 0497ab1 | 2013-03-30 14:29:21 +0000 | [diff] [blame] | 82 | void NVPTXFrameLowering::eliminateCallFramePseudoInstr( |
| 83 | MachineFunction &MF, MachineBasicBlock &MBB, |
| 84 | MachineBasicBlock::iterator I) const { |
Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 85 | // Simply discard ADJCALLSTACKDOWN, |
| 86 | // ADJCALLSTACKUP instructions. |
| 87 | MBB.erase(I); |
| 88 | } |