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];
153 bool sectionDiffsResolvable;
166 {
return sectionDiffsResolvable; }
175 virtual AsmKernelId addKernel(
const char* kernelName) = 0;
187 virtual AsmSectionId getSectionId(
const char* sectionName)
const = 0;
190 virtual void setCurrentKernel(
AsmKernelId kernel) = 0;
192 virtual void setCurrentSection(
AsmSectionId sectionId) = 0;
197 virtual bool parsePseudoOp(
const CString& firstName,
198 const char* stmtPlace,
const char* linePtr) = 0;
200 virtual void handleLabel(
const CString& label);
202 virtual bool resolveSymbol(
const AsmSymbol& symbol,
208 virtual bool prepareBinary() = 0;
210 virtual void writeBinary(std::ostream& os)
const = 0;
215 virtual bool prepareSectionDiffsResolving();
222 friend struct AsmKcodePseudoOps;
223 std::vector<AsmKernelId> kcodeSelection;
224 std::stack<std::vector<AsmKernelId> > kcodeSelStack;
231 void restoreKcodeCurrentAllocRegs();
232 void saveKcodeCurrentAllocRegs();
234 void prepareKcodeState();
236 void handleLabel(
const CString& label);
239 virtual bool isCodeSection()
const = 0;
243 virtual size_t getKernelsNum()
const = 0;
258 AsmSectionId getSectionId(
const char* sectionName)
const;
264 bool parsePseudoOp(
const CString& firstName,
265 const char* stmtPlace,
const char* linePtr);
267 bool prepareBinary();
268 void writeBinary(std::ostream& os)
const;
276 typedef std::unordered_map<CString, AsmSectionId> SectionMap;
277 friend struct AsmAmdPseudoOps;
294 std::vector<AsmSectionId> calNoteSections;
295 SectionMap extraSectionMap;
298 std::unordered_set<CString> argNamesSet;
307 std::vector<Section> sections;
309 std::vector<Kernel*> kernelStates;
310 SectionMap extraSectionMap;
315 cxuint detectedDriverVersion;
317 void saveCurrentSection();
318 void restoreCurrentAllocRegs();
319 void saveCurrentAllocRegs();
321 cxuint determineDriverVersion()
const;
331 AsmSectionId getSectionId(
const char* sectionName)
const;
336 bool parsePseudoOp(
const CString& firstName,
337 const char* stmtPlace,
const char* linePtr);
339 bool prepareBinary();
340 void writeBinary(std::ostream& os)
const;
370 typedef std::unordered_map<CString, AsmSectionId> SectionMap;
371 friend struct AsmAmdCL2PseudoOps;
388 typedef std::unordered_map<CString, Relocation> RelocMap;
400 std::unique_ptr<AsmAmdHsaKernelConfig> hsaConfig;
401 std::unordered_set<CString> argNamesSet;
411 void initializeKernelConfig();
413 std::vector<Section> sections;
415 std::vector<Kernel*> kernelStates;
417 SectionMap extraSectionMap;
418 SectionMap innerExtraSectionMap;
429 cxuint detectedDriverVersion;
431 void saveCurrentSection();
432 void restoreCurrentAllocRegs();
433 void saveCurrentAllocRegs();
434 cxuint getDriverVersion()
const;
444 AsmSectionId getSectionId(
const char* sectionName)
const;
449 bool parsePseudoOp(
const CString& firstName,
450 const char* stmtPlace,
const char* linePtr);
453 bool resolveRelocation(
const AsmExpression* expr, uint64_t& value,
455 bool prepareBinary();
456 void writeBinary(std::ostream& os)
const;
463 bool isCodeSection()
const;
465 size_t getKernelsNum()
const;
466 void handleLabel(
const CString& label);
473 enum class Inside :
cxbyte {
474 MAINLAYOUT,
CONFIG, ARGS, PROGINFO
477 typedef std::unordered_map<CString, AsmSectionId> SectionMap;
478 friend struct AsmGalliumPseudoOps;
490 std::unique_ptr<AsmAmdHsaKernelConfig> hsaConfig;
496 defaultSection(_defaultSection), hsaConfig(
nullptr),
497 ctrlDirSection(
ASMSECT_NONE), hasProgInfo(
false), progInfoEntries(0)
500 void initializeAmdHsaKernelConfig();
502 std::vector<Kernel*> kernelStates;
503 std::vector<Section> sections;
504 SectionMap extraSectionMap;
512 cxuint detectedDriverVersion;
513 cxuint detectedLLVMVersion;
516 uint32_t archStepping;
518 cxuint determineDriverVersion()
const;
519 cxuint determineLLVMVersion()
const;
529 AsmSectionId getSectionId(
const char* sectionName)
const;
534 bool parsePseudoOp(
const CString& firstName,
535 const char* stmtPlace,
const char* linePtr);
538 bool resolveRelocation(
const AsmExpression* expr, uint64_t& value,
540 bool prepareBinary();
541 void writeBinary(std::ostream& os)
const;
548 bool isCodeSection()
const;
550 size_t getKernelsNum()
const;
559 typedef std::unordered_map<CString, AsmSectionId> SectionMap;
560 friend struct AsmROCmPseudoOps;
562 std::unique_ptr<ROCmBinGenerator> binGen;
573 std::unique_ptr<AsmROCmKernelConfig> config;
579 configSection(_configSection), config(
nullptr), isFKernel(
false),
583 void initializeKernelConfig();
585 std::vector<Kernel*> kernelStates;
586 std::vector<Section> sections;
587 std::vector<CString> gotSymbols;
588 SectionMap extraSectionMap;
596 size_t prevSymbolsCount;
598 bool unresolvedGlobals;
601 void addSymbols(
bool sectionDiffsPrepared);
611 AsmSectionId getSectionId(
const char* sectionName)
const;
616 bool parsePseudoOp(
const CString& firstName,
617 const char* stmtPlace,
const char* linePtr);
619 bool prepareBinary();
620 void writeBinary(std::ostream& os)
const;
626 bool prepareSectionDiffsResolving();
629 bool isCodeSection()
const;
631 size_t getKernelsNum()
const;
code of program or kernel
common definitions for assembler and disassembler
main class of assembler
Definition: Assembler.h:516
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:353
no kernel, inner global space
Definition: AsmFormats.h:93
configuration (global or for kernel)
bool privilegedMode
prvileged mode
Definition: AsmFormats.h:360
AMD Catalyst kernel's metadata.
handles raw code format
Definition: AsmFormats.h:247
bool debugMode
debug mode
Definition: AsmFormats.h:359
AMD HSA kernel configuration structure.
Definition: Commons.h:64
an array class
Definition: Containers.h:41
bool ieeeMode
IEEE mode.
Definition: AsmFormats.h:354
cxbyte floatMode
float mode
Definition: AsmFormats.h:355
cxuint AsmSectionId
type for Asm section id (index)
Definition: Commons.h:35
handles ROCM binary format
Definition: AsmFormats.h:556
cxuint RelocType
relocation type
Definition: Commons.h:33
bool tgSize
enable TG_SIZE_EN bit
Definition: AsmFormats.h:358
data object
Definition: ROCmBinaries.h:55
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:459
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:219
unsigned int cxuint
unsigned int
Definition: Config.h:237
const GalliumInput * getOutput() const
get output object (input for bingenerator)
Definition: AsmFormats.h:544
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:351
cxbyte priority
priority
Definition: AsmFormats.h:356
GPU identification utilities.
const AmdInput * getOutput() const
get output structure pointer
Definition: AsmFormats.h:343
bool dx10Clamp
DX10 CLAMP mode.
Definition: AsmFormats.h:361
section is unresolvable
Definition: AsmFormats.h:101
const ROCmInput * getOutput() const
get output object (input for bingenerator)
Definition: AsmFormats.h:623
none section id
Definition: AsmFormats.h:87
cxuint dimMask
mask of dimension (bits: 0 - X, 1 - Y, 2 - Z)
Definition: AsmFormats.h:350
handles GalliumCompute format
Definition: AsmFormats.h:470
absolute section id
Definition: AsmFormats.h:86
cxuint usedSGPRsNum
number of used SGPRs
Definition: AsmFormats.h:352
assembler symbol structure
Definition: AsmDefs.h:143
cxbyte exceptions
enabled exceptions
Definition: AsmFormats.h:357
handles AMD Catalyst format
Definition: AsmFormats.h:273
handles AMD OpenCL 2.0 binary format
Definition: AsmFormats.h:367
Asm AMD HSA kernel configuration.
Definition: AsmFormats.h:348
simple C-string container
Definition: CString.h:38