1*9880d681SAndroid Build Coastguard Worker //=======- NVPTXFrameLowering.cpp - NVPTX Frame Information ---*- C++ -*-=====//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This file contains the NVPTX implementation of TargetFrameLowering class.
11*9880d681SAndroid Build Coastguard Worker //
12*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
13*9880d681SAndroid Build Coastguard Worker
14*9880d681SAndroid Build Coastguard Worker #include "NVPTXFrameLowering.h"
15*9880d681SAndroid Build Coastguard Worker #include "NVPTX.h"
16*9880d681SAndroid Build Coastguard Worker #include "NVPTXRegisterInfo.h"
17*9880d681SAndroid Build Coastguard Worker #include "NVPTXSubtarget.h"
18*9880d681SAndroid Build Coastguard Worker #include "NVPTXTargetMachine.h"
19*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineFrameInfo.h"
20*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineFunction.h"
21*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineInstrBuilder.h"
22*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineRegisterInfo.h"
23*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MachineLocation.h"
24*9880d681SAndroid Build Coastguard Worker #include "llvm/Target/TargetInstrInfo.h"
25*9880d681SAndroid Build Coastguard Worker
26*9880d681SAndroid Build Coastguard Worker using namespace llvm;
27*9880d681SAndroid Build Coastguard Worker
NVPTXFrameLowering()28*9880d681SAndroid Build Coastguard Worker NVPTXFrameLowering::NVPTXFrameLowering()
29*9880d681SAndroid Build Coastguard Worker : TargetFrameLowering(TargetFrameLowering::StackGrowsUp, 8, 0) {}
30*9880d681SAndroid Build Coastguard Worker
hasFP(const MachineFunction & MF) const31*9880d681SAndroid Build Coastguard Worker bool NVPTXFrameLowering::hasFP(const MachineFunction &MF) const { return true; }
32*9880d681SAndroid Build Coastguard Worker
emitPrologue(MachineFunction & MF,MachineBasicBlock & MBB) const33*9880d681SAndroid Build Coastguard Worker void NVPTXFrameLowering::emitPrologue(MachineFunction &MF,
34*9880d681SAndroid Build Coastguard Worker MachineBasicBlock &MBB) const {
35*9880d681SAndroid Build Coastguard Worker if (MF.getFrameInfo()->hasStackObjects()) {
36*9880d681SAndroid Build Coastguard Worker assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported");
37*9880d681SAndroid Build Coastguard Worker MachineInstr *MI = &MBB.front();
38*9880d681SAndroid Build Coastguard Worker MachineRegisterInfo &MR = MF.getRegInfo();
39*9880d681SAndroid Build Coastguard Worker
40*9880d681SAndroid Build Coastguard Worker // This instruction really occurs before first instruction
41*9880d681SAndroid Build Coastguard Worker // in the BB, so giving it no debug location.
42*9880d681SAndroid Build Coastguard Worker DebugLoc dl = DebugLoc();
43*9880d681SAndroid Build Coastguard Worker
44*9880d681SAndroid Build Coastguard Worker // Emits
45*9880d681SAndroid Build Coastguard Worker // mov %SPL, %depot;
46*9880d681SAndroid Build Coastguard Worker // cvta.local %SP, %SPL;
47*9880d681SAndroid Build Coastguard Worker // for local address accesses in MF.
48*9880d681SAndroid Build Coastguard Worker bool Is64Bit =
49*9880d681SAndroid Build Coastguard Worker static_cast<const NVPTXTargetMachine &>(MF.getTarget()).is64Bit();
50*9880d681SAndroid Build Coastguard Worker unsigned CvtaLocalOpcode =
51*9880d681SAndroid Build Coastguard Worker (Is64Bit ? NVPTX::cvta_local_yes_64 : NVPTX::cvta_local_yes);
52*9880d681SAndroid Build Coastguard Worker unsigned MovDepotOpcode =
53*9880d681SAndroid Build Coastguard Worker (Is64Bit ? NVPTX::MOV_DEPOT_ADDR_64 : NVPTX::MOV_DEPOT_ADDR);
54*9880d681SAndroid Build Coastguard Worker if (!MR.use_empty(NVPTX::VRFrame)) {
55*9880d681SAndroid Build Coastguard Worker // If %SP is not used, do not bother emitting "cvta.local %SP, %SPL".
56*9880d681SAndroid Build Coastguard Worker MI = BuildMI(MBB, MI, dl,
57*9880d681SAndroid Build Coastguard Worker MF.getSubtarget().getInstrInfo()->get(CvtaLocalOpcode),
58*9880d681SAndroid Build Coastguard Worker NVPTX::VRFrame)
59*9880d681SAndroid Build Coastguard Worker .addReg(NVPTX::VRFrameLocal);
60*9880d681SAndroid Build Coastguard Worker }
61*9880d681SAndroid Build Coastguard Worker BuildMI(MBB, MI, dl, MF.getSubtarget().getInstrInfo()->get(MovDepotOpcode),
62*9880d681SAndroid Build Coastguard Worker NVPTX::VRFrameLocal)
63*9880d681SAndroid Build Coastguard Worker .addImm(MF.getFunctionNumber());
64*9880d681SAndroid Build Coastguard Worker }
65*9880d681SAndroid Build Coastguard Worker }
66*9880d681SAndroid Build Coastguard Worker
emitEpilogue(MachineFunction & MF,MachineBasicBlock & MBB) const67*9880d681SAndroid Build Coastguard Worker void NVPTXFrameLowering::emitEpilogue(MachineFunction &MF,
68*9880d681SAndroid Build Coastguard Worker MachineBasicBlock &MBB) const {}
69*9880d681SAndroid Build Coastguard Worker
70*9880d681SAndroid Build Coastguard Worker // This function eliminates ADJCALLSTACKDOWN,
71*9880d681SAndroid Build Coastguard Worker // ADJCALLSTACKUP pseudo instructions
eliminateCallFramePseudoInstr(MachineFunction & MF,MachineBasicBlock & MBB,MachineBasicBlock::iterator I) const72*9880d681SAndroid Build Coastguard Worker MachineBasicBlock::iterator NVPTXFrameLowering::eliminateCallFramePseudoInstr(
73*9880d681SAndroid Build Coastguard Worker MachineFunction &MF, MachineBasicBlock &MBB,
74*9880d681SAndroid Build Coastguard Worker MachineBasicBlock::iterator I) const {
75*9880d681SAndroid Build Coastguard Worker // Simply discard ADJCALLSTACKDOWN,
76*9880d681SAndroid Build Coastguard Worker // ADJCALLSTACKUP instructions.
77*9880d681SAndroid Build Coastguard Worker return MBB.erase(I);
78*9880d681SAndroid Build Coastguard Worker }
79