blob: 34d3a66adce4e717804707c01c0b21035adff87f [file] [log] [blame]
Justin Holewinskiae556d32012-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 Holewinskiae556d32012-05-04 20:18:50 +000020#include "llvm/CodeGen/MachineFrameInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000021#include "llvm/CodeGen/MachineFunction.h"
22#include "llvm/CodeGen/MachineInstrBuilder.h"
Justin Holewinski871ec932013-08-06 14:13:31 +000023#include "llvm/CodeGen/MachineRegisterInfo.h"
Justin Holewinskiae556d32012-05-04 20:18:50 +000024#include "llvm/MC/MachineLocation.h"
25#include "llvm/Target/TargetInstrInfo.h"
26
27using namespace llvm;
28
Eric Christopher02389e32015-02-19 00:08:27 +000029NVPTXFrameLowering::NVPTXFrameLowering()
30 : TargetFrameLowering(TargetFrameLowering::StackGrowsUp, 8, 0) {}
Eric Christopherdd440f82014-06-27 02:05:24 +000031
Justin Holewinski0497ab12013-03-30 14:29:21 +000032bool NVPTXFrameLowering::hasFP(const MachineFunction &MF) const { return true; }
Justin Holewinskiae556d32012-05-04 20:18:50 +000033
34void NVPTXFrameLowering::emitPrologue(MachineFunction &MF) const {
35 if (MF.getFrameInfo()->hasStackObjects()) {
36 MachineBasicBlock &MBB = MF.front();
37 // Insert "mov.u32 %SP, %Depot"
38 MachineBasicBlock::iterator MBBI = MBB.begin();
39 // This instruction really occurs before first instruction
40 // in the BB, so giving it no debug location.
41 DebugLoc dl = DebugLoc();
42
Justin Holewinski871ec932013-08-06 14:13:31 +000043 MachineRegisterInfo &MRI = MF.getRegInfo();
44
45 // mov %SPL, %depot;
46 // cvta.local %SP, %SPL;
Eric Christopher02389e32015-02-19 00:08:27 +000047 if (static_cast<const NVPTXTargetMachine &>(MF.getTarget()).is64Bit()) {
Justin Holewinski871ec932013-08-06 14:13:31 +000048 unsigned LocalReg = MRI.createVirtualRegister(&NVPTX::Int64RegsRegClass);
Eric Christopherf0dad262014-06-27 02:05:22 +000049 MachineInstr *MI =
Eric Christopherfc6de422014-08-05 02:39:49 +000050 BuildMI(MBB, MBBI, dl, MF.getSubtarget().getInstrInfo()->get(
51 NVPTX::cvta_local_yes_64),
Eric Christopherf0dad262014-06-27 02:05:22 +000052 NVPTX::VRFrame).addReg(LocalReg);
53 BuildMI(MBB, MI, dl,
Eric Christopherfc6de422014-08-05 02:39:49 +000054 MF.getSubtarget().getInstrInfo()->get(NVPTX::MOV_DEPOT_ADDR_64),
Justin Holewinski871ec932013-08-06 14:13:31 +000055 LocalReg).addImm(MF.getFunctionNumber());
Justin Holewinski0497ab12013-03-30 14:29:21 +000056 } else {
Justin Holewinski871ec932013-08-06 14:13:31 +000057 unsigned LocalReg = MRI.createVirtualRegister(&NVPTX::Int32RegsRegClass);
Eric Christopherf0dad262014-06-27 02:05:22 +000058 MachineInstr *MI =
59 BuildMI(MBB, MBBI, dl,
Eric Christopherfc6de422014-08-05 02:39:49 +000060 MF.getSubtarget().getInstrInfo()->get(NVPTX::cvta_local_yes),
Eric Christopherf0dad262014-06-27 02:05:22 +000061 NVPTX::VRFrame).addReg(LocalReg);
62 BuildMI(MBB, MI, dl,
Eric Christopherfc6de422014-08-05 02:39:49 +000063 MF.getSubtarget().getInstrInfo()->get(NVPTX::MOV_DEPOT_ADDR),
Justin Holewinski871ec932013-08-06 14:13:31 +000064 LocalReg).addImm(MF.getFunctionNumber());
Justin Holewinskiae556d32012-05-04 20:18:50 +000065 }
66 }
67}
68
69void NVPTXFrameLowering::emitEpilogue(MachineFunction &MF,
Justin Holewinski0497ab12013-03-30 14:29:21 +000070 MachineBasicBlock &MBB) const {}
Eli Bendersky8da87162013-02-21 20:05:00 +000071
72// This function eliminates ADJCALLSTACKDOWN,
73// ADJCALLSTACKUP pseudo instructions
Justin Holewinski0497ab12013-03-30 14:29:21 +000074void NVPTXFrameLowering::eliminateCallFramePseudoInstr(
75 MachineFunction &MF, MachineBasicBlock &MBB,
76 MachineBasicBlock::iterator I) const {
Eli Bendersky8da87162013-02-21 20:05:00 +000077 // Simply discard ADJCALLSTACKDOWN,
78 // ADJCALLSTACKUP instructions.
79 MBB.erase(I);
80}