LLVM API Documentation
00001 //=======- NVPTXFrameLowering.cpp - NVPTX Frame Information ---*- C++ -*-=====// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file contains the NVPTX implementation of TargetFrameLowering class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "NVPTXFrameLowering.h" 00015 #include "NVPTX.h" 00016 #include "NVPTXRegisterInfo.h" 00017 #include "NVPTXSubtarget.h" 00018 #include "NVPTXTargetMachine.h" 00019 #include "llvm/ADT/BitVector.h" 00020 #include "llvm/CodeGen/MachineFrameInfo.h" 00021 #include "llvm/CodeGen/MachineFunction.h" 00022 #include "llvm/CodeGen/MachineInstrBuilder.h" 00023 #include "llvm/CodeGen/MachineRegisterInfo.h" 00024 #include "llvm/MC/MachineLocation.h" 00025 #include "llvm/Target/TargetInstrInfo.h" 00026 00027 using namespace llvm; 00028 00029 NVPTXFrameLowering::NVPTXFrameLowering(NVPTXSubtarget &STI) 00030 : TargetFrameLowering(TargetFrameLowering::StackGrowsUp, 8, 0), 00031 is64bit(STI.is64Bit()) {} 00032 00033 bool NVPTXFrameLowering::hasFP(const MachineFunction &MF) const { return true; } 00034 00035 void NVPTXFrameLowering::emitPrologue(MachineFunction &MF) const { 00036 if (MF.getFrameInfo()->hasStackObjects()) { 00037 MachineBasicBlock &MBB = MF.front(); 00038 // Insert "mov.u32 %SP, %Depot" 00039 MachineBasicBlock::iterator MBBI = MBB.begin(); 00040 // This instruction really occurs before first instruction 00041 // in the BB, so giving it no debug location. 00042 DebugLoc dl = DebugLoc(); 00043 00044 MachineRegisterInfo &MRI = MF.getRegInfo(); 00045 00046 // mov %SPL, %depot; 00047 // cvta.local %SP, %SPL; 00048 if (is64bit) { 00049 unsigned LocalReg = MRI.createVirtualRegister(&NVPTX::Int64RegsRegClass); 00050 MachineInstr *MI = 00051 BuildMI(MBB, MBBI, dl, MF.getSubtarget().getInstrInfo()->get( 00052 NVPTX::cvta_local_yes_64), 00053 NVPTX::VRFrame).addReg(LocalReg); 00054 BuildMI(MBB, MI, dl, 00055 MF.getSubtarget().getInstrInfo()->get(NVPTX::MOV_DEPOT_ADDR_64), 00056 LocalReg).addImm(MF.getFunctionNumber()); 00057 } else { 00058 unsigned LocalReg = MRI.createVirtualRegister(&NVPTX::Int32RegsRegClass); 00059 MachineInstr *MI = 00060 BuildMI(MBB, MBBI, dl, 00061 MF.getSubtarget().getInstrInfo()->get(NVPTX::cvta_local_yes), 00062 NVPTX::VRFrame).addReg(LocalReg); 00063 BuildMI(MBB, MI, dl, 00064 MF.getSubtarget().getInstrInfo()->get(NVPTX::MOV_DEPOT_ADDR), 00065 LocalReg).addImm(MF.getFunctionNumber()); 00066 } 00067 } 00068 } 00069 00070 void NVPTXFrameLowering::emitEpilogue(MachineFunction &MF, 00071 MachineBasicBlock &MBB) const {} 00072 00073 // This function eliminates ADJCALLSTACKDOWN, 00074 // ADJCALLSTACKUP pseudo instructions 00075 void NVPTXFrameLowering::eliminateCallFramePseudoInstr( 00076 MachineFunction &MF, MachineBasicBlock &MBB, 00077 MachineBasicBlock::iterator I) const { 00078 // Simply discard ADJCALLSTACKDOWN, 00079 // ADJCALLSTACKUP instructions. 00080 MBB.erase(I); 00081 }