1 //===- NVPTXRegisterInfo.cpp - NVPTX Register Information -----------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file contains the NVPTX implementation of the TargetRegisterInfo class.
11 //===----------------------------------------------------------------------===//
13 #include "NVPTXRegisterInfo.h"
15 #include "NVPTXSubtarget.h"
16 #include "llvm/ADT/BitVector.h"
17 #include "llvm/CodeGen/MachineFrameInfo.h"
18 #include "llvm/CodeGen/MachineFunction.h"
19 #include "llvm/CodeGen/MachineInstrBuilder.h"
20 #include "llvm/CodeGen/TargetInstrInfo.h"
21 #include "llvm/MC/MachineLocation.h"
25 #define DEBUG_TYPE "nvptx-reg-info"
28 std::string
getNVPTXRegClassName(TargetRegisterClass
const *RC
) {
29 if (RC
== &NVPTX::Float32RegsRegClass
)
31 if (RC
== &NVPTX::Float16RegsRegClass
)
32 // Ideally fp16 registers should be .f16, but this syntax is only
33 // supported on sm_53+. On the other hand, .b16 registers are
34 // accepted for all supported fp16 instructions on all GPU
35 // variants, so we can use them instead.
37 if (RC
== &NVPTX::Float16x2RegsRegClass
)
39 if (RC
== &NVPTX::Float64RegsRegClass
)
41 if (RC
== &NVPTX::Int64RegsRegClass
)
42 // We use untyped (.b) integer registers here as NVCC does.
43 // Correctness of generated code does not depend on register type,
44 // but using .s/.u registers runs into ptxas bug that prevents
45 // assembly of otherwise valid PTX into SASS. Despite PTX ISA
46 // specifying only argument size for fp16 instructions, ptxas does
47 // not allow using .s16 or .u16 arguments for .fp16
48 // instructions. At the same time it allows using .s32/.u32
49 // arguments for .fp16v2 instructions:
53 // add.f16 rb16,rb16,rb16; // OK
54 // add.f16 rs16,rs16,rs16; // Arguments mismatch for instruction 'add'
58 // add.f16v2 rb32,rb32,rb32; // OK
59 // add.f16v2 rs32,rs32,rs32; // OK
61 if (RC
== &NVPTX::Int32RegsRegClass
)
63 if (RC
== &NVPTX::Int16RegsRegClass
)
65 if (RC
== &NVPTX::Int1RegsRegClass
)
67 if (RC
== &NVPTX::SpecialRegsRegClass
)
72 std::string
getNVPTXRegClassStr(TargetRegisterClass
const *RC
) {
73 if (RC
== &NVPTX::Float32RegsRegClass
)
75 if (RC
== &NVPTX::Float16RegsRegClass
)
77 if (RC
== &NVPTX::Float16x2RegsRegClass
)
79 if (RC
== &NVPTX::Float64RegsRegClass
)
81 if (RC
== &NVPTX::Int64RegsRegClass
)
83 if (RC
== &NVPTX::Int32RegsRegClass
)
85 if (RC
== &NVPTX::Int16RegsRegClass
)
87 if (RC
== &NVPTX::Int1RegsRegClass
)
89 if (RC
== &NVPTX::SpecialRegsRegClass
)
95 NVPTXRegisterInfo::NVPTXRegisterInfo() : NVPTXGenRegisterInfo(0) {}
97 #define GET_REGINFO_TARGET_DESC
98 #include "NVPTXGenRegisterInfo.inc"
100 /// NVPTX Callee Saved Registers
102 NVPTXRegisterInfo::getCalleeSavedRegs(const MachineFunction
*) const {
103 static const MCPhysReg CalleeSavedRegs
[] = { 0 };
104 return CalleeSavedRegs
;
107 BitVector
NVPTXRegisterInfo::getReservedRegs(const MachineFunction
&MF
) const {
108 BitVector
Reserved(getNumRegs());
112 void NVPTXRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II
,
113 int SPAdj
, unsigned FIOperandNum
,
114 RegScavenger
*RS
) const {
115 assert(SPAdj
== 0 && "Unexpected");
117 MachineInstr
&MI
= *II
;
118 int FrameIndex
= MI
.getOperand(FIOperandNum
).getIndex();
120 MachineFunction
&MF
= *MI
.getParent()->getParent();
121 int Offset
= MF
.getFrameInfo().getObjectOffset(FrameIndex
) +
122 MI
.getOperand(FIOperandNum
+ 1).getImm();
124 // Using I0 as the frame pointer
125 MI
.getOperand(FIOperandNum
).ChangeToRegister(NVPTX::VRFrame
, false);
126 MI
.getOperand(FIOperandNum
+ 1).ChangeToImmediate(Offset
);
129 Register
NVPTXRegisterInfo::getFrameRegister(const MachineFunction
&MF
) const {
130 return NVPTX::VRFrame
;