LLVM API Documentation

NVPTXRegisterInfo.cpp
Go to the documentation of this file.
00001 //===- NVPTXRegisterInfo.cpp - NVPTX Register Information -----------------===//
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 the TargetRegisterInfo class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "NVPTXRegisterInfo.h"
00015 #include "NVPTX.h"
00016 #include "NVPTXSubtarget.h"
00017 #include "llvm/ADT/BitVector.h"
00018 #include "llvm/CodeGen/MachineFrameInfo.h"
00019 #include "llvm/CodeGen/MachineFunction.h"
00020 #include "llvm/CodeGen/MachineInstrBuilder.h"
00021 #include "llvm/MC/MachineLocation.h"
00022 #include "llvm/Target/TargetInstrInfo.h"
00023 
00024 using namespace llvm;
00025 
00026 #define DEBUG_TYPE "nvptx-reg-info"
00027 
00028 namespace llvm {
00029 std::string getNVPTXRegClassName(TargetRegisterClass const *RC) {
00030   if (RC == &NVPTX::Float32RegsRegClass) {
00031     return ".f32";
00032   }
00033   if (RC == &NVPTX::Float64RegsRegClass) {
00034     return ".f64";
00035   } else if (RC == &NVPTX::Int64RegsRegClass) {
00036     return ".s64";
00037   } else if (RC == &NVPTX::Int32RegsRegClass) {
00038     return ".s32";
00039   } else if (RC == &NVPTX::Int16RegsRegClass) {
00040     return ".s16";
00041   } else if (RC == &NVPTX::Int1RegsRegClass) {
00042     return ".pred";
00043   } else if (RC == &NVPTX::SpecialRegsRegClass) {
00044     return "!Special!";
00045   } else {
00046     return "INTERNAL";
00047   }
00048   return "";
00049 }
00050 
00051 std::string getNVPTXRegClassStr(TargetRegisterClass const *RC) {
00052   if (RC == &NVPTX::Float32RegsRegClass) {
00053     return "%f";
00054   }
00055   if (RC == &NVPTX::Float64RegsRegClass) {
00056     return "%fd";
00057   } else if (RC == &NVPTX::Int64RegsRegClass) {
00058     return "%rd";
00059   } else if (RC == &NVPTX::Int32RegsRegClass) {
00060     return "%r";
00061   } else if (RC == &NVPTX::Int16RegsRegClass) {
00062     return "%rs";
00063   } else if (RC == &NVPTX::Int1RegsRegClass) {
00064     return "%p";
00065   } else if (RC == &NVPTX::SpecialRegsRegClass) {
00066     return "!Special!";
00067   } else {
00068     return "INTERNAL";
00069   }
00070   return "";
00071 }
00072 }
00073 
00074 NVPTXRegisterInfo::NVPTXRegisterInfo(const NVPTXSubtarget &st)
00075     : NVPTXGenRegisterInfo(0), Is64Bit(st.is64Bit()) {}
00076 
00077 #define GET_REGINFO_TARGET_DESC
00078 #include "NVPTXGenRegisterInfo.inc"
00079 
00080 /// NVPTX Callee Saved Registers
00081 const MCPhysReg *
00082 NVPTXRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
00083   static const MCPhysReg CalleeSavedRegs[] = { 0 };
00084   return CalleeSavedRegs;
00085 }
00086 
00087 BitVector NVPTXRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
00088   BitVector Reserved(getNumRegs());
00089   return Reserved;
00090 }
00091 
00092 void NVPTXRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
00093                                             int SPAdj, unsigned FIOperandNum,
00094                                             RegScavenger *RS) const {
00095   assert(SPAdj == 0 && "Unexpected");
00096 
00097   MachineInstr &MI = *II;
00098   int FrameIndex = MI.getOperand(FIOperandNum).getIndex();
00099 
00100   MachineFunction &MF = *MI.getParent()->getParent();
00101   int Offset = MF.getFrameInfo()->getObjectOffset(FrameIndex) +
00102                MI.getOperand(FIOperandNum + 1).getImm();
00103 
00104   // Using I0 as the frame pointer
00105   MI.getOperand(FIOperandNum).ChangeToRegister(NVPTX::VRFrame, false);
00106   MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset);
00107 }
00108 
00109 unsigned NVPTXRegisterInfo::getFrameRegister(const MachineFunction &MF) const {
00110   return NVPTX::VRFrame;
00111 }