source: CLRX/CLRadeonExtender/trunk/amdasm/AsmROCmInternals.h @ 3726

Last change on this file since 3726 was 3726, checked in by matszpk, 3 years ago

CLRadeonExtender: DisasmAmd?&DisasmROCm: Check arg types and other fields before printing.
ROCmMetadata: Check arg types and other fields before generating. Escape number in string fields.
AsmROCm: Add additional pseudo-ops (only names) to set metadata info.

File size: 8.7 KB
Line 
1/*
2 *  CLRadeonExtender - Unofficial OpenCL Radeon Extensions Library
3 *  Copyright (C) 2014-2018 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 */
19
20#ifndef __CLRX_ASMROCMINTERNALS_H__
21#define __CLRX_ASMROCMINTERNALS_H__
22
23#include <CLRX/Config.h>
24#include <cstdint>
25#include <string>
26#include <unordered_set>
27#include <utility>
28#include <memory>
29#include <CLRX/utils/Utilities.h>
30#include <CLRX/amdasm/Assembler.h>
31#include "GCNInternals.h"
32#include "AsmInternals.h"
33
34namespace CLRX
35{
36
37enum ROCmConfigValueTarget
38{
39    ROCMCVAL_SGPRSNUM,
40    ROCMCVAL_VGPRSNUM,
41    ROCMCVAL_PRIVMODE,
42    ROCMCVAL_DEBUGMODE,
43    ROCMCVAL_DX10CLAMP,
44    ROCMCVAL_IEEEMODE,
45    ROCMCVAL_TGSIZE,
46    ROCMCVAL_FLOATMODE,
47    ROCMCVAL_PRIORITY,
48    ROCMCVAL_EXCEPTIONS,
49    ROCMCVAL_USERDATANUM,
50    ROCMCVAL_PGMRSRC1,
51    ROCMCVAL_PGMRSRC2,
52    ROCMCVAL_KERNEL_CODE_ENTRY_OFFSET,
53    ROCMCVAL_KERNEL_CODE_PREFETCH_OFFSET,
54    ROCMCVAL_KERNEL_CODE_PREFETCH_SIZE,
55    ROCMCVAL_MAX_SCRATCH_BACKING_MEMORY,
56    ROCMCVAL_USE_PRIVATE_SEGMENT_BUFFER,
57    ROCMCVAL_USE_DISPATCH_PTR,
58    ROCMCVAL_USE_QUEUE_PTR,
59    ROCMCVAL_USE_KERNARG_SEGMENT_PTR,
60    ROCMCVAL_USE_DISPATCH_ID,
61    ROCMCVAL_USE_FLAT_SCRATCH_INIT,
62    ROCMCVAL_USE_PRIVATE_SEGMENT_SIZE,
63    ROCMCVAL_USE_ORDERED_APPEND_GDS,
64    ROCMCVAL_PRIVATE_ELEM_SIZE,
65    ROCMCVAL_USE_PTR64,
66    ROCMCVAL_USE_DYNAMIC_CALL_STACK,
67    ROCMCVAL_USE_DEBUG_ENABLED,
68    ROCMCVAL_USE_XNACK_ENABLED,
69    ROCMCVAL_WORKITEM_PRIVATE_SEGMENT_SIZE,
70    ROCMCVAL_WORKGROUP_GROUP_SEGMENT_SIZE,
71    ROCMCVAL_GDS_SEGMENT_SIZE,
72    ROCMCVAL_KERNARG_SEGMENT_SIZE,
73    ROCMCVAL_WORKGROUP_FBARRIER_COUNT,
74    ROCMCVAL_WAVEFRONT_SGPR_COUNT,
75    ROCMCVAL_WORKITEM_VGPR_COUNT,
76    ROCMCVAL_DEBUG_WAVEFRONT_PRIVATE_SEGMENT_OFFSET_SGPR,
77    ROCMCVAL_DEBUG_PRIVATE_SEGMENT_BUFFER_SGPR,
78    ROCMCVAL_KERNARG_SEGMENT_ALIGN,
79    ROCMCVAL_GROUP_SEGMENT_ALIGN,
80    ROCMCVAL_PRIVATE_SEGMENT_ALIGN,
81    ROCMCVAL_WAVEFRONT_SIZE,
82    ROCMCVAL_CALL_CONVENTION,
83    ROCMCVAL_RUNTIME_LOADER_KERNEL_SYMBOL,
84   
85    // metadata info
86    ROCMCVAL_MD_WAVEFRONT_SIZE,
87    ROCMCVAL_MD_KERNARG_SEGMENT_ALIGN,
88    ROCMCVAL_MD_KERNARG_SEGMENT_SIZE,
89    ROCMCVAL_MD_GROUP_SEGMENT_FIXED_SIZE,
90    ROCMCVAL_MD_PRIVATE_SEGMENT_FIXED_SIZE,
91    ROCMCVAL_MD_SGPRSNUM,
92    ROCMCVAL_MD_VGPRSNUM,
93    ROCMCVAL_MD_SPILLEDSGPRS,
94    ROCMCVAL_MD_SPILLEDVGPRS,
95    ROCMCVAL_MAX_FLAT_WORK_GROUP_SIZE
96};
97
98struct CLRX_INTERNAL AsmROCmPseudoOps: AsmPseudoOps
99{
100    static bool checkPseudoOpName(const CString& string);
101   
102    // .arch_minor
103    static void setArchMinor(AsmROCmHandler& handler, const char* linePtr);
104    // .arch_stepping
105    static void setArchStepping(AsmROCmHandler& handler, const char* linePtr);
106    // set elf eflags
107    static void setEFlags(AsmROCmHandler& handler, const char* linePtr);
108   
109    // .target
110    static void setTarget(AsmROCmHandler& handler, const char* linePtr, bool tripple);
111   
112    /* user configuration pseudo-ops */
113    static void doConfig(AsmROCmHandler& handler, const char* pseudoOpPlace,
114                      const char* linePtr);
115    // .control_directive (open this seciton)
116    static void doControlDirective(AsmROCmHandler& handler, const char* pseudoOpPlace,
117                      const char* linePtr);
118    // .metadata
119    static void addMetadata(AsmROCmHandler& handler, const char* pseudoOpPlace,
120                      const char* linePtr);
121    // .md_version
122    static void setMetadataVersion(AsmROCmHandler& handler, const char* pseudoOpPlace,
123                      const char* linePtr);
124    // .cws (set reqd_work_group_size or workgroupsizehint)
125    static void setCWS(AsmROCmHandler& handler, const char* pseudoOpPlace,
126                      const char* linePtr);
127    // .work_group_size_hint
128    static void setWorkGroupSizeHint(AsmROCmHandler& handler, const char* pseudoOpPlace,
129                      const char* linePtr);
130    // .fixed_work_group_size
131    static void setFixedWorkGroupSize(AsmROCmHandler& handler, const char* pseudoOpPlace,
132                      const char* linePtr);
133    // .vectypehint
134    static void setVecTypeHint(AsmROCmHandler& handler, const char* pseudoOpPlace,
135                      const char* linePtr);
136    // .md_symname
137    static void setKernelSymName(AsmROCmHandler& handler, const char* pseudoOpPlace,
138                      const char* linePtr);
139    // .md_language
140    static void setKernelLanguage(AsmROCmHandler& handler, const char* pseudoOpPlace,
141                      const char* linePtr);
142    // .printf (add printf)
143    static void addPrintf(AsmROCmHandler& handler, const char* pseudoOpPlace,
144                      const char* linePtr);
145    // .fkernel (define kernel as function kernel)
146    static void doFKernel(AsmROCmHandler& handler, const char* pseudoOpPlace,
147                      const char* linePtr);
148    // .globaldata (go to global data (.rodata))
149    static void doGlobalData(AsmROCmHandler& handler, const char* pseudoOpPlace,
150                      const char* linePtr);
151    // .newbinfmt
152    static void setNewBinFormat(AsmROCmHandler& handler, const char* linePtr);
153   
154    // checkConfigValue, setConfigValueMain routines used by other handlers
155    // to check and set AMD HSA config value
156    static bool checkConfigValue(Assembler& asmr, const char* valuePlace,
157                    ROCmConfigValueTarget target, uint64_t value);
158    static void setConfigValueMain(AsmAmdHsaKernelConfig& config,
159                        ROCmConfigValueTarget target, uint64_t value);
160    // set config value
161    static void setConfigValue(AsmROCmHandler& handler, const char* pseudoOpPlace,
162                      const char* linePtr, ROCmConfigValueTarget target);
163   
164    // setConfigBoolValueMain routines used by other handlers to set AMD HSA config values
165    static void setConfigBoolValueMain(AsmAmdHsaKernelConfig& config,
166                        ROCmConfigValueTarget target);
167    // set boolean config value
168    static void setConfigBoolValue(AsmROCmHandler& handler, const char* pseudoOpPlace,
169                      const char* linePtr, ROCmConfigValueTarget target);
170   
171    static void setDefaultHSAFeatures(AsmROCmHandler& handler, const char* pseudoOpPlace,
172                      const char* linePtr);
173    // .dims (set dimensions)
174    static void setDimensions(AsmROCmHandler& handler, const char* pseudoOpPlace,
175                      const char* linePtr);
176    // common routine used by other handlers to parse AMD HSA machine
177    static bool parseMachine(Assembler& asmr, const char* linePtr,
178                uint16_t& machineKind, uint16_t& machineMajor, uint16_t& machineMinor,
179                uint16_t& machineStepping);
180    // .machine
181    static void setMachine(AsmROCmHandler& handler, const char* pseudoOpPlace,
182                      const char* linePtr);
183    // common routine used by other handlers to parse AMD HSA code version
184    static bool parseCodeVersion(Assembler& asmr, const char* linePtr,
185                uint16_t& codeMajor, uint16_t& codeMinor);
186    // .codeversion
187    static void setCodeVersion(AsmROCmHandler& handler, const char* pseudoOpPlace,
188                      const char* linePtr);
189    // common routine used by other handlers to parse AMD HSA reserved registers
190    static bool parseReservedXgprs(Assembler& asmr, const char* linePtr, bool inVgpr,
191                uint16_t& gprFirst, uint16_t& gprCount);
192    // .reserved_sgprs or .reserved_vgprs
193    static void setReservedXgprs(AsmROCmHandler& handler, const char* pseudoOpPlace,
194                      const char* linePtr, bool inVgpr);
195    // .use_grid_workgroup_count
196    static void setUseGridWorkGroupCount(AsmROCmHandler& handler,
197                      const char* pseudoOpPlace, const char* linePtr);
198   
199    // .kcode (open kernel code)
200    static void doKCode(AsmROCmHandler& handler, const char* pseudoOpPlace,
201                      const char* linePtr);
202    // .kcodeend (close kernel code)
203    static void doKCodeEnd(AsmROCmHandler& handler, const char* pseudoOpPlace,
204                      const char* linePtr);
205    static void updateKCodeSel(AsmROCmHandler& handler,
206                      const std::vector<cxuint>& oldset);
207};
208
209};
210
211#endif
Note: See TracBrowser for help on using the repository browser.