Skip to content

Commit 769ee73

Browse files
committed
MCExpr-ify MC layer kernel descriptor
1 parent 953c13b commit 769ee73

File tree

10 files changed

+636
-302
lines changed

10 files changed

+636
-302
lines changed

llvm/include/llvm/Support/AMDHSAKernelDescriptor.h

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
#endif // AMDHSA_BITS_SET
5656

5757
namespace llvm {
58+
59+
class MCContext;
60+
class MCExpr;
61+
5862
namespace amdhsa {
5963

6064
// Floating point rounding modes. Must match hardware definition.
@@ -241,18 +245,40 @@ enum : int32_t {
241245

242246
// Kernel descriptor. Must be kept backwards compatible.
243247
struct kernel_descriptor_t {
244-
uint32_t group_segment_fixed_size;
245-
uint32_t private_segment_fixed_size;
246-
uint32_t kernarg_size;
248+
const MCExpr *group_segment_fixed_size;
249+
const MCExpr *private_segment_fixed_size;
250+
const MCExpr *kernarg_size;
247251
uint8_t reserved0[4];
248252
int64_t kernel_code_entry_byte_offset;
249253
uint8_t reserved1[20];
250-
uint32_t compute_pgm_rsrc3; // GFX10+ and GFX90A+
251-
uint32_t compute_pgm_rsrc1;
252-
uint32_t compute_pgm_rsrc2;
253-
uint16_t kernel_code_properties;
254-
uint16_t kernarg_preload;
254+
const MCExpr *compute_pgm_rsrc3; // GFX10+ and GFX90A+
255+
const MCExpr *compute_pgm_rsrc1;
256+
const MCExpr *compute_pgm_rsrc2;
257+
const MCExpr *kernel_code_properties;
258+
const MCExpr *kernarg_preload;
255259
uint8_t reserved3[4];
260+
261+
static void bits_set(const MCExpr *&Dst, const MCExpr *Value, uint32_t Shift,
262+
uint32_t Mask, MCContext &Ctx);
263+
static const MCExpr *bits_get(const MCExpr *Src, uint32_t Shift,
264+
uint32_t Mask, MCContext &Ctx);
265+
};
266+
267+
// Sizes for kernel_descriptor_t properties, should add up to 64.
268+
enum : uint32_t {
269+
SIZEOF_GROUP_SEGMENT_FIXED_SIZE = 4,
270+
SIZEOF_PRIVATE_SEGMENT_FIXED_SIZE = 4,
271+
SIZEOF_KERNARG_SIZE = 4,
272+
SIZEOF_RESERVED0 = 4,
273+
SIZEOF_KERNEL_CODE_ENTRY_BYTE_OFFSET = 8,
274+
SIZEOF_RESERVED1 = 20,
275+
SIZEOF_COMPUTE_PGM_RSRC3 = 4,
276+
SIZEOF_COMPUTE_PGM_RSRC1 = 4,
277+
SIZEOF_COMPUTE_PGM_RSRC2 = 4,
278+
SIZEOF_KERNEL_CODE_PROPERTIES = 2,
279+
SIZEOF_KERNARG_PRELOAD = 2,
280+
SIZEOF_RESERVED3 = 4,
281+
SIZEOF_KERNEL_DESCRIPTOR = 64
256282
};
257283

258284
enum : uint32_t {
@@ -270,43 +296,6 @@ enum : uint32_t {
270296
RESERVED3_OFFSET = 60
271297
};
272298

273-
static_assert(
274-
sizeof(kernel_descriptor_t) == 64,
275-
"invalid size for kernel_descriptor_t");
276-
static_assert(offsetof(kernel_descriptor_t, group_segment_fixed_size) ==
277-
GROUP_SEGMENT_FIXED_SIZE_OFFSET,
278-
"invalid offset for group_segment_fixed_size");
279-
static_assert(offsetof(kernel_descriptor_t, private_segment_fixed_size) ==
280-
PRIVATE_SEGMENT_FIXED_SIZE_OFFSET,
281-
"invalid offset for private_segment_fixed_size");
282-
static_assert(offsetof(kernel_descriptor_t, kernarg_size) ==
283-
KERNARG_SIZE_OFFSET,
284-
"invalid offset for kernarg_size");
285-
static_assert(offsetof(kernel_descriptor_t, reserved0) == RESERVED0_OFFSET,
286-
"invalid offset for reserved0");
287-
static_assert(offsetof(kernel_descriptor_t, kernel_code_entry_byte_offset) ==
288-
KERNEL_CODE_ENTRY_BYTE_OFFSET_OFFSET,
289-
"invalid offset for kernel_code_entry_byte_offset");
290-
static_assert(offsetof(kernel_descriptor_t, reserved1) == RESERVED1_OFFSET,
291-
"invalid offset for reserved1");
292-
static_assert(offsetof(kernel_descriptor_t, compute_pgm_rsrc3) ==
293-
COMPUTE_PGM_RSRC3_OFFSET,
294-
"invalid offset for compute_pgm_rsrc3");
295-
static_assert(offsetof(kernel_descriptor_t, compute_pgm_rsrc1) ==
296-
COMPUTE_PGM_RSRC1_OFFSET,
297-
"invalid offset for compute_pgm_rsrc1");
298-
static_assert(offsetof(kernel_descriptor_t, compute_pgm_rsrc2) ==
299-
COMPUTE_PGM_RSRC2_OFFSET,
300-
"invalid offset for compute_pgm_rsrc2");
301-
static_assert(offsetof(kernel_descriptor_t, kernel_code_properties) ==
302-
KERNEL_CODE_PROPERTIES_OFFSET,
303-
"invalid offset for kernel_code_properties");
304-
static_assert(offsetof(kernel_descriptor_t, kernarg_preload) ==
305-
KERNARG_PRELOAD_OFFSET,
306-
"invalid offset for kernarg_preload");
307-
static_assert(offsetof(kernel_descriptor_t, reserved3) == RESERVED3_OFFSET,
308-
"invalid offset for reserved3");
309-
310299
} // end namespace amdhsa
311300
} // end namespace llvm
312301

llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -442,24 +442,30 @@ amdhsa::kernel_descriptor_t AMDGPUAsmPrinter::getAmdhsaKernelDescriptor(
442442
assert(isUInt<32>(PI.getComputePGMRSrc1(STM)));
443443
assert(isUInt<32>(PI.getComputePGMRSrc2()));
444444

445-
KernelDescriptor.group_segment_fixed_size = PI.LDSSize;
446-
KernelDescriptor.private_segment_fixed_size = PI.ScratchSize;
445+
KernelDescriptor.group_segment_fixed_size =
446+
MCConstantExpr::create(PI.LDSSize, MF.getContext());
447+
KernelDescriptor.private_segment_fixed_size =
448+
MCConstantExpr::create(PI.ScratchSize, MF.getContext());
447449

448450
Align MaxKernArgAlign;
449-
KernelDescriptor.kernarg_size = STM.getKernArgSegmentSize(F, MaxKernArgAlign);
451+
KernelDescriptor.kernarg_size = MCConstantExpr::create(
452+
STM.getKernArgSegmentSize(F, MaxKernArgAlign), MF.getContext());
450453

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

455461
assert(STM.hasGFX90AInsts() || CurrentProgramInfo.ComputePGMRSrc3GFX90A == 0);
456-
if (STM.hasGFX90AInsts())
457-
KernelDescriptor.compute_pgm_rsrc3 =
458-
CurrentProgramInfo.ComputePGMRSrc3GFX90A;
462+
KernelDescriptor.compute_pgm_rsrc3 = MCConstantExpr::create(
463+
STM.hasGFX90AInsts() ? CurrentProgramInfo.ComputePGMRSrc3GFX90A : 0,
464+
MF.getContext());
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+
MF.getContext());
463469

464470
return KernelDescriptor;
465471
}

0 commit comments

Comments
 (0)