@@ -41,12 +41,7 @@ std::vector<std::pair<std::string /*original file name or linker entry*/,
4141static void fillCompileCmds (
4242 std::map<std::string, std::vector<clang::tooling::CompilationInfo>>
4343 &CompileCmds,
44- std::string MigratedFileName, std::string CompileOptions,
45- std::string Compiler, std::string TargetName) {
46- clang::tooling::CompilationInfo CmpInfo;
47- CmpInfo.MigratedFileName = MigratedFileName;
48- CmpInfo.CompileOptions = CompileOptions;
49- CmpInfo.Compiler = Compiler;
44+ clang::tooling::CompilationInfo &CmpInfo, std::string TargetName) {
5045 CompileCmds[TargetName].push_back (CmpInfo);
5146}
5247
@@ -102,7 +97,7 @@ static void getCompileInfo(
10297 // Set the target name
10398 TargetName = Obj;
10499 IsTargetName = false ;
105- Tool = " $(CC) -o" ; // use 'icpx -fsycl' to link the target file in the
100+ Tool = " $(CC) -fsycl - o" ; // use 'icpx -fsycl' to link the target file in the
106101 // generated Makefile.
107102 } else if (llvm::StringRef (Obj).endswith (" .o" )) {
108103 llvm::SmallString<512 > FilePathAbs (Obj);
@@ -163,6 +158,18 @@ static void getCompileInfo(
163158 bool IsIncludeWithWhitespace = false ;
164159
165160 const std::string Directory = Entry.second [0 ];
161+
162+ llvm::SmallString<512 > RealPath;
163+ llvm::sys::fs::real_path (FileName, RealPath, true );
164+ if (!llvm::sys::path::is_absolute (FileName))
165+ RealPath = Directory + " /" + FileName;
166+ makeCanonical (RealPath);
167+ bool HasCudaSemantics = false ;
168+ if (IncludeFileMap.count (std::string (RealPath.str ())) &&
169+ IncludeFileMap.at (std::string (RealPath.str ()))) {
170+ HasCudaSemantics = true ;
171+ }
172+
166173 std::unordered_set<std::string> DuplicateDuplicateFilter;
167174 for (const auto &Option : Entry.second ) {
168175
@@ -250,19 +257,6 @@ static void getCompileInfo(
250257 auto Version = Option.substr (Idx, Option.length () - Idx);
251258 int Val = std::atoi (Version.c_str ());
252259
253- llvm::SmallString<512 > RealPath;
254- llvm::sys::fs::real_path (FileName, RealPath, true );
255- if (!llvm::sys::path::is_absolute (FileName))
256- RealPath = Directory + " /" + FileName;
257- makeCanonical (RealPath);
258-
259- bool HasCudaSemantics = false ;
260-
261- if (IncludeFileMap.count (std::string (RealPath.str ())) &&
262- IncludeFileMap.at (std::string (RealPath.str ()))) {
263- HasCudaSemantics = true ;
264- }
265-
266260 // SYCL support c++17 as default.
267261 if (HasCudaSemantics && Val <= 17 ) {
268262 NewOptions += " -std=c++17 " ;
@@ -308,7 +302,16 @@ static void getCompileInfo(
308302 // header files for migrated code, the path of the helper header files
309303 // should be included.
310304 if (llvm::sys::fs::exists (OutRoot.str () + " /include" )) {
311- NewOptions += " -I ./include " ;
305+ NewOptions += " -I ./include " ;
306+ }
307+
308+ // Add SYCL head file path to the including path in the generated Makefile
309+ // for source files which originally has CUDA Semantics and compiled by
310+ // non-nvcc compiler
311+ if (HasCudaSemantics &&
312+ !llvm::StringRef (Entry.second [1 ]).endswith (" nvcc" )) {
313+ NewOptions += " -I $(INCLUDE_SYCL) " ;
314+ NewOptions += " -I $(INCLUDE_CL) " ;
312315 }
313316
314317 SmallString<512 > OutDirectory = llvm::StringRef (FileName);
@@ -340,17 +343,15 @@ static void getCompileInfo(
340343 auto Iter = CmdsMap.find (Obj);
341344 if (Iter != CmdsMap.end ()) {
342345 auto CmpInfo = Iter->second ;
343- fillCompileCmds (CompileCmds, CmpInfo.MigratedFileName ,
344- CmpInfo.CompileOptions , CmpInfo.Compiler , Entry.first );
346+ fillCompileCmds (CompileCmds, CmpInfo, Entry.first );
345347 }
346348 }
347349 }
348350
349351 if (ObjsInLinkerCmdPerTarget.empty ()) {
350352 for (const auto &Cmd : CmdsMap) {
351- fillCompileCmds (CompileCmds, Cmd.second .MigratedFileName ,
352- Cmd.second .CompileOptions , Cmd.second .Compiler ,
353- EmptyTarget);
353+ auto CmpInfo = Cmd.second ;
354+ fillCompileCmds (CompileCmds, CmpInfo, EmptyTarget);
354355 }
355356 }
356357}
@@ -365,14 +366,22 @@ genMakefile(clang::tooling::RefactoringTool &Tool, StringRef OutRoot,
365366 llvm::raw_string_ostream OS (Buf);
366367 std::string TargetName;
367368
368- OS << " CC := icpx -fsycl \n\n " ;
369+ OS << " CC := icpx\n\n " ;
369370 OS << " LD := $(CC)\n\n " ;
370371 OS << buildString (
371372 " #" , DiagnosticsUtils::getMsgText (MakefileMsgs::GEN_MAKEFILE_LIB), " \n " );
372373 OS << " LIB := \n\n " ;
373374
374375 OS << buildString (" FLAGS := \n\n " );
375376
377+ OS << buildString (" ifeq ($(shell which $(CC)),)\n " );
378+ OS << buildString (" $(error ERROR - $(CC) compiler not found)\n " );
379+ OS << buildString (" endif\n\n " );
380+
381+ OS << buildString (" ROOT_DIR := $(shell dirname $(shell which $(CC)))\n " );
382+ OS << buildString (" INCLUDE_SYCL := $(ROOT_DIR)/../include\n " );
383+ OS << buildString (" INCLUDE_CL := $(ROOT_DIR)/../include/sycl\n\n " );
384+
376385 std::map<std::string, std::string> ObjsPerTarget;
377386
378387 int TargetIdx = 0 ;
@@ -473,7 +482,7 @@ genMakefile(clang::tooling::RefactoringTool &Tool, StringRef OutRoot,
473482 // Use 'icpx -fsycl' to compile the migrated SYCL file.
474483 std::string Compiler =
475484 llvm::StringRef ((Entry.second )[Idx].Compiler ).endswith (" nvcc" )
476- ? " $(CC)"
485+ ? " $(CC) -fsycl "
477486 : (Entry.second )[Idx].Compiler ;
478487
479488 OS << buildString (" \t " , Compiler, " -c ${" , SrcStrName, " } -o ${" ,
@@ -507,7 +516,7 @@ genMakefile(clang::tooling::RefactoringTool &Tool, StringRef OutRoot,
507516
508517 std::string Compiler =
509518 llvm::StringRef ((Entry.second )[Idx].Compiler ).endswith (" nvcc" )
510- ? " $(CC)"
519+ ? " $(CC) -fsycl "
511520 : (Entry.second )[Idx].Compiler ;
512521
513522 OS << buildString (" \t " , Compiler, " -c ${" , SrcStrName, " } -o ${" ,
0 commit comments