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,
68 GALLIUM_CONFIG_CTRL_DIRECTIVE,
72 ROCM_CONFIG_CTRL_DIRECTIVE,
77 EXTRA_PROGBITS = 0xfc,
93 ASMSECT_WRITEABLE = 1,
94 ASMSECT_ADDRESSABLE = 2,
95 ASMSECT_ABS_ADDRESSABLE = 4,
98 ASMELFSECT_ALLOCATABLE = 0x10,
99 ASMELFSECT_WRITEABLE = 0x20,
100 ASMELFSECT_EXECUTABLE = 0x40
136 cxuint _relSpace = UINT_MAX) : name(_name), type(_type), flags(_flags),
142 bool sectionDiffsResolvable;
149 cxuint& relSectionId, uint64_t& relValue);
155 {
return sectionDiffsResolvable; }
164 virtual cxuint addKernel(
const char* kernelName) = 0;
173 virtual cxuint addSection(
const char* sectionName,
cxuint kernelId) = 0;
176 virtual cxuint getSectionId(
const char* sectionName)
const = 0;
179 virtual void setCurrentKernel(
cxuint kernel) = 0;
181 virtual void setCurrentSection(
cxuint sectionId) = 0;
186 virtual bool parsePseudoOp(
const CString& firstName,
187 const char* stmtPlace,
const char* linePtr) = 0;
189 virtual void handleLabel(
const CString& label);
191 virtual bool resolveSymbol(
const AsmSymbol& symbol,
192 uint64_t& value,
cxuint& sectionId);
195 uint64_t& value,
cxuint& sectionId);
197 virtual bool prepareBinary() = 0;
199 virtual void writeBinary(std::ostream& os)
const = 0;
204 virtual bool prepareSectionDiffsResolving();
216 cxuint addKernel(
const char* kernelName);
217 cxuint addSection(
const char* sectionName,
cxuint kernelId);
219 cxuint getSectionId(
const char* sectionName)
const;
221 void setCurrentKernel(
cxuint kernel);
222 void setCurrentSection(
cxuint sectionId);
225 bool parsePseudoOp(
const CString& firstName,
226 const char* stmtPlace,
const char* linePtr);
228 bool prepareBinary();
229 void writeBinary(std::ostream& os)
const;
237 typedef std::unordered_map<CString, cxuint> SectionMap;
238 friend struct AsmAmdPseudoOps;
255 std::vector<cxuint> calNoteSections;
256 SectionMap extraSectionMap;
259 std::unordered_set<CString> argNamesSet;
260 cxuint allocRegs[MAX_REGTYPES_NUM];
263 std::vector<Section> sections;
265 std::vector<Kernel*> kernelStates;
266 SectionMap extraSectionMap;
271 cxuint detectedDriverVersion;
273 void saveCurrentSection();
274 void restoreCurrentAllocRegs();
275 void saveCurrentAllocRegs();
277 cxuint determineDriverVersion()
const;
284 cxuint addKernel(
const char* kernelName);
285 cxuint addSection(
const char* sectionName,
cxuint kernelId);
287 cxuint getSectionId(
const char* sectionName)
const;
288 void setCurrentKernel(
cxuint kernel);
289 void setCurrentSection(
cxuint sectionId);
292 bool parsePseudoOp(
const CString& firstName,
293 const char* stmtPlace,
const char* linePtr);
295 bool prepareBinary();
296 void writeBinary(std::ostream& os)
const;
326 typedef std::unordered_map<CString, cxuint> SectionMap;
327 friend struct AsmAmdCL2PseudoOps;
344 typedef std::unordered_map<CString, Relocation> RelocMap;
350 cxuint isaMetadataSection;
356 std::unique_ptr<AsmAmdHsaKernelConfig> hsaConfig;
357 std::unordered_set<CString> argNamesSet;
358 cxuint allocRegs[MAX_REGTYPES_NUM];
361 void initializeKernelConfig();
363 std::vector<Section> sections;
365 std::vector<Kernel*> kernelStates;
367 SectionMap extraSectionMap;
368 SectionMap innerExtraSectionMap;
372 cxuint samplerInitSection;
376 cxuint innerExtraSectionCount;
378 cxuint detectedDriverVersion;
380 void saveCurrentSection();
381 void restoreCurrentAllocRegs();
382 void saveCurrentAllocRegs();
383 cxuint getDriverVersion()
const;
390 cxuint addKernel(
const char* kernelName);
391 cxuint addSection(
const char* sectionName,
cxuint kernelId);
393 cxuint getSectionId(
const char* sectionName)
const;
394 void setCurrentKernel(
cxuint kernel);
395 void setCurrentSection(
cxuint sectionId);
398 bool parsePseudoOp(
const CString& firstName,
399 const char* stmtPlace,
const char* linePtr);
401 bool resolveSymbol(
const AsmSymbol& symbol, uint64_t& value,
cxuint& sectionId);
403 bool prepareBinary();
404 void writeBinary(std::ostream& os)
const;
415 enum class Inside :
cxbyte {
416 MAINLAYOUT,
CONFIG, ARGS, PROGINFO
419 typedef std::unordered_map<CString, cxuint> SectionMap;
420 friend struct AsmGalliumPseudoOps;
432 std::unique_ptr<AsmAmdHsaKernelConfig> hsaConfig;
436 cxuint allocRegs[MAX_REGTYPES_NUM];
439 void initializeAmdHsaKernelConfig();
441 std::vector<Kernel*> kernelStates;
442 std::vector<Section> sections;
443 std::vector<cxuint> kcodeSelection;
444 std::stack<std::vector<cxuint> > kcodeSelStack;
445 cxuint currentKcodeKernel;
446 SectionMap extraSectionMap;
455 cxuint detectedDriverVersion;
456 cxuint detectedLLVMVersion;
459 uint32_t archStepping;
461 void restoreKcodeCurrentAllocRegs();
462 void saveKcodeCurrentAllocRegs();
464 cxuint determineDriverVersion()
const;
465 cxuint determineLLVMVersion()
const;
472 cxuint addKernel(
const char* kernelName);
473 cxuint addSection(
const char* sectionName,
cxuint kernelId);
475 cxuint getSectionId(
const char* sectionName)
const;
476 void setCurrentKernel(
cxuint kernel);
477 void setCurrentSection(
cxuint sectionId);
480 bool parsePseudoOp(
const CString& firstName,
481 const char* stmtPlace,
const char* linePtr);
482 void handleLabel(
const CString& label);
484 bool resolveSymbol(
const AsmSymbol& symbol, uint64_t& value,
cxuint& sectionId);
486 bool prepareBinary();
487 void writeBinary(std::ostream& os)
const;
500 typedef std::unordered_map<CString, cxuint> SectionMap;
501 friend struct AsmROCmPseudoOps;
503 std::unique_ptr<ROCmBinGenerator> binGen;
514 std::unique_ptr<AsmROCmKernelConfig> config;
519 cxuint allocRegs[MAX_REGTYPES_NUM];
521 void initializeKernelConfig();
523 std::vector<Kernel*> kernelStates;
524 std::vector<Section> sections;
525 std::vector<cxuint> kcodeSelection;
526 std::stack<std::vector<cxuint> > kcodeSelStack;
527 std::vector<CString> gotSymbols;
528 cxuint currentKcodeKernel;
529 SectionMap extraSectionMap;
538 size_t prevSymbolsCount;
540 bool unresolvedGlobals;
543 void restoreKcodeCurrentAllocRegs();
544 void saveKcodeCurrentAllocRegs();
546 void addSymbols(
bool sectionDiffsPrepared);
553 cxuint addKernel(
const char* kernelName);
554 cxuint addSection(
const char* sectionName,
cxuint kernelId);
556 cxuint getSectionId(
const char* sectionName)
const;
557 void setCurrentKernel(
cxuint kernel);
558 void setCurrentSection(
cxuint sectionId);
561 bool parsePseudoOp(
const CString& firstName,
562 const char* stmtPlace,
const char* linePtr);
563 void handleLabel(
const CString& label);
565 bool prepareBinary();
566 void writeBinary(std::ostream& os)
const;
572 bool prepareSectionDiffsResolving();
code of program or kernel
common definitions for assembler and disassembler
main class of assembler
Definition: Assembler.h:404
non copyable and non movable base structure (class)
Definition: Utilities.h:43
assembler expression class
Definition: AsmDefs.h:301
uint32_t Flags
type for declaring various flags
Definition: Utilities.h:97
cxbyte userDataNum
number of user data
Definition: AsmFormats.h:309
configuration (global or for kernel)
bool privilegedMode
prvileged mode
Definition: AsmFormats.h:316
AMD Catalyst kernel's metadata.
handles raw code format
Definition: AsmFormats.h:208
bool debugMode
debug mode
Definition: AsmFormats.h:315
AMD HSA kernel configuration structure.
Definition: Commons.h:64
an array class
Definition: Containers.h:38
bool ieeeMode
IEEE mode.
Definition: AsmFormats.h:310
cxbyte floatMode
float mode
Definition: AsmFormats.h:311
handles ROCM binary format
Definition: AsmFormats.h:497
cxuint RelocType
relocation type
Definition: Commons.h:33
bool tgSize
enable TG_SIZE_EN bit
Definition: AsmFormats.h:314
data object
Definition: ROCmBinaries.h:55
empty section for scratch symbol
absolute section id
Definition: AsmFormats.h:85
GalliumCompute binaries handling (only with LLVM 3.6)
assembler relocation
Definition: AsmDefs.h:280
const AmdCL2Input * getOutput() const
get output structure pointer
Definition: AsmFormats.h:407
AsmSectionType
assembler section type
Definition: AsmFormats.h:47
none section id
Definition: AsmFormats.h:86
unsigned char cxbyte
unsigned byte
Definition: Config.h:215
AMD OpenCL2 binaries generator.
main namespace
Definition: AsmDefs.h:38
unsigned int cxuint
unsigned int
Definition: Config.h:223
const GalliumInput * getOutput() const
get output object (input for bingenerator)
Definition: AsmFormats.h:490
AMD Catalyst kernel's header.
utilities for other libraries and programs
exception class
Definition: Utilities.h:58
cxuint usedVGPRsNum
number of used VGPRs
Definition: AsmFormats.h:307
cxbyte priority
priority
Definition: AsmFormats.h:312
GPU identification utilities.
const AmdInput * getOutput() const
get output structure pointer
Definition: AsmFormats.h:299
bool dx10Clamp
DX10 CLAMP mode.
Definition: AsmFormats.h:317
const ROCmInput * getOutput() const
get output object (input for bingenerator)
Definition: AsmFormats.h:569
cxuint dimMask
mask of dimension (bits: 0 - X, 1 - Y, 2 - Z)
Definition: AsmFormats.h:306
handles GalliumCompute format
Definition: AsmFormats.h:412
cxuint usedSGPRsNum
number of used SGPRs
Definition: AsmFormats.h:308
assembler symbol structure
Definition: AsmDefs.h:158
cxbyte exceptions
enabled exceptions
Definition: AsmFormats.h:313
handles AMD Catalyst format
Definition: AsmFormats.h:234
handles AMD OpenCL 2.0 binary format
Definition: AsmFormats.h:323
Asm AMD HSA kernel configuration.
Definition: AsmFormats.h:304
section is unresolvable
Definition: AsmFormats.h:96
no kernel, inner global space
Definition: AsmFormats.h:88
simple C-string container
Definition: CString.h:38
no kernel, global space
Definition: AsmFormats.h:87