Skip to content

Commit 9e5c4a4

Browse files
committed
Merge remote-tracking branch 'otcshare_llvm/sycl' into int-header-perf-fix
2 parents 2bae7b4 + 3160de0 commit 9e5c4a4

File tree

71 files changed

+1456
-272
lines changed

Some content is hidden

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

71 files changed

+1456
-272
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,12 +1888,13 @@ def SYCLIntelFPGAInitiationInterval : DeclOrStmtAttr {
18881888
let SupportsNonconformingLambdaSyntax = 1;
18891889
}
18901890

1891-
def SYCLIntelFPGAMaxConcurrency : StmtAttr {
1891+
def SYCLIntelFPGAMaxConcurrency : DeclOrStmtAttr {
18921892
let Spellings = [CXX11<"intelfpga","max_concurrency">,
18931893
CXX11<"intel","max_concurrency">];
1894-
let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt],
1895-
ErrorDiag, "'for', 'while', and 'do' statements">;
1896-
let Args = [ExprArgument<"NThreadsExpr", /*opt*/1>];
1894+
let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt, Function],
1895+
ErrorDiag,
1896+
"'for', 'while', 'do' statements, and functions">;
1897+
let Args = [ExprArgument<"NThreadsExpr">];
18971898
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
18981899
let HasCustomTypeTransform = 1;
18991900
let Documentation = [SYCLIntelFPGAMaxConcurrencyAttrDocs];

clang/include/clang/Basic/AttrDocs.td

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2865,10 +2865,11 @@ def SYCLIntelFPGAMaxConcurrencyAttrDocs : Documentation {
28652865
let Category = DocCatVariable;
28662866
let Heading = "intel::max_concurrency";
28672867
let Content = [{
2868-
This attribute applies to a loop. Indicates that the loop should allow no more
2869-
than N threads or iterations to execute it simultaneously. N must be a non
2870-
negative integer. '0' indicates the max_concurrency case to be unbounded. Cannot
2871-
be applied multiple times to the same loop.
2868+
This attribute applies to a loop or a function. It indicates that the
2869+
loop/function should allow no more than N threads or iterations to execute it
2870+
simultaneously. N must be a non negative integer. '0' indicates the
2871+
max_concurrency case to be unbounded. Cannot be applied multiple times to the
2872+
same loop.
28722873

28732874
.. code-block:: c++
28742875

@@ -2877,10 +2878,13 @@ be applied multiple times to the same loop.
28772878
[[intel::max_concurrency(2)]] for (int i = 0; i != 10; ++i) a[i] = 0;
28782879
}
28792880

2881+
[[intel::max_concurrency(2)]] void foo1 { }
28802882
template<int N>
28812883
void bar() {
28822884
[[intel::max_concurrency(N)]] for(;;) { }
28832885
}
2886+
template<int N>
2887+
[[intel::max_concurrency(N)]] void bar1() { }
28842888

28852889
}];
28862890
}

clang/include/clang/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ class LangOptions : public LangOptionsBase {
350350
/// SYCL integration header to be generated by the device compiler
351351
std::string SYCLIntHeader;
352352

353+
/// SYCL integration footer to be generated by the device compiler
354+
std::string SYCLIntFooter;
355+
353356
LangOptions();
354357

355358
// Define accessors/mutators for language options of enumeration type.

clang/include/clang/Driver/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5685,6 +5685,11 @@ def fsycl_int_header : Separate<["-"], "fsycl-int-header">,
56855685
MarshallingInfoString<LangOpts<"SYCLIntHeader">>;
56865686
def fsycl_int_header_EQ : Joined<["-"], "fsycl-int-header=">,
56875687
Alias<fsycl_int_header>;
5688+
def fsycl_int_footer : Separate<["-"], "fsycl-int-footer">,
5689+
HelpText<"Generate SYCL integration footer into this file.">,
5690+
MarshallingInfoString<LangOpts<"SYCLIntFooter">>;
5691+
def fsycl_int_footer_EQ : Joined<["-"], "fsycl-int-footer=">,
5692+
Alias<fsycl_int_footer>;
56885693
def fsycl_std_layout_kernel_params: Flag<["-"], "fsycl-std-layout-kernel-params">,
56895694
HelpText<"Enable standard layout requirement for SYCL kernel parameters.">,
56905695
MarshallingInfoFlag<LangOpts<"SYCLStdLayoutKernelParams">>;

clang/include/clang/Sema/Sema.h

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,15 +320,14 @@ class SYCLIntegrationHeader {
320320
};
321321

322322
public:
323-
SYCLIntegrationHeader(DiagnosticsEngine &Diag, bool UnnamedLambdaSupport,
324-
Sema &S);
323+
SYCLIntegrationHeader(bool UnnamedLambdaSupport, Sema &S);
325324

326325
/// Emits contents of the header into given stream.
327326
void emit(raw_ostream &Out);
328327

329328
/// Emits contents of the header into a file with given name.
330329
/// Returns true/false on success/failure.
331-
bool emit(const StringRef &MainSrc);
330+
bool emit(StringRef MainSrc);
332331

333332
/// Signals that subsequent parameter descriptor additions will go to
334333
/// the kernel with given name. Starts new kernel invocation descriptor.
@@ -431,6 +430,16 @@ class SYCLIntegrationHeader {
431430
Sema &S;
432431
};
433432

433+
class SYCLIntegrationFooter {
434+
public:
435+
SYCLIntegrationFooter(Sema &S) : S(S) {}
436+
bool emit(StringRef MainSrc);
437+
438+
private:
439+
bool emit(raw_ostream &O);
440+
Sema &S;
441+
};
442+
434443
/// Tracks expected type during expression parsing, for use in code completion.
435444
/// The type is tied to a particular token, all functions that update or consume
436445
/// the type take a start location of the token they are looking at as a
@@ -10304,6 +10313,9 @@ class Sema final {
1030410313
SYCLIntelFPGAInitiationIntervalAttr *MergeSYCLIntelFPGAInitiationIntervalAttr(
1030510314
Decl *D, const SYCLIntelFPGAInitiationIntervalAttr &A);
1030610315

10316+
SYCLIntelFPGAMaxConcurrencyAttr *MergeSYCLIntelFPGAMaxConcurrencyAttr(
10317+
Decl *D, const SYCLIntelFPGAMaxConcurrencyAttr &A);
10318+
1030710319
/// AddAlignedAttr - Adds an aligned attribute to a particular declaration.
1030810320
void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E,
1030910321
bool IsPackExpansion);
@@ -10358,6 +10370,12 @@ class Sema final {
1035810370
/// declaration.
1035910371
void addSYCLIntelPipeIOAttr(Decl *D, const AttributeCommonInfo &CI, Expr *ID);
1036010372

10373+
/// AddSYCLIntelFPGAMaxConcurrencyAttr - Adds a max_concurrency attribute to a
10374+
/// particular declaration.
10375+
void AddSYCLIntelFPGAMaxConcurrencyAttr(Decl *D,
10376+
const AttributeCommonInfo &CI,
10377+
Expr *E);
10378+
1036110379
bool checkNSReturnsRetainedReturnType(SourceLocation loc, QualType type);
1036210380
bool checkAllowedSYCLInitializer(VarDecl *VD,
1036310381
bool CheckValueDependent = false);
@@ -13110,6 +13128,7 @@ class Sema final {
1311013128
// SYCL integration header instance for current compilation unit this Sema
1311113129
// is associated with.
1311213130
std::unique_ptr<SYCLIntegrationHeader> SyclIntHeader;
13131+
std::unique_ptr<SYCLIntegrationFooter> SyclIntFooter;
1311313132

1311413133
// Used to suppress diagnostics during kernel construction, since these were
1311513134
// already emitted earlier. Diagnosing during Kernel emissions also skips the
@@ -13124,10 +13143,16 @@ class Sema final {
1312413143
SYCLIntegrationHeader &getSyclIntegrationHeader() {
1312513144
if (SyclIntHeader == nullptr)
1312613145
SyclIntHeader = std::make_unique<SYCLIntegrationHeader>(
13127-
getDiagnostics(), getLangOpts().SYCLUnnamedLambda, *this);
13146+
getLangOpts().SYCLUnnamedLambda, *this);
1312813147
return *SyclIntHeader.get();
1312913148
}
1313013149

13150+
SYCLIntegrationFooter &getSyclIntegrationFooter() {
13151+
if (SyclIntFooter == nullptr)
13152+
SyclIntFooter = std::make_unique<SYCLIntegrationFooter>(*this);
13153+
return *SyclIntFooter.get();
13154+
}
13155+
1313113156
enum SYCLRestrictKind {
1313213157
KernelGlobalVariable,
1313313158
KernelRTTI,

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,14 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD,
739739
Fn->setMetadata("stall_enable", llvm::MDNode::get(Context, AttrMDArgs));
740740
}
741741

742+
if (const auto *A = FD->getAttr<SYCLIntelFPGAMaxConcurrencyAttr>()) {
743+
const auto *CE = cast<ConstantExpr>(A->getNThreadsExpr());
744+
llvm::APSInt ArgVal = CE->getResultAsAPSInt();
745+
llvm::Metadata *AttrMDArgs[] = {
746+
llvm::ConstantAsMetadata::get(Builder.getInt32(ArgVal.getSExtValue()))};
747+
Fn->setMetadata("max_concurrency", llvm::MDNode::get(Context, AttrMDArgs));
748+
}
749+
742750
if (FD->hasAttr<SYCLIntelFPGADisableLoopPipeliningAttr>()) {
743751
llvm::Metadata *AttrMDArgs[] = {
744752
llvm::ConstantAsMetadata::get(Builder.getInt32(1))};

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8260,8 +8260,7 @@ void SPIRVTranslator::ConstructJob(Compilation &C, const JobAction &JA,
82608260
// Prevent crash in the translator if input IR contains DIExpression
82618261
// operations which don't have mapping to OpenCL.DebugInfo.100 spec.
82628262
TranslatorArgs.push_back("-spirv-allow-extra-diexpressions");
8263-
if (C.getArgs().hasArg(options::OPT_fsycl_esimd))
8264-
TranslatorArgs.push_back("-spirv-allow-unknown-intrinsics");
8263+
TranslatorArgs.push_back("-spirv-allow-unknown-intrinsics=llvm.genx.");
82658264

82668265
// Disable SPV_INTEL_usm_storage_classes by default since it adds new
82678266
// storage classes that represent global_device and global_host address

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ const char *SYCL::Linker::constructLLVMSpirvCommand(
4343
CmdArgs.push_back("-spirv-ext=+all");
4444
CmdArgs.push_back("-spirv-debug-info-version=legacy");
4545
CmdArgs.push_back("-spirv-allow-extra-diexpressions");
46-
if (C.getArgs().hasArg(options::OPT_fsycl_esimd))
47-
CmdArgs.push_back("-spirv-allow-unknown-intrinsics");
46+
CmdArgs.push_back("-spirv-allow-unknown-intrinsics=llvm.genx.");
4847
CmdArgs.push_back("-o");
4948
CmdArgs.push_back(Output.getFilename());
5049
}

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3698,8 +3698,8 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
36983698
// '-mignore-xcoff-visibility' is implied. The generated command line will
36993699
// contain both '-fvisibility default' and '-mignore-xcoff-visibility' and
37003700
// subsequent calls to `CreateFromArgs`/`generateCC1CommandLine` will always
3701-
// produce the same arguments.
3702-
3701+
// produce the same arguments.
3702+
37033703
if (T.isOSAIX() && (Args.hasArg(OPT_mignore_xcoff_visibility) ||
37043704
!Args.hasArg(OPT_fvisibility)))
37053705
Opts.IgnoreXCOFFVisibility = 1;
@@ -4291,6 +4291,22 @@ static bool ParseTargetArgs(TargetOptions &Opts, ArgList &Args,
42914291
return Success && Diags.getNumErrors() == NumErrorsBefore;
42924292
}
42934293

4294+
static void CreateEmptyFile(StringRef HeaderName) {
4295+
if (HeaderName.empty())
4296+
return;
4297+
4298+
Expected<llvm::sys::fs::file_t> FT = llvm::sys::fs::openNativeFileForWrite(
4299+
HeaderName, llvm::sys::fs::CD_OpenAlways, llvm::sys::fs::OF_None);
4300+
if (FT)
4301+
llvm::sys::fs::closeFile(*FT);
4302+
else {
4303+
// Emit a message but don't terminate; compilation will fail
4304+
// later if this file is absent.
4305+
llvm::errs() << "Error: " << llvm::toString(FT.takeError())
4306+
<< " when opening " << HeaderName << "\n";
4307+
}
4308+
}
4309+
42944310
bool CompilerInvocation::CreateFromArgsImpl(
42954311
CompilerInvocation &Res, ArrayRef<const char *> CommandLineArgs,
42964312
DiagnosticsEngine &Diags, const char *Argv0) {
@@ -4372,21 +4388,9 @@ bool CompilerInvocation::CreateFromArgsImpl(
43724388
if (LangOpts.SYCLIsDevice) {
43734389
// Set the triple of the host for SYCL device compile.
43744390
Res.getTargetOpts().HostTriple = Res.getFrontendOpts().AuxTriple;
4375-
// If specified, create an empty integration header file for now.
4376-
const StringRef &HeaderName = LangOpts.SYCLIntHeader;
4377-
if (!HeaderName.empty()) {
4378-
Expected<llvm::sys::fs::file_t> ft =
4379-
llvm::sys::fs::openNativeFileForWrite(
4380-
HeaderName, llvm::sys::fs::CD_OpenAlways, llvm::sys::fs::OF_None);
4381-
if (ft)
4382-
llvm::sys::fs::closeFile(*ft);
4383-
else {
4384-
// Emit a message but don't terminate; compilation will fail
4385-
// later if this file is absent.
4386-
llvm::errs() << "Error: " << llvm::toString(ft.takeError())
4387-
<< " when opening " << HeaderName << "\n";
4388-
}
4389-
}
4391+
// If specified, create empty integration header files for now.
4392+
CreateEmptyFile(LangOpts.SYCLIntHeader);
4393+
CreateEmptyFile(LangOpts.SYCLIntFooter);
43904394
}
43914395

43924396
Success &= ParseCodeGenArgs(Res.getCodeGenOpts(), Args, DashX, Diags, T,

clang/lib/Sema/Sema.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
183183
DisableTypoCorrection(false), TyposCorrected(0), AnalysisWarnings(*this),
184184
ThreadSafetyDeclCache(nullptr), VarDataSharingAttributesStack(nullptr),
185185
CurScope(nullptr), Ident_super(nullptr), Ident___float128(nullptr),
186-
SyclIntHeader(nullptr) {
186+
SyclIntHeader(nullptr), SyclIntFooter(nullptr) {
187187
TUScope = nullptr;
188188
isConstantEvaluatedOverride = false;
189189

@@ -1037,6 +1037,8 @@ void Sema::ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind) {
10371037
// Emit SYCL integration header for current translation unit if needed
10381038
if (SyclIntHeader != nullptr)
10391039
SyclIntHeader->emit(getLangOpts().SYCLIntHeader);
1040+
if (SyclIntFooter != nullptr)
1041+
SyclIntFooter->emit(getLangOpts().SYCLIntFooter);
10401042
MarkDevice();
10411043
}
10421044

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,6 +2628,8 @@ static bool mergeDeclAttribute(Sema &S, NamedDecl *D,
26282628
NewAttr = S.MergeSYCLIntelNoGlobalWorkOffsetAttr(D, *A);
26292629
else if (const auto *A = dyn_cast<IntelFPGAMaxReplicatesAttr>(Attr))
26302630
NewAttr = S.MergeIntelFPGAMaxReplicatesAttr(D, *A);
2631+
else if (const auto *A = dyn_cast<SYCLIntelFPGAMaxConcurrencyAttr>(Attr))
2632+
NewAttr = S.MergeSYCLIntelFPGAMaxConcurrencyAttr(D, *A);
26312633
else if (const auto *A = dyn_cast<IntelFPGAForcePow2DepthAttr>(Attr))
26322634
NewAttr = S.MergeIntelFPGAForcePow2DepthAttr(D, *A);
26332635
else if (const auto *A = dyn_cast<SYCLIntelFPGAInitiationIntervalAttr>(Attr))

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6435,6 +6435,76 @@ static void handleSYCLIntelPipeIOAttr(Sema &S, Decl *D,
64356435
S.addSYCLIntelPipeIOAttr(D, Attr, E);
64366436
}
64376437

6438+
SYCLIntelFPGAMaxConcurrencyAttr *Sema::MergeSYCLIntelFPGAMaxConcurrencyAttr(
6439+
Decl *D, const SYCLIntelFPGAMaxConcurrencyAttr &A) {
6440+
// Check to see if there's a duplicate attribute with different values
6441+
// already applied to the declaration.
6442+
if (const auto *DeclAttr = D->getAttr<SYCLIntelFPGAMaxConcurrencyAttr>()) {
6443+
const auto *DeclExpr = dyn_cast<ConstantExpr>(DeclAttr->getNThreadsExpr());
6444+
const auto *MergeExpr = dyn_cast<ConstantExpr>(A.getNThreadsExpr());
6445+
if (DeclExpr && MergeExpr &&
6446+
DeclExpr->getResultAsAPSInt() != MergeExpr->getResultAsAPSInt()) {
6447+
Diag(DeclAttr->getLoc(), diag::warn_duplicate_attribute) << &A;
6448+
Diag(A.getLoc(), diag::note_previous_attribute);
6449+
}
6450+
return nullptr;
6451+
}
6452+
// FIXME
6453+
// max_concurrency and disable_component_pipelining attributes can't be
6454+
// applied to the same function. Upcoming patch needs to have this code
6455+
// added to it:
6456+
// if (checkAttrMutualExclusion<IntelDisableComponentPipeline>(S, D, AL))
6457+
// return;
6458+
6459+
return ::new (Context)
6460+
SYCLIntelFPGAMaxConcurrencyAttr(Context, A, A.getNThreadsExpr());
6461+
}
6462+
6463+
void Sema::AddSYCLIntelFPGAMaxConcurrencyAttr(Decl *D,
6464+
const AttributeCommonInfo &CI,
6465+
Expr *E) {
6466+
if (!E->isValueDependent()) {
6467+
llvm::APSInt ArgVal;
6468+
ExprResult Res = VerifyIntegerConstantExpression(E, &ArgVal);
6469+
if (Res.isInvalid())
6470+
return;
6471+
E = Res.get();
6472+
6473+
// This attribute requires a non-negative value.
6474+
if (ArgVal < 0) {
6475+
Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer)
6476+
<< CI << /*non-negative*/ 1;
6477+
return;
6478+
}
6479+
6480+
if (const auto *DeclAttr = D->getAttr<SYCLIntelFPGAMaxConcurrencyAttr>()) {
6481+
const auto *DeclExpr =
6482+
dyn_cast<ConstantExpr>(DeclAttr->getNThreadsExpr());
6483+
if (DeclExpr && ArgVal != DeclExpr->getResultAsAPSInt()) {
6484+
Diag(CI.getLoc(), diag::warn_duplicate_attribute) << CI;
6485+
Diag(DeclAttr->getLoc(), diag::note_previous_attribute);
6486+
}
6487+
return;
6488+
}
6489+
}
6490+
6491+
D->addAttr(::new (Context) SYCLIntelFPGAMaxConcurrencyAttr(Context, CI, E));
6492+
}
6493+
6494+
static void handleSYCLIntelFPGAMaxConcurrencyAttr(Sema &S, Decl *D,
6495+
const ParsedAttr &A) {
6496+
S.CheckDeprecatedSYCLAttributeSpelling(A);
6497+
// FIXME
6498+
// max_concurrency and disable_component_pipelining attributes can't be
6499+
// applied to the same function. Upcoming patch needs to have this code
6500+
// added to it:
6501+
// if (checkAttrMutualExclusion<IntelDisableComponentPipeline>(S, D, AL))
6502+
// return;
6503+
6504+
Expr *E = A.getArgAsExpr(0);
6505+
S.AddSYCLIntelFPGAMaxConcurrencyAttr(D, A, E);
6506+
}
6507+
64386508
namespace {
64396509
struct IntrinToName {
64406510
uint32_t Id;
@@ -9689,6 +9759,9 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
96899759
case ParsedAttr::AT_SYCLIntelPipeIO:
96909760
handleSYCLIntelPipeIOAttr(S, D, AL);
96919761
break;
9762+
case ParsedAttr::AT_SYCLIntelFPGAMaxConcurrency:
9763+
handleSYCLIntelFPGAMaxConcurrencyAttr(S, D, AL);
9764+
break;
96929765

96939766
// Swift attributes.
96949767
case ParsedAttr::AT_SwiftAsyncName:

0 commit comments

Comments
 (0)