149683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski//=======- NVPTXFrameLowering.cpp - NVPTX Frame Information ---*- C++ -*-=====// 249683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski// 349683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski// The LLVM Compiler Infrastructure 449683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski// 549683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski// This file is distributed under the University of Illinois Open Source 649683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski// License. See LICENSE.TXT for details. 749683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski// 849683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski//===----------------------------------------------------------------------===// 949683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski// 1049683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski// This file contains the NVPTX implementation of TargetFrameLowering class. 1149683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski// 1249683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski//===----------------------------------------------------------------------===// 1349683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski 1449683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski#include "NVPTXFrameLowering.h" 1549683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski#include "NVPTX.h" 1649683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski#include "NVPTXRegisterInfo.h" 1749683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski#include "NVPTXSubtarget.h" 1849683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski#include "NVPTXTargetMachine.h" 1949683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski#include "llvm/ADT/BitVector.h" 2049683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski#include "llvm/CodeGen/MachineFrameInfo.h" 21d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/CodeGen/MachineFunction.h" 22d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/CodeGen/MachineInstrBuilder.h" 23a3635eefc749389aed84d9791fab657297203e1bJustin Holewinski#include "llvm/CodeGen/MachineRegisterInfo.h" 2449683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski#include "llvm/MC/MachineLocation.h" 2549683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski#include "llvm/Target/TargetInstrInfo.h" 2649683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski 2749683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinskiusing namespace llvm; 2849683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski 293639ce2575660a0e6938d2e84e8bd9a738fd7051Justin Holewinskibool NVPTXFrameLowering::hasFP(const MachineFunction &MF) const { return true; } 3049683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski 3149683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinskivoid NVPTXFrameLowering::emitPrologue(MachineFunction &MF) const { 3249683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski if (MF.getFrameInfo()->hasStackObjects()) { 3349683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski MachineBasicBlock &MBB = MF.front(); 3449683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski // Insert "mov.u32 %SP, %Depot" 3549683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski MachineBasicBlock::iterator MBBI = MBB.begin(); 3649683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski // This instruction really occurs before first instruction 3749683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski // in the BB, so giving it no debug location. 3849683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski DebugLoc dl = DebugLoc(); 3949683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski 40a3635eefc749389aed84d9791fab657297203e1bJustin Holewinski MachineRegisterInfo &MRI = MF.getRegInfo(); 41a3635eefc749389aed84d9791fab657297203e1bJustin Holewinski 42a3635eefc749389aed84d9791fab657297203e1bJustin Holewinski // mov %SPL, %depot; 43a3635eefc749389aed84d9791fab657297203e1bJustin Holewinski // cvta.local %SP, %SPL; 44a3635eefc749389aed84d9791fab657297203e1bJustin Holewinski if (is64bit) { 45a3635eefc749389aed84d9791fab657297203e1bJustin Holewinski unsigned LocalReg = MRI.createVirtualRegister(&NVPTX::Int64RegsRegClass); 46a3635eefc749389aed84d9791fab657297203e1bJustin Holewinski MachineInstr *MI = BuildMI( 47a3635eefc749389aed84d9791fab657297203e1bJustin Holewinski MBB, MBBI, dl, tm.getInstrInfo()->get(NVPTX::cvta_local_yes_64), 48a3635eefc749389aed84d9791fab657297203e1bJustin Holewinski NVPTX::VRFrame).addReg(LocalReg); 49a3635eefc749389aed84d9791fab657297203e1bJustin Holewinski BuildMI(MBB, MI, dl, tm.getInstrInfo()->get(NVPTX::MOV_DEPOT_ADDR_64), 50a3635eefc749389aed84d9791fab657297203e1bJustin Holewinski LocalReg).addImm(MF.getFunctionNumber()); 513639ce2575660a0e6938d2e84e8bd9a738fd7051Justin Holewinski } else { 52a3635eefc749389aed84d9791fab657297203e1bJustin Holewinski unsigned LocalReg = MRI.createVirtualRegister(&NVPTX::Int32RegsRegClass); 53a3635eefc749389aed84d9791fab657297203e1bJustin Holewinski MachineInstr *MI = BuildMI( 54a3635eefc749389aed84d9791fab657297203e1bJustin Holewinski MBB, MBBI, dl, tm.getInstrInfo()->get(NVPTX::cvta_local_yes), 55a3635eefc749389aed84d9791fab657297203e1bJustin Holewinski NVPTX::VRFrame).addReg(LocalReg); 56a3635eefc749389aed84d9791fab657297203e1bJustin Holewinski BuildMI(MBB, MI, dl, tm.getInstrInfo()->get(NVPTX::MOV_DEPOT_ADDR), 57a3635eefc749389aed84d9791fab657297203e1bJustin Holewinski LocalReg).addImm(MF.getFunctionNumber()); 5849683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski } 5949683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski } 6049683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski} 6149683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski 6249683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinskivoid NVPTXFrameLowering::emitEpilogue(MachineFunction &MF, 633639ce2575660a0e6938d2e84e8bd9a738fd7051Justin Holewinski MachineBasicBlock &MBB) const {} 64700ed80d3da5e98e05ceb90e9bfb66058581a6dbEli Bendersky 65700ed80d3da5e98e05ceb90e9bfb66058581a6dbEli Bendersky// This function eliminates ADJCALLSTACKDOWN, 66700ed80d3da5e98e05ceb90e9bfb66058581a6dbEli Bendersky// ADJCALLSTACKUP pseudo instructions 673639ce2575660a0e6938d2e84e8bd9a738fd7051Justin Holewinskivoid NVPTXFrameLowering::eliminateCallFramePseudoInstr( 683639ce2575660a0e6938d2e84e8bd9a738fd7051Justin Holewinski MachineFunction &MF, MachineBasicBlock &MBB, 693639ce2575660a0e6938d2e84e8bd9a738fd7051Justin Holewinski MachineBasicBlock::iterator I) const { 70700ed80d3da5e98e05ceb90e9bfb66058581a6dbEli Bendersky // Simply discard ADJCALLSTACKDOWN, 71700ed80d3da5e98e05ceb90e9bfb66058581a6dbEli Bendersky // ADJCALLSTACKUP instructions. 72700ed80d3da5e98e05ceb90e9bfb66058581a6dbEli Bendersky MBB.erase(I); 73700ed80d3da5e98e05ceb90e9bfb66058581a6dbEli Bendersky} 74