LLVM 24.0.0git
NVPTXRegisterInfo.cpp
Go to the documentation of this file.
1//===- NVPTXRegisterInfo.cpp - NVPTX Register Information -----------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the NVPTX implementation of the TargetRegisterInfo class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "NVPTXRegisterInfo.h"
16#include "NVPTX.h"
17#include "NVPTXSubtarget.h"
18#include "llvm/ADT/BitVector.h"
23
24using namespace llvm;
25
26#define DEBUG_TYPE "nvptx-reg-info"
27
29
30#define GET_REGINFO_TARGET_DESC
31#include "NVPTXGenRegisterInfo.inc"
32
33/// NVPTX Callee Saved Registers
34const MCPhysReg *
36 static const MCPhysReg CalleeSavedRegs[] = { 0 };
37 return CalleeSavedRegs;
38}
39
41 BitVector Reserved(getNumRegs());
42 for (unsigned Reg = NVPTX::ENVREG0; Reg <= NVPTX::ENVREG31; ++Reg) {
43 markSuperRegs(Reserved, Reg);
44 }
45 markSuperRegs(Reserved, NVPTX::VRFrame32);
46 markSuperRegs(Reserved, NVPTX::VRFrameLocal32);
47 markSuperRegs(Reserved, NVPTX::VRFrame64);
48 markSuperRegs(Reserved, NVPTX::VRFrameLocal64);
49 markSuperRegs(Reserved, NVPTX::VRDepot);
50 return Reserved;
51}
52
54 int SPAdj, unsigned FIOperandNum,
55 RegScavenger *) const {
56 assert(SPAdj == 0 && "Unexpected");
57
58 MachineInstr &MI = *II;
59 if (MI.isLifetimeMarker()) {
60 MI.eraseFromParent();
61 return true;
62 }
63
64 const int FrameIndex = MI.getOperand(FIOperandNum).getIndex();
65
66 const MachineFunction &MF = *MI.getParent()->getParent();
67 const MachineFrameInfo &MFI = MF.getFrameInfo();
68 const int Offset = MFI.getObjectOffset(FrameIndex) +
69 MI.getOperand(FIOperandNum + 1).getImm();
70
71 // Local (addrspace 5) allocas are addressed through the local frame pointer
72 // (%SPL); everything else uses the generic frame pointer (%SP).
73 const AllocaInst *AI = MFI.getObjectAllocation(FrameIndex);
74 const Register FrameReg = AI && AI->getAddressSpace() == ADDRESS_SPACE_LOCAL
76 : getFrameRegister(MF);
77 MI.getOperand(FIOperandNum).ChangeToRegister(FrameReg, false);
78 MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset);
79 return false;
80}
81
84 ? NVPTX::VRFrame64
85 : NVPTX::VRFrame32;
86}
87
91 ? NVPTX::VRFrameLocal64
92 : NVPTX::VRFrameLocal32;
93}
94
96 DebugRegisterMap.clear();
97}
98
100 if (RegisterName.size() > 8)
101 // The name is more than 8 characters long, and so won't fit into 64 bits.
102 return 0;
103
104 // Encode the name string into a DWARF register number using cuda-gdb's
105 // encoding. See cuda_check_dwarf2_reg_ptx_virtual_register in cuda-tdep.c,
106 // https://github.com/NVIDIA/cuda-gdb/blob/e5cf3bddae520ffb326f95b4d98ce5c7474b828b/gdb/cuda/cuda-tdep.c#L353
107 // IE the bytes of the string are concatenated in reverse into a single
108 // number, which is stored in ULEB128, but in practice must be no more than 8
109 // bytes (excluding null terminator, which is not included).
110 uint64_t Result = 0;
111 for (unsigned char C : RegisterName)
112 Result = (Result << 8) | C;
113 return Result;
114}
115
117 StringRef RegisterName) const {
118 if (const uint64_t Encoded = encodeRegisterForDwarf(RegisterName))
119 DebugRegisterMap.insert({VirtReg, Encoded});
120}
121
122int64_t NVPTXRegisterInfo::getDwarfRegNum(MCRegister RegNum, bool isEH) const {
124 // In NVPTXFrameLowering.cpp, we do arrange for %Depot to be accessible from
125 // %SP. Using the %Depot register doesn't provide any debug info in
126 // cuda-gdb, but switching it to %SP does.
127 if (RegNum.id() == NVPTX::VRDepot)
128 Name = "%SP";
129 return encodeRegisterForDwarf(Name);
130}
131
133 bool isEH) const {
134 assert(RegNum.isVirtual());
135 if (const uint64_t Encoded = DebugRegisterMap.lookup(RegNum))
136 return Encoded;
137 return -1;
138}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements the BitVector class.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
IRTranslator LLVM IR MI
static uint64_t encodeRegisterForDwarf(StringRef RegisterName)
uint64_t IntrinsicInst * II
an instruction to allocate memory on the stack
unsigned getAddressSpace() const
Return the address space for the allocation.
unsigned getPointerSizeInBits(unsigned AS=0) const
The size in bits of the pointer representation in a given address space.
Definition DataLayout.h:501
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
constexpr unsigned id() const
Definition MCRegister.h:82
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
const AllocaInst * getObjectAllocation(int ObjectIdx) const
Return the underlying Alloca of the specified stack object if it exists.
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
Representation of each machine instruction.
static const char * getRegisterName(MCRegister Reg)
void addToDebugRegisterMap(Register VirtReg, StringRef RegisterName) const
Register getFrameLocalRegister(const MachineFunction &MF) const
const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const override
NVPTX Callee Saved Registers.
bool eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj, unsigned FIOperandNum, RegScavenger *RS=nullptr) const override
BitVector getReservedRegs(const MachineFunction &MF) const override
int64_t getDwarfRegNum(MCRegister RegNum, bool isEH) const override
Register getFrameRegister(const MachineFunction &MF) const override
int64_t getDwarfRegNumForVirtReg(Register RegNum, bool isEH) const override
Wrapper class representing virtual and physical registers.
Definition Register.h:20
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition Register.h:79
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:578
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21