blob: 5503494fc3c89ceeb7e40a4144ea4401568926e0 [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
Quentin Colombet61b305e2015-05-05 17:38:16 +000034void NVPTXFrameLowering::emitPrologue(MachineFunction &MF,
35 MachineBasicBlock &MBB) const {
Justin Holewinskiae556d32012-05-04 20:18:50 +000036 if (MF.getFrameInfo()->hasStackObjects()) {
Quentin Colombet61b305e2015-05-05 17:38:16 +000037 assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported");
Justin Holewinskiae556d32012-05-04 20:18:50 +000038 // Insert "mov.u32 %SP, %Depot"
39 MachineBasicBlock::iterator MBBI = MBB.begin();
40 // This instruction really occurs before first instruction
41 // in the BB, so giving it no debug location.
42 DebugLoc dl = DebugLoc();
43
Justin Holewinski871ec932013-08-06 14:13:31 +000044 MachineRegisterInfo &MRI = MF.getRegInfo();
45
46 // mov %SPL, %depot;
47 // cvta.local %SP, %SPL;
Eric Christopher02389e32015-02-19 00:08:27 +000048 if (static_cast<const NVPTXTargetMachine &>(MF.getTarget()).is64Bit()) {
Justin Holewinski871ec932013-08-06 14:13:31 +000049 unsigned LocalReg = MRI.createVirtualRegister(&NVPTX::Int64RegsRegClass);
Eric Christopherf0dad262014-06-27 02:05:22 +000050 MachineInstr *MI =
Eric Christopherfc6de422014-08-05 02:39:49 +000051 BuildMI(MBB, MBBI, dl, MF.getSubtarget().getInstrInfo()->get(
52 NVPTX::cvta_local_yes_64),
Eric Christopherf0dad262014-06-27 02:05:22 +000053 NVPTX::VRFrame).addReg(LocalReg);
54 BuildMI(MBB, MI, dl,
Eric Christopherfc6de422014-08-05 02:39:49 +000055 MF.getSubtarget().getInstrInfo()->get(NVPTX::MOV_DEPOT_ADDR_64),
Justin Holewinski871ec932013-08-06 14:13:31 +000056 LocalReg).addImm(MF.getFunctionNumber());
Justin Holewinski0497ab12013-03-30 14:29:21 +000057 } else {
Justin Holewinski871ec932013-08-06 14:13:31 +000058 unsigned LocalReg = MRI.createVirtualRegister(&NVPTX::Int32RegsRegClass);
Eric Christopherf0dad262014-06-27 02:05:22 +000059 MachineInstr *MI =
60 BuildMI(MBB, MBBI, dl,
Eric Christopherfc6de422014-08-05 02:39:49 +000061 MF.getSubtarget().getInstrInfo()->get(NVPTX::cvta_local_yes),
Eric Christopherf0dad262014-06-27 02:05:22 +000062 NVPTX::VRFrame).addReg(LocalReg);
63 BuildMI(MBB, MI, dl,
Eric Christopherfc6de422014-08-05 02:39:49 +000064 MF.getSubtarget().getInstrInfo()->get(NVPTX::MOV_DEPOT_ADDR),
Justin Holewinski871ec932013-08-06 14:13:31 +000065 LocalReg).addImm(MF.getFunctionNumber());
Justin Holewinskiae556d32012-05-04 20:18:50 +000066 }
67 }
68}
69
70void NVPTXFrameLowering::emitEpilogue(MachineFunction &MF,
Justin Holewinski0497ab12013-03-30 14:29:21 +000071 MachineBasicBlock &MBB) const {}
Eli Bendersky8da87162013-02-21 20:05:00 +000072
73// This function eliminates ADJCALLSTACKDOWN,
74// ADJCALLSTACKUP pseudo instructions
Justin Holewinski0497ab12013-03-30 14:29:21 +000075void NVPTXFrameLowering::eliminateCallFramePseudoInstr(
76 MachineFunction &MF, MachineBasicBlock &MBB,
77 MachineBasicBlock::iterator I) const {
Eli Bendersky8da87162013-02-21 20:05:00 +000078 // Simply discard ADJCALLSTACKDOWN,
79 // ADJCALLSTACKUP instructions.
80 MBB.erase(I);
81}