@@ -85,7 +85,7 @@ static volatile bool lazyCCInit =
8585 true ; // the flag must be 'volatile' to prevent caching in a CPU register
8686static llvm::sys::Mutex lazyCCInitMutex;
8787
88- static llvm::ManagedStatic<llvm::sys::SmartMutex<true > > compileMutex;
88+ static llvm::ManagedStatic<llvm::sys::SmartMutex<true >> compileMutex;
8989
9090void CommonClangTerminate () { llvm::llvm_shutdown (); }
9191
@@ -113,16 +113,26 @@ void CommonClangInitialize() {
113113}
114114
115115static bool GetHeaders (std::vector<Resource> &Result) {
116- struct {const char *ID; const char *Name;} Headers[] = {
117- {OPENCL_C_H, " opencl-c.h" },
118- };
116+ struct {
117+ const char *ID;
118+ const char *Name;
119+ } Headers[] = {{OPENCL_C_H, " opencl-c.h" },
120+ {OPENCL_C_12_SPIR_PCM, " opencl-c-12-spir.pcm" },
121+ {OPENCL_C_20_SPIR_PCM, " opencl-c-20-spir.pcm" },
122+ {OPENCL_C_12_SPIR64_PCM, " opencl-c-12-spir64.pcm" },
123+ {OPENCL_C_20_SPIR64_PCM, " opencl-c-20-spir64.pcm" },
124+ {OPENCL_C_12_SPIR_FP64_PCM, " opencl-c-12-spir-fp64.pcm" },
125+ {OPENCL_C_20_SPIR_FP64_PCM, " opencl-c-20-spir-fp64.pcm" },
126+ {OPENCL_C_12_SPIR64_FP64_PCM, " opencl-c-12-spir64-fp64.pcm" },
127+ {OPENCL_C_20_SPIR64_FP64_PCM, " opencl-c-20-spir64-fp64.pcm" },
128+ {OPENCL_C_MODULE_MAP, " module.modulemap" }};
119129
120130 Result.clear ();
121131 Result.reserve (sizeof (Headers) / sizeof (*Headers));
122132
123133 ResourceManager &RM = ResourceManager::instance ();
124134
125- for (auto Header: Headers) {
135+ for (auto Header : Headers) {
126136 Resource R = RM.get_resource (Header.Name , Header.ID , " PCM" , true );
127137 if (!R) {
128138 assert (0 && " Resource not found" );
@@ -135,17 +145,21 @@ static bool GetHeaders(std::vector<Resource> &Result) {
135145 return true ;
136146}
137147
138- static void PrintCompileOptions (const char *pszOptions, const char *pszOptionsEx,
139- const char *pszOpenCLVer, const char * pszSource) {
148+ static void PrintCompileOptions (const char *pszOptions,
149+ const char *pszOptionsEx,
150+ const char *pszOpenCLVer,
151+ const char *pszSource) {
140152#ifdef _DEBUG
141153 static int ID = 0 ;
142154
143- if (!getenv (" CCLANG_OPTIONS_DIR" )) return ;
155+ if (!getenv (" CCLANG_OPTIONS_DIR" ))
156+ return ;
144157
145158 std::string OptionsDir = getenv (" CCLANG_OPTIONS_DIR" );
146159
147160 std::stringstream logPath;
148- logPath << OptionsDir << " /log_" << std::this_thread::get_id () << " _" << ID << " .txt" ;
161+ logPath << OptionsDir << " /log_" << std::this_thread::get_id () << " _" << ID
162+ << " .txt" ;
149163 std::cout << logPath.str () << std::endl;
150164
151165 // Creating log file
@@ -165,22 +179,21 @@ static void PrintCompileOptions(const char *pszOptions, const char *pszOptionsEx
165179#endif
166180}
167181
168- class SmallVectorBuffer : public std ::streambuf
169- {
182+ class SmallVectorBuffer : public std ::streambuf {
170183 // All memory management is delegated to llvm::SmallVectorImpl
171184 llvm::SmallVectorImpl<char > &OS;
172185
173186 // Since we don't touch any pointer in streambuf(pbase, pptr, epptr) this is
174187 // the only method we need to override.
175- virtual std::streamsize xsputn (const char *s, std::streamsize n) override {
188+ virtual std::streamsize xsputn (const char *s, std::streamsize n) override {
176189 OS.append (s, s + n);
177190 return n;
178191 }
179192
180193public:
181194 SmallVectorBuffer () = delete ;
182- SmallVectorBuffer (const SmallVectorBuffer&) = delete ;
183- SmallVectorBuffer &operator =(const SmallVectorBuffer&) = delete ;
195+ SmallVectorBuffer (const SmallVectorBuffer &) = delete ;
196+ SmallVectorBuffer &operator =(const SmallVectorBuffer &) = delete ;
184197 SmallVectorBuffer (llvm::SmallVectorImpl<char > &O) : OS(O) {}
185198};
186199
@@ -202,7 +215,7 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
202215
203216 // LLVM doesn't guarantee thread safety,
204217 // therefore we serialize execution of LLVM code.
205- llvm::sys::SmartScopedLock<true > compileGuard {*compileMutex};
218+ llvm::sys::SmartScopedLock<true > compileGuard{*compileMutex};
206219
207220 // Parse options
208221 CompileOptionsParser optionsParser (pszOpenCLVer);
@@ -227,16 +240,16 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
227240 new clang::CompilerInstance ());
228241
229242 // Prepare output buffer
230- std::unique_ptr<llvm::raw_pwrite_stream>
231- ir_ostream ( new llvm::raw_svector_ostream (pResult->getIRBufferRef ()));
243+ std::unique_ptr<llvm::raw_pwrite_stream> ir_ostream (
244+ new llvm::raw_svector_ostream (pResult->getIRBufferRef ()));
232245 // Set buffers
233246 // CompilerInstance takes ownership over output stream
234247 compiler->setOutputStream (std::move (ir_ostream));
235248
236249 compiler->setDiagnostics (&*Diags);
237250
238- auto OverlayFS = new llvm::vfs::OverlayFileSystem (
239- llvm::vfs::getRealFileSystem ());
251+ auto OverlayFS =
252+ new llvm::vfs::OverlayFileSystem ( llvm::vfs::getRealFileSystem ());
240253 auto MemFS = new llvm::vfs::InMemoryFileSystem ();
241254 OverlayFS->pushOverlay (MemFS);
242255
@@ -258,31 +271,29 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
258271 // Source file
259272 MemFS->addFile (
260273 optionsParser.getSourceName (), (time_t )0 ,
261- llvm::MemoryBuffer::getMemBuffer (
262- llvm::StringRef (pszProgramSource), optionsParser.getSourceName ()));
274+ llvm::MemoryBuffer::getMemBuffer (llvm::StringRef (pszProgramSource),
275+ optionsParser.getSourceName ()));
263276
264277 // Input header with OpenCL defines.
265278 std::vector<Resource> vHeaderWithDefs;
266279 if (!GetHeaders (vHeaderWithDefs)) {
267280 return CL_COMPILE_PROGRAM_FAILURE;
268281 }
269282
270- for (const auto &Header: vHeaderWithDefs) {
283+ for (const auto &Header : vHeaderWithDefs) {
271284 auto Buf = llvm::MemoryBuffer::getMemBuffer (
272- llvm::StringRef (Header.m_data , Header.m_size ),
273- Header.m_name );
285+ llvm::StringRef (Header.m_data , Header.m_size ), Header.m_name );
274286
275- MemFS->addFile (Header.m_name ,(time_t )0 , std::move (Buf));
287+ MemFS->addFile (Header.m_name , (time_t )0 , std::move (Buf));
276288 }
277289
278290 // Input Headers
279291 for (unsigned int i = 0 ; i < uiNumInputHeaders; ++i) {
280- auto Header = llvm::MemoryBuffer::getMemBuffer (
281- pInputHeaders[i], pInputHeadersNames[i]);
292+ auto Header = llvm::MemoryBuffer::getMemBuffer (pInputHeaders[i],
293+ pInputHeadersNames[i]);
282294 MemFS->addFile (pInputHeadersNames[i], (time_t )0 , std::move (Header));
283295 }
284296
285-
286297 // Execute the frontend actions.
287298 bool success = false ;
288299 try {
@@ -303,12 +314,14 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
303314
304315 if (success && optionsParser.hasEmitSPIRV ()) {
305316 // Translate LLVM IR to SPIR-V.
306- llvm::StringRef LLVM_IR (static_cast <const char *>(pResult->GetIR ()),
317+ llvm::StringRef LLVM_IR (static_cast <const char *>(pResult->GetIR ()),
307318 pResult->GetIRSize ());
308- std::unique_ptr<llvm::MemoryBuffer> MB = llvm::MemoryBuffer::getMemBuffer (LLVM_IR, pResult->GetIRName (), false );
319+ std::unique_ptr<llvm::MemoryBuffer> MB = llvm::MemoryBuffer::getMemBuffer (
320+ LLVM_IR, pResult->GetIRName (), false );
309321 llvm::LLVMContext Context;
310- auto E = llvm::getOwningLazyBitcodeModule (std::move (MB), Context,
311- /* ShouldLazyLoadMetadata=*/ true );
322+ auto E =
323+ llvm::getOwningLazyBitcodeModule (std::move (MB), Context,
324+ /* ShouldLazyLoadMetadata=*/ true );
312325 llvm::logAllUnhandledErrors (E.takeError (), err_ostream, " error: " );
313326 std::unique_ptr<llvm::Module> M = std::move (*E);
314327
0 commit comments