| 1 | /*========================== begin_copyright_notice ============================ |
| 2 | |
| 3 | Copyright (C) 2017-2021 Intel Corporation |
| 4 | |
| 5 | SPDX-License-Identifier: MIT |
| 6 | |
| 7 | ============================= end_copyright_notice ===========================*/ |
| 8 | |
| 9 | #pragma once |
| 10 | |
| 11 | #if defined(_WIN32) |
| 12 | #if defined(COMMON_CLANG_EXPORTS) |
| 13 | #define CC_DLL_EXPORT _declspec(dllexport) |
| 14 | #else |
| 15 | #define CC_DLL_EXPORT _declspec(dllimport) |
| 16 | #endif |
| 17 | #else |
| 18 | #define CC_DLL_EXPORT |
| 19 | #endif |
| 20 | |
| 21 | namespace Intel { |
| 22 | namespace OpenCL { |
| 23 | namespace ClangFE { |
| 24 | // |
| 25 | // Type of the binary returned after compilation and/or link |
| 26 | // |
| 27 | enum IR_TYPE { IR_TYPE_UNKNOWN, IR_TYPE_EXECUTABLE, IR_TYPE_LIBRARY, IR_TYPE_COMPILED_OBJECT }; |
| 28 | |
| 29 | // |
| 30 | // Compilation results interface |
| 31 | // Returned by Compile method |
| 32 | // |
| 33 | struct IOCLFEBinaryResult { |
| 34 | IOCLFEBinaryResult(const IOCLFEBinaryResult &cm) = delete; |
| 35 | IOCLFEBinaryResult &operator=(const IOCLFEBinaryResult &cm) = delete; |
| 36 | // Returns the size in bytes of the IR buffer |
| 37 | virtual size_t GetIRSize() const = 0; |
| 38 | // Returns the pointer to the IR buffer or NULL if no IR buffer is present |
| 39 | virtual const void *GetIR() const = 0; |
| 40 | // Returns the name of the program |
| 41 | virtual const char *GetIRName() const = 0; |
| 42 | // Returns the type of the resulted binary |
| 43 | virtual IR_TYPE GetIRType() const = 0; |
| 44 | // Returns the pointer to the compilation log string or NULL if not log was created |
| 45 | virtual const char *GetErrorLog() const = 0; |
| 46 | // Releases the result object |
| 47 | virtual void Release() = 0; |
| 48 | |
| 49 | protected: |
| 50 | virtual ~IOCLFEBinaryResult() {} |
| 51 | }; |
| 52 | } // namespace ClangFE |
| 53 | } // namespace OpenCL |
| 54 | } // namespace Intel |
| 55 | |
| 56 | // |
| 57 | // Verifies the given OpenCL application supplied compilation options |
| 58 | // Params: |
| 59 | // pszOptions - compilation options string |
| 60 | // pszUnknownOptions - optional outbound pointer to the space separated unrecognized options |
| 61 | // uiUnknownOptionsSize - size of the pszUnknownOptions buffer |
| 62 | // Returns: |
| 63 | // true if the options verification was succesfull, false otherwise |
| 64 | // |
| 65 | extern "C" CC_DLL_EXPORT bool CheckCompileOptions( |
| 66 | // A string for compile options |
| 67 | const char *pszOptions, |
| 68 | // buffer to get the list of unknown options |
| 69 | char *pszUnknownOptions, |
| 70 | // size of the buffer for unknown options |
| 71 | size_t uiUnknownOptionsSize); |
| 72 | |
| 73 | // |
| 74 | // Verifies the given OpenCL application supplied link options |
| 75 | // Params: |
| 76 | // pszOptions - compilation options string |
| 77 | // pszUnknownOptions - optional outbound pointer to the space separated unrecognized options |
| 78 | // uiUnknownOptionsSize - size of the pszUnknownOptions buffer |
| 79 | // Returns: |
| 80 | // true if the options verification was succesfull, false otherwise |
| 81 | // |
| 82 | extern "C" CC_DLL_EXPORT bool CheckLinkOptions( |
| 83 | // A string for compile options |
| 84 | const char *pszOptions, |
| 85 | // buffer to get the list of unknown options |
| 86 | char *pszUnknownOptions, |
| 87 | // size of the buffer for unknown options |
| 88 | size_t uiUnknownOptionsSize); |
| 89 | |
| 90 | // |
| 91 | // Compiles the given OpenCL program to the LLVM IR |
| 92 | // Params: |
| 93 | // pProgramSource - OpenCL source program to compile |
| 94 | // pInputHeaders - array of the header buffers |
| 95 | // uiNumInputHeader - size of the pInputHeaders array |
| 96 | // pszInputHeadersNames - array of the headers names |
| 97 | // pPCHBuffer - optional pointer to the pch buffer |
| 98 | // uiPCHBufferSize - size of the pch buffer |
| 99 | // pszOptions - OpenCL application supplied options |
| 100 | // pszOptionsEx - optional extra options string usually supplied by runtime |
| 101 | // pszDeviceSupportedExtentions - space separated list of the supported OpenCL extensions string |
| 102 | // pszOpenCLVer - OpenCL version string - "120" for OpenCL 1.2, "200" for OpenCL 2.0, ... |
| 103 | // pBinaryResult - optional outbound pointer to the compilation results |
| 104 | // Returns: |
| 105 | // Compilation Result as int: 0 - success, error otherwise. |
| 106 | // |
| 107 | extern "C" CC_DLL_EXPORT int Compile( |
| 108 | // A pointer to main program's source (null terminated string) |
| 109 | const char *pszProgramSource, |
| 110 | // array of additional input headers to be passed in memory (each null terminated) |
| 111 | const char **pInputHeaders, |
| 112 | // the number of input headers in pInputHeaders |
| 113 | unsigned int uiNumInputHeaders, |
| 114 | // array of input headers names corresponding to pInputHeaders |
| 115 | const char **pInputHeadersNames, |
| 116 | // optional pointer to the pch buffer |
| 117 | const char *pPCHBuffer, |
| 118 | // size of the pch buffer |
| 119 | size_t uiPCHBufferSize, |
| 120 | // OpenCL application supplied options |
| 121 | const char *pszOptions, |
| 122 | // optional extra options string usually supplied by runtime |
| 123 | const char *pszOptionsEx, |
| 124 | // OpenCL version string - "120" for OpenCL 1.2, "200" for OpenCL 2.0, ... |
| 125 | const char *pszOpenCLVer, |
| 126 | // optional outbound pointer to the compilation results |
| 127 | Intel::OpenCL::ClangFE::IOCLFEBinaryResult **pBinaryResult); |
| 128 | |
| 129 | // |
| 130 | // Links the given OpenCL binaries |
| 131 | // Params: |
| 132 | // pInputHeaders - array of the header buffers |
| 133 | // uiNumInputHeader - size of the pInputHeaders array |
| 134 | // pszInputHeadersNames - array of the headers names |
| 135 | // pPCHBuffer - optional pointer to the pch buffer |
| 136 | // uiPCHBufferSize - size of the pch buffer |
| 137 | // pszOptions - OpenCL application supplied options |
| 138 | // pszOptionsEx - optional extra options string usually supplied by runtime |
| 139 | // pszDeviceSupportedExtentions - space separated list of the supported OpenCL extensions string |
| 140 | // pszOpenCLVer - OpenCL version string - "120" for OpenCL 1.2, "200" for OpenCL 2.0, ... |
| 141 | // pBinaryResult - optional outbound pointer to the compilation results |
| 142 | // Returns: |
| 143 | // Link Result as int: 0 - success, error otherwise. |
| 144 | // |
| 145 | extern "C" CC_DLL_EXPORT int Link( |
| 146 | // array of additional input headers to be passed in memory |
| 147 | const void **pInputBinaries, |
| 148 | // the number of input binaries |
| 149 | unsigned int uiNumBinaries, |
| 150 | // the size in bytes of each binary |
| 151 | const size_t *puiBinariesSizes, |
| 152 | // OpenCL application supplied options |
| 153 | const char *pszOptions, |
| 154 | // optional outbound pointer to the compilation results |
| 155 | Intel::OpenCL::ClangFE::IOCLFEBinaryResult **pBinaryResult); |