| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 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 |
|
| 21 |
|
| 22 |
#include "common_clang.h" |
| 23 |
|
| 24 |
namespace llvm { |
| 25 |
class MemoryBuffer; |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
namespace CLElfLib { |
| 30 |
class CElfReader; |
| 31 |
} |
| 32 |
|
| 33 |
namespace Intel { |
| 34 |
namespace OpenCL { |
| 35 |
namespace ClangFE { |
| 36 |
struct IOCLFEBinaryResult; |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 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 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 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 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
std::string m_OCL_Ver; |
| 97 |
|
| 98 |
|
| 99 |
std::vector<std::string> m_Extensions; |
| 100 |
|
| 101 |
PRODUCT_FAMILY m_HWPlatform{}; |
| 102 |
GFXCORE_FAMILY m_CoreFamily{}; |
| 103 |
SGlobalData m_GlobalData{}; |
| 104 |
|
| 105 |
|
| 106 |
char *m_cthBuffer = nullptr; |
| 107 |
|
| 108 |
protected: |
| 109 |
CClangTranslationBlock(void); |
| 110 |
|
| 111 |
virtual ~CClangTranslationBlock(void); |
| 112 |
|
| 113 |
|
| 114 |
|
| 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 |
} |
| 137 |
|
| 138 |
namespace FCL { |
| 139 |
|
| 140 |
|
| 141 |
using OutputFolderName = const char *; |
| 142 |
|
| 143 |
|
| 144 |
OutputFolderName GetShaderOutputFolder(); |
| 145 |
|
| 146 |
|
| 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 |
} |
| 156 |
|
| 157 |
|
| 158 |
#define FCL_IGC_IS_FLAG_ENABLED(name) FCL::GetFCL##name() |