LLVM API Documentation

SIMachineFunctionInfo.cpp
Go to the documentation of this file.
00001 //===-- SIMachineFunctionInfo.cpp - SI Machine Function Info -------===//
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 /// \file
00009 //===----------------------------------------------------------------------===//
00010 
00011 
00012 #include "SIMachineFunctionInfo.h"
00013 #include "SIInstrInfo.h"
00014 #include "SIRegisterInfo.h"
00015 #include "llvm/CodeGen/MachineFrameInfo.h"
00016 #include "llvm/CodeGen/MachineRegisterInfo.h"
00017 #include "llvm/IR/Function.h"
00018 #include "llvm/IR/LLVMContext.h"
00019 
00020 #define MAX_LANES 64
00021 
00022 using namespace llvm;
00023 
00024 
00025 // Pin the vtable to this file.
00026 void SIMachineFunctionInfo::anchor() {}
00027 
00028 SIMachineFunctionInfo::SIMachineFunctionInfo(const MachineFunction &MF)
00029   : AMDGPUMachineFunction(MF),
00030     PSInputAddr(0),
00031     NumUserSGPRs(0) { }
00032 
00033 /// \brief Returns a register that is not used at any point in the function.
00034 ///        If all registers are used, then this function will return
00035 //         AMDGPU::NoRegister.
00036 static unsigned findUnusedVGPR(const MachineRegisterInfo &MRI) {
00037 
00038   const TargetRegisterClass *RC = &AMDGPU::VGPR_32RegClass;
00039 
00040   for (TargetRegisterClass::iterator I = RC->begin(), E = RC->end();
00041        I != E; ++I) {
00042     if (!MRI.isPhysRegUsed(*I))
00043       return *I;
00044   }
00045   return AMDGPU::NoRegister;
00046 }
00047 
00048 SIMachineFunctionInfo::SpilledReg SIMachineFunctionInfo::getSpilledReg(
00049                                                        MachineFunction *MF,
00050                                                        unsigned FrameIndex,
00051                                                        unsigned SubIdx) {
00052   const MachineFrameInfo *FrameInfo = MF->getFrameInfo();
00053   MachineRegisterInfo &MRI = MF->getRegInfo();
00054   int64_t Offset = FrameInfo->getObjectOffset(FrameIndex);
00055   Offset += SubIdx * 4;
00056 
00057   unsigned LaneVGPRIdx = Offset / (64 * 4);
00058   unsigned Lane = (Offset / 4) % 64;
00059 
00060   struct SpilledReg Spill;
00061 
00062   if (!LaneVGPRs.count(LaneVGPRIdx)) {
00063     unsigned LaneVGPR = findUnusedVGPR(MRI);
00064     LaneVGPRs[LaneVGPRIdx] = LaneVGPR;
00065     MRI.setPhysRegUsed(LaneVGPR);
00066 
00067     // Add this register as live-in to all blocks to avoid machine verifer
00068     // complaining about use of an undefined physical register.
00069     for (MachineFunction::iterator BI = MF->begin(), BE = MF->end();
00070          BI != BE; ++BI) {
00071       BI->addLiveIn(LaneVGPR);
00072     }
00073   }
00074 
00075   Spill.VGPR = LaneVGPRs[LaneVGPRIdx];
00076   Spill.Lane = Lane;
00077   return Spill;
00078 }