CLRX  1
An unofficial OpenCL extensions designed for Radeon GPUs
Assembler.h
Go to the documentation of this file.
1 /*
2  * CLRadeonExtender - Unofficial OpenCL Radeon Extensions Library
3  * Copyright (C) 2014-2017 Mateusz Szpakowski
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
23 #ifndef __CLRX_ASSEMBLER_H__
24 #define __CLRX_ASSEMBLER_H__
25 
26 #include <CLRX/Config.h>
27 #include <cstdint>
28 #include <string>
29 #include <istream>
30 #include <ostream>
31 #include <iostream>
32 #include <vector>
33 #include <utility>
34 #include <stack>
35 #include <list>
36 #include <unordered_set>
37 #include <unordered_map>
38 #include <CLRX/utils/Utilities.h>
39 #include <CLRX/amdasm/Commons.h>
40 #include <CLRX/amdasm/AsmSource.h>
41 #include <CLRX/amdasm/AsmFormats.h>
42 #include <CLRX/amdasm/AsmDefs.h>
43 
45 namespace CLRX
46 {
47 
48 enum: Flags
49 {
51  ASM_FORCE_ADD_SYMBOLS = 2,
52  ASM_ALTMACRO = 4,
53  ASM_BUGGYFPLIT = 8, // buggy handling of fpliterals (including fp constants)
54  ASM_MACRONOCASE = 16, // disable case-insensitive naming (default)
55  ASM_OLDMODPARAM = 32, // use old modifier parametrization (values 0 and 1 only)
56  ASM_TESTRUN = (1U<<31),
57  ASM_ALL = FLAGS_ALL&~(ASM_TESTRUN|ASM_BUGGYFPLIT|ASM_MACRONOCASE|
58  ASM_OLDMODPARAM)
59 };
60 
61 struct AsmRegVar;
62 
65 {
66 public:
68  struct ReadPos
69  {
70  size_t readOffset;
71  size_t instrStructPos;
72  size_t regUsagesPos;
73  size_t regUsages2Pos;
74  size_t regVarUsagesPos;
75  uint16_t pushedArgs;
76  bool useRegMode;
77  };
78 protected:
79  std::vector<cxbyte> instrStruct;
80  std::vector<AsmRegUsageInt> regUsages;
81  std::vector<AsmRegUsage2Int> regUsages2;
82  std::vector<AsmRegVarUsageInt> regVarUsages;
83  const std::vector<cxbyte>& content;
84  size_t lastOffset;
85  size_t readOffset;
86  size_t instrStructPos;
87  size_t regUsagesPos;
88  size_t regUsages2Pos;
89  size_t regVarUsagesPos;
90  uint16_t pushedArgs;
94  bool isNext;
95  bool useRegMode;
96 
97  void skipBytesInInstrStruct();
99  void putSpace(size_t offset);
100 
102  explicit ISAUsageHandler(const std::vector<cxbyte>& content);
103 public:
105  virtual ~ISAUsageHandler();
107  virtual ISAUsageHandler* copy() const = 0;
108 
110  void pushUsage(const AsmRegVarUsage& rvu);
112  void rewind();
114  void flush();
116  bool hasNext() const
117  { return isNext; }
120 
123  {
125  regVarUsagesPos, pushedArgs, useRegMode };
126  }
128  void setReadPos(const ReadPos rpos)
129  {
130  readOffset = rpos.readOffset;
131  instrStructPos = rpos.instrStructPos;
132  regUsagesPos = rpos.regUsagesPos;
133  regUsages2Pos = rpos.regUsages2Pos;
134  regVarUsagesPos = rpos.regVarUsagesPos;
135  pushedArgs = rpos.pushedArgs;
136  useRegMode = rpos.useRegMode;
137  }
138 
140  void pushUseRegUsage(const AsmRegVarUsage& rvu);
141 
143  virtual cxbyte getRwFlags(AsmRegField regField, uint16_t rstart,
144  uint16_t rend) const = 0;
146  virtual std::pair<uint16_t,uint16_t> getRegPair(AsmRegField regField,
147  cxbyte rwFlags) const = 0;
149  virtual void getUsageDependencies(cxuint rvusNum, const AsmRegVarUsage* rvus,
150  cxbyte* linearDeps, cxbyte* equalToDeps) const = 0;
151 };
152 
155 {
156 private:
157  uint16_t archMask;
158 public:
160  GCNUsageHandler(const std::vector<cxbyte>& content, uint16_t archMask);
162  ~GCNUsageHandler();
163 
165  ISAUsageHandler* copy() const;
166 
167  cxbyte getRwFlags(AsmRegField regFied, uint16_t rstart, uint16_t rend) const;
168  std::pair<uint16_t,uint16_t> getRegPair(AsmRegField regField, cxbyte rwFlags) const;
169  void getUsageDependencies(cxuint rvusNum, const AsmRegVarUsage* rvus,
170  cxbyte* linearDeps, cxbyte* equalToDeps) const;
171 };
172 
175 {
176 protected:
178 
180  void printWarning(const char* linePtr, const char* message);
182  void printError(const char* linePtr, const char* message);
184  void printWarning(const AsmSourcePos& sourcePos, const char* message);
186  void printError(const AsmSourcePos& sourcePos, const char* message);
188  void printWarningForRange(cxuint bits, uint64_t value, const AsmSourcePos& pos,
189  cxbyte signess = WS_BOTH);
190  void addCodeFlowEntry(cxuint sectionId, const AsmCodeFlowEntry& entry);
192  explicit ISAAssembler(Assembler& assembler);
193 public:
195  virtual ~ISAAssembler();
197  virtual ISAUsageHandler* createUsageHandler(std::vector<cxbyte>& content) const = 0;
198 
200  virtual void assemble(const CString& mnemonic, const char* mnemPlace,
201  const char* linePtr, const char* lineEnd, std::vector<cxbyte>& output,
202  ISAUsageHandler* usageHandler) = 0;
204  virtual bool resolveCode(const AsmSourcePos& sourcePos, cxuint targetSectionId,
205  cxbyte* sectionData, size_t offset, AsmExprTargetType targetType,
206  cxuint sectionId, uint64_t value) = 0;
208  virtual bool checkMnemonic(const CString& mnemonic) const = 0;
210  virtual void setAllocatedRegisters(const cxuint* regs = nullptr,
211  Flags regFlags = 0) = 0;
213  virtual const cxuint* getAllocatedRegisters(size_t& regTypesNum,
214  Flags& regFlags) const = 0;
216  virtual void getMaxRegistersNum(size_t& regTypesNum, cxuint* maxRegs) const = 0;
218  virtual void getRegisterRanges(size_t& regTypesNum, cxuint* regRanges) const = 0;
220  virtual void fillAlignment(size_t size, cxbyte* output) = 0;
222  virtual bool parseRegisterRange(const char*& linePtr, cxuint& regStart,
223  cxuint& regEnd, const AsmRegVar*& regVar) = 0;
225  virtual bool relocationIsFit(cxuint bits, AsmExprTargetType tgtType) = 0;
227  virtual bool parseRegisterType(const char*& linePtr,
228  const char* end, cxuint& type) = 0;
230  virtual size_t getInstructionSize(size_t codeSize, const cxbyte* code) const = 0;
231 };
232 
235 {
236 public:
238  struct Regs {
242  };
243 private:
244  friend struct GCNAsmUtils; // INTERNAL LOGIC
245  union {
246  Regs regs;
247  cxuint regTable[2];
248  };
249  uint16_t curArchMask;
250  cxbyte currentRVUIndex;
251  AsmRegVarUsage instrRVUs[6];
252 
253  void resetInstrRVUs()
254  {
255  for (AsmRegVarUsage& rvu: instrRVUs)
256  rvu.regField = ASMFIELD_NONE;
257  }
258  void setCurrentRVU(cxbyte idx)
259  { currentRVUIndex = idx; }
260 
261  void setRegVarUsage(const AsmRegVarUsage& rvu)
262  { instrRVUs[currentRVUIndex] = rvu; }
263 
264  void flushInstrRVUs(ISAUsageHandler* usageHandler)
265  {
266  for (const AsmRegVarUsage& rvu: instrRVUs)
267  if (rvu.regField != ASMFIELD_NONE)
268  usageHandler->pushUsage(rvu);
269  }
270 public:
272  explicit GCNAssembler(Assembler& assembler);
274  ~GCNAssembler();
275 
276  ISAUsageHandler* createUsageHandler(std::vector<cxbyte>& content) const;
277 
278  void assemble(const CString& mnemonic, const char* mnemPlace, const char* linePtr,
279  const char* lineEnd, std::vector<cxbyte>& output,
280  ISAUsageHandler* usageHandler);
281  bool resolveCode(const AsmSourcePos& sourcePos, cxuint targetSectionId,
282  cxbyte* sectionData, size_t offset, AsmExprTargetType targetType,
283  cxuint sectionId, uint64_t value);
284  bool checkMnemonic(const CString& mnemonic) const;
285  void setAllocatedRegisters(const cxuint* regs, Flags regFlags);
286  const cxuint* getAllocatedRegisters(size_t& regTypesNum, Flags& regFlags) const;
287  void getMaxRegistersNum(size_t& regTypesNum, cxuint* maxRegs) const;
288  void getRegisterRanges(size_t& regTypesNum, cxuint* regRanges) const;
289  void fillAlignment(size_t size, cxbyte* output);
290  bool parseRegisterRange(const char*& linePtr, cxuint& regStart, cxuint& regEnd,
291  const AsmRegVar*& regVar);
292  bool relocationIsFit(cxuint bits, AsmExprTargetType tgtType);
293  bool parseRegisterType(const char*& linePtr, const char* end, cxuint& type);
294  size_t getInstructionSize(size_t codeSize, const cxbyte* code) const;
295 };
296 
298 {
299 public:
300  struct NextBlock
301  {
302  size_t block;
303  bool isCall;
304  };
305  struct SSAInfo
306  {
307  size_t ssaIdBefore;
308  size_t ssaIdFirst; // SSA id at first change
309  size_t ssaId;
310  size_t ssaIdLast;
311  size_t ssaIdChange;
312  size_t firstPos;
313  size_t lastPos;
315  SSAInfo(size_t _bssaId = SIZE_MAX, size_t _ssaIdF = SIZE_MAX,
316  size_t _ssaId = SIZE_MAX, size_t _ssaIdL = SIZE_MAX,
317  size_t _ssaIdChange = 0, bool _readBeforeWrite = false)
318  : ssaIdBefore(_bssaId), ssaIdFirst(_ssaIdF), ssaId(_ssaId),
319  ssaIdLast(_ssaIdL), ssaIdChange(_ssaIdChange),
320  readBeforeWrite(_readBeforeWrite)
321  { }
322  };
323  struct CodeBlock
324  {
325  size_t start, end; // place in code
326  std::vector<NextBlock> nexts;
327  bool haveCalls;
328  bool haveReturn;
329  bool haveEnd;
330  // key - regvar, value - SSA info for this regvar
331  std::unordered_map<AsmSingleVReg, SSAInfo> ssaInfoMap;
332  ISAUsageHandler::ReadPos usagePos;
333  };
334 
335  // first - orig ssaid, second - dest ssaid
336  typedef std::pair<size_t, size_t> SSAReplace;
337  typedef std::unordered_map<AsmSingleVReg, std::vector<SSAReplace> > SSAReplacesMap;
338  // interference graph type
340  typedef std::unordered_map<AsmSingleVReg, std::vector<size_t> > VarIndexMap;
341  struct LinearDep
342  {
343  cxbyte align;
344  std::vector<size_t> prevVidxes;
345  std::vector<size_t> nextVidxes;
346  };
347  struct EqualToDep
348  {
349  std::vector<size_t> prevVidxes;
350  std::vector<size_t> nextVidxes;
351  };
352 private:
353  Assembler& assembler;
354  std::vector<CodeBlock> codeBlocks;
355  SSAReplacesMap ssaReplacesMap;
356  size_t regTypesNum;
357 
358  VarIndexMap vregIndexMaps[MAX_REGTYPES_NUM]; // indices to igraph for 2 reg types
359  InterGraph interGraphs[MAX_REGTYPES_NUM]; // for 2 register
360  Array<cxuint> graphColorMaps[MAX_REGTYPES_NUM];
361  std::unordered_map<size_t, LinearDep> linearDepMaps[MAX_REGTYPES_NUM];
362  std::unordered_map<size_t, EqualToDep> equalToDepMaps[MAX_REGTYPES_NUM];
363  std::unordered_map<size_t, size_t> equalSetMaps[MAX_REGTYPES_NUM];
364  std::vector<std::vector<size_t> > equalSetLists[MAX_REGTYPES_NUM];
365 public:
366  AsmRegAllocator(Assembler& assembler);
367 
368  void createCodeStructure(const std::vector<AsmCodeFlowEntry>& codeFlow,
369  size_t codeSize, const cxbyte* code);
370  void createSSAData(ISAUsageHandler& usageHandler);
371  void applySSAReplaces();
372  void createInterferenceGraph(ISAUsageHandler& usageHandler);
373  void colorInterferenceGraph();
374 
375  void allocateRegisters(cxuint sectionId);
376 
377  const std::vector<CodeBlock>& getCodeBlocks() const
378  { return codeBlocks; }
379  const SSAReplacesMap& getSSAReplacesMap() const
380  { return ssaReplacesMap; }
381 };
382 
384 enum class AsmClauseType
385 {
386  IF,
387  ELSEIF,
388  ELSE,
389  REPEAT,
390  MACRO
391 };
392 
394 struct AsmClause
395 {
400 };
401 
404 {
405 public:
407  typedef std::pair<CString, uint64_t> DefSym;
409  typedef std::unordered_map<CString, cxuint> KernelMap;
410 private:
411  friend class AsmStreamInputFilter;
412  friend class AsmMacroInputFilter;
413  friend class AsmExpression;
414  friend class AsmFormatHandler;
415  friend class AsmRawCodeHandler;
416  friend class AsmAmdHandler;
417  friend class AsmAmdCL2Handler;
418  friend class AsmGalliumHandler;
419  friend class AsmROCmHandler;
420  friend class ISAAssembler;
421  friend class AsmRegAllocator;
422 
423  friend struct AsmParseUtils; // INTERNAL LOGIC
424  friend struct AsmPseudoOps; // INTERNAL LOGIC
425  friend struct AsmGalliumPseudoOps; // INTERNAL LOGIC
426  friend struct AsmAmdPseudoOps; // INTERNAL LOGIC
427  friend struct AsmAmdCL2PseudoOps; // INTERNAL LOGIC
428  friend struct AsmROCmPseudoOps; // INTERNAL LOGIC
429  friend struct GCNAsmUtils; // INTERNAL LOGIC
430 
431  Array<CString> filenames;
432  BinaryFormat format;
433  GPUDeviceType deviceType;
434  uint32_t driverVersion;
435  uint32_t llvmVersion; // GalliumCompute
436  bool _64bit;
437  bool good;
438  bool resolvingRelocs;
439  ISAAssembler* isaAssembler;
440  std::vector<DefSym> defSyms;
441  std::vector<CString> includeDirs;
442  std::vector<AsmSection> sections;
443  std::unordered_set<AsmSymbolEntry*> symbolSnapshots;
444  std::vector<AsmRelocation> relocations;
445  AsmScope globalScope;
446  AsmMacroMap macroMap;
447  std::stack<AsmScope*> scopeStack;
448  std::vector<AsmScope*> abandonedScopes;
449  AsmScope* currentScope;
450  KernelMap kernelMap;
451  std::vector<AsmKernel> kernels;
453  Flags flags;
454  uint64_t macroCount;
455  uint64_t localCount; // macro's local count
456  bool alternateMacro;
457  bool buggyFPLit;
458  bool macroCase;
459  bool oldModParam;
460 
461  cxuint inclusionLevel;
462  cxuint macroSubstLevel;
463  cxuint repetitionLevel;
464  bool lineAlreadyRead; // if line already read
465 
466  size_t lineSize;
467  const char* line;
468  bool endOfAssembly;
469 
470  cxuint filenameIndex;
471  std::stack<AsmInputFilter*> asmInputFilters;
472  AsmInputFilter* currentInputFilter;
473 
474  std::ostream& messageStream;
475  std::ostream& printStream;
476 
477  AsmFormatHandler* formatHandler;
478 
479  std::stack<AsmClause> clauses;
480 
481  cxuint currentKernel;
482  cxuint& currentSection;
483  uint64_t& currentOutPos;
484 
485  AsmSourcePos getSourcePos(LineCol lineCol) const
486  {
487  return { currentInputFilter->getMacroSubst(), currentInputFilter->getSource(),
488  lineCol.lineNo, lineCol.colNo };
489  }
490 
491  AsmSourcePos getSourcePos(size_t pos) const
492  { return currentInputFilter->getSourcePos(pos); }
493  AsmSourcePos getSourcePos(const char* linePtr) const
494  { return getSourcePos(linePtr-line); }
495 
496  void printWarning(const AsmSourcePos& pos, const char* message);
497  void printError(const AsmSourcePos& pos, const char* message);
498 
499  void printWarning(const char* linePtr, const char* message)
500  { printWarning(getSourcePos(linePtr), message); }
501  void printError(const char* linePtr, const char* message)
502  { printError(getSourcePos(linePtr), message); }
503 
504  void printWarning(LineCol lineCol, const char* message)
505  { printWarning(getSourcePos(lineCol), message); }
506  void printError(LineCol lineCol, const char* message)
507  { printError(getSourcePos(lineCol), message); }
508 
509  LineCol translatePos(const char* linePtr) const
510  { return currentInputFilter->translatePos(linePtr-line); }
511  LineCol translatePos(size_t pos) const
512  { return currentInputFilter->translatePos(pos); }
513 
514  bool parseLiteral(uint64_t& value, const char*& linePtr);
515  bool parseString(std::string& outString, const char*& linePtr);
516 
517  enum class ParseState
518  {
519  FAILED = 0,
520  PARSED,
521  MISSING // missing element
522  };
523 
527  ParseState parseSymbol(const char*& linePtr, AsmSymbolEntry*& entry,
528  bool localLabel = true, bool dontCreateSymbol = false);
529  bool skipSymbol(const char*& linePtr);
530 
531  bool setSymbol(AsmSymbolEntry& symEntry, uint64_t value, cxuint sectionId);
532 
533  bool assignSymbol(const CString& symbolName, const char* symbolPlace,
534  const char* linePtr, bool reassign = true, bool baseExpr = false);
535 
536  bool assignOutputCounter(const char* symbolPlace, uint64_t value, cxuint sectionId,
537  cxbyte fillValue = 0);
538 
539  void parsePseudoOps(const CString& firstName, const char* stmtPlace,
540  const char* linePtr);
541 
543  bool skipClauses(bool exitm = false);
544  bool putMacroContent(RefPtr<AsmMacro> macro);
545  bool putRepetitionContent(AsmRepeat& repeat);
546 
547  void initializeOutputFormat();
548 
549  bool pushClause(const char* string, AsmClauseType clauseType)
550  {
551  bool included; // to ignore
552  return pushClause(string, clauseType, true, included);
553  }
554  bool pushClause(const char* string, AsmClauseType clauseType,
555  bool satisfied, bool& included);
556  // return false when failed (for example no clauses)
557  bool popClause(const char* string, AsmClauseType clauseType);
558 
559  // recursive function to find scope in scope
560  AsmScope* findScopeInScope(AsmScope* scope, const CString& scopeName,
561  std::unordered_set<AsmScope*>& scopeSet);
562  // find scope by identifier
563  AsmScope* getRecurScope(const CString& scopePlace, bool ignoreLast = false,
564  const char** lastStep = nullptr);
565  // find symbol in scopes
566  // internal recursive function to find symbol in scope
567  AsmSymbolEntry* findSymbolInScopeInt(AsmScope* scope, const CString& symName,
568  std::unordered_set<AsmScope*>& scopeSet);
569  // scope - return scope from scoped name
570  AsmSymbolEntry* findSymbolInScope(const CString& symName, AsmScope*& scope,
571  CString& sameSymName, bool insertMode = false);
572  // similar to map::insert, but returns pointer
573  std::pair<AsmSymbolEntry*, bool> insertSymbolInScope(const CString& symName,
574  const AsmSymbol& symbol);
575 
576  // internal recursive function to find symbol in scope
577  AsmRegVarEntry* findRegVarInScopeInt(AsmScope* scope, const CString& rvName,
578  std::unordered_set<AsmScope*>& scopeSet);
579  // scope - return scope from scoped name
580  AsmRegVarEntry* findRegVarInScope(const CString& rvName, AsmScope*& scope,
581  CString& sameRvName, bool insertMode = false);
582  // similar to map::insert, but returns pointer
583  std::pair<AsmRegVarEntry*, bool> insertRegVarInScope(const CString& rvName,
584  const AsmRegVar& regVar);
585 
586  // create scope
587  bool getScope(AsmScope* parent, const CString& scopeName, AsmScope*& scope);
588  // push new scope level
589  bool pushScope(const CString& scopeName);
590  bool popScope();
591 
593  bool includeFile(const char* pseudoOpPlace, const std::string& filename);
594 
595  ParseState makeMacroSubstitution(const char* string);
596 
597  bool parseMacroArgValue(const char*& linePtr, std::string& outStr);
598 
599  void putData(size_t size, const cxbyte* data)
600  {
601  AsmSection& section = sections[currentSection];
602  section.content.insert(section.content.end(), data, data+size);
603  currentOutPos += size;
604  }
605 
606  cxbyte* reserveData(size_t size, cxbyte fillValue = 0);
607 
608  void goToMain(const char* pseudoOpPlace);
609  void goToKernel(const char* pseudoOpPlace, const char* kernelName);
610  void goToSection(const char* pseudoOpPlace, const char* sectionName, uint64_t align=0);
611  void goToSection(const char* pseudoOpPlace, const char* sectionName,
612  AsmSectionType type, Flags flags, uint64_t align=0);
613  void goToSection(const char* pseudoOpPlace, cxuint sectionId, uint64_t align=0);
614 
615  void printWarningForRange(cxuint bits, uint64_t value, const AsmSourcePos& pos,
616  cxbyte signess = WS_BOTH);
617 
618  bool isAddressableSection() const
619  {
620  return currentSection==ASMSECT_ABS ||
621  (sections[currentSection].flags & ASMSECT_ADDRESSABLE) != 0;
622  }
623  bool isWriteableSection() const
624  {
625  return currentSection!=ASMSECT_ABS &&
626  (sections[currentSection].flags & ASMSECT_WRITEABLE) != 0;
627  }
628  bool isResolvableSection() const
629  {
630  return currentSection==ASMSECT_ABS ||
631  (sections[currentSection].flags & ASMSECT_UNRESOLVABLE) == 0;
632  }
633  bool isResolvableSection(cxuint sectionId) const
634  {
635  return sectionId==ASMSECT_ABS ||
636  (sections[sectionId].flags & ASMSECT_UNRESOLVABLE) == 0;
637  }
638 
639  // oldKernels and newKernels must be sorted
640  void handleRegionsOnKernels(const std::vector<cxuint>& newKernels,
641  const std::vector<cxuint>& oldKernels, cxuint codeSection);
642 
643  void tryToResolveSymbols(AsmScope* scope);
644  void printUnresolvedSymbols(AsmScope* scope);
645 
646 protected:
648  bool readLine();
649 public:
651 
660  explicit Assembler(const CString& filename, std::istream& input, Flags flags = 0,
663  std::ostream& msgStream = std::cerr, std::ostream& printStream = std::cout);
664 
666 
674  explicit Assembler(const Array<CString>& filenames, Flags flags = 0,
677  std::ostream& msgStream = std::cerr, std::ostream& printStream = std::cout);
679  ~Assembler();
680 
682  bool assemble();
683 
685  void writeBinary(const char* filename) const;
687  void writeBinary(std::ostream& outStream) const;
689  void writeBinary(Array<cxbyte>& array) const;
690 
692  uint32_t getDriverVersion() const
693  { return driverVersion; }
695  void setDriverVersion(uint32_t driverVersion)
696  { this->driverVersion = driverVersion; }
697 
699  uint32_t getLLVMVersion() const
700  { return llvmVersion; }
702  void setLLVMVersion(uint32_t llvmVersion)
703  { this->llvmVersion = llvmVersion; }
704 
707  { return deviceType; }
709  void setDeviceType(const GPUDeviceType deviceType)
710  { this->deviceType = deviceType; }
713  { return format; }
716  { format = binFormat; }
718  bool is64Bit() const
719  { return _64bit; }
721  void set64Bit(bool this64Bit)
722  { _64bit = this64Bit; }
724  Flags getFlags() const
725  { return flags; }
727  void setFlags(Flags flags)
728  { this->flags = flags; }
729  // get oldModParam
730  bool isOldModParam() const
731  { return oldModParam; }
733  const std::vector<CString>& getIncludeDirs() const
734  { return includeDirs; }
736  void addIncludeDir(const CString& includeDir);
738  const AsmSymbolMap& getSymbolMap() const
739  { return globalScope.symbolMap; }
741  const std::vector<AsmSection>& getSections() const
742  { return sections; }
744  const KernelMap& getKernelMap() const
745  { return kernelMap; }
747  const std::vector<AsmKernel>& getKernels() const
748  { return kernels; }
750  const AsmRegVarMap& getRegVarMap() const
751  { return globalScope.regVarMap; }
753  bool addRegVar(const CString& name, const AsmRegVar& var)
754  { return insertRegVarInScope(name, var).second; }
756  bool getRegVar(const CString& name, const AsmRegVar*& regVar);
757 
759  const AsmScope& getGlobalScope() const
760  { return globalScope; }
761 
763  bool isAbsoluteSymbol(const AsmSymbol& symbol) const;
764 
766  void addInitialDefSym(const CString& symName, uint64_t value);
767 
770  { return formatHandler; }
771 };
772 
773 inline void ISAAssembler::printWarning(const char* linePtr, const char* message)
774 { assembler.printWarning(linePtr, message); }
775 
776 inline void ISAAssembler::printError(const char* linePtr, const char* message)
777 { assembler.printError(linePtr, message); }
778 
779 inline void ISAAssembler::printWarningForRange(cxuint bits, uint64_t value,
780  const AsmSourcePos& pos, cxbyte signess)
781 { assembler.printWarningForRange(bits, value, pos, signess); }
782 
783 inline void ISAAssembler::printWarning(const AsmSourcePos& sourcePos, const char* message)
784 { assembler.printWarning(sourcePos, message); }
785 
786 inline void ISAAssembler::printError(const AsmSourcePos& sourcePos, const char* message)
787 { assembler.printError(sourcePos, message); }
788 
789 inline void ISAAssembler::addCodeFlowEntry(cxuint sectionId, const AsmCodeFlowEntry& entry)
790 { assembler.sections[sectionId].addCodeFlowEntry(entry); }
791 
792 };
793 
794 #endif
void pushUseRegUsage(const AsmRegVarUsage &rvu)
push regvar or register from usereg pseudo-op
AsmRepeatInputFilter or AsmIRPInputFilter.
bool useRegMode
true if in usereg mode
Definition: Assembler.h:95
bool is64Bit() const
get bitness
Definition: Assembler.h:718
void set64Bit(bool this64Bit)
set bitness
Definition: Assembler.h:721
AsmRegVarMap regVarMap
regvar map
Definition: AsmDefs.h:615
common definitions for assembler and disassembler
Definition: Assembler.h:300
main class of assembler
Definition: Assembler.h:403
non copyable and non movable base structure (class)
Definition: Utilities.h:43
assembler expression class
Definition: AsmDefs.h:289
uint32_t Flags
type for declaring various flags
Definition: Utilities.h:97
size_t readOffset
read offset
Definition: Assembler.h:85
Flags getFlags() const
get flags
Definition: Assembler.h:724
std::unordered_map< CString, AsmRegVar > AsmRegVarMap
regvar map
Definition: AsmDefs.h:531
assembler repeat
Definition: AsmSource.h:238
virtual ~ISAUsageHandler()
destructor
std::unordered_map< CString, cxuint > KernelMap
kernel map type
Definition: Assembler.h:409
AMD CATALYST format.
size_t ssaIdChange
number of SSA id changes
Definition: Assembler.h:311
GPUDeviceType getDeviceType() const
get GPU device type
Definition: Assembler.h:706
AsmRegVarMap::value_type AsmRegVarEntry
regvar entry
Definition: AsmDefs.h:533
BinaryFormat
binary for Disassembler
Definition: Commons.h:33
const std::vector< AsmSection > & getSections() const
get sections
Definition: Assembler.h:741
ColNo colNo
column number, for macro substitution and IRP points to column preprocessed line
Definition: AsmSource.h:49
void setDriverVersion(uint32_t driverVersion)
set AMD driver version
Definition: Assembler.h:695
reference pointer based on Glibmm refptr
Definition: Utilities.h:774
AsmClauseType
type of clause
Definition: Assembler.h:384
Assembler & assembler
assembler
Definition: Assembler.h:177
const AsmRegVarMap & getRegVarMap() const
get regvar map
Definition: Assembler.h:750
ReadPos getReadPos() const
get reading position
Definition: Assembler.h:122
assembler section
Definition: AsmDefs.h:652
assembler macro input filter (for macro filtering)
Definition: AsmSource.h:423
std::pair< CString, uint64_t > DefSym
defined symbol entry
Definition: Assembler.h:407
size_t regUsagesPos
position in reg usage
Definition: Assembler.h:87
handles raw code format
Definition: AsmFormats.h:183
assembler input layout filter
Definition: AsmSource.h:389
assembler scope for symbol, macros, regvars
Definition: AsmDefs.h:611
Regvar info structure.
Definition: AsmDefs.h:510
void printError(const char *linePtr, const char *message)
print error for position pointed by line pointer
Definition: Assembler.h:776
AsmRegVarUsage nextUsage()
get next usage
ISAUsageHandler(const std::vector< cxbyte > &content)
constructor
size_t lastOffset
last offset
Definition: Assembler.h:84
void printWarning(const char *linePtr, const char *message)
print warning for position pointed by line pointer
Definition: Assembler.h:773
cxuint sgprsNum
SGPRs number.
Definition: Assembler.h:239
virtual ISAUsageHandler * copy() const =0
copy this usage handler
an array class
Definition: Containers.h:38
size_t regUsagesPos
position in reg usage
Definition: Assembler.h:72
std::vector< NextBlock > nexts
nexts blocks, if empty then direct next block
Definition: Assembler.h:326
Flags regFlags
define what extra register must be included
Definition: Assembler.h:241
void pushUsage(const AsmRegVarUsage &rvu)
push regvar or register usage
Configuration header.
void rewind()
rewind to start for reading
handles ROCM binary format
Definition: AsmFormats.h:469
size_t ssaId
original SSA id
Definition: Assembler.h:309
all flags
Definition: Assembler.h:57
size_t regVarUsagesPos
position in regvar usage
Definition: Assembler.h:89
line and column
Definition: AsmSource.h:44
size_t instrStructPos
position in instr struct
Definition: Assembler.h:86
std::unordered_map< CString, AsmSymbol > AsmSymbolMap
assembler symbol map
Definition: AsmDefs.h:217
an assembler formats
void setFlags(Flags flags)
set flags
Definition: Assembler.h:727
absolute section id
Definition: AsmFormats.h:81
AsmSourcePos sourcePos
position in source code
Definition: Assembler.h:397
uint16_t pushedArgs
pushed args
Definition: Assembler.h:90
void setReadPos(const ReadPos rpos)
set reading position
Definition: Assembler.h:128
size_t regVarUsagesPos
position in regVarUsage
Definition: Assembler.h:74
AsmSectionType
assembler section type
Definition: AsmFormats.h:46
assdembler format handler
Definition: AsmFormats.h:117
RefPtr< const AsmSource > getSource() const
get current source after reading line
Definition: AsmSource.h:368
unsigned char cxbyte
unsigned byte
Definition: Config.h:215
const std::vector< CString > & getIncludeDirs() const
get include directory list
Definition: Assembler.h:733
cxuint vgprsNum
VGPRs number.
Definition: Assembler.h:240
std::unordered_map< CString, RefPtr< const AsmMacro > > AsmMacroMap
assembler macro map
Definition: AsmDefs.h:603
AsmSourcePos prevIfPos
position of previous if-clause
Definition: Assembler.h:399
size_t ssaIdLast
last SSA id in last
Definition: Assembler.h:310
main namespace
Definition: AsmDefs.h:38
bool hasNext() const
has next regvar usage
Definition: Assembler.h:116
LineCol translatePos(size_t position) const
translate position to line number and column number
cxbyte argPos
argument position
Definition: Assembler.h:91
AsmClauseType type
type of clause
Definition: Assembler.h:396
only for running tests
Definition: Assembler.h:56
Definition: Assembler.h:297
unsigned int cxuint
unsigned int
Definition: Config.h:223
const KernelMap & getKernelMap() const
get kernel map
Definition: Assembler.h:744
BinaryFormat getBinaryFormat() const
get binary format
Definition: Assembler.h:712
const AsmSymbolMap & getSymbolMap() const
get symbols map
Definition: Assembler.h:738
std::vector< cxbyte > instrStruct
structure of register usage
Definition: Assembler.h:79
cxbyte AsmExprTargetType
expression target type (one byte)
Definition: AsmDefs.h:59
macro substitution
std::vector< cxbyte > content
content of section
Definition: AsmDefs.h:660
AsmSymbolMap::value_type AsmSymbolEntry
assembler symbol entry
Definition: AsmDefs.h:219
virtual cxbyte getRwFlags(AsmRegField regField, uint16_t rstart, uint16_t rend) const =0
get RW flags (used by assembler)
Definition: Assembler.h:341
GCN (register and regvar) Usage handler.
Definition: Assembler.h:154
cxbyte argFlags
???
Definition: Assembler.h:92
GPUDeviceType
type of GPU device
Definition: GPUId.h:51
bool useRegMode
true if in usereg mode
Definition: Assembler.h:76
void setDeviceType(const GPUDeviceType deviceType)
set GPU device type
Definition: Assembler.h:709
utilities for other libraries and programs
bool isNext
is next
Definition: Assembler.h:94
bool readBeforeWrite
have read before write
Definition: Assembler.h:314
GCN arch assembler.
Definition: Assembler.h:234
size_t ssaIdBefore
SSA id before first SSA in block.
Definition: Assembler.h:307
AsmSymbolMap symbolMap
symbol map
Definition: AsmDefs.h:614
register pool numbers
Definition: Assembler.h:238
size_t regUsages2Pos
position in regUsage2
Definition: Assembler.h:73
uint32_t getLLVMVersion() const
get LLVM version
Definition: Assembler.h:699
assembler&#39;s clause (if,else,macro,rept)
Definition: Assembler.h:394
regvar usage in code
Definition: AsmDefs.h:545
AsmSourcePos getSourcePos(size_t position) const
get source position after reading line
Definition: AsmSource.h:375
Definition: Assembler.h:305
const std::vector< cxbyte > & content
code content
Definition: Assembler.h:83
cxbyte defaultInstrSize
default instruction size
Definition: Assembler.h:93
void putSpace(size_t offset)
put space to offset
LineNo lineNo
line number
Definition: AsmSource.h:46
bool addRegVar(const CString &name, const AsmRegVar &var)
add regvar
Definition: Assembler.h:753
stgructure that hold read position to store later
Definition: Assembler.h:68
code flow entry
Definition: AsmDefs.h:595
void flush()
flush last pending register usages
uint32_t getDriverVersion() const
get AMD driver version
Definition: Assembler.h:692
size_t instrStructPos
position instrStructs
Definition: Assembler.h:71
const AsmFormatHandler * getFormatHandler() const
get format handler
Definition: Assembler.h:769
std::vector< AsmRegUsage2Int > regUsages2
register usage (by .usereg)
Definition: Assembler.h:81
void printWarningForRange(cxuint bits, uint64_t value, const AsmSourcePos &pos, cxbyte signess=WS_BOTH)
print warning about integer out of range
Definition: Assembler.h:779
handles GalliumCompute format
Definition: AsmFormats.h:387
const AsmScope & getGlobalScope() const
get global scope
Definition: Assembler.h:759
an assembler sources handling
Definition: Assembler.h:347
assembler input filter for reading lines
Definition: AsmSource.h:326
size_t readOffset
read offset
Definition: Assembler.h:70
void setLLVMVersion(uint32_t llvmVersion)
set LLVM version
Definition: Assembler.h:702
uint16_t pushedArgs
pused argds number
Definition: Assembler.h:75
assembler symbol structure
Definition: AsmDefs.h:159
virtual void getUsageDependencies(cxuint rvusNum, const AsmRegVarUsage *rvus, cxbyte *linearDeps, cxbyte *equalToDeps) const =0
get usage dependencies around single instruction
RefPtr< const AsmMacroSubst > getMacroSubst() const
get current macro substitution after reading line
Definition: AsmSource.h:371
cxbyte AsmRegField
type of register field
Definition: AsmDefs.h:457
enable all warnings for assembler
Definition: Assembler.h:50
ISA (register and regvar) Usage handler.
Definition: Assembler.h:64
handles AMD Catalyst format
Definition: AsmFormats.h:209
handles AMD OpenCL 2.0 binary format
Definition: AsmFormats.h:298
Definition: Assembler.h:323
virtual std::pair< uint16_t, uint16_t > getRegPair(AsmRegField regField, cxbyte rwFlags) const =0
get reg pair (used by assembler)
AsmRegField regField
place in instruction
Definition: AsmDefs.h:551
ISA assembler class.
Definition: Assembler.h:174
section is unresolvable
Definition: AsmFormats.h:92
simple C-string container
Definition: CString.h:38
an assembler for Radeon GPU&#39;s
void setBinaryFormat(BinaryFormat binFormat)
set binary format
Definition: Assembler.h:715
std::vector< AsmRegVarUsageInt > regVarUsages
regvar usage
Definition: Assembler.h:82
size_t regUsages2Pos
position in reg usage 2
Definition: Assembler.h:88
bool condSatisfied
if conditional clause has already been satisfied
Definition: Assembler.h:398
const std::vector< AsmKernel > & getKernels() const
get kernels
Definition: Assembler.h:747
assembler source position
Definition: AsmSource.h:152
std::vector< AsmRegUsageInt > regUsages
register usage
Definition: Assembler.h:80