blob: 6533da5102b0fe22734a6aa3456f2ee4dd481915 [file] [log] [blame]
Justin Holewinski49683f32012-05-04 20:18:50 +00001//=======- 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 Holewinski49683f32012-05-04 20:18:50 +000020#include "llvm/CodeGen/MachineFrameInfo.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000021#include "llvm/CodeGen/MachineFunction.h"
22#include "llvm/CodeGen/MachineInstrBuilder.h"
Justin Holewinski49683f32012-05-04 20:18:50 +000023#include "llvm/MC/MachineLocation.h"
24#include "llvm/Target/TargetInstrInfo.h"
25
26using namespace llvm;
27
Justin Holewinski3639ce22013-03-30 14:29:21 +000028bool NVPTXFrameLowering::hasFP(const MachineFunction &MF) const { return true; }
Justin Holewinski49683f32012-05-04 20:18:50 +000029
30void 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 Holewinski3639ce22013-03-30 14:29:21 +000043 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 Holewinski49683f32012-05-04 20:18:50 +000048 } else {
Justin Holewinski3639ce22013-03-30 14:29:21 +000049 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 Holewinski49683f32012-05-04 20:18:50 +000054 }
Justin Holewinski3639ce22013-03-30 14:29:21 +000055 } else {
Justin Holewinski49683f32012-05-04 20:18:50 +000056 // mov %SP, %depot;
57 if (is64bit)
Justin Holewinski3639ce22013-03-30 14:29:21 +000058 BuildMI(MBB, MBBI, dl, tm.getInstrInfo()->get(NVPTX::IMOV64rr),
59 NVPTX::VRFrame).addReg(NVPTX::VRDepot);
Justin Holewinski49683f32012-05-04 20:18:50 +000060 else
Justin Holewinski3639ce22013-03-30 14:29:21 +000061 BuildMI(MBB, MBBI, dl, tm.getInstrInfo()->get(NVPTX::IMOV32rr),
62 NVPTX::VRFrame).addReg(NVPTX::VRDepot);
Justin Holewinski49683f32012-05-04 20:18:50 +000063 }
64 }
65}
66
67void NVPTXFrameLowering::emitEpilogue(MachineFunction &MF,
Justin Holewinski3639ce22013-03-30 14:29:21 +000068 MachineBasicBlock &MBB) const {}
Eli Bendersky700ed802013-02-21 20:05:00 +000069
70// This function eliminates ADJCALLSTACKDOWN,
71// ADJCALLSTACKUP pseudo instructions
Justin Holewinski3639ce22013-03-30 14:29:21 +000072void NVPTXFrameLowering::eliminateCallFramePseudoInstr(
73 MachineFunction &MF, MachineBasicBlock &MBB,
74 MachineBasicBlock::iterator I) const {
Eli Bendersky700ed802013-02-21 20:05:00 +000075 // Simply discard ADJCALLSTACKDOWN,
76 // ADJCALLSTACKUP instructions.
77 MBB.erase(I);
78}