clang 20.0.0git
SYCL.cpp
Go to the documentation of this file.
1//===--- SYCL.cpp - SYCL Tool and ToolChain Implementations -----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#include "SYCL.h"
9#include "CommonArgs.h"
10#include "llvm/Support/Path.h"
11
12using namespace clang::driver;
13using namespace clang::driver::toolchains;
14using namespace clang::driver::tools;
15using namespace clang;
16using namespace llvm::opt;
17
19 const Driver &D, const llvm::Triple &HostTriple,
20 const llvm::opt::ArgList &Args) {}
21
23 const ArgList &DriverArgs, ArgStringList &CC1Args) const {
24 if (DriverArgs.hasArg(clang::driver::options::OPT_nobuiltininc))
25 return;
26
27 // Add the SYCL header search locations in the specified order.
28 // FIXME: Add the header file locations once the SYCL library and headers
29 // are properly established within the build.
30}
31
32// Unsupported options for SYCL device compilation.
34 static constexpr options::ID UnsupportedOpts[] = {
35 options::OPT_fsanitize_EQ, // -fsanitize
36 options::OPT_fcf_protection_EQ, // -fcf-protection
37 options::OPT_fprofile_generate,
38 options::OPT_fprofile_generate_EQ,
39 options::OPT_fno_profile_generate, // -f[no-]profile-generate
40 options::OPT_ftest_coverage,
41 options::OPT_fno_test_coverage, // -f[no-]test-coverage
42 options::OPT_fcoverage_mapping,
43 options::OPT_fno_coverage_mapping, // -f[no-]coverage-mapping
44 options::OPT_coverage, // --coverage
45 options::OPT_fprofile_instr_generate,
46 options::OPT_fprofile_instr_generate_EQ,
47 options::OPT_fno_profile_instr_generate, // -f[no-]profile-instr-generate
48 options::OPT_fprofile_arcs,
49 options::OPT_fno_profile_arcs, // -f[no-]profile-arcs
50 options::OPT_fcreate_profile, // -fcreate-profile
51 options::OPT_fprofile_instr_use,
52 options::OPT_fprofile_instr_use_EQ, // -fprofile-instr-use
53 options::OPT_forder_file_instrumentation, // -forder-file-instrumentation
54 options::OPT_fcs_profile_generate, // -fcs-profile-generate
55 options::OPT_fcs_profile_generate_EQ,
56 };
57 return UnsupportedOpts;
58}
59
60SYCLToolChain::SYCLToolChain(const Driver &D, const llvm::Triple &Triple,
61 const ToolChain &HostTC, const ArgList &Args)
62 : ToolChain(D, Triple, Args), HostTC(HostTC),
63 SYCLInstallation(D, Triple, Args) {
64 // Lookup binaries into the driver directory, this is used to discover any
65 // dependent SYCL offload compilation tools.
66 getProgramPaths().push_back(getDriver().Dir);
67
68 // Diagnose unsupported options only once.
69 for (OptSpecifier Opt : getUnsupportedOpts()) {
70 if (const Arg *A = Args.getLastArg(Opt)) {
71 D.Diag(clang::diag::warn_drv_unsupported_option_for_target)
72 << A->getAsString(Args) << getTriple().str();
73 }
74 }
75}
76
78 const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
79 Action::OffloadKind DeviceOffloadingKind) const {
80 HostTC.addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind);
81}
82
83llvm::opt::DerivedArgList *
84SYCLToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
85 StringRef BoundArch,
86 Action::OffloadKind DeviceOffloadKind) const {
87 DerivedArgList *DAL =
88 HostTC.TranslateArgs(Args, BoundArch, DeviceOffloadKind);
89
90 bool IsNewDAL = false;
91 if (!DAL) {
92 DAL = new DerivedArgList(Args.getBaseArgs());
93 IsNewDAL = true;
94 }
95
96 for (Arg *A : Args) {
97 // Filter out any options we do not want to pass along to the device
98 // compilation.
99 auto Opt(A->getOption());
100 bool Unsupported = false;
101 for (OptSpecifier UnsupportedOpt : getUnsupportedOpts()) {
102 if (Opt.matches(UnsupportedOpt)) {
103 if (Opt.getID() == options::OPT_fsanitize_EQ &&
104 A->getValues().size() == 1) {
105 std::string SanitizeVal = A->getValue();
106 if (SanitizeVal == "address") {
107 if (IsNewDAL)
108 DAL->append(A);
109 continue;
110 }
111 }
112 if (!IsNewDAL)
113 DAL->eraseArg(Opt.getID());
114 Unsupported = true;
115 }
116 }
117 if (Unsupported)
118 continue;
119 if (IsNewDAL)
120 DAL->append(A);
121 }
122
123 const OptTable &Opts = getDriver().getOpts();
124 if (!BoundArch.empty()) {
125 DAL->eraseArg(options::OPT_march_EQ);
126 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
127 BoundArch);
128 }
129 return DAL;
130}
131
132void SYCLToolChain::addClangWarningOptions(ArgStringList &CC1Args) const {
133 HostTC.addClangWarningOptions(CC1Args);
134}
135
137SYCLToolChain::GetCXXStdlibType(const ArgList &Args) const {
138 return HostTC.GetCXXStdlibType(Args);
139}
140
141void SYCLToolChain::addSYCLIncludeArgs(const ArgList &DriverArgs,
142 ArgStringList &CC1Args) const {
143 SYCLInstallation.addSYCLIncludeArgs(DriverArgs, CC1Args);
144}
145
146void SYCLToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
147 ArgStringList &CC1Args) const {
148 HostTC.AddClangSystemIncludeArgs(DriverArgs, CC1Args);
149}
150
152 ArgStringList &CC1Args) const {
153 HostTC.AddClangCXXStdlibIncludeArgs(Args, CC1Args);
154}
const Decl * D
static ArrayRef< options::ID > getUnsupportedOpts()
Definition: SYCL.cpp:33
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:77
const llvm::opt::OptTable & getOpts() const
Definition: Driver.h:401
SYCLInstallationDetector(const Driver &D, const llvm::Triple &HostTriple, const llvm::opt::ArgList &Args)
Definition: SYCL.cpp:18
void addSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Definition: SYCL.cpp:22
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:92
virtual void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const
Add warning options that need to be passed to cc1 for this target.
Definition: ToolChain.cpp:1167
const Driver & getDriver() const
Definition: ToolChain.h:252
path_list & getProgramPaths()
Definition: ToolChain.h:297
virtual llvm::opt::DerivedArgList * TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch, Action::OffloadKind DeviceOffloadKind) const
TranslateArgs - Create a new derived argument list for any argument translations this ToolChain may w...
Definition: ToolChain.h:358
const llvm::Triple & getTriple() const
Definition: ToolChain.h:254
virtual void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set the include paths to use for...
Definition: ToolChain.cpp:1335
virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const
Definition: ToolChain.cpp:1239
virtual void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, Action::OffloadKind DeviceOffloadKind) const
Add options that need to be passed to cc1 for this target.
Definition: ToolChain.cpp:1160
virtual void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Add the clang cc1 arguments for system include paths.
Definition: ToolChain.cpp:1155
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, Action::OffloadKind DeviceOffloadKind) const override
Add options that need to be passed to cc1 for this target.
Definition: SYCL.cpp:77
void addSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add arguments to use system-specific SYCL includes.
Definition: SYCL.cpp:141
CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override
Definition: SYCL.cpp:137
void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CC1Args) const override
AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set the include paths to use for...
Definition: SYCL.cpp:151
void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add the clang cc1 arguments for system include paths.
Definition: SYCL.cpp:146
SYCLToolChain(const Driver &D, const llvm::Triple &Triple, const ToolChain &HostTC, const llvm::opt::ArgList &Args)
Definition: SYCL.cpp:60
llvm::opt::DerivedArgList * TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch, Action::OffloadKind DeviceOffloadKind) const override
TranslateArgs - Create a new derived argument list for any argument translations this ToolChain may w...
Definition: SYCL.cpp:84
void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override
Add warning options that need to be passed to cc1 for this target.
Definition: SYCL.cpp:132
The JSON file list parser is used to communicate input to InstallAPI.