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