Skip to content

Commit 47c14a5

Browse files
committed
Merge from 'sycl' to 'sycl-web' (29 commits)
CONFLICT (content): Merge conflict in clang/lib/Sema/SemaChecking.cpp
2 parents c6a016a + 960f71a commit 47c14a5

File tree

1,922 files changed

+5784
-3028
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,922 files changed

+5784
-3028
lines changed

clang/include/clang/Basic/Builtins.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ enum LanguageID : uint16_t {
4343
OCL_DSE = 0x400, // builtin requires OpenCL device side enqueue.
4444
ALL_OCL_LANGUAGES = 0x800, // builtin for OCL languages.
4545
HLSL_LANG = 0x1000, // builtin requires HLSL.
46+
SYCL_LANG = 0x2000, // builtin requires SYCL.
4647
ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.
4748
ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG, // builtin requires GNU mode.
4849
ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG // builtin requires MS mode.

clang/include/clang/Basic/Builtins.td

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4737,6 +4737,25 @@ def GetDeviceSideMangledName : LangBuiltin<"CUDA_LANG"> {
47374737
let Prototype = "char const*(...)";
47384738
}
47394739

4740+
// SYCL
4741+
def SYCLIsKernel : LangBuiltin<"SYCL_LANG"> {
4742+
let Spellings = ["__builtin_sycl_is_kernel"];
4743+
let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
4744+
let Prototype = "bool(...)";
4745+
}
4746+
4747+
def SYCLIsSingleTaskKernel : LangBuiltin<"SYCL_LANG"> {
4748+
let Spellings = ["__builtin_sycl_is_single_task_kernel"];
4749+
let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
4750+
let Prototype = "bool(...)";
4751+
}
4752+
4753+
def SYCLIsNDRangeKernel : LangBuiltin<"SYCL_LANG"> {
4754+
let Spellings = ["__builtin_sycl_is_nd_range_kernel"];
4755+
let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
4756+
let Prototype = "bool(...)";
4757+
}
4758+
47404759
// HLSL
47414760
def HLSLResourceGetPointer : LangBuiltin<"HLSL_LANG"> {
47424761
let Spellings = ["__builtin_hlsl_resource_getpointer"];

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,9 @@ def warn_unreachable_association : Warning<
827827
InGroup<UnreachableCodeGenericAssoc>;
828828

829829
/// Built-in functions.
830+
def err_builtin_invalid_argument_count : Error<
831+
"builtin %plural{0:takes no arguments|1:takes one argument|"
832+
":requires exactly %0 arguments}0">;
830833
def ext_implicit_lib_function_decl : ExtWarn<
831834
"implicitly declaring library function '%0' with type %1">,
832835
InGroup<ImplicitFunctionDeclare>;
@@ -12448,7 +12451,11 @@ def err_builtin_invalid_arg_type: Error <
1244812451
"a vector of integers|"
1244912452
"an unsigned integer|"
1245012453
"an 'int'|"
12451-
"a vector of floating points}1 (was %2)">;
12454+
"a vector of floating points|"
12455+
"a function pointer}1 (was %2)">;
12456+
12457+
def err_builtin_invalid_arg_value: Error<
12458+
"%ordinal0 argument must be a strictly positive value (was %1)">;
1245212459

1245312460
def err_builtin_matrix_disabled: Error<
1245412461
"matrix types extension is disabled. Pass -fenable-matrix to enable it">;

clang/lib/AST/ExprConstant.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12768,6 +12768,45 @@ static bool getBuiltinAlignArguments(const CallExpr *E, EvalInfo &Info,
1276812768
return true;
1276912769
}
1277012770

12771+
static bool isSYCLFreeFunctionKernel(IntExprEvaluator &IEV,
12772+
const EvalInfo &Info, const CallExpr *E,
12773+
StringRef NameStr1, StringRef NameStr2,
12774+
bool CheckNDRangeKernelDim = false) {
12775+
const Expr *ArgExpr = E->getArg(0)->IgnoreParenImpCasts();
12776+
while (isa<CastExpr>(ArgExpr))
12777+
ArgExpr = cast<CastExpr>(ArgExpr)->getSubExpr();
12778+
auto *DRE = dyn_cast<DeclRefExpr>(ArgExpr);
12779+
if (DRE) {
12780+
const FunctionDecl *FD = dyn_cast<FunctionDecl>(DRE->getDecl());
12781+
if (FD) {
12782+
auto *SAIRAttr = FD->getAttr<SYCLAddIRAttributesFunctionAttr>();
12783+
if (!SAIRAttr)
12784+
return IEV.Success(false, E);
12785+
SmallVector<std::pair<std::string, std::string>, 4> NameValuePairs =
12786+
SAIRAttr->getFilteredAttributeNameValuePairs(Info.Ctx);
12787+
for (const auto &NVPair : NameValuePairs) {
12788+
if (!NVPair.first.compare(NameStr1) ||
12789+
(!NameStr2.empty() && !NVPair.first.compare(NameStr2))) {
12790+
if (CheckNDRangeKernelDim) {
12791+
uint64_t Dim =
12792+
E->getArg(1)->EvaluateKnownConstInt(Info.Ctx).getZExtValue();
12793+
// Return true only if the dimensions match.
12794+
if (std::stoul(NVPair.second) == Dim)
12795+
return IEV.Success(true, E);
12796+
else
12797+
return IEV.Success(false, E);
12798+
}
12799+
// Return true if it has the sycl-single-task-kernel or the
12800+
// sycl-nd-range-kernel attribute.
12801+
return IEV.Success(true, E);
12802+
}
12803+
}
12804+
return IEV.Success(false, E);
12805+
}
12806+
}
12807+
return false;
12808+
}
12809+
1277112810
bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
1277212811
unsigned BuiltinOp) {
1277312812
switch (BuiltinOp) {
@@ -13762,6 +13801,19 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
1376213801
Result.setBitVal(P++, Val[I]);
1376313802
return Success(Result, E);
1376413803
}
13804+
13805+
case Builtin::BI__builtin_sycl_is_kernel: {
13806+
return isSYCLFreeFunctionKernel(*this, Info, E, "sycl-single-task-kernel",
13807+
"sycl-nd-range-kernel");
13808+
}
13809+
case Builtin::BI__builtin_sycl_is_single_task_kernel: {
13810+
return isSYCLFreeFunctionKernel(*this, Info, E, "sycl-single-task-kernel",
13811+
"");
13812+
}
13813+
case Builtin::BI__builtin_sycl_is_nd_range_kernel: {
13814+
return isSYCLFreeFunctionKernel(*this, Info, E, "sycl-nd-range-kernel", "",
13815+
/*CheckNDRangeDim=*/true);
13816+
}
1376513817
}
1376613818
}
1376713819

clang/lib/Basic/Builtins.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ static bool builtinIsSupported(const Builtin::Info &BuiltinInfo,
119119
/* CUDA Unsupported */
120120
if (!LangOpts.CUDA && BuiltinInfo.Langs == CUDA_LANG)
121121
return false;
122+
/* SYCL Unsupported */
123+
if (!LangOpts.isSYCL() && BuiltinInfo.Langs == SYCL_LANG)
124+
return false;
122125
/* CPlusPlus Unsupported */
123126
if (!LangOpts.CPlusPlus && BuiltinInfo.Langs == CXX_LANG)
124127
return false;

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2842,6 +2842,53 @@ static RValue EmitHipStdParUnsupportedBuiltin(CodeGenFunction *CGF,
28422842
return RValue::get(CGF->Builder.CreateCall(UBF, Args));
28432843
}
28442844

2845+
static RValue EmitSYCLFreeFunctionKernelBuiltin(CodeGenFunction &CGF,
2846+
const CallExpr *E,
2847+
StringRef NameStr1,
2848+
StringRef NameStr2,
2849+
bool CheckNDRangeDim = false) {
2850+
const Expr *ArgExpr = E->getArg(0)->IgnoreImpCasts();
2851+
auto *UO = dyn_cast<clang::UnaryOperator>(ArgExpr);
2852+
// If this is of the form &function or *function, get to the function
2853+
// sub-expression.
2854+
if (UO && (UO->getOpcode() == UO_AddrOf || UO->getOpcode() == UO_Deref))
2855+
ArgExpr = UO->getSubExpr()->IgnoreParenImpCasts();
2856+
while (isa<CastExpr>(ArgExpr))
2857+
ArgExpr = cast<CastExpr>(ArgExpr)->getSubExpr();
2858+
auto *DRE = dyn_cast<DeclRefExpr>(ArgExpr);
2859+
if (DRE) {
2860+
const FunctionDecl *FD = dyn_cast<FunctionDecl>(DRE->getDecl());
2861+
if (FD && FD->hasAttr<SYCLAddIRAttributesFunctionAttr>()) {
2862+
auto *SAIRAttr = FD->getAttr<SYCLAddIRAttributesFunctionAttr>();
2863+
SmallVector<std::pair<std::string, std::string>, 4> NameValuePairs =
2864+
SAIRAttr->getFilteredAttributeNameValuePairs(CGF.CGM.getContext());
2865+
for (const auto &NVPair : NameValuePairs) {
2866+
if (!NVPair.first.compare(NameStr1) ||
2867+
(!NameStr2.empty() && !!NVPair.first.compare(NameStr2))) {
2868+
if (CheckNDRangeDim) {
2869+
uint64_t Dim = E->getArg(1)
2870+
->EvaluateKnownConstInt(CGF.CGM.getContext())
2871+
.getZExtValue();
2872+
// Return true only if the dimensions match.
2873+
if (std::stoul(NVPair.second) == Dim)
2874+
return RValue::get(
2875+
llvm::ConstantInt::getTrue(CGF.ConvertType(E->getType())));
2876+
else
2877+
return RValue::get(
2878+
llvm::ConstantInt::getFalse(CGF.ConvertType(E->getType())));
2879+
}
2880+
// Return true if the kernel type matches.
2881+
return RValue::get(
2882+
llvm::ConstantInt::getTrue(CGF.ConvertType(E->getType())));
2883+
}
2884+
}
2885+
}
2886+
}
2887+
// Return false otherwise.
2888+
return RValue::get(
2889+
llvm::ConstantInt::getFalse(CGF.ConvertType(E->getType())));
2890+
}
2891+
28452892
RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
28462893
const CallExpr *E,
28472894
ReturnValueSlot ReturnValue) {
@@ -6632,6 +6679,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
66326679
auto Str = CGM.GetAddrOfConstantCString(Name, "");
66336680
return RValue::get(Str.getPointer());
66346681
}
6682+
case Builtin::BI__builtin_sycl_is_kernel: {
6683+
return EmitSYCLFreeFunctionKernelBuiltin(
6684+
*this, E, "sycl-single-task-kernel", "sycl-nd-range-kernel");
6685+
}
6686+
case Builtin::BI__builtin_sycl_is_single_task_kernel: {
6687+
return EmitSYCLFreeFunctionKernelBuiltin(*this, E,
6688+
"sycl-single-task-kernel", "");
6689+
}
6690+
case Builtin::BI__builtin_sycl_is_nd_range_kernel: {
6691+
return EmitSYCLFreeFunctionKernelBuiltin(*this, E, "sycl-nd-range-kernel",
6692+
"", /*CheckNDRangeDim=*/true);
6693+
}
66356694
}
66366695

66376696
// If this is an alias for a lib function (e.g. __builtin_sin), emit

clang/lib/CodeGen/CGCall.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,6 +3019,21 @@ namespace {
30193019
};
30203020
}
30213021

3022+
static bool hasSYCLRestrictPropertyIRAttr(const VarDecl *Arg,
3023+
const ASTContext &Context) {
3024+
auto *IRAttr = Arg->getAttr<SYCLAddIRAttributesKernelParameterAttr>();
3025+
if (!IRAttr)
3026+
return false;
3027+
3028+
SmallVector<std::pair<std::string, std::string>, 4> NameValuePairs =
3029+
IRAttr->getAttributeNameValuePairs(Context);
3030+
return std::any_of(
3031+
NameValuePairs.begin(), NameValuePairs.end(),
3032+
[](const std::pair<std::string, std::string> &NameValuePair) {
3033+
return NameValuePair.first == "sycl-restrict";
3034+
});
3035+
}
3036+
30223037
void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
30233038
llvm::Function *Fn,
30243039
const FunctionArgList &Args) {
@@ -3243,9 +3258,10 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
32433258

32443259
// Set 'noalias' if an argument type has the `restrict` qualifier.
32453260
if (Arg->getType().isRestrictQualified() ||
3246-
(CurCodeDecl &&
3247-
CurCodeDecl->hasAttr<SYCLIntelKernelArgsRestrictAttr>() &&
3248-
Arg->getType()->isPointerType()) ||
3261+
(Arg->getType()->isPointerType() &&
3262+
((CurCodeDecl &&
3263+
CurCodeDecl->hasAttr<SYCLIntelKernelArgsRestrictAttr>()) ||
3264+
hasSYCLRestrictPropertyIRAttr(Arg, getContext()))) ||
32493265
(Arg->hasAttr<RestrictAttr>() && Arg->getType()->isPointerType()))
32503266
AI->addAttr(llvm::Attribute::NoAlias);
32513267
}

clang/lib/Driver/OffloadBundler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ class ObjectFileHandler final : public FileHandler {
691691
if (SF->isIR() &&
692692
(Name == "llvm.used" || Name == "llvm.compiler.used" ||
693693
Name == "__AsanDeviceGlobalMetadata" ||
694-
Name == "__AsanKernelMetadata"))
694+
Name == "__AsanKernelMetadata" || Name == "__MsanKernelMetadata"))
695695
continue;
696696

697697
// Add symbol name with the target prefix to the buffer.

clang/lib/Driver/SanitizerArgs.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,7 @@ void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
11661166
// SPIR/SPIRV sanitizer support is experimental and will pass a fixed set of
11671167
// flags
11681168
if (TC.getTriple().isSPIROrSPIRV()) {
1169+
#if !defined(_WIN32)
11691170
if (Sanitizers.has(SanitizerKind::Address)) {
11701171
CmdArgs.push_back("-fsanitize=address");
11711172
CmdArgs.push_back("-fsanitize-address-use-after-return=never");
@@ -1197,7 +1198,26 @@ void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
11971198

11981199
addSpecialCaseListOpt(Args, CmdArgs,
11991200
"-fsanitize-ignorelist=", UserIgnorelistFiles);
1201+
} else if (Sanitizers.has(SanitizerKind::Memory)) {
1202+
CmdArgs.push_back("-fsanitize=memory");
1203+
1204+
CmdArgs.push_back("-mllvm");
1205+
CmdArgs.push_back("-msan-instrumentation-with-call-threshold=0");
1206+
1207+
CmdArgs.push_back("-mllvm");
1208+
CmdArgs.push_back("-msan-eager-checks=1");
12001209
}
1210+
#else // _WIN32
1211+
std::string SanitizeArg;
1212+
if (Sanitizers.has(SanitizerKind::Address))
1213+
SanitizeArg = "-fsanitize=address";
1214+
else if (Sanitizers.has(SanitizerKind::Memory))
1215+
SanitizeArg = "-fsanitize=memory";
1216+
1217+
if (!SanitizeArg.empty())
1218+
TC.getDriver().Diag(diag::warn_drv_unsupported_option_for_target)
1219+
<< SanitizeArg << TC.getTripleString();
1220+
#endif
12011221
return;
12021222
}
12031223

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8604,7 +8604,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
86048604
}
86058605
}
86068606

8607-
if (IsCuda) {
8607+
// Propagate -fcuda-short-ptr if compiling CUDA or SYCL for NVPTX
8608+
if (IsCuda || (IsSYCLDevice && Triple.isNVPTX())) {
86088609
if (Args.hasFlag(options::OPT_fcuda_short_ptr,
86098610
options::OPT_fno_cuda_short_ptr, false))
86108611
CmdArgs.push_back("-fcuda-short-ptr");

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
555555
{"libsycl-asan-cpu", "internal"},
556556
{"libsycl-asan-dg2", "internal"},
557557
{"libsycl-asan-pvc", "internal"}};
558+
const SYCLDeviceLibsList SYCLDeviceMsanLibs = {{"libsycl-msan", "internal"}};
558559
#endif
559560

560561
const SYCLDeviceLibsList SYCLNativeCpuDeviceLibs = {
@@ -670,12 +671,15 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
670671
};
671672

672673
std::string SanitizeVal;
674+
std::string SanitizeArg;
673675
size_t sanitizer_lib_idx = getSingleBuildTarget();
674676
if (Arg *A = Args.getLastArg(options::OPT_fsanitize_EQ,
675677
options::OPT_fno_sanitize_EQ)) {
676678
if (A->getOption().matches(options::OPT_fsanitize_EQ) &&
677-
A->getValues().size() == 1)
679+
A->getValues().size() == 1) {
678680
SanitizeVal = A->getValue();
681+
SanitizeArg = A->getAsString(Args);
682+
}
679683
} else {
680684
// User can pass -fsanitize=address to device compiler via
681685
// -Xsycl-target-frontend, sanitize device library must be
@@ -699,14 +703,21 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
699703
for (const std::string &Arg : ArgVals) {
700704
if (Arg.find("-fsanitize=address") != std::string::npos) {
701705
SanitizeVal = "address";
706+
SanitizeArg = Arg;
707+
break;
708+
}
709+
if (Arg.find("-fsanitize=memory") != std::string::npos) {
710+
SanitizeVal = "memory";
711+
SanitizeArg = Arg;
702712
break;
703713
}
704714
}
705715
}
706716

707717
if (SanitizeVal == "address")
708718
addSingleLibrary(SYCLDeviceAsanLibs[sanitizer_lib_idx]);
709-
719+
else if (SanitizeVal == "memory")
720+
addLibraries(SYCLDeviceMsanLibs);
710721
#endif
711722

712723
if (isNativeCPU)
@@ -826,6 +837,7 @@ static llvm::SmallVector<StringRef, 16> SYCLDeviceLibList{
826837
"asan-pvc",
827838
"asan-cpu",
828839
"asan-dg2",
840+
"msan",
829841
#endif
830842
"imf",
831843
"imf-fp64",
@@ -1408,6 +1420,8 @@ StringRef SYCL::gen::resolveGenDevice(StringRef DeviceName) {
14081420
.Cases("intel_gpu_arl_h", "intel_gpu_12_74_4", "arl_h")
14091421
.Cases("intel_gpu_bmg_g21", "intel_gpu_20_1_4", "bmg_g21")
14101422
.Cases("intel_gpu_lnl_m", "intel_gpu_20_4_4", "lnl_m")
1423+
.Cases("intel_gpu_ptl_h", "intel_gpu_30_0_4", "ptl_h")
1424+
.Cases("intel_gpu_ptl_u", "intel_gpu_30_1_1", "ptl_u")
14111425
.Case("nvidia_gpu_sm_50", "sm_50")
14121426
.Case("nvidia_gpu_sm_52", "sm_52")
14131427
.Case("nvidia_gpu_sm_53", "sm_53")
@@ -1498,6 +1512,8 @@ SmallString<64> SYCL::gen::getGenDeviceMacro(StringRef DeviceName) {
14981512
.Case("arl_h", "INTEL_GPU_ARL_H")
14991513
.Case("bmg_g21", "INTEL_GPU_BMG_G21")
15001514
.Case("lnl_m", "INTEL_GPU_LNL_M")
1515+
.Case("ptl_h", "INTEL_GPU_PTL_H")
1516+
.Case("ptl_u", "INTEL_GPU_PTL_U")
15011517
.Case("sm_50", "NVIDIA_GPU_SM_50")
15021518
.Case("sm_52", "NVIDIA_GPU_SM_52")
15031519
.Case("sm_53", "NVIDIA_GPU_SM_53")
@@ -1661,11 +1677,11 @@ SYCLToolChain::SYCLToolChain(const Driver &D, const llvm::Triple &Triple,
16611677
if (SupportedByNativeCPU(*this, Opt))
16621678
continue;
16631679
// All sanitizer options are not currently supported, except
1664-
// AddressSanitizer
1680+
// AddressSanitizer and MemorySanitizer
16651681
if (A->getOption().getID() == options::OPT_fsanitize_EQ &&
16661682
A->getValues().size() == 1) {
16671683
std::string SanitizeVal = A->getValue();
1668-
if (SanitizeVal == "address")
1684+
if (SanitizeVal == "address" || SanitizeVal == "memory")
16691685
continue;
16701686
}
16711687
D.Diag(clang::diag::warn_drv_unsupported_option_for_target)
@@ -1706,7 +1722,7 @@ SYCLToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
17061722
if (Opt.getID() == options::OPT_fsanitize_EQ &&
17071723
A->getValues().size() == 1) {
17081724
std::string SanitizeVal = A->getValue();
1709-
if (SanitizeVal == "address") {
1725+
if (SanitizeVal == "address" || SanitizeVal == "memory") {
17101726
if (IsNewDAL)
17111727
DAL->append(A);
17121728
continue;
@@ -2115,5 +2131,5 @@ void SYCLToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &Args,
21152131
}
21162132

21172133
SanitizerMask SYCLToolChain::getSupportedSanitizers() const {
2118-
return SanitizerKind::Address;
2134+
return SanitizerKind::Address | SanitizerKind::Memory;
21192135
}

0 commit comments

Comments
 (0)