Justin Holewinski | 49683f3 | 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 | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineFunction.h" |
| 22 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Justin Holewinski | 49683f3 | 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 | |
Justin Holewinski | 3639ce2 | 2013-03-30 14:29:21 +0000 | [diff] [blame^] | 28 | bool NVPTXFrameLowering::hasFP(const MachineFunction &MF) const { return true; } |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 29 | |
| 30 | void NVPTXFrameLowering::emitPrologue(MachineFunction &MF) const { |
| 31 | if (MF.getFrameInfo()->hasStackObjects()) { |
| 32 | MachineBasicBlock &MBB = MF.front(); |
| 33 | // Insert "mov.u32 %SP, %Depot" |
| 34 | MachineBasicBlock::iterator MBBI = MBB.begin(); |
| 35 | // This instruction really occurs before first instruction |
| 36 | // in the BB, so giving it no debug location. |
| 37 | DebugLoc dl = DebugLoc(); |
| 38 | |
| 39 | if (tm.getSubtargetImpl()->hasGenericLdSt()) { |
| 40 | // mov %SPL, %depot; |
| 41 | // cvta.local %SP, %SPL; |
| 42 | if (is64bit) { |
Justin Holewinski | 3639ce2 | 2013-03-30 14:29:21 +0000 | [diff] [blame^] | 43 | MachineInstr *MI = BuildMI( |
| 44 | MBB, MBBI, dl, tm.getInstrInfo()->get(NVPTX::cvta_local_yes_64), |
| 45 | NVPTX::VRFrame).addReg(NVPTX::VRFrameLocal); |
| 46 | BuildMI(MBB, MI, dl, tm.getInstrInfo()->get(NVPTX::IMOV64rr), |
| 47 | NVPTX::VRFrameLocal).addReg(NVPTX::VRDepot); |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 48 | } else { |
Justin Holewinski | 3639ce2 | 2013-03-30 14:29:21 +0000 | [diff] [blame^] | 49 | MachineInstr *MI = BuildMI( |
| 50 | MBB, MBBI, dl, tm.getInstrInfo()->get(NVPTX::cvta_local_yes), |
| 51 | NVPTX::VRFrame).addReg(NVPTX::VRFrameLocal); |
| 52 | BuildMI(MBB, MI, dl, tm.getInstrInfo()->get(NVPTX::IMOV32rr), |
| 53 | NVPTX::VRFrameLocal).addReg(NVPTX::VRDepot); |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 54 | } |
Justin Holewinski | 3639ce2 | 2013-03-30 14:29:21 +0000 | [diff] [blame^] | 55 | } else { |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 56 | // mov %SP, %depot; |
| 57 | if (is64bit) |
Justin Holewinski | 3639ce2 | 2013-03-30 14:29:21 +0000 | [diff] [blame^] | 58 | BuildMI(MBB, MBBI, dl, tm.getInstrInfo()->get(NVPTX::IMOV64rr), |
| 59 | NVPTX::VRFrame).addReg(NVPTX::VRDepot); |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 60 | else |
Justin Holewinski | 3639ce2 | 2013-03-30 14:29:21 +0000 | [diff] [blame^] | 61 | BuildMI(MBB, MBBI, dl, tm.getInstrInfo()->get(NVPTX::IMOV32rr), |
| 62 | NVPTX::VRFrame).addReg(NVPTX::VRDepot); |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | void NVPTXFrameLowering::emitEpilogue(MachineFunction &MF, |
Justin Holewinski | 3639ce2 | 2013-03-30 14:29:21 +0000 | [diff] [blame^] | 68 | MachineBasicBlock &MBB) const {} |
Eli Bendersky | 700ed80 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 69 | |
| 70 | // This function eliminates ADJCALLSTACKDOWN, |
| 71 | // ADJCALLSTACKUP pseudo instructions |
Justin Holewinski | 3639ce2 | 2013-03-30 14:29:21 +0000 | [diff] [blame^] | 72 | void NVPTXFrameLowering::eliminateCallFramePseudoInstr( |
| 73 | MachineFunction &MF, MachineBasicBlock &MBB, |
| 74 | MachineBasicBlock::iterator I) const { |
Eli Bendersky | 700ed80 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 75 | // Simply discard ADJCALLSTACKDOWN, |
| 76 | // ADJCALLSTACKUP instructions. |
| 77 | MBB.erase(I); |
| 78 | } |