23 #ifndef __CLRX_ASMFORMATS_H__ 24 #define __CLRX_ASMFORMATS_H__ 32 #include <unordered_set> 33 #include <unordered_map> 58 AMDCL2_RWDATA = LAST_COMMON+1,
65 AMDCL2_CONFIG_CTRL_DIRECTIVE,
69 GALLIUM_CONFIG_CTRL_DIRECTIVE,
73 ROCM_CONFIG_CTRL_DIRECTIVE,
78 EXTRA_PROGBITS = 0xfc,
98 ASMSECT_WRITEABLE = 1,
99 ASMSECT_ADDRESSABLE = 2,
100 ASMSECT_ABS_ADDRESSABLE = 4,
103 ASMELFSECT_ALLOCATABLE = 0x10,
104 ASMELFSECT_WRITEABLE = 0x20,
105 ASMELFSECT_EXECUTABLE = 0x40
141 cxuint _relSpace = UINT_MAX) : name(_name), type(_type), flags(_flags),
148 cxuint allocRegs[MAX_REGTYPES_NUM];
154 bool sectionDiffsResolvable;
167 {
return sectionDiffsResolvable; }
176 virtual AsmKernelId addKernel(
const char* kernelName) = 0;
188 virtual AsmSectionId getSectionId(
const char* sectionName)
const = 0;
191 virtual void setCurrentKernel(
AsmKernelId kernel) = 0;
193 virtual void setCurrentSection(
AsmSectionId sectionId) = 0;
198 virtual bool parsePseudoOp(
const CString& firstName,
199 const char* stmtPlace,
const char* linePtr) = 0;
201 virtual void handleLabel(
const CString& label);
203 virtual bool resolveSymbol(
const AsmSymbol& symbol,
209 virtual bool prepareBinary() = 0;
211 virtual void writeBinary(std::ostream& os)
const = 0;
216 virtual bool prepareSectionDiffsResolving();
217 virtual void setCodeFlags(
Flags codeFlags);
224 friend struct AsmKcodePseudoOps;
225 std::vector<AsmKernelId> kcodeSelection;
226 std::stack<std::vector<AsmKernelId> > kcodeSelStack;
233 void restoreKcodeCurrentAllocRegs();
234 void saveKcodeCurrentAllocRegs();
236 void prepareKcodeState();
238 void handleLabel(
const CString& label);
241 virtual bool isCodeSection()
const = 0;
247 virtual size_t getKernelsNum()
const = 0;
262 AsmSectionId getSectionId(
const char* sectionName)
const;
268 bool parsePseudoOp(
const CString& firstName,
269 const char* stmtPlace,
const char* linePtr);
271 bool prepareBinary();
272 void writeBinary(std::ostream& os)
const;
280 typedef std::unordered_map<CString, AsmSectionId> SectionMap;
281 friend struct AsmAmdPseudoOps;
298 std::vector<AsmSectionId> calNoteSections;
299 SectionMap extraSectionMap;
302 std::unordered_set<CString> argNamesSet;
311 std::vector<Section> sections;
313 std::vector<Kernel*> kernelStates;
314 SectionMap extraSectionMap;
319 cxuint detectedDriverVersion;
321 void saveCurrentSection();
322 void restoreCurrentAllocRegs();
323 void saveCurrentAllocRegs();
325 cxuint determineDriverVersion()
const;
335 AsmSectionId getSectionId(
const char* sectionName)
const;
340 bool parsePseudoOp(
const CString& firstName,
341 const char* stmtPlace,
const char* linePtr);
343 bool prepareBinary();
344 void writeBinary(std::ostream& os)
const;
376 typedef std::unordered_map<CString, AsmSectionId> SectionMap;
377 friend struct AsmAmdCL2PseudoOps;
394 typedef std::unordered_map<CString, Relocation> RelocMap;
406 std::unique_ptr<AsmAmdHsaKernelConfig> hsaConfig;
407 std::unordered_set<CString> argNamesSet;
417 void initializeKernelConfig();
419 std::vector<Section> sections;
421 std::vector<Kernel*> kernelStates;
423 SectionMap extraSectionMap;
424 SectionMap innerExtraSectionMap;
435 cxuint detectedDriverVersion;
437 void saveCurrentSection();
438 void restoreCurrentAllocRegs();
439 void saveCurrentAllocRegs();
440 cxuint getDriverVersion()
const;
450 AsmSectionId getSectionId(
const char* sectionName)
const;
455 bool parsePseudoOp(
const CString& firstName,
456 const char* stmtPlace,
const char* linePtr);
459 bool resolveRelocation(
const AsmExpression* expr, uint64_t& value,
461 bool prepareBinary();
462 void writeBinary(std::ostream& os)
const;
469 bool isCodeSection()
const;
472 size_t getKernelsNum()
const;
473 void handleLabel(
const CString& label);
480 enum class Inside :
cxbyte {
481 MAINLAYOUT,
CONFIG, ARGS, PROGINFO
484 typedef std::unordered_map<CString, AsmSectionId> SectionMap;
485 friend struct AsmGalliumPseudoOps;
497 std::unique_ptr<AsmAmdHsaKernelConfig> hsaConfig;
503 defaultSection(_defaultSection), hsaConfig(
nullptr),
504 ctrlDirSection(
ASMSECT_NONE), hasProgInfo(
false), progInfoEntries(0)
507 void initializeAmdHsaKernelConfig();
509 std::vector<Kernel*> kernelStates;
510 std::vector<Section> sections;
511 SectionMap extraSectionMap;
519 cxuint detectedDriverVersion;
520 cxuint detectedLLVMVersion;
523 uint32_t archStepping;
525 cxuint determineDriverVersion()
const;
526 cxuint determineLLVMVersion()
const;
536 AsmSectionId getSectionId(
const char* sectionName)
const;
541 bool parsePseudoOp(
const CString& firstName,
542 const char* stmtPlace,
const char* linePtr);
545 bool resolveRelocation(
const AsmExpression* expr, uint64_t& value,
547 bool prepareBinary();
548 void writeBinary(std::ostream& os)
const;
555 bool isCodeSection()
const;
558 size_t getKernelsNum()
const;
567 typedef std::unordered_map<CString, AsmSectionId> SectionMap;
568 friend struct AsmROCmPseudoOps;
570 std::unique_ptr<ROCmBinGenerator> binGen;
581 std::unique_ptr<AsmROCmKernelConfig> config;
587 configSection(_configSection), config(
nullptr), isFKernel(
false),
591 void initializeKernelConfig();
593 std::vector<Kernel*> kernelStates;
594 std::vector<Section> sections;
595 std::vector<CString> gotSymbols;
596 SectionMap extraSectionMap;
604 size_t prevSymbolsCount;
606 bool unresolvedGlobals;
609 void addSymbols(
bool sectionDiffsPrepared);
619 AsmSectionId getSectionId(
const char* sectionName)
const;
624 bool parsePseudoOp(
const CString& firstName,
625 const char* stmtPlace,
const char* linePtr);
627 bool prepareBinary();
628 void writeBinary(std::ostream& os)
const;
634 bool prepareSectionDiffsResolving();
637 bool isCodeSection()
const;
640 size_t getKernelsNum()
const;
641 void setCodeFlags(
Flags codeFlags);
code of program or kernel
common definitions for assembler and disassembler
main class of assembler
Definition: Assembler.h:529
non copyable and non movable base structure (class)
Definition: Utilities.h:46
assembler expression class
Definition: AsmDefs.h:286
uint32_t Flags
type for declaring various flags
Definition: Utilities.h:100
dummy (empty) section for kernel
cxbyte userDataNum
number of user data
Definition: AsmFormats.h:357
no kernel, inner global space
Definition: AsmFormats.h:93
configuration (global or for kernel)
bool privilegedMode
prvileged mode
Definition: AsmFormats.h:364
AMD Catalyst kernel's metadata.
handles raw code format
Definition: AsmFormats.h:251
bool debugMode
debug mode
Definition: AsmFormats.h:363
AMD HSA kernel configuration structure.
Definition: Commons.h:66
an array class
Definition: Containers.h:41
bool ieeeMode
IEEE mode.
Definition: AsmFormats.h:358
cxbyte floatMode
float mode
Definition: AsmFormats.h:359
cxuint AsmSectionId
type for Asm section id (index)
Definition: Commons.h:35
handles ROCM binary format
Definition: AsmFormats.h:564
cxuint RelocType
relocation type
Definition: Commons.h:33
bool tgSize
enable TG_SIZE_EN bit
Definition: AsmFormats.h:362
empty section for scratch symbol
GalliumCompute binaries handling (only with LLVM 3.6)
assembler relocation
Definition: AsmDefs.h:265
const AmdCL2Input * getOutput() const
get output structure pointer
Definition: AsmFormats.h:465
AsmSectionType
assembler section type
Definition: AsmFormats.h:47
unsigned char cxbyte
unsigned byte
Definition: Config.h:229
AMD OpenCL2 binaries generator.
main namespace
Definition: AsmDefs.h:38
format handler with Kcode (kernel-code) handling
Definition: AsmFormats.h:221
unsigned int cxuint
unsigned int
Definition: Config.h:237
const GalliumInput * getOutput() const
get output object (input for bingenerator)
Definition: AsmFormats.h:551
cxuint AsmKernelId
type for Asm kernel id (index)
Definition: Commons.h:33
AMD Catalyst kernel's header.
no kernel, global space
Definition: AsmFormats.h:92
utilities for other libraries and programs
exception class
Definition: Utilities.h:61
cxuint usedVGPRsNum
number of used VGPRs
Definition: AsmFormats.h:355
cxbyte priority
priority
Definition: AsmFormats.h:360
GPU identification utilities.
const AmdInput * getOutput() const
get output structure pointer
Definition: AsmFormats.h:347
bool dx10Clamp
DX10 CLAMP mode.
Definition: AsmFormats.h:365
section is unresolvable
Definition: AsmFormats.h:101
const ROCmInput * getOutput() const
get output object (input for bingenerator)
Definition: AsmFormats.h:631
none section id
Definition: AsmFormats.h:87
cxuint dimMask
mask of dimension (bits: 0 - X, 1 - Y, 2 - Z)
Definition: AsmFormats.h:354
handles GalliumCompute format
Definition: AsmFormats.h:477
absolute section id
Definition: AsmFormats.h:86
cxuint usedSGPRsNum
number of used SGPRs
Definition: AsmFormats.h:356
assembler symbol structure
Definition: AsmDefs.h:143
cxbyte exceptions
enabled exceptions
Definition: AsmFormats.h:361
handles AMD Catalyst format
Definition: AsmFormats.h:277
handles AMD OpenCL 2.0 binary format
Definition: AsmFormats.h:373
Asm AMD HSA kernel configuration.
Definition: AsmFormats.h:352
simple C-string container
Definition: CString.h:38