Skip to content

Commit

Permalink
Feedback, additional comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JanekvO committed May 20, 2024
1 parent 6896158 commit e10be1a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 44 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ void AMDGPUAsmPrinter::getAmdKernelCode(AMDGPUMCKernelCodeT &Out,
const GCNSubtarget &STM = MF.getSubtarget<GCNSubtarget>();
MCContext &Ctx = MF.getContext();

AMDGPU::initDefaultAMDKernelCodeT(Out, &STM);
Out.initDefault(&STM, Ctx, /*InitMCExpr=*/false);

Out.compute_pgm_resource1_registers =
CurrentProgramInfo.getComputePGMRSrc1(STM, Ctx);
Expand Down
31 changes: 0 additions & 31 deletions llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,37 +1222,6 @@ unsigned getAllocatedNumVGPRBlocks(const MCSubtargetInfo *STI,
void initDefaultAMDKernelCodeT(AMDGPUMCKernelCodeT &KernelCode,
const MCSubtargetInfo *STI) {
IsaVersion Version = getIsaVersion(STI->getCPU());

KernelCode.amd_kernel_code_version_major = 0;
KernelCode.amd_kernel_code_version_minor = 0;
KernelCode.amd_machine_kind = 0;
KernelCode.amd_machine_version_major = 0;
KernelCode.amd_machine_version_minor = 0;
KernelCode.amd_machine_version_stepping = 0;
KernelCode.kernel_code_prefetch_byte_offset = 0;
KernelCode.kernel_code_prefetch_byte_size = 0;
KernelCode.reserved0 = 0;
KernelCode.compute_pgm_resource_registers = 0;
KernelCode.code_properties = 0;
KernelCode.workgroup_group_segment_byte_size = 0;
KernelCode.gds_segment_byte_size = 0;
KernelCode.kernarg_segment_byte_size = 0;
KernelCode.workgroup_fbarrier_count = 0;
KernelCode.reserved_vgpr_first = 0;
KernelCode.reserved_vgpr_count = 0;
KernelCode.reserved_sgpr_first = 0;
KernelCode.reserved_sgpr_count = 0;
KernelCode.debug_wavefront_private_segment_offset_sgpr = 0;
KernelCode.debug_private_segment_buffer_sgpr = 0;
KernelCode.kernarg_segment_alignment = 0;
KernelCode.group_segment_alignment = 0;
KernelCode.private_segment_alignment = 0;
KernelCode.call_convention = 0;
memset(KernelCode.reserved3, 0, sizeof(KernelCode.reserved3));
KernelCode.runtime_loader_kernel_symbol = 0;
memset(KernelCode.control_directives, 0,
sizeof(KernelCode.control_directives));

KernelCode.amd_kernel_code_version_major = 1;
KernelCode.amd_kernel_code_version_minor = 2;
KernelCode.amd_machine_kind = 1; // AMD_MACHINE_KIND_AMDGPU
Expand Down
60 changes: 50 additions & 10 deletions llvm/lib/Target/AMDGPU/Utils/AMDKernelCodeTUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ using namespace llvm::AMDGPU;
// A check to see if AMDGPUMCKernelCodeT has a specific member so it can
// determine which of the original amd_kernel_code_t members are duplicated
// (if the names don't match, the table driven strategy won't work).
// - IsMCExprXXXXX class
// Check whether a AMDGPUMCKernelcodeT struct member is MCExpr-ified or not.
// - GetMemberXXXXX class
// A retrieval helper for said member (of type const MCExpr *&). Will return
// a `Phony` const MCExpr * initialized to nullptr to preserve reference
Expand Down Expand Up @@ -418,18 +420,56 @@ static void printAmdKernelCodeField(const AMDGPUMCKernelCodeT &C, int FldIndex,
Printer(get_amd_kernel_code_t_FldNames()[FldIndex + 1], C, OS, Ctx);
}

AMDGPUMCKernelCodeT::AMDGPUMCKernelCodeT() {
amd_kernel_code_version_major = 0;
amd_kernel_code_version_minor = 0;
amd_machine_kind = 0;
amd_machine_version_major = 0;
amd_machine_version_minor = 0;
amd_machine_version_stepping = 0;
kernel_code_entry_byte_offset = 0;
kernel_code_prefetch_byte_offset = 0;
kernel_code_prefetch_byte_size = 0;
reserved0 = 0;
compute_pgm_resource_registers = 0;
code_properties = 0;
workgroup_group_segment_byte_size = 0;
gds_segment_byte_size = 0;
kernarg_segment_byte_size = 0;
workgroup_fbarrier_count = 0;
reserved_vgpr_first = 0;
reserved_vgpr_count = 0;
reserved_sgpr_first = 0;
reserved_sgpr_count = 0;
debug_wavefront_private_segment_offset_sgpr = 0;
debug_private_segment_buffer_sgpr = 0;
kernarg_segment_alignment = 0;
group_segment_alignment = 0;
private_segment_alignment = 0;
wavefront_size = 0;
call_convention = 0;
memset(reserved3, 0, sizeof(reserved3));
runtime_loader_kernel_symbol = 0;
memset(control_directives, 0, sizeof(control_directives));
}

void AMDGPUMCKernelCodeT::initDefault(const MCSubtargetInfo *STI,
MCContext &Ctx) {
MCContext &Ctx, bool InitMCExpr) {
AMDGPUMCKernelCodeT();

AMDGPU::initDefaultAMDKernelCodeT(*this, STI);
const MCExpr *ZeroExpr = MCConstantExpr::create(0, Ctx);
compute_pgm_resource1_registers =
MCConstantExpr::create(Lo_32(compute_pgm_resource_registers), Ctx);
compute_pgm_resource2_registers =
MCConstantExpr::create(Hi_32(compute_pgm_resource_registers), Ctx);
is_dynamic_callstack = ZeroExpr;
wavefront_sgpr_count = ZeroExpr;
workitem_vgpr_count = ZeroExpr;
workitem_private_segment_byte_size = ZeroExpr;

if (InitMCExpr) {
const MCExpr *ZeroExpr = MCConstantExpr::create(0, Ctx);
compute_pgm_resource1_registers =
MCConstantExpr::create(Lo_32(compute_pgm_resource_registers), Ctx);
compute_pgm_resource2_registers =
MCConstantExpr::create(Hi_32(compute_pgm_resource_registers), Ctx);
is_dynamic_callstack = ZeroExpr;
wavefront_sgpr_count = ZeroExpr;
workitem_vgpr_count = ZeroExpr;
workitem_private_segment_byte_size = ZeroExpr;
}
}

void AMDGPUMCKernelCodeT::validate(const MCSubtargetInfo *STI, MCContext &Ctx) {
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Target/AMDGPU/Utils/AMDKernelCodeTUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class raw_ostream;
namespace AMDGPU {

struct AMDGPUMCKernelCodeT {
AMDGPUMCKernelCodeT() = default;
AMDGPUMCKernelCodeT();

uint32_t amd_kernel_code_version_major;
uint32_t amd_kernel_code_version_minor;
Expand Down Expand Up @@ -73,7 +73,8 @@ struct AMDGPUMCKernelCodeT {
const MCExpr *workitem_vgpr_count = nullptr;
const MCExpr *workitem_private_segment_byte_size = nullptr;

void initDefault(const MCSubtargetInfo *STI, MCContext &Ctx);
void initDefault(const MCSubtargetInfo *STI, MCContext &Ctx,
bool InitMCExpr = true);
void validate(const MCSubtargetInfo *STI, MCContext &Ctx);

const MCExpr *&getMCExprForIndex(int Index);
Expand Down

0 comments on commit e10be1a

Please sign in to comment.