Skip to content

Commit f86c81b

Browse files
committed
[AMDGPU] Avoid CodeGen dependencies from AMDGPU/Utils and MCTargetDesc
This required two substantial changes: 1. Moving a `getRegBitWidth(TargetRegisterClass)` overload out of Utils and into CodeGen 2. Passing the string function name to AMDGPUPALMetadata instead of the MachineFunction Other changes are minor or updates to accommodate the first two. See issue #64166 for more information on the layering issue. Differential Revision: https://reviews.llvm.org/D156486
1 parent a55f93f commit f86c81b

9 files changed

+28
-30
lines changed

llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -1113,17 +1113,18 @@ void AMDGPUAsmPrinter::EmitPALMetadata(const MachineFunction &MF,
11131113
void AMDGPUAsmPrinter::emitPALFunctionMetadata(const MachineFunction &MF) {
11141114
auto *MD = getTargetStreamer()->getPALMetadata();
11151115
const MachineFrameInfo &MFI = MF.getFrameInfo();
1116-
MD->setFunctionScratchSize(MF, MFI.getStackSize());
1116+
StringRef FnName = MF.getFunction().getName();
1117+
MD->setFunctionScratchSize(FnName, MFI.getStackSize());
11171118

11181119
// Set compute registers
11191120
MD->setRsrc1(CallingConv::AMDGPU_CS,
11201121
CurrentProgramInfo.getPGMRSrc1(CallingConv::AMDGPU_CS));
11211122
MD->setRsrc2(CallingConv::AMDGPU_CS, CurrentProgramInfo.getComputePGMRSrc2());
11221123

11231124
// Set optional info
1124-
MD->setFunctionLdsSize(MF, CurrentProgramInfo.LDSSize);
1125-
MD->setFunctionNumUsedVgprs(MF, CurrentProgramInfo.NumVGPRsForWavesPerEU);
1126-
MD->setFunctionNumUsedSgprs(MF, CurrentProgramInfo.NumSGPRsForWavesPerEU);
1125+
MD->setFunctionLdsSize(FnName, CurrentProgramInfo.LDSSize);
1126+
MD->setFunctionNumUsedVgprs(FnName, CurrentProgramInfo.NumVGPRsForWavesPerEU);
1127+
MD->setFunctionNumUsedSgprs(FnName, CurrentProgramInfo.NumSGPRsForWavesPerEU);
11271128
}
11281129

11291130
// This is supposed to be log2(Size)

llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ class ApplyRegBankMapping final : public GISelChangeObserver {
193193
};
194194

195195
}
196+
196197
AMDGPURegisterBankInfo::AMDGPURegisterBankInfo(const GCNSubtarget &ST)
197198
: Subtarget(ST), TRI(Subtarget.getRegisterInfo()),
198199
TII(Subtarget.getInstrInfo()) {

llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
#include "AMDGPUInstPrinter.h"
1111
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
1212
#include "SIDefines.h"
13-
#include "SIRegisterInfo.h"
1413
#include "Utils/AMDGPUAsmUtils.h"
1514
#include "Utils/AMDGPUBaseInfo.h"
1615
#include "llvm/MC/MCExpr.h"
1716
#include "llvm/MC/MCInst.h"
1817
#include "llvm/MC/MCInstrDesc.h"
1918
#include "llvm/MC/MCInstrInfo.h"
19+
#include "llvm/MC/MCRegisterInfo.h"
2020
#include "llvm/MC/MCSubtargetInfo.h"
2121
#include "llvm/Support/CommandLine.h"
2222
#include "llvm/TargetParser/TargetParser.h"

llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -2568,6 +2568,10 @@ StringRef SIRegisterInfo::getRegAsmName(MCRegister Reg) const {
25682568
return AMDGPUInstPrinter::getRegisterName(Reg);
25692569
}
25702570

2571+
unsigned AMDGPU::getRegBitWidth(const TargetRegisterClass &RC) {
2572+
return getRegBitWidth(RC.getID());
2573+
}
2574+
25712575
static const TargetRegisterClass *
25722576
getAnyVGPRClassForBitWidth(unsigned BitWidth) {
25732577
if (BitWidth == 64)

llvm/lib/Target/AMDGPU/SIRegisterInfo.h

+5
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,11 @@ class SIRegisterInfo final : public AMDGPUGenRegisterInfo {
445445
unsigned SubReg) const;
446446
};
447447

448+
namespace AMDGPU {
449+
/// Get the size in bits of a register from the register class \p RC.
450+
unsigned getRegBitWidth(const TargetRegisterClass &RC);
451+
} // namespace AMDGPU
452+
448453
} // End namespace llvm
449454

450455
#endif

llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "AMDKernelCodeT.h"
1313
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
1414
#include "llvm/BinaryFormat/ELF.h"
15-
#include "llvm/CodeGen/TargetRegisterInfo.h"
1615
#include "llvm/IR/Attributes.h"
1716
#include "llvm/IR/Constants.h"
1817
#include "llvm/IR/Function.h"
@@ -2423,10 +2422,6 @@ unsigned getRegBitWidth(const MCRegisterClass &RC) {
24232422
return getRegBitWidth(RC.getID());
24242423
}
24252424

2426-
unsigned getRegBitWidth(const TargetRegisterClass &RC) {
2427-
return getRegBitWidth(RC.getID());
2428-
}
2429-
24302425
unsigned getRegOperandSize(const MCRegisterInfo *MRI, const MCInstrDesc &Desc,
24312426
unsigned OpNo) {
24322427
assert(OpNo < Desc.NumOperands);

llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h

-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class MCRegisterClass;
3131
class MCRegisterInfo;
3232
class MCSubtargetInfo;
3333
class StringRef;
34-
class TargetRegisterClass;
3534
class Triple;
3635
class raw_ostream;
3736

@@ -1202,9 +1201,6 @@ unsigned getRegBitWidth(unsigned RCID);
12021201
/// Get the size in bits of a register from the register class \p RC.
12031202
unsigned getRegBitWidth(const MCRegisterClass &RC);
12041203

1205-
/// Get the size in bits of a register from the register class \p RC.
1206-
unsigned getRegBitWidth(const TargetRegisterClass &RC);
1207-
12081204
/// Get size of register operand
12091205
unsigned getRegOperandSize(const MCRegisterInfo *MRI, const MCInstrDesc &Desc,
12101206
unsigned OpNo);

llvm/lib/Target/AMDGPU/Utils/AMDGPUPALMetadata.cpp

+8-11
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "AMDGPUPTNote.h"
1919
#include "SIDefines.h"
2020
#include "llvm/BinaryFormat/ELF.h"
21-
#include "llvm/CodeGen/MachineFunction.h"
2221
#include "llvm/IR/Constants.h"
2322
#include "llvm/IR/Module.h"
2423
#include "llvm/Support/AMDGPUMetadata.h"
@@ -242,30 +241,28 @@ void AMDGPUPALMetadata::setScratchSize(CallingConv::ID CC, unsigned Val) {
242241
}
243242

244243
// Set the stack frame size of a function in the metadata.
245-
void AMDGPUPALMetadata::setFunctionScratchSize(const MachineFunction &MF,
246-
unsigned Val) {
247-
auto Node = getShaderFunction(MF.getFunction().getName());
244+
void AMDGPUPALMetadata::setFunctionScratchSize(StringRef FnName, unsigned Val) {
245+
auto Node = getShaderFunction(FnName);
248246
Node[".stack_frame_size_in_bytes"] = MsgPackDoc.getNode(Val);
249247
}
250248

251249
// Set the amount of LDS used in bytes in the metadata.
252-
void AMDGPUPALMetadata::setFunctionLdsSize(const MachineFunction &MF,
253-
unsigned Val) {
254-
auto Node = getShaderFunction(MF.getFunction().getName());
250+
void AMDGPUPALMetadata::setFunctionLdsSize(StringRef FnName, unsigned Val) {
251+
auto Node = getShaderFunction(FnName);
255252
Node[".lds_size"] = MsgPackDoc.getNode(Val);
256253
}
257254

258255
// Set the number of used vgprs in the metadata.
259-
void AMDGPUPALMetadata::setFunctionNumUsedVgprs(const MachineFunction &MF,
256+
void AMDGPUPALMetadata::setFunctionNumUsedVgprs(StringRef FnName,
260257
unsigned Val) {
261-
auto Node = getShaderFunction(MF.getFunction().getName());
258+
auto Node = getShaderFunction(FnName);
262259
Node[".vgpr_count"] = MsgPackDoc.getNode(Val);
263260
}
264261

265262
// Set the number of used vgprs in the metadata.
266-
void AMDGPUPALMetadata::setFunctionNumUsedSgprs(const MachineFunction &MF,
263+
void AMDGPUPALMetadata::setFunctionNumUsedSgprs(StringRef FnName,
267264
unsigned Val) {
268-
auto Node = getShaderFunction(MF.getFunction().getName());
265+
auto Node = getShaderFunction(FnName);
269266
Node[".sgpr_count"] = MsgPackDoc.getNode(Val);
270267
}
271268

llvm/lib/Target/AMDGPU/Utils/AMDGPUPALMetadata.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
namespace llvm {
1919

20-
class MachineFunction;
2120
class Module;
2221
class StringRef;
2322

@@ -87,22 +86,22 @@ class AMDGPUPALMetadata {
8786
void setScratchSize(unsigned CC, unsigned Val);
8887

8988
// Set the stack frame size of a function in the metadata.
90-
void setFunctionScratchSize(const MachineFunction &MF, unsigned Val);
89+
void setFunctionScratchSize(StringRef FnName, unsigned Val);
9190

9291
// Set the amount of LDS used in bytes in the metadata. This is an optional
9392
// advisory record for logging etc; wave dispatch actually uses the rsrc1
9493
// register for the shader stage to determine the amount of LDS to allocate.
95-
void setFunctionLdsSize(const MachineFunction &MF, unsigned Val);
94+
void setFunctionLdsSize(StringRef FnName, unsigned Val);
9695

9796
// Set the number of used vgprs in the metadata. This is an optional advisory
9897
// record for logging etc; wave dispatch actually uses the rsrc1 register for
9998
// the shader stage to determine the number of vgprs to allocate.
100-
void setFunctionNumUsedVgprs(const MachineFunction &MF, unsigned Val);
99+
void setFunctionNumUsedVgprs(StringRef FnName, unsigned Val);
101100

102101
// Set the number of used sgprs in the metadata. This is an optional advisory
103102
// record for logging etc; wave dispatch actually uses the rsrc1 register for
104103
// the shader stage to determine the number of sgprs to allocate.
105-
void setFunctionNumUsedSgprs(const MachineFunction &MF, unsigned Val);
104+
void setFunctionNumUsedSgprs(StringRef FnName, unsigned Val);
106105

107106
// Set the hardware register bit in PAL metadata to enable wave32 on the
108107
// shader of the given calling convention.

0 commit comments

Comments
 (0)