Skip to content

Commit 2f2a758

Browse files
committed
Merge branch 'sycl' into chedy/fix-mipmap-leak
2 parents 4e31a5f + 28e8416 commit 2f2a758

File tree

1,962 files changed

+5832
-3636
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,962 files changed

+5832
-3636
lines changed

.github/workflows/sycl-nightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ jobs:
110110
image_options: ${{ matrix.image_options }}
111111
target_devices: ${{ matrix.target_devices }}
112112
tests_selector: ${{ matrix.tests_selector }}
113-
extra_lit_opts: ${{ matrix.extra_lit_opts }}
113+
extra_lit_opts: "--param 'cxx_flags=-D_GLIBCXX_USE_CXX11_ABI=0' ${{ matrix.extra_lit_opts }}"
114114
reset_intel_gpu: ${{ matrix.reset_intel_gpu }}
115115
ref: ${{ github.sha }}
116116
merge_ref: ''

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
@@ -4731,6 +4731,25 @@ def GetDeviceSideMangledName : LangBuiltin<"CUDA_LANG"> {
47314731
let Prototype = "char const*(...)";
47324732
}
47334733

4734+
// SYCL
4735+
def SYCLIsKernel : LangBuiltin<"SYCL_LANG"> {
4736+
let Spellings = ["__builtin_sycl_is_kernel"];
4737+
let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
4738+
let Prototype = "bool(...)";
4739+
}
4740+
4741+
def SYCLIsSingleTaskKernel : LangBuiltin<"SYCL_LANG"> {
4742+
let Spellings = ["__builtin_sycl_is_single_task_kernel"];
4743+
let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
4744+
let Prototype = "bool(...)";
4745+
}
4746+
4747+
def SYCLIsNDRangeKernel : LangBuiltin<"SYCL_LANG"> {
4748+
let Spellings = ["__builtin_sycl_is_nd_range_kernel"];
4749+
let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
4750+
let Prototype = "bool(...)";
4751+
}
4752+
47344753
// HLSL
47354754
def HLSLAll : LangBuiltin<"HLSL_LANG"> {
47364755
let Spellings = ["__builtin_hlsl_all"];

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>;
@@ -12397,7 +12400,11 @@ def err_builtin_invalid_arg_type: Error <
1239712400
"a vector of integers|"
1239812401
"an unsigned integer|"
1239912402
"an 'int'|"
12400-
"a vector of floating points}1 (was %2)">;
12403+
"a vector of floating points|"
12404+
"a function pointer}1 (was %2)">;
12405+
12406+
def err_builtin_invalid_arg_value: Error<
12407+
"%ordinal0 argument must be a strictly positive value (was %1)">;
1240112408

1240212409
def err_builtin_matrix_disabled: Error<
1240312410
"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
@@ -12729,6 +12729,45 @@ static bool getBuiltinAlignArguments(const CallExpr *E, EvalInfo &Info,
1272912729
return true;
1273012730
}
1273112731

12732+
static bool isSYCLFreeFunctionKernel(IntExprEvaluator &IEV,
12733+
const EvalInfo &Info, const CallExpr *E,
12734+
StringRef NameStr1, StringRef NameStr2,
12735+
bool CheckNDRangeKernelDim = false) {
12736+
const Expr *ArgExpr = E->getArg(0)->IgnoreParenImpCasts();
12737+
while (isa<CastExpr>(ArgExpr))
12738+
ArgExpr = cast<CastExpr>(ArgExpr)->getSubExpr();
12739+
auto *DRE = dyn_cast<DeclRefExpr>(ArgExpr);
12740+
if (DRE) {
12741+
const FunctionDecl *FD = dyn_cast<FunctionDecl>(DRE->getDecl());
12742+
if (FD) {
12743+
auto *SAIRAttr = FD->getAttr<SYCLAddIRAttributesFunctionAttr>();
12744+
if (!SAIRAttr)
12745+
return IEV.Success(false, E);
12746+
SmallVector<std::pair<std::string, std::string>, 4> NameValuePairs =
12747+
SAIRAttr->getFilteredAttributeNameValuePairs(Info.Ctx);
12748+
for (const auto &NVPair : NameValuePairs) {
12749+
if (!NVPair.first.compare(NameStr1) ||
12750+
(!NameStr2.empty() && !NVPair.first.compare(NameStr2))) {
12751+
if (CheckNDRangeKernelDim) {
12752+
uint64_t Dim =
12753+
E->getArg(1)->EvaluateKnownConstInt(Info.Ctx).getZExtValue();
12754+
// Return true only if the dimensions match.
12755+
if (std::stoul(NVPair.second) == Dim)
12756+
return IEV.Success(true, E);
12757+
else
12758+
return IEV.Success(false, E);
12759+
}
12760+
// Return true if it has the sycl-single-task-kernel or the
12761+
// sycl-nd-range-kernel attribute.
12762+
return IEV.Success(true, E);
12763+
}
12764+
}
12765+
return IEV.Success(false, E);
12766+
}
12767+
}
12768+
return false;
12769+
}
12770+
1273212771
bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
1273312772
unsigned BuiltinOp) {
1273412773
switch (BuiltinOp) {
@@ -13674,6 +13713,19 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
1367413713
Result.setBitVal(P++, Val[I]);
1367513714
return Success(Result, E);
1367613715
}
13716+
13717+
case Builtin::BI__builtin_sycl_is_kernel: {
13718+
return isSYCLFreeFunctionKernel(*this, Info, E, "sycl-single-task-kernel",
13719+
"sycl-nd-range-kernel");
13720+
}
13721+
case Builtin::BI__builtin_sycl_is_single_task_kernel: {
13722+
return isSYCLFreeFunctionKernel(*this, Info, E, "sycl-single-task-kernel",
13723+
"");
13724+
}
13725+
case Builtin::BI__builtin_sycl_is_nd_range_kernel: {
13726+
return isSYCLFreeFunctionKernel(*this, Info, E, "sycl-nd-range-kernel", "",
13727+
/*CheckNDRangeDim=*/true);
13728+
}
1367713729
}
1367813730
}
1367913731

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
@@ -2716,6 +2716,53 @@ static RValue EmitHipStdParUnsupportedBuiltin(CodeGenFunction *CGF,
27162716
return RValue::get(CGF->Builder.CreateCall(UBF, Args));
27172717
}
27182718

2719+
static RValue EmitSYCLFreeFunctionKernelBuiltin(CodeGenFunction &CGF,
2720+
const CallExpr *E,
2721+
StringRef NameStr1,
2722+
StringRef NameStr2,
2723+
bool CheckNDRangeDim = false) {
2724+
const Expr *ArgExpr = E->getArg(0)->IgnoreImpCasts();
2725+
auto *UO = dyn_cast<clang::UnaryOperator>(ArgExpr);
2726+
// If this is of the form &function or *function, get to the function
2727+
// sub-expression.
2728+
if (UO && (UO->getOpcode() == UO_AddrOf || UO->getOpcode() == UO_Deref))
2729+
ArgExpr = UO->getSubExpr()->IgnoreParenImpCasts();
2730+
while (isa<CastExpr>(ArgExpr))
2731+
ArgExpr = cast<CastExpr>(ArgExpr)->getSubExpr();
2732+
auto *DRE = dyn_cast<DeclRefExpr>(ArgExpr);
2733+
if (DRE) {
2734+
const FunctionDecl *FD = dyn_cast<FunctionDecl>(DRE->getDecl());
2735+
if (FD && FD->hasAttr<SYCLAddIRAttributesFunctionAttr>()) {
2736+
auto *SAIRAttr = FD->getAttr<SYCLAddIRAttributesFunctionAttr>();
2737+
SmallVector<std::pair<std::string, std::string>, 4> NameValuePairs =
2738+
SAIRAttr->getFilteredAttributeNameValuePairs(CGF.CGM.getContext());
2739+
for (const auto &NVPair : NameValuePairs) {
2740+
if (!NVPair.first.compare(NameStr1) ||
2741+
(!NameStr2.empty() && !!NVPair.first.compare(NameStr2))) {
2742+
if (CheckNDRangeDim) {
2743+
uint64_t Dim = E->getArg(1)
2744+
->EvaluateKnownConstInt(CGF.CGM.getContext())
2745+
.getZExtValue();
2746+
// Return true only if the dimensions match.
2747+
if (std::stoul(NVPair.second) == Dim)
2748+
return RValue::get(
2749+
llvm::ConstantInt::getTrue(CGF.ConvertType(E->getType())));
2750+
else
2751+
return RValue::get(
2752+
llvm::ConstantInt::getFalse(CGF.ConvertType(E->getType())));
2753+
}
2754+
// Return true if the kernel type matches.
2755+
return RValue::get(
2756+
llvm::ConstantInt::getTrue(CGF.ConvertType(E->getType())));
2757+
}
2758+
}
2759+
}
2760+
}
2761+
// Return false otherwise.
2762+
return RValue::get(
2763+
llvm::ConstantInt::getFalse(CGF.ConvertType(E->getType())));
2764+
}
2765+
27192766
RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
27202767
const CallExpr *E,
27212768
ReturnValueSlot ReturnValue) {
@@ -6363,6 +6410,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
63636410
auto Str = CGM.GetAddrOfConstantCString(Name, "");
63646411
return RValue::get(Str.getPointer());
63656412
}
6413+
case Builtin::BI__builtin_sycl_is_kernel: {
6414+
return EmitSYCLFreeFunctionKernelBuiltin(
6415+
*this, E, "sycl-single-task-kernel", "sycl-nd-range-kernel");
6416+
}
6417+
case Builtin::BI__builtin_sycl_is_single_task_kernel: {
6418+
return EmitSYCLFreeFunctionKernelBuiltin(*this, E,
6419+
"sycl-single-task-kernel", "");
6420+
}
6421+
case Builtin::BI__builtin_sycl_is_nd_range_kernel: {
6422+
return EmitSYCLFreeFunctionKernelBuiltin(*this, E, "sycl-nd-range-kernel",
6423+
"", /*CheckNDRangeDim=*/true);
6424+
}
63666425
}
63676426

63686427
// 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
@@ -3020,6 +3020,21 @@ namespace {
30203020
};
30213021
}
30223022

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

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

clang/lib/Driver/OffloadBundler.cpp

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

698698
// 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
@@ -1169,6 +1169,7 @@ void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
11691169
// SPIR/SPIRV sanitizer support is experimental and will pass a fixed set of
11701170
// flags
11711171
if (TC.getTriple().isSPIROrSPIRV()) {
1172+
#if !defined(_WIN32)
11721173
if (Sanitizers.has(SanitizerKind::Address)) {
11731174
CmdArgs.push_back("-fsanitize=address");
11741175
CmdArgs.push_back("-fsanitize-address-use-after-return=never");
@@ -1200,7 +1201,26 @@ void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
12001201

12011202
addSpecialCaseListOpt(Args, CmdArgs,
12021203
"-fsanitize-ignorelist=", UserIgnorelistFiles);
1204+
} else if (Sanitizers.has(SanitizerKind::Memory)) {
1205+
CmdArgs.push_back("-fsanitize=memory");
1206+
1207+
CmdArgs.push_back("-mllvm");
1208+
CmdArgs.push_back("-msan-instrumentation-with-call-threshold=0");
1209+
1210+
CmdArgs.push_back("-mllvm");
1211+
CmdArgs.push_back("-msan-eager-checks=1");
12031212
}
1213+
#else // _WIN32
1214+
std::string SanitizeArg;
1215+
if (Sanitizers.has(SanitizerKind::Address))
1216+
SanitizeArg = "-fsanitize=address";
1217+
else if (Sanitizers.has(SanitizerKind::Memory))
1218+
SanitizeArg = "-fsanitize=memory";
1219+
1220+
if (!SanitizeArg.empty())
1221+
TC.getDriver().Diag(diag::warn_drv_unsupported_option_for_target)
1222+
<< SanitizeArg << TC.getTripleString();
1223+
#endif
12041224
return;
12051225
}
12061226

0 commit comments

Comments
 (0)