Debian Codegraph @

IGC/OCLFE/igd_fcl_mcl/headers/clang_tb.h

raw symbols SCIP
1 /*========================== begin_copyright_notice ============================
2
3 Copyright (C) 2017-2023 Intel Corporation
4
5 SPDX-License-Identifier: MIT
6
7 ============================= end_copyright_notice ===========================*/
8
9 #pragma once
10
11 #include "GlobalData.h"
12 #include "igfxfmid.h"
13 #include "TranslationBlock.h"
14 #include <string>
15 #include <memory>
16 #include <vector>
17
18 #include "LoadBuffer.h"
19 #include "AdaptorOCL/CLElfLib/ElfReader.h"
20 // TODO: really need this to point to the header file from the common clang
21 // zip instead of our own copy.
22 #include "common_clang.h"
23
24 namespace llvm {
25 class MemoryBuffer;
26 }
27
28 // forward decls
29 namespace CLElfLib {
30 class CElfReader;
31 }
32
33 namespace Intel {
34 namespace OpenCL {
35 namespace ClangFE {
36 struct IOCLFEBinaryResult;
37 }
38 } // namespace OpenCL
39 } // namespace Intel
40
41 namespace TC {
42 struct TranslateClangArgs;
43
44 static const STB_TranslationCode g_cClangTranslationCodes[] = {
45 {TB_DATA_FORMAT_OCL_TEXT, TB_DATA_FORMAT_LLVM_TEXT}, {TB_DATA_FORMAT_OCL_TEXT, TB_DATA_FORMAT_LLVM_BINARY},
46 {TB_DATA_FORMAT_OCL_TEXT, TB_DATA_FORMAT_SPIR_V}, {TB_DATA_FORMAT_ELF, TB_DATA_FORMAT_LLVM_BINARY},
47 {TB_DATA_FORMAT_ELF, TB_DATA_FORMAT_SPIR_V}, {TB_DATA_FORMAT_ELF, TB_DATA_FORMAT_LLVM_ARCHIVE}};
48
49 #ifdef _WIN32
50 #ifdef COMMON_CLANG_LIB_FULL_NAME
51 struct CCModuleStruct {
52 typedef decltype(Compile) *PFcnCCCompile;
53
54 void *pModule = nullptr;
55 PFcnCCCompile pCompile = nullptr;
56
57 const char *pModuleName = COMMON_CLANG_LIB_FULL_NAME;
58 };
59 #else
60 #error "Common clang name not defined"
61 #endif
62 #endif
63
64 /***************************************************************************\
65
66 Class:
67 CClangTranslationBlock
68
69 Description:
70
71 \***************************************************************************/
72 class CClangTranslationBlock : public CTranslationBlock {
73 TB_DATA_FORMAT m_InputFormat{};
74 TB_DATA_FORMAT m_OutputFormat{};
75 #ifdef _WIN32
76 CCModuleStruct m_CCModule;
77 #endif
78
79 public:
80 static bool Create(const STB_CreateArgs *pCreateArgs, STB_TranslateOutputArgs *pOutputArgs,
81 CClangTranslationBlock *&pTranslationBlock);
82
83 static void Delete(CClangTranslationBlock *&pTranslationBlock);
84
85 virtual bool Translate(const STB_TranslateInputArgs *pInputArgs, STB_TranslateOutputArgs *pOutputArgs);
86
87 void SetOclApiVersion(unsigned int oclVersion) { m_OCL_Ver = std::to_string(oclVersion); }
88
89 static void SetErrorString(const char *pErrorString, STB_TranslateOutputArgs *pOutputArgs);
90
91 private:
92 // Is assigned the value of the OpenCL API version that corresponds to the
93 // current OCL runtime driver. The values are defined in the OpenCL spec
94 // (e.g., 1.1 -> 110, 1.2 -> 120, etc.). This is equivalent to
95 // the __OPENCL_VERSION__ macro (spec 6.10).
96 std::string m_OCL_Ver;
97
98 // vector of supported OpenCL extensions for current device
99 std::vector<std::string> m_Extensions;
100
101 PRODUCT_FAMILY m_HWPlatform{}; // The HW platform that the device is running on
102 GFXCORE_FAMILY m_CoreFamily{};
103 SGlobalData m_GlobalData{};
104
105 // Using auto pointer to get CTH MemoryBuffer from LoadBuffer
106 char *m_cthBuffer = nullptr;
107
108 protected:
109 CClangTranslationBlock(void);
110
111 virtual ~CClangTranslationBlock(void);
112
113
114 // Read OCL version from internal options
115 std::string GetOclApiVersion(const char *pInternalOptions) const;
116
117 bool TranslateClang(const TranslateClangArgs *pInputArgs, STB_TranslateOutputArgs *pOutputArgs,
118 std::string &exceptString, const char *pInternalOptions);
119
120 bool TranslateElf(const STB_TranslateInputArgs *pInputArgs, STB_TranslateOutputArgs *pOutputArgs,
121 std::string &exceptString);
122
123 void GetTranslateClangArgs(char *pInput, uint32_t uiInputSize, const char *pOptions, const char *pInternalOptions,
124 TranslateClangArgs *pClangArgs, std::string &exceptString);
125
126 void GetTranslateClangArgs(CLElfLib::CElfReader *pElfReader, const char *pOptions, const char *pInternalOptions,
127 TranslateClangArgs *pClangArgs, std::string &exceptString);
128
129 void EnsureProperPCH(TranslateClangArgs *pArgs, const char *pInternalOptions, std::string &exceptString);
130
131 bool ReturnSuppliedIR(const STB_TranslateInputArgs *pInputArgs, STB_TranslateOutputArgs *pOutputArgs);
132
133 bool Initialize(const STB_CreateArgs *pCreateArgs);
134 };
135
136 } // namespace TC
137
138 namespace FCL {
139
140 // type for name of output folder
141 using OutputFolderName = const char *;
142
143 // function returns full path where to dump shaders for FCL
144 OutputFolderName GetShaderOutputFolder();
145
146 // different register-dependent functions
147 bool GetFCLShaderDumpEnable();
148 bool GetFCLShaderDumpPidDisable();
149 bool GetFCLDumpToCurrentDir();
150 bool GetFCLDumpToCustomDir();
151 bool GetFCLEnableKernelNamesBasedHash();
152 #if LLVM_VERSION_MAJOR < 17 || defined(IGC_LLVM_TRUNK_REVISION)
153 bool GetFCLEnableOpaquePointersBackend();
154 #endif
155 } // namespace FCL
156
157 // convenient macro to check FCL flags
158 #define FCL_IGC_IS_FLAG_ENABLED(name) FCL::GetFCL##name()