Skip to content

Commit 857161c

Browse files
authored
[AMDGPU] MCExpr-ify MC layer kernel descriptor (#80855)
Kernel descriptor attributes, with their respective emit and asm parse functionality, converted to MCExpr.
1 parent 2bfa7d0 commit 857161c

19 files changed

+1988
-304
lines changed

llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "AMDKernelCodeT.h"
2323
#include "GCNSubtarget.h"
2424
#include "MCTargetDesc/AMDGPUInstPrinter.h"
25+
#include "MCTargetDesc/AMDGPUMCKernelDescriptor.h"
2526
#include "MCTargetDesc/AMDGPUTargetStreamer.h"
2627
#include "R600AsmPrinter.h"
2728
#include "SIMachineFunctionInfo.h"
@@ -428,38 +429,43 @@ uint16_t AMDGPUAsmPrinter::getAmdhsaKernelCodeProperties(
428429
return KernelCodeProperties;
429430
}
430431

431-
amdhsa::kernel_descriptor_t AMDGPUAsmPrinter::getAmdhsaKernelDescriptor(
432-
const MachineFunction &MF,
433-
const SIProgramInfo &PI) const {
432+
MCKernelDescriptor
433+
AMDGPUAsmPrinter::getAmdhsaKernelDescriptor(const MachineFunction &MF,
434+
const SIProgramInfo &PI) const {
434435
const GCNSubtarget &STM = MF.getSubtarget<GCNSubtarget>();
435436
const Function &F = MF.getFunction();
436437
const SIMachineFunctionInfo *Info = MF.getInfo<SIMachineFunctionInfo>();
438+
MCContext &Ctx = MF.getContext();
437439

438-
amdhsa::kernel_descriptor_t KernelDescriptor;
439-
memset(&KernelDescriptor, 0x0, sizeof(KernelDescriptor));
440+
MCKernelDescriptor KernelDescriptor;
440441

441442
assert(isUInt<32>(PI.ScratchSize));
442443
assert(isUInt<32>(PI.getComputePGMRSrc1(STM)));
443444
assert(isUInt<32>(PI.getComputePGMRSrc2()));
444445

445-
KernelDescriptor.group_segment_fixed_size = PI.LDSSize;
446-
KernelDescriptor.private_segment_fixed_size = PI.ScratchSize;
446+
KernelDescriptor.group_segment_fixed_size =
447+
MCConstantExpr::create(PI.LDSSize, Ctx);
448+
KernelDescriptor.private_segment_fixed_size =
449+
MCConstantExpr::create(PI.ScratchSize, Ctx);
447450

448451
Align MaxKernArgAlign;
449-
KernelDescriptor.kernarg_size = STM.getKernArgSegmentSize(F, MaxKernArgAlign);
452+
KernelDescriptor.kernarg_size = MCConstantExpr::create(
453+
STM.getKernArgSegmentSize(F, MaxKernArgAlign), Ctx);
450454

451-
KernelDescriptor.compute_pgm_rsrc1 = PI.getComputePGMRSrc1(STM);
452-
KernelDescriptor.compute_pgm_rsrc2 = PI.getComputePGMRSrc2();
453-
KernelDescriptor.kernel_code_properties = getAmdhsaKernelCodeProperties(MF);
455+
KernelDescriptor.compute_pgm_rsrc1 =
456+
MCConstantExpr::create(PI.getComputePGMRSrc1(STM), Ctx);
457+
KernelDescriptor.compute_pgm_rsrc2 =
458+
MCConstantExpr::create(PI.getComputePGMRSrc2(), Ctx);
459+
KernelDescriptor.kernel_code_properties =
460+
MCConstantExpr::create(getAmdhsaKernelCodeProperties(MF), Ctx);
454461

455462
assert(STM.hasGFX90AInsts() || CurrentProgramInfo.ComputePGMRSrc3GFX90A == 0);
456-
if (STM.hasGFX90AInsts())
457-
KernelDescriptor.compute_pgm_rsrc3 =
458-
CurrentProgramInfo.ComputePGMRSrc3GFX90A;
463+
KernelDescriptor.compute_pgm_rsrc3 = MCConstantExpr::create(
464+
STM.hasGFX90AInsts() ? CurrentProgramInfo.ComputePGMRSrc3GFX90A : 0, Ctx);
459465

460-
if (AMDGPU::hasKernargPreload(STM))
461-
KernelDescriptor.kernarg_preload =
462-
static_cast<uint16_t>(Info->getNumKernargPreloadedSGPRs());
466+
KernelDescriptor.kernarg_preload = MCConstantExpr::create(
467+
AMDGPU::hasKernargPreload(STM) ? Info->getNumKernargPreloadedSGPRs() : 0,
468+
Ctx);
463469

464470
return KernelDescriptor;
465471
}

llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,12 @@ class MCCodeEmitter;
2828
class MCOperand;
2929

3030
namespace AMDGPU {
31+
struct MCKernelDescriptor;
3132
namespace HSAMD {
3233
class MetadataStreamer;
3334
}
3435
} // namespace AMDGPU
3536

36-
namespace amdhsa {
37-
struct kernel_descriptor_t;
38-
}
39-
4037
class AMDGPUAsmPrinter final : public AsmPrinter {
4138
private:
4239
unsigned CodeObjectVersion;
@@ -75,9 +72,9 @@ class AMDGPUAsmPrinter final : public AsmPrinter {
7572
uint16_t getAmdhsaKernelCodeProperties(
7673
const MachineFunction &MF) const;
7774

78-
amdhsa::kernel_descriptor_t getAmdhsaKernelDescriptor(
79-
const MachineFunction &MF,
80-
const SIProgramInfo &PI) const;
75+
AMDGPU::MCKernelDescriptor
76+
getAmdhsaKernelDescriptor(const MachineFunction &MF,
77+
const SIProgramInfo &PI) const;
8178

8279
void initTargetStreamer(Module &M);
8380

0 commit comments

Comments
 (0)