Skip to content

Commit d6cd3fc

Browse files
committed
Merge branch 'sycl' into devicelibTest
Signed-off-by: haonanya <[email protected]>
2 parents 0e84acf + 3baec18 commit d6cd3fc

35 files changed

+883
-278
lines changed

clang/include/clang/Basic/AttrDocs.td

+2-2
Original file line numberDiff line numberDiff line change
@@ -2117,8 +2117,8 @@ def SYCLDeviceIndirectlyCallableDocs : Documentation {
21172117
This attribute can only be applied to functions and indicates that the
21182118
function must be treated as a device function and must be emitted even if it has
21192119
no direct uses from other SYCL device functions. However, it cannot be applied
2120-
to functions marked as 'static', functions declared within an anonymous
2121-
namespace or class member functions.
2120+
to functions marked as 'static' and functions declared within an anonymous
2121+
namespace.
21222122

21232123
It also means that function should be available externally and
21242124
cannot be optimized out due to reachability analysis or by any other

clang/include/clang/Basic/DiagnosticSemaKinds.td

+1-2
Original file line numberDiff line numberDiff line change
@@ -10694,8 +10694,7 @@ def warn_boolean_attribute_argument_is_not_valid: Warning<
1069410694
InGroup<AdjustedAttributes>;
1069510695
def err_sycl_attibute_cannot_be_applied_here
1069610696
: Error<"%0 attribute cannot be applied to a "
10697-
"%select{static function or function in an anonymous namespace"
10698-
"|class member function}1">;
10697+
"static function or function in an anonymous namespace">;
1069910698
def warn_sycl_attibute_function_raw_ptr
1070010699
: Warning<"SYCL 1.2.1 specification does not allow %0 attribute applied "
1070110700
"to a function with a raw pointer "

clang/include/clang/Basic/LangOptions.def

+1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ LANGOPT(SYCLAllowFuncPtr , 1, 0, "Allow function pointers in SYCL device code")
237237
LANGOPT(SYCLStdLayoutKernelParams, 1, 0, "Enable standard layout requirement for SYCL kernel parameters")
238238
LANGOPT(SYCLUnnamedLambda , 1, 0, "Allow unnamed lambda SYCL kernels")
239239
LANGOPT(SYCLVersion , 32, 0, "Version of the SYCL standard used")
240+
LANGOPT(DeclareSPIRVBuiltins, 1, 0, "Declare SPIR-V builtin functions")
240241

241242
LANGOPT(HIPUseNewLaunchAPI, 1, 0, "Use new kernel launching API for HIP")
242243

clang/include/clang/Driver/CC1Options.td

+2
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,8 @@ def finclude_default_header : Flag<["-"], "finclude-default-header">,
807807
HelpText<"Include default header file for OpenCL">;
808808
def fdeclare_opencl_builtins : Flag<["-"], "fdeclare-opencl-builtins">,
809809
HelpText<"Add OpenCL builtin function declarations (experimental)">;
810+
def fdeclare_spirv_builtins : Flag<["-"], "fdeclare-spirv-builtins">,
811+
HelpText<"Add SPIR-V builtin function declarations (experimental)">;
810812
def fpreserve_vec3_type : Flag<["-"], "fpreserve-vec3-type">,
811813
HelpText<"Preserve 3-component vector type">;
812814
def fwchar_type_EQ : Joined<["-"], "fwchar-type=">,

clang/lib/AST/ASTContext.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -10156,6 +10156,10 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
1015610156
if (D->hasAttr<AliasAttr>() || D->hasAttr<UsedAttr>())
1015710157
return true;
1015810158

10159+
if (LangOpts.SYCLIsDevice && !D->hasAttr<OpenCLKernelAttr>() &&
10160+
!D->hasAttr<SYCLDeviceAttr>())
10161+
return false;
10162+
1015910163
if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
1016010164
// Forward declarations aren't required.
1016110165
if (!FD->doesThisDeclarationHaveABody())
@@ -10178,6 +10182,16 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
1017810182
}
1017910183
}
1018010184

10185+
// Methods explcitly marked with 'sycl_device' attribute (via SYCL_EXTERNAL)
10186+
// or `indirectly_callable' attribute must be emitted regardless of number
10187+
// of actual uses
10188+
if (LangOpts.SYCLIsDevice && isa<CXXMethodDecl>(D)) {
10189+
if (auto *A = D->getAttr<SYCLDeviceIndirectlyCallableAttr>())
10190+
return !A->isImplicit();
10191+
if (auto *A = D->getAttr<SYCLDeviceAttr>())
10192+
return !A->isImplicit();
10193+
}
10194+
1018110195
GVALinkage Linkage = GetGVALinkageForFunction(FD);
1018210196

1018310197
// static, static inline, always_inline, and extern inline functions can

clang/lib/CodeGen/CodeGenModule.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -2516,11 +2516,6 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
25162516
if (Global->hasAttr<IFuncAttr>())
25172517
return emitIFuncDefinition(GD);
25182518

2519-
if (LangOpts.SYCLIsDevice) {
2520-
if (!Global->hasAttr<SYCLDeviceAttr>())
2521-
return;
2522-
}
2523-
25242519
// If this is a cpu_dispatch multiversion function, emit the resolver.
25252520
if (Global->hasAttr<CPUDispatchAttr>())
25262521
return emitCPUDispatchDefinition(GD);
@@ -2565,6 +2560,11 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
25652560
}
25662561
}
25672562

2563+
if (LangOpts.SYCLIsDevice && MustBeEmitted(Global)) {
2564+
addDeferredDeclToEmit(GD);
2565+
return;
2566+
}
2567+
25682568
// Ignore declarations, they will be emitted on their first use.
25692569
if (const auto *FD = dyn_cast<FunctionDecl>(Global)) {
25702570
// Forward declarations are emitted lazily on first use.

clang/lib/Frontend/CompilerInvocation.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -2577,6 +2577,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
25772577

25782578
Opts.IncludeDefaultHeader = Args.hasArg(OPT_finclude_default_header);
25792579
Opts.DeclareOpenCLBuiltins = Args.hasArg(OPT_fdeclare_opencl_builtins);
2580+
Opts.DeclareSPIRVBuiltins = Args.hasArg(OPT_fdeclare_spirv_builtins);
25802581

25812582
llvm::Triple T(TargetOpts.Triple);
25822583
CompilerInvocation::setLangDefaults(Opts, IK, T, PPOpts, LangStd);

clang/lib/Sema/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ clang_tablegen(OpenCLBuiltins.inc -gen-clang-opencl-builtins
1717
TARGET ClangOpenCLBuiltinsImpl
1818
)
1919

20+
clang_tablegen(SPIRVBuiltins.inc -gen-clang-spirv-builtins
21+
SOURCE SPIRVBuiltins.td
22+
TARGET ClangSPIRVBuiltinsImpl
23+
)
24+
2025
add_clang_library(clangSema
2126
AnalysisBasedWarnings.cpp
2227
CodeCompleteConsumer.cpp
@@ -72,6 +77,7 @@ add_clang_library(clangSema
7277

7378
DEPENDS
7479
ClangOpenCLBuiltinsImpl
80+
ClangSPIRVBuiltinsImpl
7581

7682
LINK_LIBS
7783
clangAST

clang/lib/Sema/OpenCLBuiltins.td

+2
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ class Builtin<string _Name, list<Type> _Signature, list<bit> _Attributes = Attr.
234234
bit IsConst = _Attributes[1];
235235
// Function attribute __attribute__((convergent))
236236
bit IsConv = _Attributes[2];
237+
// Is function a variadic one
238+
bit IsVariadic = 0;
237239
// OpenCL extensions to which the function belongs.
238240
FunctionExtension Extension = FuncExtNone;
239241
// Version of OpenCL from which the function is available (e.g.: CL10).

0 commit comments

Comments
 (0)