Skip to content

Commit 7feb6ce

Browse files
author
Sergey Kanaev
committed
Merge branch 'sycl' into private/s-kanaev/kp-cache
2 parents d141bef + 81deb7c commit 7feb6ce

30 files changed

+451
-308
lines changed

.github/workflows/gh_pages.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
jobs:
88
build:
99
runs-on: ubuntu-latest
10+
if: github.repository == 'intel/llvm'
1011
steps:
1112
- uses: actions/checkout@v2
1213
with:

clang/include/clang/Basic/Attr.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ def SYCLIntelKernelArgsRestrict : InheritableAttr {
12091209

12101210
def SYCLIntelNumSimdWorkItems : InheritableAttr {
12111211
let Spellings = [CXX11<"intelfpga","num_simd_work_items">];
1212-
let Args = [UnsignedArgument<"Number">];
1212+
let Args = [ExprArgument<"Value">];
12131213
let LangOpts = [SYCLIsDevice, SYCLIsHost];
12141214
let Subjects = SubjectList<[Function], ErrorDiag>;
12151215
let Documentation = [SYCLIntelNumSimdWorkItemsAttrDocs];
@@ -1300,7 +1300,7 @@ def LoopUnrollHint : InheritableAttr {
13001300
def IntelReqdSubGroupSize: InheritableAttr {
13011301
let Spellings = [GNU<"intel_reqd_sub_group_size">,
13021302
CXX11<"intel", "reqd_sub_group_size">];
1303-
let Args = [ExprArgument<"SubGroupSize">];
1303+
let Args = [ExprArgument<"Value">];
13041304
let Subjects = SubjectList<[Function, CXXMethod], ErrorDiag>;
13051305
let Documentation = [IntelReqdSubGroupSizeDocs];
13061306
let LangOpts = [OpenCL, SYCLIsDevice, SYCLIsHost];

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def err_drv_expecting_fopenmp_with_fopenmp_targets : Error<
274274
def err_drv_expecting_fsycl_with_sycl_opt : Error<
275275
"The option %0 must be used in conjunction with -fsycl to enable offloading.">;
276276
def err_drv_fsycl_with_c_type : Error<
277-
"The option %0%1 must not be used in conjunction with -fsycl which expects C++ source.">;
277+
"The option '%0' must not be used in conjunction with '-fsycl', which expects C++ source.">;
278278
def warn_drv_omp_offload_target_duplicate : Warning<
279279
"The OpenMP offloading target '%0' is similar to target '%1' already specified - will be ignored.">,
280280
InGroup<OpenMPTarget>;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11004,8 +11004,8 @@ def err_sycl_restrict : Error<
1100411004
"nor constant-initialized"
1100511005
"}0">;
1100611006
def warn_sycl_kernel_too_big_args : Warning<
11007-
"size of kernel arguments (%0 bytes) exceeds supported maximum of %1 bytes "
11008-
"on GPU">, InGroup<SyclStrict>;
11007+
"size of kernel arguments (%0 bytes) may exceed the supported maximum "
11008+
"of %1 bytes on some devices">, InGroup<SyclStrict>;
1100911009
def err_sycl_virtual_types : Error<
1101011010
"No class with a vtable can be used in a SYCL kernel or any code included in the kernel">;
1101111011
def note_sycl_recursive_function_declared_here: Note<"function implemented using recursion declared here">;

clang/include/clang/Sema/Sema.h

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9986,7 +9986,9 @@ class Sema final {
99869986
Expr *E);
99879987
void AddIntelFPGABankBitsAttr(Decl *D, const AttributeCommonInfo &CI,
99889988
Expr **Exprs, unsigned Size);
9989-
9989+
template <typename AttrType>
9990+
void addIntelSYCLSingleArgFunctionAttr(Decl *D, const AttributeCommonInfo &CI,
9991+
Expr *E);
99909992
/// AddAlignedAttr - Adds an aligned attribute to a particular declaration.
99919993
void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E,
99929994
bool IsPackExpansion);
@@ -10041,10 +10043,6 @@ class Sema final {
1004110043
bool checkAllowedSYCLInitializer(VarDecl *VD,
1004210044
bool CheckValueDependent = false);
1004310045

10044-
// Adds an intel_reqd_sub_group_size attribute to a particular declaration.
10045-
void addIntelReqdSubGroupSizeAttr(Decl *D, const AttributeCommonInfo &CI,
10046-
Expr *E);
10047-
1004810046
//===--------------------------------------------------------------------===//
1004910047
// C++ Coroutines TS
1005010048
//
@@ -12836,6 +12834,31 @@ class Sema final {
1283612834
}
1283712835
};
1283812836

12837+
template <typename AttrType>
12838+
void Sema::addIntelSYCLSingleArgFunctionAttr(Decl *D,
12839+
const AttributeCommonInfo &CI,
12840+
Expr *E) {
12841+
assert(E && "Attribute must have an argument.");
12842+
12843+
if (!E->isInstantiationDependent()) {
12844+
Optional<llvm::APSInt> ArgVal = E->getIntegerConstantExpr(getASTContext());
12845+
if (!ArgVal) {
12846+
Diag(E->getExprLoc(), diag::err_attribute_argument_type)
12847+
<< CI.getAttrName() << AANT_ArgumentIntegerConstant
12848+
<< E->getSourceRange();
12849+
return;
12850+
}
12851+
int32_t ArgInt = ArgVal->getSExtValue();
12852+
if (ArgInt <= 0) {
12853+
Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer)
12854+
<< CI.getAttrName() << /*positive*/ 0;
12855+
return;
12856+
}
12857+
}
12858+
12859+
D->addAttr(::new (Context) AttrType(Context, CI, E));
12860+
}
12861+
1283912862
template <typename AttrType>
1284012863
void Sema::AddOneConstantValueAttr(Decl *D, const AttributeCommonInfo &CI,
1284112864
Expr *E) {

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD,
611611
FD->getAttr<IntelReqdSubGroupSizeAttr>()) {
612612
llvm::LLVMContext &Context = getLLVMContext();
613613
Optional<llvm::APSInt> ArgVal =
614-
A->getSubGroupSize()->getIntegerConstantExpr(FD->getASTContext());
614+
A->getValue()->getIntegerConstantExpr(FD->getASTContext());
615615
assert(ArgVal.hasValue() && "Not an integer constant expression");
616616
llvm::Metadata *AttrMDArgs[] = {llvm::ConstantAsMetadata::get(
617617
Builder.getInt32(ArgVal->getSExtValue()))};
@@ -629,8 +629,12 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD,
629629

630630
if (const SYCLIntelNumSimdWorkItemsAttr *A =
631631
FD->getAttr<SYCLIntelNumSimdWorkItemsAttr>()) {
632-
llvm::Metadata *AttrMDArgs[] = {
633-
llvm::ConstantAsMetadata::get(Builder.getInt32(A->getNumber()))};
632+
llvm::LLVMContext &Context = getLLVMContext();
633+
Optional<llvm::APSInt> ArgVal =
634+
A->getValue()->getIntegerConstantExpr(FD->getASTContext());
635+
assert(ArgVal.hasValue() && "Not an integer constant expression");
636+
llvm::Metadata *AttrMDArgs[] = {llvm::ConstantAsMetadata::get(
637+
Builder.getInt32(ArgVal->getSExtValue()))};
634638
Fn->setMetadata("num_simd_work_items",
635639
llvm::MDNode::get(Context, AttrMDArgs));
636640
}

clang/lib/Driver/Driver.cpp

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -810,14 +810,6 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
810810
return SYCLArg;
811811
};
812812

813-
// Emit an error if c-compilation is forced in -fsycl mode
814-
if (HasValidSYCLRuntime)
815-
for (StringRef XValue : C.getInputArgs().getAllArgValues(options::OPT_x)) {
816-
if (XValue == "c" || XValue == "c-header")
817-
C.getDriver().Diag(clang::diag::err_drv_fsycl_with_c_type)
818-
<< "-x " << XValue;
819-
}
820-
821813
Arg *SYCLTargets = getArgRequiringSYCLRuntime(options::OPT_fsycl_targets_EQ);
822814
Arg *SYCLLinkTargets =
823815
getArgRequiringSYCLRuntime(options::OPT_fsycl_link_targets_EQ);
@@ -2385,12 +2377,13 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
23852377
// actually use it, so we warn about unused -x arguments.
23862378
types::ID InputType = types::TY_Nothing;
23872379
Arg *InputTypeArg = nullptr;
2380+
bool IsSYCL = Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false);
23882381

23892382
// The last /TC or /TP option sets the input type to C or C++ globally.
23902383
if (Arg *TCTP = Args.getLastArgNoClaim(options::OPT__SLASH_TC,
23912384
options::OPT__SLASH_TP)) {
23922385
InputTypeArg = TCTP;
2393-
InputType = TCTP->getOption().matches(options::OPT__SLASH_TC)
2386+
InputType = TCTP->getOption().matches(options::OPT__SLASH_TC) && !IsSYCL
23942387
? types::TY_C
23952388
: types::TY_CXX;
23962389

@@ -2423,6 +2416,11 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
24232416
if (InputTypeArg)
24242417
InputTypeArg->claim();
24252418

2419+
types::ID CType = types::TY_C;
2420+
// For SYCL, all source file inputs are considered C++.
2421+
if (IsSYCL)
2422+
CType = types::TY_CXX;
2423+
24262424
// stdin must be handled specially.
24272425
if (memcmp(Value, "-", 2) == 0) {
24282426
// If running with -E, treat as a C input (this changes the builtin
@@ -2433,7 +2431,7 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
24332431
if (!Args.hasArgNoClaim(options::OPT_E) && !CCCIsCPP())
24342432
Diag(IsCLMode() ? clang::diag::err_drv_unknown_stdin_type_clang_cl
24352433
: clang::diag::err_drv_unknown_stdin_type);
2436-
Ty = types::TY_C;
2434+
Ty = CType;
24372435
} else {
24382436
// Otherwise lookup by extension.
24392437
// Fallback is C if invoked as C preprocessor, C++ if invoked with
@@ -2443,9 +2441,29 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
24432441
if (const char *Ext = strrchr(Value, '.'))
24442442
Ty = TC.LookupTypeForExtension(Ext + 1);
24452443

2444+
// For SYCL, convert C-type sources to C++-type sources.
2445+
if (IsSYCL) {
2446+
switch (Ty) {
2447+
case types::TY_C:
2448+
Ty = types::TY_CXX;
2449+
break;
2450+
case types::TY_CHeader:
2451+
Ty = types::TY_CXXHeader;
2452+
break;
2453+
case types::TY_PP_C:
2454+
Ty = types::TY_PP_CXX;
2455+
break;
2456+
case types::TY_PP_CHeader:
2457+
Ty = types::TY_PP_CXXHeader;
2458+
break;
2459+
default:
2460+
break;
2461+
}
2462+
}
2463+
24462464
if (Ty == types::TY_INVALID) {
24472465
if (CCCIsCPP())
2448-
Ty = types::TY_C;
2466+
Ty = CType;
24492467
else if (IsCLMode() && Args.hasArgNoClaim(options::OPT_E))
24502468
Ty = types::TY_CXX;
24512469
else
@@ -2504,7 +2522,8 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
25042522
if (DiagnoseInputExistence(Args, Value, types::TY_C,
25052523
/*TypoCorrect=*/false)) {
25062524
Arg *InputArg = MakeInputArg(Args, Opts, A->getValue());
2507-
Inputs.push_back(std::make_pair(types::TY_C, InputArg));
2525+
Inputs.push_back(
2526+
std::make_pair(IsSYCL ? types::TY_CXX : types::TY_C, InputArg));
25082527
}
25092528
A->claim();
25102529
} else if (A->getOption().matches(options::OPT__SLASH_Tp)) {
@@ -2532,6 +2551,11 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
25322551
Diag(clang::diag::err_drv_unknown_language) << A->getValue();
25332552
InputType = types::TY_Object;
25342553
}
2554+
// Emit an error if c-compilation is forced in -fsycl mode
2555+
if (IsSYCL && (InputType == types::TY_C || InputType == types::TY_PP_C ||
2556+
InputType == types::TY_CHeader))
2557+
Diag(clang::diag::err_drv_fsycl_with_c_type) << A->getAsString(Args);
2558+
25352559
} else if (A->getOption().getID() == options::OPT_U) {
25362560
assert(A->getNumValues() == 1 && "The /U option has one value.");
25372561
StringRef Val = A->getValue(0);

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "clang/Basic/CharInfo.h"
2727
#include "clang/Basic/CodeGenOptions.h"
2828
#include "clang/Basic/LangOptions.h"
29+
#include "clang/Basic/LangStandard.h"
2930
#include "clang/Basic/ObjCRuntime.h"
3031
#include "clang/Basic/Version.h"
3132
#include "clang/Driver/Distro.h"
@@ -5153,8 +5154,17 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
51535154
CmdArgs.push_back("-std=c++98");
51545155
else
51555156
CmdArgs.push_back("-std=c89");
5156-
else
5157+
else {
5158+
if (Args.hasArg(options::OPT_fsycl)) {
5159+
// Use of -std= with 'C' is not supported for SYCL.
5160+
const LangStandard *LangStd =
5161+
LangStandard::getLangStandardForName(Std->getValue());
5162+
if (LangStd && LangStd->getLanguage() == Language::C)
5163+
D.Diag(diag::err_drv_argument_not_allowed_with)
5164+
<< Std->getAsString(Args) << "-fsycl";
5165+
}
51575166
Std->render(Args, CmdArgs);
5167+
}
51585168

51595169
// If -f(no-)trigraphs appears after the language standard flag, honor it.
51605170
if (Arg *A = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi,

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2979,31 +2979,6 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
29792979
}
29802980

29812981
// Handles intel_reqd_sub_group_size.
2982-
void Sema::addIntelReqdSubGroupSizeAttr(Decl *D,
2983-
const AttributeCommonInfo &Attr,
2984-
Expr *E) {
2985-
if (!E)
2986-
return;
2987-
2988-
if (!E->isInstantiationDependent()) {
2989-
Optional<llvm::APSInt> ArgVal = E->getIntegerConstantExpr(getASTContext());
2990-
if (!ArgVal) {
2991-
Diag(E->getExprLoc(), diag::err_attribute_argument_type)
2992-
<< Attr.getAttrName() << AANT_ArgumentIntegerConstant
2993-
<< E->getSourceRange();
2994-
return;
2995-
}
2996-
int32_t ArgInt = ArgVal->getSExtValue();
2997-
if (ArgInt <= 0) {
2998-
Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer)
2999-
<< Attr.getAttrName() << /*positive*/ 0;
3000-
return;
3001-
}
3002-
}
3003-
3004-
D->addAttr(::new (Context) IntelReqdSubGroupSizeAttr(Context, Attr, E));
3005-
}
3006-
30072982
static void handleSubGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
30082983
if (S.LangOpts.SYCLIsHost)
30092984
return;
@@ -3013,7 +2988,7 @@ static void handleSubGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
30132988
if (D->getAttr<IntelReqdSubGroupSizeAttr>())
30142989
S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
30152990

3016-
S.addIntelReqdSubGroupSizeAttr(D, AL, E);
2991+
S.addIntelSYCLSingleArgFunctionAttr<IntelReqdSubGroupSizeAttr>(D, AL, E);
30172992
}
30182993

30192994
// Handles num_simd_work_items.
@@ -3022,23 +2997,13 @@ static void handleNumSimdWorkItemsAttr(Sema &S, Decl *D,
30222997
if (D->isInvalidDecl())
30232998
return;
30242999

3025-
uint32_t NumSimdWorkItems = 0;
3026-
const Expr *E = Attr.getArgAsExpr(0);
3027-
if (!checkUInt32Argument(S, Attr, E, NumSimdWorkItems, 0,
3028-
/*StrictlyUnsigned=*/true))
3029-
return;
3030-
3031-
if (NumSimdWorkItems == 0) {
3032-
S.Diag(Attr.getLoc(), diag::err_attribute_argument_is_zero)
3033-
<< Attr << E->getSourceRange();
3034-
return;
3035-
}
3000+
Expr *E = Attr.getArgAsExpr(0);
30363001

30373002
if (D->getAttr<SYCLIntelNumSimdWorkItemsAttr>())
30383003
S.Diag(Attr.getLoc(), diag::warn_duplicate_attribute) << Attr;
30393004

3040-
D->addAttr(::new (S.Context) SYCLIntelNumSimdWorkItemsAttr(
3041-
S.Context, Attr, NumSimdWorkItems));
3005+
S.addIntelSYCLSingleArgFunctionAttr<SYCLIntelNumSimdWorkItemsAttr>(D, Attr,
3006+
E);
30423007
}
30433008

30443009
// Handles max_global_work_dim.

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ enum KernelInvocationKind {
5858

5959
const static std::string InitMethodName = "__init";
6060
const static std::string FinalizeMethodName = "__finalize";
61-
constexpr unsigned GPUMaxKernelArgsSize = 2048;
61+
constexpr unsigned MaxKernelArgsSize = 2048;
6262

6363
namespace {
6464

@@ -1697,11 +1697,9 @@ class SyclKernelArgsSizeChecker : public SyclKernelFieldHandler {
16971697
: SyclKernelFieldHandler(S), KernelLoc(Loc) {}
16981698

16991699
~SyclKernelArgsSizeChecker() {
1700-
if (SemaRef.Context.getTargetInfo().getTriple().getSubArch() ==
1701-
llvm::Triple::SPIRSubArch_gen)
1702-
if (SizeOfParams > GPUMaxKernelArgsSize)
1703-
SemaRef.Diag(KernelLoc, diag::warn_sycl_kernel_too_big_args)
1704-
<< SizeOfParams << GPUMaxKernelArgsSize;
1700+
if (SizeOfParams > MaxKernelArgsSize)
1701+
SemaRef.Diag(KernelLoc, diag::warn_sycl_kernel_too_big_args)
1702+
<< SizeOfParams << MaxKernelArgsSize;
17051703
}
17061704

17071705
bool handleSyclAccessorType(FieldDecl *FD, QualType FieldTy) final {
@@ -2740,15 +2738,15 @@ void Sema::MarkDevice(void) {
27402738
KernelBody ? KernelBody->getAttr<SYCLSimdAttr>() : nullptr;
27412739
if (auto *Existing =
27422740
SYCLKernel->getAttr<IntelReqdSubGroupSizeAttr>()) {
2743-
if (getIntExprValue(Existing->getSubGroupSize(), getASTContext()) !=
2744-
getIntExprValue(Attr->getSubGroupSize(), getASTContext())) {
2741+
if (getIntExprValue(Existing->getValue(), getASTContext()) !=
2742+
getIntExprValue(Attr->getValue(), getASTContext())) {
27452743
Diag(SYCLKernel->getLocation(),
27462744
diag::err_conflicting_sycl_kernel_attributes);
27472745
Diag(Existing->getLocation(), diag::note_conflicting_attribute);
27482746
Diag(Attr->getLocation(), diag::note_conflicting_attribute);
27492747
SYCLKernel->setInvalidDecl();
27502748
}
2751-
} else if (KBSimdAttr && (getIntExprValue(Attr->getSubGroupSize(),
2749+
} else if (KBSimdAttr && (getIntExprValue(Attr->getValue(),
27522750
getASTContext()) != 1)) {
27532751
reportConflictingAttrs(*this, KernelBody, KBSimdAttr, Attr);
27542752
} else {

0 commit comments

Comments
 (0)