NVPTXFrameLowering.cpp revision d04a8d4b33ff316ca4cf961e06c9e312eff8e64f
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" 2349683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski#include "llvm/MC/MachineLocation.h" 2449683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski#include "llvm/Target/TargetInstrInfo.h" 2549683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski 2649683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinskiusing namespace llvm; 2749683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski 2849683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinskibool NVPTXFrameLowering::hasFP(const MachineFunction &MF) const { 2949683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski return true; 3049683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski} 3149683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski 3249683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinskivoid NVPTXFrameLowering::emitPrologue(MachineFunction &MF) const { 3349683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski if (MF.getFrameInfo()->hasStackObjects()) { 3449683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski MachineBasicBlock &MBB = MF.front(); 3549683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski // Insert "mov.u32 %SP, %Depot" 3649683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski MachineBasicBlock::iterator MBBI = MBB.begin(); 3749683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski // This instruction really occurs before first instruction 3849683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski // in the BB, so giving it no debug location. 3949683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski DebugLoc dl = DebugLoc(); 4049683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski 4149683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski if (tm.getSubtargetImpl()->hasGenericLdSt()) { 4249683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski // mov %SPL, %depot; 4349683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski // cvta.local %SP, %SPL; 4449683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski if (is64bit) { 4549683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski MachineInstr *MI = BuildMI(MBB, MBBI, dl, 4649683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski tm.getInstrInfo()->get(NVPTX::cvta_local_yes_64), 4749683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski NVPTX::VRFrame).addReg(NVPTX::VRFrameLocal); 4849683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski BuildMI(MBB, MI, dl, 4949683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski tm.getInstrInfo()->get(NVPTX::IMOV64rr), NVPTX::VRFrameLocal) 5049683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski .addReg(NVPTX::VRDepot); 5149683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski } else { 5249683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski MachineInstr *MI = BuildMI(MBB, MBBI, dl, 5349683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski tm.getInstrInfo()->get(NVPTX::cvta_local_yes), 5449683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski NVPTX::VRFrame).addReg(NVPTX::VRFrameLocal); 5549683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski BuildMI(MBB, MI, dl, 5649683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski tm.getInstrInfo()->get(NVPTX::IMOV32rr), NVPTX::VRFrameLocal) 5749683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski .addReg(NVPTX::VRDepot); 5849683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski } 5949683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski } 6049683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski else { 6149683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski // mov %SP, %depot; 6249683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski if (is64bit) 6349683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski BuildMI(MBB, MBBI, dl, 6449683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski tm.getInstrInfo()->get(NVPTX::IMOV64rr), NVPTX::VRFrame) 6549683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski .addReg(NVPTX::VRDepot); 6649683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski else 6749683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski BuildMI(MBB, MBBI, dl, 6849683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski tm.getInstrInfo()->get(NVPTX::IMOV32rr), NVPTX::VRFrame) 6949683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski .addReg(NVPTX::VRDepot); 7049683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski } 7149683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski } 7249683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski} 7349683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski 7449683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinskivoid NVPTXFrameLowering::emitEpilogue(MachineFunction &MF, 7549683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski MachineBasicBlock &MBB) const { 7649683f3c961379fbc088871a5d6304950f1f1cbcJustin Holewinski} 77