2012-05-05 04:18:50 +08:00
|
|
|
//=======- NVPTXFrameLowering.cpp - NVPTX Frame Information ---*- C++ -*-=====//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the NVPTX implementation of TargetFrameLowering class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "NVPTXFrameLowering.h"
|
|
|
|
#include "NVPTX.h"
|
|
|
|
#include "NVPTXRegisterInfo.h"
|
|
|
|
#include "NVPTXSubtarget.h"
|
|
|
|
#include "NVPTXTargetMachine.h"
|
|
|
|
#include "llvm/ADT/BitVector.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2013-08-06 22:13:31 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2012-05-05 04:18:50 +08:00
|
|
|
#include "llvm/MC/MachineLocation.h"
|
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2015-02-19 08:08:27 +08:00
|
|
|
NVPTXFrameLowering::NVPTXFrameLowering()
|
|
|
|
: TargetFrameLowering(TargetFrameLowering::StackGrowsUp, 8, 0) {}
|
2014-06-27 10:05:24 +08:00
|
|
|
|
2013-03-30 22:29:21 +08:00
|
|
|
bool NVPTXFrameLowering::hasFP(const MachineFunction &MF) const { return true; }
|
2012-05-05 04:18:50 +08:00
|
|
|
|
|
|
|
void NVPTXFrameLowering::emitPrologue(MachineFunction &MF) const {
|
|
|
|
if (MF.getFrameInfo()->hasStackObjects()) {
|
|
|
|
MachineBasicBlock &MBB = MF.front();
|
|
|
|
// Insert "mov.u32 %SP, %Depot"
|
|
|
|
MachineBasicBlock::iterator MBBI = MBB.begin();
|
|
|
|
// This instruction really occurs before first instruction
|
|
|
|
// in the BB, so giving it no debug location.
|
|
|
|
DebugLoc dl = DebugLoc();
|
|
|
|
|
2013-08-06 22:13:31 +08:00
|
|
|
MachineRegisterInfo &MRI = MF.getRegInfo();
|
|
|
|
|
|
|
|
// mov %SPL, %depot;
|
|
|
|
// cvta.local %SP, %SPL;
|
2015-02-19 08:08:27 +08:00
|
|
|
if (static_cast<const NVPTXTargetMachine &>(MF.getTarget()).is64Bit()) {
|
2013-08-06 22:13:31 +08:00
|
|
|
unsigned LocalReg = MRI.createVirtualRegister(&NVPTX::Int64RegsRegClass);
|
2014-06-27 10:05:22 +08:00
|
|
|
MachineInstr *MI =
|
2014-08-05 10:39:49 +08:00
|
|
|
BuildMI(MBB, MBBI, dl, MF.getSubtarget().getInstrInfo()->get(
|
|
|
|
NVPTX::cvta_local_yes_64),
|
2014-06-27 10:05:22 +08:00
|
|
|
NVPTX::VRFrame).addReg(LocalReg);
|
|
|
|
BuildMI(MBB, MI, dl,
|
2014-08-05 10:39:49 +08:00
|
|
|
MF.getSubtarget().getInstrInfo()->get(NVPTX::MOV_DEPOT_ADDR_64),
|
2013-08-06 22:13:31 +08:00
|
|
|
LocalReg).addImm(MF.getFunctionNumber());
|
2013-03-30 22:29:21 +08:00
|
|
|
} else {
|
2013-08-06 22:13:31 +08:00
|
|
|
unsigned LocalReg = MRI.createVirtualRegister(&NVPTX::Int32RegsRegClass);
|
2014-06-27 10:05:22 +08:00
|
|
|
MachineInstr *MI =
|
|
|
|
BuildMI(MBB, MBBI, dl,
|
2014-08-05 10:39:49 +08:00
|
|
|
MF.getSubtarget().getInstrInfo()->get(NVPTX::cvta_local_yes),
|
2014-06-27 10:05:22 +08:00
|
|
|
NVPTX::VRFrame).addReg(LocalReg);
|
|
|
|
BuildMI(MBB, MI, dl,
|
2014-08-05 10:39:49 +08:00
|
|
|
MF.getSubtarget().getInstrInfo()->get(NVPTX::MOV_DEPOT_ADDR),
|
2013-08-06 22:13:31 +08:00
|
|
|
LocalReg).addImm(MF.getFunctionNumber());
|
2012-05-05 04:18:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NVPTXFrameLowering::emitEpilogue(MachineFunction &MF,
|
2013-03-30 22:29:21 +08:00
|
|
|
MachineBasicBlock &MBB) const {}
|
2013-02-22 04:05:00 +08:00
|
|
|
|
|
|
|
// This function eliminates ADJCALLSTACKDOWN,
|
|
|
|
// ADJCALLSTACKUP pseudo instructions
|
2013-03-30 22:29:21 +08:00
|
|
|
void NVPTXFrameLowering::eliminateCallFramePseudoInstr(
|
|
|
|
MachineFunction &MF, MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I) const {
|
2013-02-22 04:05:00 +08:00
|
|
|
// Simply discard ADJCALLSTACKDOWN,
|
|
|
|
// ADJCALLSTACKUP instructions.
|
|
|
|
MBB.erase(I);
|
|
|
|
}
|