Skip to content

Commit 4826347

Browse files
committed
Merge remote-tracking branch 'upstream/sycl' into stmt-attr-cleanups
2 parents 551230d + 0a990f8 commit 4826347

Some content is hidden

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

60 files changed

+2618
-683
lines changed

.github/workflows/linux_post_commit.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ jobs:
2727
;;
2828
SharedLibs)
2929
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
30-
sudo add-apt-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main"
30+
sudo add-apt-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-12 main"
3131
sudo apt-get update
32-
sudo apt-get install -y clang-13
32+
sudo apt-get install -y clang-12
3333
export ARGS="--shared-libs"
34-
export CC="clang-13"
35-
export CXX="clang++-13"
34+
export CC="clang-12"
35+
export CXX="clang++-12"
3636
;;
3737
NoAssertions)
3838
export ARGS="--no-assertions"

clang/include/clang/Basic/Attr.td

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ def SYCL : LangOpt<"SYCL">;
337337
def SYCLIsDevice : LangOpt<"SYCLIsDevice">;
338338
def SYCLIsHost : LangOpt<"SYCLIsHost">;
339339
def SilentlyIgnoreSYCLIsHost : LangOpt<"SYCLIsHost", "", 1>;
340-
def SYCLExplicitSIMD : LangOpt<"SYCLExplicitSIMD">;
341340
def COnly : LangOpt<"", "!LangOpts.CPlusPlus">;
342341
def CPlusPlus : LangOpt<"CPlusPlus">;
343342
def OpenCL : LangOpt<"OpenCL">;
@@ -1195,7 +1194,6 @@ def SYCLSimd : InheritableAttr {
11951194
let Spellings = [GNU<"sycl_explicit_simd">,
11961195
CXX11<"intel", "sycl_explicit_simd">];
11971196
let Subjects = SubjectList<[Function, GlobalVar]>;
1198-
let LangOpts = [SYCLExplicitSIMD];
11991197
let Documentation = [SYCLSimdDocs];
12001198
let SupportsNonconformingLambdaSyntax = 1;
12011199
}
@@ -1208,7 +1206,6 @@ def SYCLRegisterNum : InheritableAttr {
12081206
let Subjects = SubjectList<[GlobalVar]>;
12091207
// This attribute is applied to file-scope variables and must be compilable
12101208
// for the host device as well
1211-
let LangOpts = [SYCLExplicitSIMD];
12121209
let Documentation = [SYCLRegisterNumDocs];
12131210
}
12141211

@@ -1221,7 +1218,6 @@ def SYCLSimdAccessorPtr : InheritableAttr {
12211218
// No spelling, as this attribute can't be created in the source code.
12221219
let Spellings = [];
12231220
let Subjects = SubjectList<[ParmVar]>;
1224-
let LangOpts = [SYCLExplicitSIMD];
12251221
let Documentation = [Undocumented];
12261222
}
12271223

@@ -1878,16 +1874,18 @@ def SYCLIntelFPGAIVDep : StmtAttr {
18781874
let Documentation = [SYCLIntelFPGAIVDepAttrDocs];
18791875
}
18801876

1881-
def SYCLIntelFPGAInitiationInterval : StmtAttr {
1877+
def SYCLIntelFPGAInitiationInterval : DeclOrStmtAttr {
18821878
let Spellings = [CXX11<"intelfpga","ii">,
18831879
CXX11<"intel","ii">,
18841880
CXX11<"intel", "initiation_interval">];
1885-
let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt],
1886-
ErrorDiag, "'for', 'while', and 'do' statements">;
1881+
let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt, Function],
1882+
ErrorDiag,
1883+
"'for', 'while', 'do' statements, and functions">;
18871884
let Args = [ExprArgument<"IntervalExpr">];
18881885
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
18891886
let HasCustomTypeTransform = 1;
18901887
let Documentation = [SYCLIntelFPGAInitiationIntervalAttrDocs];
1888+
let SupportsNonconformingLambdaSyntax = 1;
18911889
}
18921890

18931891
def SYCLIntelFPGAMaxConcurrency : StmtAttr {
@@ -1912,14 +1910,16 @@ def SYCLIntelFPGALoopCoalesce : StmtAttr {
19121910
let Documentation = [SYCLIntelFPGALoopCoalesceAttrDocs];
19131911
}
19141912

1915-
def SYCLIntelFPGADisableLoopPipelining : StmtAttr {
1913+
def SYCLIntelFPGADisableLoopPipelining : DeclOrStmtAttr {
19161914
let Spellings = [CXX11<"intelfpga","disable_loop_pipelining">,
19171915
CXX11<"intel","disable_loop_pipelining">];
1918-
let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt],
1919-
ErrorDiag, "'for', 'while', and 'do' statements">;
1916+
let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt, Function],
1917+
ErrorDiag,
1918+
"'for', 'while', 'do' statements, and functions">;
19201919
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
19211920
let HasCustomTypeTransform = 1;
19221921
let Documentation = [SYCLIntelFPGADisableLoopPipeliningAttrDocs];
1922+
let SupportsNonconformingLambdaSyntax = 1;
19231923
}
19241924

19251925
def SYCLIntelFPGAMaxInterleaving : StmtAttr {

clang/include/clang/Basic/AttrDocs.td

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2832,9 +2832,11 @@ def SYCLIntelFPGAInitiationIntervalAttrDocs : Documentation {
28322832
let Category = DocCatVariable;
28332833
let Heading = "intel::initiation_interval";
28342834
let Content = [{
2835-
This attribute applies to a loop. Indicates that the loop should be pipelined
2836-
with an initiation interval of N. N must be a positive integer. Cannot be
2837-
applied multiple times to the same loop.
2835+
This attribute applies to a loop or a function. Indicates that the loop or
2836+
function should be pipelined with an initiation interval of N. N must be a
2837+
positive integer. Cannot be applied multiple times to the same loop or function.
2838+
Cannot be used on the same loop or function in conjunction with
2839+
disable_loop_pipelining.
28382840

28392841
The ``[[intel::ii]]`` attribute spelling is a deprecated synonym for
28402842
``[[intel::initiation_interval]]`` and will be removed in the future.
@@ -2846,11 +2848,16 @@ The ``[[intel::ii]]`` attribute spelling is a deprecated synonym for
28462848
[[intel::initiation_interval(4)]] for (int i = 0; i < 10; ++i) var++;
28472849
}
28482850

2851+
[[intel::initiation_interval(4)]] void foo1 { }
2852+
28492853
template<int N>
28502854
void bar() {
28512855
[[intel::initiation_interval(N)]] for(;;) { }
28522856
}
28532857

2858+
template<int N>
2859+
[[intel::initiation_interval(N)]] void bar1 { }
2860+
28542861
}];
28552862
}
28562863

@@ -2921,10 +2928,11 @@ def SYCLIntelFPGADisableLoopPipeliningAttrDocs : Documentation {
29212928
let Category = DocCatVariable;
29222929
let Heading = "intel::disable_loop_pipelining";
29232930
let Content = [{
2924-
This attribute applies to a loop. Disables pipelining of the loop data path,
2925-
causing the loop to be executed serially. Cannot be used on the same loop in
2926-
conjunction with max_interleaving, speculated_iterations, max_concurrency, ii
2927-
or ivdep.
2931+
This attribute applies to a loop or a function. Takes no arguments and
2932+
disables pipelining of the loop or function data path, causing the loop
2933+
or function to be executed serially. Cannot be used on the same loop or
2934+
function in conjunction with max_interleaving, speculated_iterations,
2935+
max_concurrency, initiation_interval, or ivdep.
29282936

29292937
.. code-block:: c++
29302938

@@ -2933,6 +2941,8 @@ or ivdep.
29332941
[[intel::disable_loop_pipelining] for (int i = 0; i < 10; ++i) var++;
29342942
}
29352943

2944+
[[intel::disable_loop_pipelining] void foo1() { }
2945+
29362946
}];
29372947
}
29382948

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11214,6 +11214,8 @@ def err_ext_int_max_size : Error<"%select{signed|unsigned}0 _ExtInt of bit "
1121411214
"sizes greater than %1 not supported">;
1121511215
def err_esimd_glob_cant_init : Error<
1121611216
"SYCL explicit SIMD does not permit private global variable to have an initializer">;
11217+
def err_esimd_global_in_sycl_context : Error<
11218+
"ESIMD globals cannot be used in a SYCL context">;
1121711219

1121811220
def err_sycl_kernel_incorrectly_named : Error<"%0 is an invalid kernel name type">;
1121911221
def note_invalid_type_in_sycl_kernel : Note<

clang/include/clang/Sema/Sema.h

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,34 @@ class Sema final {
17691769
}
17701770
};
17711771

1772+
/// Bitmask to contain the list of reasons a single diagnostic should be
1773+
/// emitted, based on its language. This permits multiple offload systems
1774+
/// to coexist in the same translation unit.
1775+
enum class DeviceDiagnosticReason {
1776+
/// Diagnostic doesn't apply to anything. Included for completeness, but
1777+
/// should make this a no-op.
1778+
None = 0,
1779+
/// OpenMP specific diagnostic.
1780+
OmpDevice = 1 << 0,
1781+
OmpHost = 1 << 1,
1782+
OmpAll = OmpDevice | OmpHost,
1783+
/// CUDA specific diagnostics.
1784+
CudaDevice = 1 << 2,
1785+
CudaHost = 1 << 3,
1786+
CudaAll = CudaDevice | CudaHost,
1787+
/// SYCL specific diagnostic.
1788+
Sycl = 1 << 4,
1789+
/// ESIMD specific diagnostic.
1790+
Esimd = 1 << 5,
1791+
/// A flag representing 'all'. This can be used to avoid the check
1792+
/// all-together and make this behave as it did before the
1793+
/// DiagnosticReason was added (that is, unconditionally emit).
1794+
/// Note: This needs to be updated if any flags above are added.
1795+
All = OmpAll | CudaAll | Sycl | Esimd,
1796+
1797+
LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/All)
1798+
};
1799+
17721800
/// A generic diagnostic builder for errors which may or may not be deferred.
17731801
///
17741802
/// In CUDA, there exist constructs (e.g. variable-length arrays, try/catch)
@@ -1801,7 +1829,7 @@ class Sema final {
18011829
};
18021830

18031831
SemaDiagnosticBuilder(Kind K, SourceLocation Loc, unsigned DiagID,
1804-
FunctionDecl *Fn, Sema &S);
1832+
FunctionDecl *Fn, Sema &S, DeviceDiagnosticReason R);
18051833
SemaDiagnosticBuilder(SemaDiagnosticBuilder &&D);
18061834
SemaDiagnosticBuilder(const SemaDiagnosticBuilder &) = default;
18071835
~SemaDiagnosticBuilder();
@@ -1826,7 +1854,9 @@ class Sema final {
18261854
if (Diag.ImmediateDiag.hasValue())
18271855
*Diag.ImmediateDiag << Value;
18281856
else if (Diag.PartialDiagId.hasValue())
1829-
Diag.S.DeviceDeferredDiags[Diag.Fn][*Diag.PartialDiagId].second
1857+
Diag.S.DeviceDeferredDiags[Diag.Fn][*Diag.PartialDiagId]
1858+
.getDiag()
1859+
.second
18301860
<< Value;
18311861
return Diag;
18321862
}
@@ -1840,7 +1870,8 @@ class Sema final {
18401870
if (ImmediateDiag.hasValue())
18411871
*ImmediateDiag << std::move(V);
18421872
else if (PartialDiagId.hasValue())
1843-
S.DeviceDeferredDiags[Fn][*PartialDiagId].second << std::move(V);
1873+
S.DeviceDeferredDiags[Fn][*PartialDiagId].getDiag().second
1874+
<< std::move(V);
18441875
return *this;
18451876
}
18461877

@@ -1849,15 +1880,18 @@ class Sema final {
18491880
if (Diag.ImmediateDiag.hasValue())
18501881
PD.Emit(*Diag.ImmediateDiag);
18511882
else if (Diag.PartialDiagId.hasValue())
1852-
Diag.S.DeviceDeferredDiags[Diag.Fn][*Diag.PartialDiagId].second = PD;
1883+
Diag.S.DeviceDeferredDiags[Diag.Fn][*Diag.PartialDiagId]
1884+
.getDiag()
1885+
.second = PD;
18531886
return Diag;
18541887
}
18551888

18561889
void AddFixItHint(const FixItHint &Hint) const {
18571890
if (ImmediateDiag.hasValue())
18581891
ImmediateDiag->AddFixItHint(Hint);
18591892
else if (PartialDiagId.hasValue())
1860-
S.DeviceDeferredDiags[Fn][*PartialDiagId].second.AddFixItHint(Hint);
1893+
S.DeviceDeferredDiags[Fn][*PartialDiagId].getDiag().second.AddFixItHint(
1894+
Hint);
18611895
}
18621896

18631897
friend ExprResult ExprError(const SemaDiagnosticBuilder &) {
@@ -4281,6 +4315,7 @@ class Sema final {
42814315
};
42824316
FunctionEmissionStatus getEmissionStatus(FunctionDecl *Decl,
42834317
bool Final = false);
4318+
DeviceDiagnosticReason getEmissionReason(const FunctionDecl *Decl);
42844319

42854320
// Whether the callee should be ignored in CUDA/HIP/OpenMP host/device check.
42864321
bool shouldIgnoreInHostDeviceCheck(FunctionDecl *Callee);
@@ -10263,6 +10298,11 @@ class Sema final {
1026310298
IntelFPGAForcePow2DepthAttr *
1026410299
MergeIntelFPGAForcePow2DepthAttr(Decl *D,
1026510300
const IntelFPGAForcePow2DepthAttr &A);
10301+
void AddSYCLIntelFPGAInitiationIntervalAttr(Decl *D,
10302+
const AttributeCommonInfo &CI,
10303+
Expr *E);
10304+
SYCLIntelFPGAInitiationIntervalAttr *MergeSYCLIntelFPGAInitiationIntervalAttr(
10305+
Decl *D, const SYCLIntelFPGAInitiationIntervalAttr &A);
1026610306

1026710307
/// AddAlignedAttr - Adds an aligned attribute to a particular declaration.
1026810308
void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E,
@@ -12157,11 +12197,25 @@ class Sema final {
1215712197
/// before incrementing, so you can emit an error.
1215812198
bool PopForceCUDAHostDevice();
1215912199

12200+
class DeviceDeferredDiagnostic {
12201+
public:
12202+
DeviceDeferredDiagnostic(SourceLocation SL, const PartialDiagnostic &PD,
12203+
DeviceDiagnosticReason R)
12204+
: Diagnostic(SL, PD), Reason(R) {}
12205+
12206+
PartialDiagnosticAt &getDiag() { return Diagnostic; }
12207+
DeviceDiagnosticReason getReason() const { return Reason; }
12208+
12209+
private:
12210+
PartialDiagnosticAt Diagnostic;
12211+
DeviceDiagnosticReason Reason;
12212+
};
12213+
1216012214
/// Diagnostics that are emitted only if we discover that the given function
1216112215
/// must be codegen'ed. Because handling these correctly adds overhead to
1216212216
/// compilation, this is currently only enabled for CUDA compilations.
1216312217
llvm::DenseMap<CanonicalDeclPtr<FunctionDecl>,
12164-
std::vector<PartialDiagnosticAt>>
12218+
std::vector<DeviceDeferredDiagnostic>>
1216512219
DeviceDeferredDiags;
1216612220

1216712221
/// A pair of a canonical FunctionDecl and a SourceLocation. When used as the
@@ -13124,8 +13178,10 @@ class Sema final {
1312413178
/// if (!S.Context.getTargetInfo().hasFloat128Type() &&
1312513179
/// S.getLangOpts().SYCLIsDevice)
1312613180
/// SYCLDiagIfDeviceCode(Loc, diag::err_type_unsupported) << "__float128";
13127-
SemaDiagnosticBuilder SYCLDiagIfDeviceCode(SourceLocation Loc,
13128-
unsigned DiagID);
13181+
SemaDiagnosticBuilder SYCLDiagIfDeviceCode(
13182+
SourceLocation Loc, unsigned DiagID,
13183+
DeviceDiagnosticReason Reason = DeviceDiagnosticReason::Sycl |
13184+
DeviceDiagnosticReason::Esimd);
1312913185

1313013186
/// Check whether we're allowed to call Callee from the current context.
1313113187
///

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,22 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD,
738738
llvm::ConstantAsMetadata::get(Builder.getInt32(1))};
739739
Fn->setMetadata("stall_enable", llvm::MDNode::get(Context, AttrMDArgs));
740740
}
741+
742+
if (FD->hasAttr<SYCLIntelFPGADisableLoopPipeliningAttr>()) {
743+
llvm::Metadata *AttrMDArgs[] = {
744+
llvm::ConstantAsMetadata::get(Builder.getInt32(1))};
745+
Fn->setMetadata("disable_loop_pipelining",
746+
llvm::MDNode::get(Context, AttrMDArgs));
747+
}
748+
749+
if (const auto *A = FD->getAttr<SYCLIntelFPGAInitiationIntervalAttr>()) {
750+
const auto *CE = cast<ConstantExpr>(A->getIntervalExpr());
751+
llvm::APSInt ArgVal = CE->getResultAsAPSInt();
752+
llvm::Metadata *AttrMDArgs[] = {
753+
llvm::ConstantAsMetadata::get(Builder.getInt32(ArgVal.getSExtValue()))};
754+
Fn->setMetadata("initiation_interval",
755+
llvm::MDNode::get(Context, AttrMDArgs));
756+
}
741757
}
742758

743759
/// Determine whether the function F ends with a return stmt.

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,8 +1139,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
11391139
Builder.defineMacro("__SYCL_NVPTX__", "1");
11401140
}
11411141
}
1142-
if (LangOpts.SYCLExplicitSIMD)
1143-
Builder.defineMacro("__SYCL_EXPLICIT_SIMD__", "1");
11441142
if (LangOpts.SYCLUnnamedLambda)
11451143
Builder.defineMacro("__SYCL_UNNAMED_LAMBDA__", "1");
11461144

0 commit comments

Comments
 (0)