51 return EmitHSAMetadata(HSAMetadata);
55 std::shared_ptr<msgpack::Node> HSAMetadataRoot;
56 yaml::Input YIn(HSAMetadataString);
57 YIn >> HSAMetadataRoot;
60 return EmitHSAMetadata(HSAMetadataRoot,
false);
161 OS <<
"\t.amdgcn_target \"" << Target <<
"\"\n";
166 OS <<
"\t.hsa_code_object_version " <<
176 OS <<
"\t.hsa_code_object_isa " <<
178 ",\"" << VendorName <<
"\",\"" << ArchName <<
"\"\n";
184 OS <<
"\t.amd_kernel_code_t\n";
186 OS <<
"\t.end_amd_kernel_code_t\n";
194 OS <<
"\t.amdgpu_hsa_kernel " << SymbolName <<
'\n' ;
200 OS <<
"\t.amd_amdgpu_isa \"" << IsaVersionString <<
"\"\n";
206 std::string HSAMetadataString;
211 OS << HSAMetadataString <<
'\n';
217 std::shared_ptr<msgpack::Node> &HSAMetadataRoot,
bool Strict) {
219 if (!Verifier.
verify(*HSAMetadataRoot))
222 std::string HSAMetadataString;
224 yaml::Output YOut(StrOS);
225 YOut << HSAMetadataRoot;
228 OS << StrOS.
str() <<
'\n';
235 std::string PALMetadataString;
246 bool ReserveVCC,
bool ReserveFlatScr,
bool ReserveXNACK) {
249 OS <<
"\t.amdhsa_kernel " << KernelName <<
'\n';
251 #define PRINT_FIELD(STREAM, DIRECTIVE, KERNEL_DESC, MEMBER_NAME, FIELD_NAME) \ 252 STREAM << "\t\t" << DIRECTIVE << " " \ 253 << AMDHSA_BITS_GET(KERNEL_DESC.MEMBER_NAME, FIELD_NAME) << '\n'; 257 OS <<
"\t\t.amdhsa_private_segment_fixed_size " 260 PRINT_FIELD(OS,
".amdhsa_user_sgpr_private_segment_buffer", KD,
261 kernel_code_properties,
262 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER);
263 PRINT_FIELD(OS,
".amdhsa_user_sgpr_dispatch_ptr", KD,
264 kernel_code_properties,
265 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_PTR);
267 kernel_code_properties,
268 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_QUEUE_PTR);
269 PRINT_FIELD(OS,
".amdhsa_user_sgpr_kernarg_segment_ptr", KD,
270 kernel_code_properties,
271 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_KERNARG_SEGMENT_PTR);
272 PRINT_FIELD(OS,
".amdhsa_user_sgpr_dispatch_id", KD,
273 kernel_code_properties,
274 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_ID);
275 PRINT_FIELD(OS,
".amdhsa_user_sgpr_flat_scratch_init", KD,
276 kernel_code_properties,
277 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_FLAT_SCRATCH_INIT);
278 PRINT_FIELD(OS,
".amdhsa_user_sgpr_private_segment_size", KD,
279 kernel_code_properties,
280 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_SIZE);
282 OS,
".amdhsa_system_sgpr_private_segment_wavefront_offset", KD,
284 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_SGPR_PRIVATE_SEGMENT_WAVEFRONT_OFFSET);
285 PRINT_FIELD(OS,
".amdhsa_system_sgpr_workgroup_id_x", KD,
287 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_ID_X);
288 PRINT_FIELD(OS,
".amdhsa_system_sgpr_workgroup_id_y", KD,
290 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_ID_Y);
291 PRINT_FIELD(OS,
".amdhsa_system_sgpr_workgroup_id_z", KD,
293 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_ID_Z);
294 PRINT_FIELD(OS,
".amdhsa_system_sgpr_workgroup_info", KD,
296 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_INFO);
297 PRINT_FIELD(OS,
".amdhsa_system_vgpr_workitem_id", KD,
299 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_VGPR_WORKITEM_ID);
302 OS <<
"\t\t.amdhsa_next_free_vgpr " << NextVGPR <<
'\n';
303 OS <<
"\t\t.amdhsa_next_free_sgpr " << NextSGPR <<
'\n';
306 OS <<
"\t\t.amdhsa_reserve_vcc " << ReserveVCC <<
'\n';
307 if (IVersion.
Major >= 7 && !ReserveFlatScr)
308 OS <<
"\t\t.amdhsa_reserve_flat_scratch " << ReserveFlatScr <<
'\n';
310 OS <<
"\t\t.amdhsa_reserve_xnack_mask " << ReserveXNACK <<
'\n';
314 amdhsa::COMPUTE_PGM_RSRC1_FLOAT_ROUND_MODE_32);
315 PRINT_FIELD(OS,
".amdhsa_float_round_mode_16_64", KD,
317 amdhsa::COMPUTE_PGM_RSRC1_FLOAT_ROUND_MODE_16_64);
318 PRINT_FIELD(OS,
".amdhsa_float_denorm_mode_32", KD,
320 amdhsa::COMPUTE_PGM_RSRC1_FLOAT_DENORM_MODE_32);
321 PRINT_FIELD(OS,
".amdhsa_float_denorm_mode_16_64", KD,
323 amdhsa::COMPUTE_PGM_RSRC1_FLOAT_DENORM_MODE_16_64);
326 amdhsa::COMPUTE_PGM_RSRC1_ENABLE_DX10_CLAMP);
329 amdhsa::COMPUTE_PGM_RSRC1_ENABLE_IEEE_MODE);
330 if (IVersion.
Major >= 9)
333 amdhsa::COMPUTE_PGM_RSRC1_FP16_OVFL);
335 OS,
".amdhsa_exception_fp_ieee_invalid_op", KD,
337 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_INVALID_OPERATION);
338 PRINT_FIELD(OS,
".amdhsa_exception_fp_denorm_src", KD,
340 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_FP_DENORMAL_SOURCE);
342 OS,
".amdhsa_exception_fp_ieee_div_zero", KD,
344 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_DIVISION_BY_ZERO);
345 PRINT_FIELD(OS,
".amdhsa_exception_fp_ieee_overflow", KD,
347 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_OVERFLOW);
348 PRINT_FIELD(OS,
".amdhsa_exception_fp_ieee_underflow", KD,
350 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_UNDERFLOW);
351 PRINT_FIELD(OS,
".amdhsa_exception_fp_ieee_inexact", KD,
353 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_INEXACT);
354 PRINT_FIELD(OS,
".amdhsa_exception_int_div_zero", KD,
356 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_INT_DIVIDE_BY_ZERO);
359 OS <<
"\t.end_amdhsa_kernel\n";
390 void AMDGPUTargetELFStreamer::EmitNote(
394 auto &
Context = S.getContext();
396 auto NameSZ = Name.
size() + 1;
399 S.SwitchSection(
Context.getELFSection(
401 S.EmitIntValue(NameSZ, 4);
402 S.EmitValue(DescSZ, 4);
403 S.EmitIntValue(NoteType, 4);
405 S.EmitValueToAlignment(4, 0, 1, 0);
407 S.EmitValueToAlignment(4, 0, 1, 0);
429 uint16_t VendorNameSize = VendorName.
size() + 1;
430 uint16_t ArchNameSize = ArchName.
size() + 1;
432 unsigned DescSZ =
sizeof(VendorNameSize) +
sizeof(ArchNameSize) +
433 sizeof(Major) +
sizeof(Minor) +
sizeof(Stepping) +
434 VendorNameSize + ArchNameSize;
470 auto *DescBegin =
Context.createTempSymbol();
471 auto *DescEnd =
Context.createTempSymbol();
486 std::shared_ptr<msgpack::Node> &HSAMetadataRoot,
bool Strict) {
488 if (!Verifier.
verify(*HSAMetadataRoot))
491 std::string HSAMetadataString;
494 HSAMetadataRoot->write(MPWriter);
499 auto *DescBegin =
Context.createTempSymbol();
500 auto *DescEnd =
Context.createTempSymbol();
516 std::string HSAMetadataString;
523 auto *DescBegin =
Context.createTempSymbol();
524 auto *DescEnd =
Context.createTempSymbol();
544 for (
auto I : PALMetadata)
553 uint64_t NextSGPR,
bool ReserveVCC,
bool ReserveFlatScr,
558 MCSymbolELF *KernelDescriptorSymbol = cast<MCSymbolELF>(
562 KernelDescriptorSymbol->
setSize(
569 Streamer.
EmitLabel(KernelDescriptorSymbol);
571 (
const char*)&(KernelDescriptor),
585 (
const char*)&(KernelDescriptor) +
588 sizeof(KernelDescriptor) -
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)
StringRef getArchNameR600(GPUKind AK)
This class represents lattice values for constants.
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.
An efficient, type-erasing, non-owning reference to a callable.
virtual bool EmitHSAMetadataV2(StringRef HSAMetadataString)
Instruction set architecture version.
void PushSection()
Save the current and previous section on the section stack.
bool EmitHSAMetadata(std::shared_ptr< msgpack::Node > &HSAMetadata, bool Strict) override
virtual bool EmitHSAMetadataV3(StringRef HSAMetadataString)
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
#define PRINT_FIELD(STREAM, DIRECTIVE, KERNEL_DESC, MEMBER_NAME, FIELD_NAME)
MCContext & getContext() const
amdgpu Simplify well known AMD library false Value Value const Twine & Name
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
AMD Kernel Code Object (amd_kernel_code_t).
Base class for the full range of assembler expressions which are needed for parsing.
Writes MessagePack objects to an output stream, one at a time.
static StringRef getArchNameFromElfMach(unsigned ElfMach)
StringRef getArchNameAMDGCN(GPUKind AK)
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())
This is a data structure for representing MessagePack "documents", with methods to go to and from Mes...
bool hasSRAMECC(const MCSubtargetInfo &STI)
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...
GPUKind
GPU kinds supported by the AMDGPU target.
void setSize(const MCExpr *SS)
void EmitDirectiveHSACodeObjectVersion(uint32_t Major, uint32_t Minor) override
static unsigned getElfMach(StringRef GPU)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
GPUKind parseArchAMDGCN(StringRef CPU)
MCAssembler & getAssembler()
#define offsetof(TYPE, MEMBER)
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.
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setType(unsigned Type) const
MCELFStreamer & getStreamer()
IsaVersion getIsaVersion(StringRef GPU)
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
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)
verify safepoint Safepoint IR Verifier
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.
bool EmitHSAMetadata(std::shared_ptr< msgpack::Node > &HSAMetadata, bool Strict) override
void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override
void dumpAmdKernelCode(const amd_kernel_code_t *C, raw_ostream &OS, const char *tab)
A raw_ostream that writes to an std::string.
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.
GPUKind parseArchR600(StringRef CPU)
std::string toString(wasm::WasmSymbolType type)
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
std::vector< uint32_t > Metadata
PAL metadata represented as a vector.