Skip to content

Commit e21b9bd

Browse files
committed
MCExpr-ify MC layer kernel descriptor
1 parent 2cd19df commit e21b9bd

File tree

11 files changed

+639
-305
lines changed

11 files changed

+639
-305
lines changed

llvm/include/llvm/Support/AMDHSAKernelDescriptor.h

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
#endif // AMDHSA_BITS_SET
5353

5454
namespace llvm {
55+
56+
class MCContext;
57+
class MCExpr;
58+
5559
namespace amdhsa {
5660

5761
// Floating point rounding modes. Must match hardware definition.
@@ -238,18 +242,40 @@ enum : int32_t {
238242

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

255281
enum : uint32_t {
@@ -267,43 +293,6 @@ enum : uint32_t {
267293
RESERVED3_OFFSET = 60
268294
};
269295

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

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)