2012-05-04 20:18:50 +00: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-03 16:50:05 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2013-08-06 14:13:31 +00:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2012-05-04 20:18:50 +00:00
|
|
|
#include "llvm/MC/MachineLocation.h"
|
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-06-27 02:05:24 +00:00
|
|
|
NVPTXFrameLowering::NVPTXFrameLowering(NVPTXSubtarget &STI)
|
|
|
|
: TargetFrameLowering(TargetFrameLowering::StackGrowsUp, 8, 0),
|
|
|
|
is64bit(STI.is64Bit()) {}
|
|
|
|
|
2013-03-30 14:29:21 +00:00
|
|
|
bool NVPTXFrameLowering::hasFP(const MachineFunction &MF) const { return true; }
|
2012-05-04 20:18:50 +00: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 14:13:31 +00:00
|
|
|
MachineRegisterInfo &MRI = MF.getRegInfo();
|
|
|
|
|
|
|
|
// mov %SPL, %depot;
|
|
|
|
// cvta.local %SP, %SPL;
|
|
|
|
if (is64bit) {
|
|
|
|
unsigned LocalReg = MRI.createVirtualRegister(&NVPTX::Int64RegsRegClass);
|
2014-06-27 02:05:22 +00:00
|
|
|
MachineInstr *MI =
|
|
|
|
BuildMI(MBB, MBBI, dl,
|
|
|
|
MF.getTarget().getInstrInfo()->get(NVPTX::cvta_local_yes_64),
|
|
|
|
NVPTX::VRFrame).addReg(LocalReg);
|
|
|
|
BuildMI(MBB, MI, dl,
|
|
|
|
MF.getTarget().getInstrInfo()->get(NVPTX::MOV_DEPOT_ADDR_64),
|
2013-08-06 14:13:31 +00:00
|
|
|
LocalReg).addImm(MF.getFunctionNumber());
|
2013-03-30 14:29:21 +00:00
|
|
|
} else {
|
2013-08-06 14:13:31 +00:00
|
|
|
unsigned LocalReg = MRI.createVirtualRegister(&NVPTX::Int32RegsRegClass);
|
2014-06-27 02:05:22 +00:00
|
|
|
MachineInstr *MI =
|
|
|
|
BuildMI(MBB, MBBI, dl,
|
|
|
|
MF.getTarget().getInstrInfo()->get(NVPTX::cvta_local_yes),
|
|
|
|
NVPTX::VRFrame).addReg(LocalReg);
|
|
|
|
BuildMI(MBB, MI, dl,
|
|
|
|
MF.getTarget().getInstrInfo()->get(NVPTX::MOV_DEPOT_ADDR),
|
2013-08-06 14:13:31 +00:00
|
|
|
LocalReg).addImm(MF.getFunctionNumber());
|
2012-05-04 20:18:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NVPTXFrameLowering::emitEpilogue(MachineFunction &MF,
|
2013-03-30 14:29:21 +00:00
|
|
|
MachineBasicBlock &MBB) const {}
|
2013-02-21 20:05:00 +00:00
|
|
|
|
|
|
|
// This function eliminates ADJCALLSTACKDOWN,
|
|
|
|
// ADJCALLSTACKUP pseudo instructions
|
2013-03-30 14:29:21 +00:00
|
|
|
void NVPTXFrameLowering::eliminateCallFramePseudoInstr(
|
|
|
|
MachineFunction &MF, MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I) const {
|
2013-02-21 20:05:00 +00:00
|
|
|
// Simply discard ADJCALLSTACKDOWN,
|
|
|
|
// ADJCALLSTACKUP instructions.
|
|
|
|
MBB.erase(I);
|
|
|
|
}
|