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