108 for (; Entry->Name && GPU != Entry->Name; ++Entry)
115 for (; Entry->Name && Mach != Entry->Mach; ++Entry)
125 return EmitHSAMetadata(HSAMetadata);
137 OS <<
"\t.amdgcn_target \"" << Target <<
"\"\n";
142 OS <<
"\t.hsa_code_object_version " <<
152 OS <<
"\t.hsa_code_object_isa " <<
154 ",\"" << VendorName <<
"\",\"" << ArchName <<
"\"\n";
160 OS <<
"\t.amd_kernel_code_t\n";
162 OS <<
"\t.end_amd_kernel_code_t\n";
170 OS <<
"\t.amdgpu_hsa_kernel " << SymbolName <<
'\n' ;
176 OS <<
"\t.amd_amdgpu_isa \"" << IsaVersionString <<
"\"\n";
182 std::string HSAMetadataString;
187 OS << HSAMetadataString <<
'\n';
194 std::string PALMetadataString;
205 bool ReserveVCC,
bool ReserveFlatScr,
bool ReserveXNACK) {
210 OS <<
"\t.amdhsa_kernel " << KernelName <<
'\n';
212 #define PRINT_IF_NOT_DEFAULT(STREAM, DIRECTIVE, KERNEL_DESC, \ 213 DEFAULT_KERNEL_DESC, MEMBER_NAME, FIELD_NAME) \ 214 if (AMDHSA_BITS_GET(KERNEL_DESC.MEMBER_NAME, FIELD_NAME) != \ 215 AMDHSA_BITS_GET(DEFAULT_KERNEL_DESC.MEMBER_NAME, FIELD_NAME)) \ 216 STREAM << "\t\t" << DIRECTIVE << " " \ 217 << AMDHSA_BITS_GET(KERNEL_DESC.MEMBER_NAME, FIELD_NAME) << '\n'; 223 OS <<
"\t\t.amdhsa_private_segment_fixed_size " 227 OS,
".amdhsa_user_sgpr_private_segment_buffer", KD, DefaultKD,
228 kernel_code_properties,
229 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER);
231 kernel_code_properties,
232 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_PTR);
234 kernel_code_properties,
235 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_QUEUE_PTR);
237 OS,
".amdhsa_user_sgpr_kernarg_segment_ptr", KD, DefaultKD,
238 kernel_code_properties,
239 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_KERNARG_SEGMENT_PTR);
241 kernel_code_properties,
242 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_ID);
244 OS,
".amdhsa_user_sgpr_flat_scratch_init", KD, DefaultKD,
245 kernel_code_properties,
246 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_FLAT_SCRATCH_INIT);
248 OS,
".amdhsa_user_sgpr_private_segment_size", KD, DefaultKD,
249 kernel_code_properties,
250 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_SIZE);
252 OS,
".amdhsa_system_sgpr_private_segment_wavefront_offset", KD, DefaultKD,
254 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_SGPR_PRIVATE_SEGMENT_WAVEFRONT_OFFSET);
257 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_ID_X);
260 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_ID_Y);
263 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_ID_Z);
266 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_INFO);
269 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_VGPR_WORKITEM_ID);
272 OS <<
"\t\t.amdhsa_next_free_vgpr " << NextVGPR <<
'\n';
273 OS <<
"\t\t.amdhsa_next_free_sgpr " << NextSGPR <<
'\n';
276 OS <<
"\t\t.amdhsa_reserve_vcc " << ReserveVCC <<
'\n';
277 if (IVersion.
Major >= 7 && !ReserveFlatScr)
278 OS <<
"\t\t.amdhsa_reserve_flat_scratch " << ReserveFlatScr <<
'\n';
280 OS <<
"\t\t.amdhsa_reserve_xnack_mask " << ReserveXNACK <<
'\n';
284 amdhsa::COMPUTE_PGM_RSRC1_FLOAT_ROUND_MODE_32);
287 amdhsa::COMPUTE_PGM_RSRC1_FLOAT_ROUND_MODE_16_64);
290 amdhsa::COMPUTE_PGM_RSRC1_FLOAT_DENORM_MODE_32);
293 amdhsa::COMPUTE_PGM_RSRC1_FLOAT_DENORM_MODE_16_64);
296 amdhsa::COMPUTE_PGM_RSRC1_ENABLE_DX10_CLAMP);
299 amdhsa::COMPUTE_PGM_RSRC1_ENABLE_IEEE_MODE);
300 if (IVersion.
Major >= 9)
303 amdhsa::COMPUTE_PGM_RSRC1_FP16_OVFL);
305 OS,
".amdhsa_exception_fp_ieee_invalid_op", KD, DefaultKD,
307 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_INVALID_OPERATION);
309 OS,
".amdhsa_exception_fp_denorm_src", KD, DefaultKD, compute_pgm_rsrc2,
310 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_FP_DENORMAL_SOURCE);
312 OS,
".amdhsa_exception_fp_ieee_div_zero", KD, DefaultKD,
314 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_DIVISION_BY_ZERO);
316 OS,
".amdhsa_exception_fp_ieee_overflow", KD, DefaultKD,
318 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_OVERFLOW);
320 OS,
".amdhsa_exception_fp_ieee_underflow", KD, DefaultKD,
322 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_UNDERFLOW);
324 OS,
".amdhsa_exception_fp_ieee_inexact", KD, DefaultKD, compute_pgm_rsrc2,
325 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_INEXACT);
327 OS,
".amdhsa_exception_int_div_zero", KD, DefaultKD, compute_pgm_rsrc2,
328 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_INT_DIVIDE_BY_ZERO);
329 #undef PRINT_IF_NOT_DEFAULT 331 OS <<
"\t.end_amdhsa_kernel\n";
358 void AMDGPUTargetELFStreamer::EmitAMDGPUNote(
362 auto &
Context = S.getContext();
367 S.SwitchSection(
Context.getELFSection(
369 S.EmitIntValue(NameSZ, 4);
370 S.EmitValue(DescSZ, 4);
371 S.EmitIntValue(NoteType, 4);
373 S.EmitValueToAlignment(4, 0, 1, 0);
375 S.EmitValueToAlignment(4, 0, 1, 0);
400 uint16_t VendorNameSize = VendorName.
size() + 1;
401 uint16_t ArchNameSize = ArchName.
size() + 1;
403 unsigned DescSZ =
sizeof(VendorNameSize) +
sizeof(ArchNameSize) +
404 sizeof(Major) +
sizeof(Minor) +
sizeof(Stepping) +
405 VendorNameSize + ArchNameSize;
444 auto *DescBegin =
Context.createTempSymbol();
445 auto *DescEnd =
Context.createTempSymbol();
464 std::string HSAMetadataString;
471 auto *DescBegin =
Context.createTempSymbol();
472 auto *DescEnd =
Context.createTempSymbol();
495 for (
auto I : PALMetadata)
505 uint64_t NextSGPR,
bool ReserveVCC,
bool ReserveFlatScr,
510 MCSymbolELF *KernelDescriptorSymbol = cast<MCSymbolELF>(
514 KernelDescriptorSymbol->
setSize(
521 Streamer.
EmitLabel(KernelDescriptorSymbol);
523 (
const char*)&(KernelDescriptor),
537 (
const char*)&(KernelDescriptor) +
540 sizeof(KernelDescriptor) -
bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) override
void setELFHeaderEFlags(unsigned Flags)
int64_t kernel_code_entry_byte_offset
void EmitBytes(StringRef Data) override
Emit the bytes in Data into the output.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Compute iterated dominance frontiers using a linear time algorithm.
void EmitAmdhsaKernelDescriptor(const MCSubtargetInfo &STI, StringRef KernelName, const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR, uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr, bool ReserveXNACK) override
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
virtual void EmitBytes(StringRef Data)
Emit the bytes in Data into the output.
#define PRINT_IF_NOT_DEFAULT(STREAM, DIRECTIVE, KERNEL_DESC, DEFAULT_KERNEL_DESC, MEMBER_NAME, FIELD_NAME)
An efficient, type-erasing, non-owning reference to a callable.
void PushSection()
Save the current and previous section on the section stack.
static const struct @358 MachTable[]
void EmitDirectiveHSACodeObjectISA(uint32_t Major, uint32_t Minor, uint32_t Stepping, StringRef VendorName, StringRef ArchName) override
void EmitDirectiveHSACodeObjectISA(uint32_t Major, uint32_t Minor, uint32_t Stepping, StringRef VendorName, StringRef ArchName) override
amdhsa::kernel_descriptor_t getDefaultAmdhsaKernelDescriptor()
MCContext & getContext() const
virtual bool EmitHSAMetadata(StringRef HSAMetadataString)
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
const FeatureBitset & getFeatureBits() const
AMD Kernel Code Object (amd_kernel_code_t).
Base class for the full range of assembler expressions which are needed for parsing.
bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) override
uint32_t private_segment_fixed_size
std::error_code fromString(std::string String, Metadata &HSAMetadata)
Converts String to HSAMetadata.
uint32_t group_segment_fixed_size
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
virtual void EmitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers...
void EmitValue(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
Streaming machine code generation interface.
constexpr char AssemblerDirectiveBegin[]
HSA metadata beginning assembler directive.
The instances of the Type class are immutable: once they are created, they are never changed...
void setSize(const MCExpr *SS)
void EmitDirectiveHSACodeObjectVersion(uint32_t Major, uint32_t Minor) override
This file contains the declarations for the subclasses of Constant, which represent the different fla...
MCAssembler & getAssembler()
#define offsetof(TYPE, MEMBER)
Instruction set architecture version.
AMDGPUTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS)
constexpr char AssemblerDirectiveEnd[]
HSA metadata ending assembler directive.
constexpr char AssemblerDirective[]
PAL metadata assembler directive.
unsigned getELFHeaderEFlags() const
ELF e_header flags.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setType(unsigned Type) const
MCELFStreamer & getStreamer()
void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override
Enums and constants for AMDGPU PT_NOTE sections.
void EmitAmdhsaKernelDescriptor(const MCSubtargetInfo &STI, StringRef KernelName, const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR, uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr, bool ReserveXNACK) override
MCContext & getContext() const
Module.h This file contains the declarations for the Module class.
void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override
void setBinding(unsigned Binding) const
unsigned getMACH(StringRef GPU) const
static const char * getMachName(unsigned Mach)
void EmitDirectiveAMDGCNTarget(StringRef Target) override
void EmitDirectiveHSACodeObjectVersion(uint32_t Major, uint32_t Minor) override
Target - Wrapper for Target specific information.
bool EmitPALMetadata(const AMDGPU::PALMD::Metadata &PALMetadata) override
bool EmitISAVersion(StringRef IsaVersionString) override
void EmitDirectiveAMDGCNTarget(StringRef Target) override
void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
bool hasXNACK(const MCSubtargetInfo &STI)
bool EmitISAVersion(StringRef IsaVersionString) override
Generic base class for all target subtargets.
bool EmitPALMetadata(const AMDGPU::PALMD::Metadata &PALMetadata) override
AMDGPUTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override
void dumpAmdKernelCode(const amd_kernel_code_t *C, raw_ostream &OS, const char *tab)
bool PopSection()
Restore the current and previous section from the section stack.
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
StringRef - Represent a constant reference to a string, i.e.
std::string toString(wasm::WasmSymbolType type)
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
IsaVersion getIsaVersion(const FeatureBitset &Features)
std::vector< uint32_t > Metadata
PAL metadata represented as a vector.