@@ -3412,6 +3412,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
34123412 InputInfoList ModuleHeaderInputs;
34133413 const InputInfo *CudaDeviceInput = nullptr ;
34143414 const InputInfo *OpenMPDeviceInput = nullptr ;
3415+ const InputInfo *SYCLDeviceInput = nullptr ;
34153416 for (const InputInfo &I : Inputs) {
34163417 if (&I == &Input) {
34173418 // This is the primary input.
@@ -3428,6 +3429,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
34283429 CudaDeviceInput = &I;
34293430 } else if (IsOpenMPDevice && !OpenMPDeviceInput) {
34303431 OpenMPDeviceInput = &I;
3432+ } else if (IsSYCL && !SYCLDeviceInput) {
3433+ SYCLDeviceInput = &I;
34313434 } else {
34323435 llvm_unreachable (" unexpectedly given multiple inputs" );
34333436 }
@@ -3544,8 +3547,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
35443547 } else if (isa<AssembleJobAction>(JA)) {
35453548 if (IsSYCLOffloadDevice && IsSYCLDevice) {
35463549 CmdArgs.push_back (" -emit-spirv" );
3547- }
3548- else {
3550+ } else {
35493551 CmdArgs.push_back (" -emit-obj" );
35503552 CollectArgsForIntegratedAssembler (C, Args, CmdArgs, D);
35513553 }
@@ -5221,11 +5223,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
52215223 }
52225224
52235225 if (IsSYCL) {
5224- // Host-side SYCL compilation receives the integrated header file as
5226+ // Host-side SYCL compilation receives the integration header file as
52255227 // Inputs[1]. Include the header with -include
5226- if (!IsSYCLOffloadDevice && Inputs. size () > 1 ) {
5228+ if (!IsSYCLOffloadDevice && SYCLDeviceInput ) {
52275229 CmdArgs.push_back (" -include" );
5228- CmdArgs.push_back (Inputs[ 1 ]. getFilename ());
5230+ CmdArgs.push_back (SYCLDeviceInput-> getFilename ());
52295231 }
52305232 if (IsSYCLOffloadDevice && JA.getType () == types::TY_SYCL_Header) {
52315233 // Generating a SYCL Header
@@ -6254,3 +6256,66 @@ void OffloadBundler::ConstructJobMultipleOutputs(
62546256 TCArgs.MakeArgString (getToolChain ().GetProgramPath (getShortName ())),
62556257 CmdArgs, None));
62566258}
6259+
6260+ // Begin OffloadWrapper
6261+
6262+ void OffloadWrapper::ConstructJob (Compilation &C, const JobAction &JA,
6263+ const InputInfo &Output,
6264+ const InputInfoList &Inputs,
6265+ const llvm::opt::ArgList &TCArgs,
6266+ const char *LinkingOutput) const {
6267+ // Construct offload-wrapper command. Also calls llc to generate the
6268+ // object that is fed to the linker from the wrapper generated bc file
6269+ assert (isa<OffloadWrappingJobAction>(JA) && " Expecting wrapping job!" );
6270+
6271+ // The wrapper command looks like this:
6272+ // clang-offload-wrapper
6273+ // -o=<outputfile>.bc
6274+ // -target=sycl-x86_64-pc-linux-gnu <inputfile(s)>.spv
6275+ ArgStringList WrapperArgs;
6276+
6277+ std::string OutTmpName = C.getDriver ().GetTemporaryPath (" wrapper" , " bc" );
6278+ const char * WrapperFileName =
6279+ C.addTempFile (C.getArgs ().MakeArgString (OutTmpName));
6280+ SmallString<128 > OutOpt (" -o=" );
6281+ OutOpt += WrapperFileName;
6282+ WrapperArgs.push_back (C.getArgs ().MakeArgString (OutOpt));
6283+ for (auto I : Inputs) {
6284+ WrapperArgs.push_back (I.getFilename ());
6285+ }
6286+
6287+ SmallString<128 > TargetOpt (" -target=" );
6288+ TargetOpt += Action::GetOffloadKindName (JA.getOffloadingDeviceKind ());
6289+ TargetOpt += ' -' ;
6290+ TargetOpt += getToolChain ().getAuxTriple ()->str ();
6291+ WrapperArgs.push_back (C.getArgs ().MakeArgString (TargetOpt));
6292+
6293+ // For SYCL, do not emit entry tables
6294+ if (JA.isOffloading (Action::OFK_SYCL))
6295+ WrapperArgs.push_back (" -emit-entry-table=0" );
6296+
6297+ C.addCommand (llvm::make_unique<Command>(JA, *this ,
6298+ TCArgs.MakeArgString (getToolChain ().GetProgramPath (getShortName ())),
6299+ WrapperArgs, None));
6300+
6301+ // Construct llc command.
6302+ // The output is an object file
6303+ ArgStringList LlcArgs{" -filetype=obj" , " -o" , Output.getFilename (),
6304+ WrapperFileName};
6305+ llvm::Reloc::Model RelocationModel;
6306+ unsigned PICLevel;
6307+ bool IsPIE;
6308+ std::tie (RelocationModel, PICLevel, IsPIE) =
6309+ ParsePICArgs (getToolChain (), TCArgs);
6310+ if (PICLevel > 0 ) {
6311+ LlcArgs.push_back (" -relocation-model=pic" );
6312+ }
6313+ if (IsPIE) {
6314+ LlcArgs.push_back (" -enable-pie" );
6315+ }
6316+ SmallString<128 > LlcPath (C.getDriver ().Dir );
6317+ llvm::sys::path::append (LlcPath, " llc" );
6318+ const char *Llc = C.getArgs ().MakeArgString (LlcPath);
6319+ C.addCommand (llvm::make_unique<Command>(JA, *this , Llc, LlcArgs, None));
6320+ }
6321+
0 commit comments