File: TranslationBlock.h

package info (click to toggle)
intel-graphics-compiler2 2.16.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 106,644 kB
  • sloc: cpp: 805,640; lisp: 287,672; ansic: 16,414; python: 3,952; yacc: 2,588; lex: 1,666; pascal: 313; sh: 186; makefile: 35
file content (267 lines) | stat: -rw-r--r-- 8,499 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/*========================== begin_copyright_notice ============================

Copyright (C) 2017-2021 Intel Corporation

SPDX-License-Identifier: MIT

============================= end_copyright_notice ===========================*/

#pragma once

#include <stdint.h>
#include <stddef.h>
#include "CommonMacros.h"

#if defined(_WIN32)
// INSIDE_PLUGIN must be defined in the pre-processor definitions of the
// CTranslationBlock DLL project
#define TRANSLATION_BLOCK_CALLING_CONV __cdecl
#ifndef TRANSLATION_BLOCK_API
#ifdef INSIDE_PLUGIN
#define TRANSLATION_BLOCK_API __declspec(dllexport)
#else
#define TRANSLATION_BLOCK_API __declspec(dllimport)
#endif
#endif
#else
#define TRANSLATION_BLOCK_CALLING_CONV
#ifndef TRANSLATION_BLOCK_API
#define TRANSLATION_BLOCK_API __attribute__((visibility("default")))
#endif
#endif

namespace TC {
static const uint32_t STB_VERSION = 1006UL;
static const uint32_t STB_MAX_ERROR_STRING_SIZE = 1024UL;

// Forward prototyping
struct STB_RegisterArgs;
struct STB_CreateArgs;
class CTranslationBlock;

extern "C" TRANSLATION_BLOCK_API void TRANSLATION_BLOCK_CALLING_CONV Register(STB_RegisterArgs *pRegisterArgs);
extern "C" TRANSLATION_BLOCK_API CTranslationBlock *TRANSLATION_BLOCK_CALLING_CONV Create(STB_CreateArgs *pCreateArgs);
extern "C" TRANSLATION_BLOCK_API void TRANSLATION_BLOCK_CALLING_CONV Delete(CTranslationBlock *pBlock);

typedef void(TRANSLATION_BLOCK_CALLING_CONV *PFNREGISTER)(STB_RegisterArgs *pRegisterArgs);
typedef CTranslationBlock *(TRANSLATION_BLOCK_CALLING_CONV *PFNCREATE)(STB_CreateArgs *pCreateArgs);
typedef void(TRANSLATION_BLOCK_CALLING_CONV *PFNDELETE)(CTranslationBlock *pBlock);

#undef TRANSLATION_BLOCK_CALLING_CONV

/******************************************************************************\

Enumeration:
    TB_DATA_FORMAT

Description:
    Possible i/o formats for the translation classes

\******************************************************************************/
enum TB_DATA_FORMAT {
  TB_DATA_FORMAT_UNKNOWN,
  TB_DATA_FORMAT_OCL_TEXT,
  TB_DATA_FORMAT_OCL_BINARY,
  TB_DATA_FORMAT_LLVM_TEXT,
  TB_DATA_FORMAT_LLVM_BINARY,
  TB_DATA_FORMAT_GHAL_TEXT,
  TB_DATA_FORMAT_GHAL_BINARY,
  TB_DATA_FORMAT_DEVICE_TEXT,
  TB_DATA_FORMAT_DEVICE_BINARY,
  TB_DATA_FORMAT_LLVM_ARCHIVE,
  TB_DATA_FORMAT_ELF,
  TB_DATA_FORMAT_RS_LLVM_BINARY,
  TB_DATA_FORMAT_RS_INFO,
  TB_DATA_FORMAT_SPIR_V,
  TB_DATA_FORMAT_COHERENT_DEVICE_BINARY,
  TB_DATA_FORMAT_NON_COHERENT_DEVICE_BINARY,
  NUM_TB_DATA_FORMATS
};

/******************************************************************************\

Structure:
    STB_TranslationCode

Description:
    Structure used to describe the requested translation type

\******************************************************************************/
union STB_TranslationCode {
  struct {
    TB_DATA_FORMAT Input : 16;
    TB_DATA_FORMAT Output : 16;
  } Type;

  uint32_t Code;
};

/******************************************************************************\

Structure:
    STB_CreateArgs

Description:
    Structure used to store arguments used to pass data to the Create function

\******************************************************************************/
struct STB_CreateArgs {
  // INFO keep two first fields in this order ! for version ICBE 1003 compatibility
  STB_TranslationCode TranslationCode;
  void *pCreateData;

  STB_CreateArgs() {
    TranslationCode.Code = 0;
    pCreateData = NULL;
  }
};

/******************************************************************************\

Structure:
    STB_RegisterArgs

Description:
    Structure containing a pointer to an array of supported translation codes
    and a variable informing us of the size of the translation code array.

    The calling function is responsible for deleting the memory allocated
    for the translation code array.

Note:
    Version is contained in this header

\******************************************************************************/
struct STB_RegisterArgs {
  uint32_t Version;
  uint32_t NumTranslationCodes;
  STB_TranslationCode *pTranslationCodes;

  STB_RegisterArgs() {
    Version = STB_VERSION;
    NumTranslationCodes = 0;
    pTranslationCodes = NULL;
  }
};

/******************************************************************************\

Structure:
    STB_TranslateInputArgs

Description:
    Structure used to pass input variables to the translation block

\******************************************************************************/
struct STB_TranslateInputArgs {
  char *pInput;                 // data to be translated
  uint32_t InputSize;           // size of data to be translated
  const char *pOptions;         // list of build/compile options
  uint32_t OptionsSize;         // size of options list
  const char *pInternalOptions; // list of build/compile options
  uint32_t InternalOptionsSize; // size of options list
  void *pTracingOptions;        // instrumentation options
  uint32_t TracingOptionsCount; // number of instrumentation options
  void *GTPinInput;             // input structure for GTPin requests
  bool CompileTimeStatisticsEnable;
  const uint32_t *pSpecConstantsIds;    // user-defined spec constants ids
  const uint64_t *pSpecConstantsValues; // spec constants values to be translated
  uint32_t SpecConstantsSize;           // number of specialization constants
  const char **pVISAAsmToLinkArray;     // array of additional visa assembly in text format
                                        // that should be linked with compiled module.
                                        // Used e.g. for "sginvoke" functionality.
  uint32_t NumVISAAsmsToLink;
  const char **pDirectCallFunctions;
  uint32_t NumDirectCallFunctions;

  STB_TranslateInputArgs() {
    pInput = NULL;
    InputSize = 0;
    pOptions = NULL;
    OptionsSize = 0;
    pInternalOptions = NULL;
    InternalOptionsSize = 0;
    pTracingOptions = NULL;
    TracingOptionsCount = 0;
    GTPinInput = NULL;
    CompileTimeStatisticsEnable = false;
    pSpecConstantsIds = NULL;
    pSpecConstantsValues = NULL;
    SpecConstantsSize = 0;
    pVISAAsmToLinkArray = NULL;
    NumVISAAsmsToLink = 0;
    pDirectCallFunctions = NULL;
    NumDirectCallFunctions = 0;
  }
};

/******************************************************************************\

Structure:
    STB_TranslateOutputArgs

Description:
    Structure used to hold data returned from the translation block

\******************************************************************************/
struct STB_TranslateOutputArgs {
  char *pOutput;            // pointer to translated data buffer
  uint32_t OutputSize;      // translated data buffer size (bytes)
  char *pErrorString;       // string to print if translate fails
  uint32_t ErrorStringSize; // size of error string
  char *pDebugData;         // pointer to translated debug data buffer
  uint32_t DebugDataSize;   // translated debug data data size (bytes)

  STB_TranslateOutputArgs() {
    pOutput = NULL;
    OutputSize = 0;
    pErrorString = NULL;
    ErrorStringSize = 0;
    pDebugData = NULL;
    DebugDataSize = 0;
  }
};

struct TranslationBlockVersion {
  static const uint32_t VersioningIsUnsupported = (uint32_t)-1;
  uint32_t TBVersion; // STB_VERSION version of this translation block
  uint32_t BuildId;   // build ID (for CI builds) of this translation block
};

/******************************************************************************\
Class:
    CTranslationBlock

Description:
    Interface used to expose required functions to translation plug-ins
\******************************************************************************/
class CTranslationBlock {
public:
  virtual bool Translate(const STB_TranslateInputArgs *pInput, STB_TranslateOutputArgs *pOutput) = 0;

  virtual bool FreeAllocations(STB_TranslateOutputArgs *pOutput) = 0;

  virtual bool GetOpcodes(void *pOpcodes, uint32_t pOpcodesSize) {
    IGC_UNUSED(pOpcodes);
    IGC_UNUSED(pOpcodesSize);
    return false;
  }
  virtual bool GetOpcodesCount(uint32_t *pOpcodesCount, uint32_t *pOpcodeSize) {
    IGC_UNUSED(pOpcodesCount);
    IGC_UNUSED(pOpcodeSize);
    return false;
  }
  virtual TranslationBlockVersion GetVersion() const {
    TranslationBlockVersion tbv;
    tbv.TBVersion = TC::STB_VERSION;
    uint32_t buildId = TranslationBlockVersion::VersioningIsUnsupported;
#ifdef TB_BUILD_ID
    buildId = TB_BUILD_ID;
#endif
    tbv.BuildId = buildId;

    return tbv;
  }
  virtual ~CTranslationBlock() {}
};
} // namespace TC