49 return EmitHSAMetadata(HSAMetadata);
54 if (!HSAMetadataDoc.
fromYAML(HSAMetadataString))
56 return EmitHSAMetadata(HSAMetadataDoc,
false);
174 OS <<
"\t.amdgcn_target \"" << Target <<
"\"\n";
179 OS <<
"\t.hsa_code_object_version " <<
189 OS <<
"\t.hsa_code_object_isa " <<
191 ",\"" << VendorName <<
"\",\"" << ArchName <<
"\"\n";
197 OS <<
"\t.amd_kernel_code_t\n";
199 OS <<
"\t.end_amd_kernel_code_t\n";
207 OS <<
"\t.amdgpu_hsa_kernel " << SymbolName <<
'\n' ;
214 OS <<
"\t.amdgpu_lds " << Symbol->
getName() <<
", " << Size <<
", " << Align
219 OS <<
"\t.amd_amdgpu_isa \"" << IsaVersionString <<
"\"\n";
225 std::string HSAMetadataString;
230 OS << HSAMetadataString <<
'\n';
241 std::string HSAMetadataString;
243 HSAMetadataDoc.
toYAML(StrOS);
246 OS << StrOS.
str() <<
'\n';
252 const uint32_t Encoded_s_code_end = 0xbf9f0000;
253 OS <<
"\t.p2alignl 6, " << Encoded_s_code_end <<
'\n';
254 OS <<
"\t.fill 48, 4, " << Encoded_s_code_end <<
'\n';
261 bool ReserveVCC,
bool ReserveFlatScr,
bool ReserveXNACK) {
264 OS <<
"\t.amdhsa_kernel " << KernelName <<
'\n';
266 #define PRINT_FIELD(STREAM, DIRECTIVE, KERNEL_DESC, MEMBER_NAME, FIELD_NAME) \ 267 STREAM << "\t\t" << DIRECTIVE << " " \ 268 << AMDHSA_BITS_GET(KERNEL_DESC.MEMBER_NAME, FIELD_NAME) << '\n'; 272 OS <<
"\t\t.amdhsa_private_segment_fixed_size " 275 PRINT_FIELD(OS,
".amdhsa_user_sgpr_private_segment_buffer", KD,
276 kernel_code_properties,
277 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER);
278 PRINT_FIELD(OS,
".amdhsa_user_sgpr_dispatch_ptr", KD,
279 kernel_code_properties,
280 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_PTR);
282 kernel_code_properties,
283 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_QUEUE_PTR);
284 PRINT_FIELD(OS,
".amdhsa_user_sgpr_kernarg_segment_ptr", KD,
285 kernel_code_properties,
286 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_KERNARG_SEGMENT_PTR);
287 PRINT_FIELD(OS,
".amdhsa_user_sgpr_dispatch_id", KD,
288 kernel_code_properties,
289 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_ID);
290 PRINT_FIELD(OS,
".amdhsa_user_sgpr_flat_scratch_init", KD,
291 kernel_code_properties,
292 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_FLAT_SCRATCH_INIT);
293 PRINT_FIELD(OS,
".amdhsa_user_sgpr_private_segment_size", KD,
294 kernel_code_properties,
295 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_SIZE);
296 if (IVersion.
Major >= 10)
298 kernel_code_properties,
299 amdhsa::KERNEL_CODE_PROPERTY_ENABLE_WAVEFRONT_SIZE32);
301 OS,
".amdhsa_system_sgpr_private_segment_wavefront_offset", KD,
303 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_SGPR_PRIVATE_SEGMENT_WAVEFRONT_OFFSET);
304 PRINT_FIELD(OS,
".amdhsa_system_sgpr_workgroup_id_x", KD,
306 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_ID_X);
307 PRINT_FIELD(OS,
".amdhsa_system_sgpr_workgroup_id_y", KD,
309 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_ID_Y);
310 PRINT_FIELD(OS,
".amdhsa_system_sgpr_workgroup_id_z", KD,
312 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_ID_Z);
313 PRINT_FIELD(OS,
".amdhsa_system_sgpr_workgroup_info", KD,
315 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_SGPR_WORKGROUP_INFO);
316 PRINT_FIELD(OS,
".amdhsa_system_vgpr_workitem_id", KD,
318 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_VGPR_WORKITEM_ID);
321 OS <<
"\t\t.amdhsa_next_free_vgpr " << NextVGPR <<
'\n';
322 OS <<
"\t\t.amdhsa_next_free_sgpr " << NextSGPR <<
'\n';
325 OS <<
"\t\t.amdhsa_reserve_vcc " << ReserveVCC <<
'\n';
326 if (IVersion.
Major >= 7 && !ReserveFlatScr)
327 OS <<
"\t\t.amdhsa_reserve_flat_scratch " << ReserveFlatScr <<
'\n';
329 OS <<
"\t\t.amdhsa_reserve_xnack_mask " << ReserveXNACK <<
'\n';
333 amdhsa::COMPUTE_PGM_RSRC1_FLOAT_ROUND_MODE_32);
334 PRINT_FIELD(OS,
".amdhsa_float_round_mode_16_64", KD,
336 amdhsa::COMPUTE_PGM_RSRC1_FLOAT_ROUND_MODE_16_64);
337 PRINT_FIELD(OS,
".amdhsa_float_denorm_mode_32", KD,
339 amdhsa::COMPUTE_PGM_RSRC1_FLOAT_DENORM_MODE_32);
340 PRINT_FIELD(OS,
".amdhsa_float_denorm_mode_16_64", KD,
342 amdhsa::COMPUTE_PGM_RSRC1_FLOAT_DENORM_MODE_16_64);
345 amdhsa::COMPUTE_PGM_RSRC1_ENABLE_DX10_CLAMP);
348 amdhsa::COMPUTE_PGM_RSRC1_ENABLE_IEEE_MODE);
349 if (IVersion.
Major >= 9)
352 amdhsa::COMPUTE_PGM_RSRC1_FP16_OVFL);
353 if (IVersion.
Major >= 10) {
354 PRINT_FIELD(OS,
".amdhsa_workgroup_processor_mode", KD,
356 amdhsa::COMPUTE_PGM_RSRC1_WGP_MODE);
359 amdhsa::COMPUTE_PGM_RSRC1_MEM_ORDERED);
362 amdhsa::COMPUTE_PGM_RSRC1_FWD_PROGRESS);
365 OS,
".amdhsa_exception_fp_ieee_invalid_op", KD,
367 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_INVALID_OPERATION);
368 PRINT_FIELD(OS,
".amdhsa_exception_fp_denorm_src", KD,
370 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_FP_DENORMAL_SOURCE);
372 OS,
".amdhsa_exception_fp_ieee_div_zero", KD,
374 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_DIVISION_BY_ZERO);
375 PRINT_FIELD(OS,
".amdhsa_exception_fp_ieee_overflow", KD,
377 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_OVERFLOW);
378 PRINT_FIELD(OS,
".amdhsa_exception_fp_ieee_underflow", KD,
380 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_UNDERFLOW);
381 PRINT_FIELD(OS,
".amdhsa_exception_fp_ieee_inexact", KD,
383 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_IEEE_754_FP_INEXACT);
384 PRINT_FIELD(OS,
".amdhsa_exception_int_div_zero", KD,
386 amdhsa::COMPUTE_PGM_RSRC2_ENABLE_EXCEPTION_INT_DIVIDE_BY_ZERO);
389 OS <<
"\t.end_amdhsa_kernel\n";
433 void AMDGPUTargetELFStreamer::EmitNote(
437 auto &
Context = S.getContext();
439 auto NameSZ = Name.
size() + 1;
442 S.SwitchSection(
Context.getELFSection(
444 S.EmitIntValue(NameSZ, 4);
445 S.EmitValue(DescSZ, 4);
446 S.EmitIntValue(NoteType, 4);
448 S.EmitValueToAlignment(4, 0, 1, 0);
450 S.EmitValueToAlignment(4, 0, 1, 0);
475 unsigned DescSZ =
sizeof(VendorNameSize) +
sizeof(ArchNameSize) +
476 sizeof(Major) +
sizeof(Minor) +
sizeof(Stepping) +
477 VendorNameSize + ArchNameSize;
523 " redeclared as different type");
534 auto *DescBegin =
Context.createTempSymbol();
535 auto *DescEnd =
Context.createTempSymbol();
555 std::string HSAMetadataString;
561 auto *DescBegin =
Context.createTempSymbol();
562 auto *DescEnd =
Context.createTempSymbol();
578 std::string HSAMetadataString;
585 auto *DescBegin =
Context.createTempSymbol();
586 auto *DescEnd =
Context.createTempSymbol();
601 const uint32_t Encoded_s_code_end = 0xbf9f0000;
606 for (
unsigned I = 0;
I < 48; ++
I)
615 uint64_t NextSGPR,
bool ReserveVCC,
bool ReserveFlatScr,
622 MCSymbolELF *KernelDescriptorSymbol = cast<MCSymbolELF>(
628 KernelDescriptorSymbol->setOther(KernelCodeSymbol->
getOther());
629 KernelDescriptorSymbol->setVisibility(KernelCodeSymbol->
getVisibility());
632 KernelDescriptorSymbol->setSize(
640 Streamer.
EmitLabel(KernelDescriptorSymbol);
642 (
const char*)&(KernelDescriptor),
656 (
const char*)&(KernelDescriptor) +
659 sizeof(KernelDescriptor) -
void setELFHeaderEFlags(unsigned Flags)
bool EmitCodeEnd() override
int64_t kernel_code_entry_byte_offset
void EmitBytes(StringRef Data) override
Emit the bytes in Data into the output.
DocNode & getRoot()
Get ref to the document's root element.
bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
StringRef getArchNameR600(GPUKind AK)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
unsigned getVisibility() const
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
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
void toYAML(raw_ostream &OS)
Convert MsgPack Document to YAML text.
void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, unsigned Align) override
bool declareCommon(uint64_t Size, unsigned Align, bool Target=false)
Declare this symbol as being 'common'.
unsigned getBinding() const
virtual void EmitBytes(StringRef Data)
Emit the bytes in Data into the output.
void setVisibility(unsigned Visibility)
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 EmitCodeEnd() 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
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
void setExternal(bool Value) const
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.
static StringRef getArchNameFromElfMach(unsigned ElfMach)
StringRef getArchNameAMDGCN(GPUKind AK)
uint32_t private_segment_fixed_size
bool fromYAML(StringRef S)
Read YAML text into the MsgPack document. Returns false on failure.
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)
bool isBindingSet() const
LLVM_NODISCARD size_t size() const
size - Get the string size.
unsigned getOther() const
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())
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false)
bool hasSRAMECC(const MCSubtargetInfo &STI)
Streaming machine code generation interface.
constexpr char AssemblerDirectiveBegin[]
HSA metadata beginning assembler directive.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
AMDGPUPALMetadata * getPALMetadata()
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)
virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0)
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
AMDGPUTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS)
constexpr char AssemblerDirectiveEnd[]
HSA metadata ending 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.
This struct is a compact representation of a valid (non-zero power of two) alignment.
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.
std::string toString(WasmSymbolType type)
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
void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, unsigned Align) override
Module.h This file contains the declarations for the Module class.
void writeToBlob(std::string &Blob)
Write a MsgPack document to a binary MsgPack blob.
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 EmitISAVersion(StringRef IsaVersionString) override
Simple in-memory representation of a document of msgpack objects with ability to find and create arra...
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 EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override
bool hasXNACK(const MCSubtargetInfo &STI)
verify safepoint Safepoint IR Verifier
bool EmitISAVersion(StringRef IsaVersionString) override
Generic base class for all target subtargets.
AMDGPUTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
StringRef getName() const
getName - Get the symbol name.
void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override
void dumpAmdKernelCode(const amd_kernel_code_t *C, raw_ostream &OS, const char *tab)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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)
void setIndex(uint32_t Value) const
Set the (implementation defined) index.