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

Last change on this file since 3900 was 3900, checked in by matszpk, 16 months ago

CLRadeonExtender: AsmROCm: Add '.nosectdiffs' for compatibility with the ROCm behaviour from older assembler's versions.

File size: 9.6 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_METADATA_START,
87    ROCMCVAL_MD_WAVEFRONT_SIZE = ROCMCVAL_METADATA_START,
88    ROCMCVAL_MD_KERNARG_SEGMENT_ALIGN,
89    ROCMCVAL_MD_KERNARG_SEGMENT_SIZE,
90    ROCMCVAL_MD_GROUP_SEGMENT_FIXED_SIZE,
91    ROCMCVAL_MD_PRIVATE_SEGMENT_FIXED_SIZE,
92    ROCMCVAL_MD_SGPRSNUM,
93    ROCMCVAL_MD_VGPRSNUM,
94    ROCMCVAL_MD_SPILLEDSGPRS,
95    ROCMCVAL_MD_SPILLEDVGPRS,
96    ROCMCVAL_MAX_FLAT_WORK_GROUP_SIZE
97};
98
99struct CLRX_INTERNAL AsmROCmPseudoOps: AsmPseudoOps
100{
101    static bool checkPseudoOpName(const CString& string);
102   
103    // .arch_minor
104    static void setArchMinor(AsmROCmHandler& handler, const char* linePtr);
105    // .arch_stepping
106    static void setArchStepping(AsmROCmHandler& handler, const char* linePtr);
107    // set elf eflags
108    static void setEFlags(AsmROCmHandler& handler, const char* linePtr);
109   
110    // .target
111    static void setTarget(AsmROCmHandler& handler, const char* linePtr, bool tripple);
112   
113    /* user configuration pseudo-ops */
114    static void doConfig(AsmROCmHandler& handler, const char* pseudoOpPlace,
115                      const char* linePtr);
116    // .control_directive (open this seciton)
117    static void doControlDirective(AsmROCmHandler& handler, const char* pseudoOpPlace,
118                      const char* linePtr);
119    // .metadata
120    static void addMetadata(AsmROCmHandler& handler, const char* pseudoOpPlace,
121                      const char* linePtr);
122    // .md_version
123    static void setMetadataVersion(AsmROCmHandler& handler, const char* pseudoOpPlace,
124                      const char* linePtr);
125    // .cws (set reqd_work_group_size or workgroupsizehint)
126    static void setCWS(AsmROCmHandler& handler, const char* pseudoOpPlace,
127                      const char* linePtr);
128    // .work_group_size_hint
129    static void setWorkGroupSizeHint(AsmROCmHandler& handler, const char* pseudoOpPlace,
130                      const char* linePtr);
131    // .fixed_work_group_size
132    static void setFixedWorkGroupSize(AsmROCmHandler& handler, const char* pseudoOpPlace,
133                      const char* linePtr);
134    // .vectypehint
135    static void setVecTypeHint(AsmROCmHandler& handler, const char* pseudoOpPlace,
136                      const char* linePtr);
137    // .md_symname
138    static void setKernelSymName(AsmROCmHandler& handler, const char* pseudoOpPlace,
139                      const char* linePtr);
140    // .md_language
141    static void setKernelLanguage(AsmROCmHandler& handler, const char* pseudoOpPlace,
142                      const char* linePtr);
143    // .runtime_handle
144    static void setRuntimeHandle(AsmROCmHandler& handler, const char* pseudoOpPlace,
145                      const char* linePtr);
146    // .printf (add printf)
147    static void addPrintf(AsmROCmHandler& handler, const char* pseudoOpPlace,
148                      const char* linePtr);
149    // .arg (add kernel argument to metadata)
150    static void addKernelArg(AsmROCmHandler& handler, const char* pseudoOpPlace,
151                    const char* linePtr);
152    // .fkernel (define kernel as function kernel)
153    static void doFKernel(AsmROCmHandler& handler, const char* pseudoOpPlace,
154                      const char* linePtr);
155    // .globaldata (go to global data (.rodata))
156    static void doGlobalData(AsmROCmHandler& handler, const char* pseudoOpPlace,
157                      const char* linePtr);
158    // .newbinfmt
159    static void setNewBinFormat(AsmROCmHandler& handler, const char* linePtr);
160   
161    // checkConfigValue, setConfigValueMain routines used by other handlers
162    // to check and set AMD HSA config value
163    static bool checkConfigValue(Assembler& asmr, const char* valuePlace,
164                    ROCmConfigValueTarget target, uint64_t value);
165    static void setConfigValueMain(AsmAmdHsaKernelConfig& config,
166                        ROCmConfigValueTarget target, uint64_t value);
167    // checkConfigMdValue
168    static bool checkMDConfigValue(Assembler& asmr, const char* valuePlace,
169                    ROCmConfigValueTarget target, uint64_t value);
170    // setConfigMdValue
171    static void setMDConfigValue(ROCmKernelMetadata& metadata,
172                ROCmConfigValueTarget target, uint64_t value);
173    // set config value
174    static void setConfigValue(AsmROCmHandler& handler, const char* pseudoOpPlace,
175                      const char* linePtr, ROCmConfigValueTarget target);
176    // setConfigBoolValueMain routines used by other handlers to set AMD HSA config values
177    static void setConfigBoolValueMain(AsmAmdHsaKernelConfig& config,
178                        ROCmConfigValueTarget target);
179    // set boolean config value
180    static void setConfigBoolValue(AsmROCmHandler& handler, const char* pseudoOpPlace,
181                      const char* linePtr, ROCmConfigValueTarget target);
182   
183    static void setDefaultHSAFeatures(AsmROCmHandler& handler, const char* pseudoOpPlace,
184                      const char* linePtr);
185    // .dims (set dimensions)
186    static void setDimensions(AsmROCmHandler& handler, const char* pseudoOpPlace,
187                      const char* linePtr);
188    // common routine used by other handlers to parse AMD HSA machine
189    static bool parseMachine(Assembler& asmr, const char* linePtr,
190                uint16_t& machineKind, uint16_t& machineMajor, uint16_t& machineMinor,
191                uint16_t& machineStepping);
192    // .machine
193    static void setMachine(AsmROCmHandler& handler, const char* pseudoOpPlace,
194                      const char* linePtr);
195    // common routine used by other handlers to parse AMD HSA code version
196    static bool parseCodeVersion(Assembler& asmr, const char* linePtr,
197                uint16_t& codeMajor, uint16_t& codeMinor);
198    // .codeversion
199    static void setCodeVersion(AsmROCmHandler& handler, const char* pseudoOpPlace,
200                      const char* linePtr);
201    // common routine used by other handlers to parse AMD HSA reserved registers
202    static bool parseReservedXgprs(Assembler& asmr, const char* linePtr, bool inVgpr,
203                uint16_t& gprFirst, uint16_t& gprCount);
204    // .reserved_sgprs or .reserved_vgprs
205    static void setReservedXgprs(AsmROCmHandler& handler, const char* pseudoOpPlace,
206                      const char* linePtr, bool inVgpr);
207    // .use_grid_workgroup_count
208    static void setUseGridWorkGroupCount(AsmROCmHandler& handler,
209                      const char* pseudoOpPlace, const char* linePtr);
210   
211    // .gotsym
212    static void addGotSymbol(AsmROCmHandler& handler,
213                    const char* pseudoOpPlace, const char* linePtr);
214   
215    // .nosectdiffs
216    static void noSectionDiffs(AsmROCmHandler& handler, const char* linePtr);
217   
218    // .kcode (open kernel code)
219    static void doKCode(AsmROCmHandler& handler, const char* pseudoOpPlace,
220                      const char* linePtr);
221    // .kcodeend (close kernel code)
222    static void doKCodeEnd(AsmROCmHandler& handler, const char* pseudoOpPlace,
223                      const char* linePtr);
224    static void updateKCodeSel(AsmROCmHandler& handler,
225                      const std::vector<cxuint>& oldset);
226};
227
228};
229
230#endif
Note: See TracBrowser for help on using the repository browser.