Skip to content

Commit 7673dd6

Browse files
authored
Merge branch 'sycl' into clangusm
2 parents 955618a + 5f1c8d4 commit 7673dd6

Some content is hidden

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

54 files changed

+1698
-1063
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ Home for Intel LLVM-based projects:
77
- SYCL* Compiler and Runtimes - compiler and runtime libraries for SYCL ([https://www.khronos.org/sycl/](https://www.khronos.org/sycl/)). See **sycl** branch.
88

99
## License
10-
See [LICENSE.txt](https://github.com/intel/llvm/blob/intel/llvm/LICENSE.TXT) for details.
10+
See [LICENSE.txt](sycl/LICENSE.TXT) for details.
1111

1212

1313
## Contributing
14-
See [CONTRIBUTING.md](https://github.com/intel/llvm/blob/intel/CONTRIBUTING.md) for details.
14+
See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
1515

1616
## Sub-projects Documentation
17-
- SYCL Compiler and Runtimes - See [GetStartedWithSYCLCompiler.md](https://github.com/intel/llvm/blob/sycl/sycl/doc/GetStartedWithSYCLCompiler.md)
17+
- SYCL Compiler and Runtimes - See [GetStartedWithSYCLCompiler.md](sycl/doc/GetStartedWithSYCLCompiler.md)
1818

1919
*Other names and brands may be claimed as the property of others.
2020

2121
## SYCL Extension Proposal Documents
2222

23-
See [sycl/doc/extensions](https://github.com/intel/llvm/tree/sycl/sycl/doc/extensions)
23+
See [sycl/doc/extensions](sycl/doc/extensions)

clang/include/clang/Basic/Attr.td

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,41 @@ def IntelFPGAMaxPrivateCopies : InheritableAttr {
15601560
}];
15611561
}
15621562

1563+
// Two string arguments.
1564+
def IntelFPGAMerge : Attr {
1565+
let Spellings = [CXX11<"intelfpga","merge">];
1566+
let Args = [StringArgument<"Name">, StringArgument<"Direction">];
1567+
let Subjects = SubjectList<[IntelFPGAConstVar, IntelFPGALocalOrStaticVar,
1568+
Field], ErrorDiag>;
1569+
let LangOpts = [SYCL];
1570+
let Documentation = [IntelFPGAMergeAttrDocs];
1571+
}
1572+
1573+
def IntelFPGAMaxReplicates : Attr {
1574+
let Spellings = [CXX11<"intelfpga","max_replicates">];
1575+
let Args = [ExprArgument<"Value">];
1576+
let Subjects = SubjectList<[IntelFPGAConstVar, IntelFPGALocalStaticSlaveMemVar,
1577+
Field], ErrorDiag>;
1578+
let LangOpts = [SYCL];
1579+
let Documentation = [IntelFPGAMaxReplicatesAttrDocs];
1580+
let AdditionalMembers = [{
1581+
static unsigned getMinValue() {
1582+
return 1;
1583+
}
1584+
static unsigned getMaxValue() {
1585+
return 1024*1024;
1586+
}
1587+
}];
1588+
}
1589+
1590+
def IntelFPGASimpleDualPort : Attr {
1591+
let Spellings = [CXX11<"intelfpga","simple_dual_port">];
1592+
let Subjects = SubjectList<[IntelFPGAConstVar, IntelFPGALocalStaticSlaveMemVar,
1593+
Field], ErrorDiag>;
1594+
let LangOpts = [SYCL];
1595+
let Documentation = [IntelFPGASimpleDualPortAttrDocs];
1596+
}
1597+
15631598
def Naked : InheritableAttr {
15641599
let Spellings = [GCC<"naked">, Declspec<"naked">];
15651600
let Subjects = SubjectList<[Function]>;

clang/include/clang/Basic/AttrDocs.td

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,40 @@ threads or loop iterations.
17141714
}];
17151715
}
17161716

1717+
def IntelFPGAMergeAttrDocs : Documentation {
1718+
let Category = DocCatVariable;
1719+
let Heading = "merge (IntelFPGA)";
1720+
let Content = [{
1721+
This attribute may be attached to a variable or struct member declaration and
1722+
instructs the backend to merge the memories used to implement any variable or
1723+
struct members that are annotated with this attribute and the same first
1724+
argument. The second argument indicates if the memories should be merged in a
1725+
depth-wise or width-wise manner.
1726+
}];
1727+
}
1728+
1729+
def IntelFPGAMaxReplicatesAttrDocs : Documentation {
1730+
let Category = DocCatVariable;
1731+
let Heading = "max_replicates (IntelFPGA)";
1732+
let Content = [{
1733+
This attribute may be attached to a variable or struct member declaration and
1734+
instructs the backend to replicate the memory generated for the variable or
1735+
struct member no more than the specified maximum number of times to enable
1736+
simultaneous accesses from different load/store sites in the program.
1737+
}];
1738+
}
1739+
1740+
def IntelFPGASimpleDualPortAttrDocs : Documentation {
1741+
let Category = DocCatVariable;
1742+
let Heading = "simple_dual_port (IntelFPGA)";
1743+
let Content = [{
1744+
This attribute may be attached to a variable or struct member declaration and
1745+
instructs the backend to implement the variable or struct member in a memory
1746+
with simple dual port configuration (no memory port services both stores and
1747+
loads).
1748+
}];
1749+
}
1750+
17171751
def SYCLIntelFPGAIVDepAttrDocs : Documentation {
17181752
let Category = DocCatVariable;
17191753
let Heading = "ivdep";

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ def err_intel_fpga_memory_arg_invalid : Error<
130130
"%0 attribute requires either no argument or one of: %1">;
131131
def err_intel_fpga_loop_attr_duplication : Error<
132132
"duplicate Intel FPGA loop attribute '%0'">;
133+
def err_intel_fpga_merge_dir_invalid : Error<
134+
"merge direction must be 'depth' or 'width'">;
133135

134136
// C99 variable-length arrays
135137
def ext_vla : Extension<"variable length arrays are a C99 feature">,

clang/lib/CodeGen/CGLoopInfo.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,12 @@ MDNode *LoopInfo::createMetadata(
446446

447447
LoopAttributes::LoopAttributes(bool IsParallel)
448448
: IsParallel(IsParallel), VectorizeEnable(LoopAttributes::Unspecified),
449-
SYCLIVDepEnable(false), SYCLIVDepSafelen(0), SYCLIInterval(0),
450-
SYCLMaxConcurrencyNThreads(0),
451449
UnrollEnable(LoopAttributes::Unspecified),
452450
UnrollAndJamEnable(LoopAttributes::Unspecified), VectorizeWidth(0),
453-
InterleaveCount(0), UnrollCount(0), UnrollAndJamCount(0),
454-
DistributeEnable(LoopAttributes::Unspecified), PipelineDisabled(false),
455-
PipelineInitiationInterval(0) {}
451+
InterleaveCount(0), SYCLIVDepEnable(false), SYCLIVDepSafelen(0),
452+
SYCLIInterval(0), SYCLMaxConcurrencyNThreads(0), UnrollCount(0),
453+
UnrollAndJamCount(0), DistributeEnable(LoopAttributes::Unspecified),
454+
PipelineDisabled(false), PipelineInitiationInterval(0) {}
456455

457456
void LoopAttributes::clear() {
458457
IsParallel = false;

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3800,6 +3800,16 @@ void CodeGenModule::generateIntelFPGAAnnotation(
38003800
llvm::APSInt BWAInt = NBA->getValue()->EvaluateKnownConstInt(getContext());
38013801
Out << '{' << NBA->getSpelling() << ':' << BWAInt << '}';
38023802
}
3803+
if (const auto *MRA = D->getAttr<IntelFPGAMaxReplicatesAttr>()) {
3804+
llvm::APSInt MRAInt = MRA->getValue()->EvaluateKnownConstInt(getContext());
3805+
Out << '{' << MRA->getSpelling() << ':' << MRAInt << '}';
3806+
}
3807+
if (const auto *MA = D->getAttr<IntelFPGAMergeAttr>()) {
3808+
Out << '{' << MA->getSpelling() << ':' << MA->getName() << ':'
3809+
<< MA->getDirection() << '}';
3810+
}
3811+
if (D->hasAttr<IntelFPGASimpleDualPortAttr>())
3812+
Out << "{simple_dual_port:1}";
38033813
}
38043814

38053815
void CodeGenModule::addGlobalIntelFPGAAnnotation(const VarDecl *VD,

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5091,6 +5091,12 @@ static bool checkIntelFPGARegisterAttrCompatibility(Sema &S, Decl *D,
50915091
if (!NBA->isImplicit() &&
50925092
checkAttrMutualExclusion<IntelFPGANumBanksAttr>(S, D, Attr))
50935093
InCompat = true;
5094+
if (checkAttrMutualExclusion<IntelFPGAMaxReplicatesAttr>(S, D, Attr))
5095+
InCompat = true;
5096+
if (checkAttrMutualExclusion<IntelFPGASimpleDualPortAttr>(S, D, Attr))
5097+
InCompat = true;
5098+
if (checkAttrMutualExclusion<IntelFPGAMergeAttr>(S, D, Attr))
5099+
InCompat = true;
50945100

50955101
return InCompat;
50965102
}
@@ -5124,6 +5130,65 @@ static void handleOneConstantPowerTwoValueAttr(Sema &S, Decl *D,
51245130
Attr.getAttributeSpellingListIndex());
51255131
}
51265132

5133+
static void handleIntelFPGASimpleDualPortAttr(Sema &S, Decl *D,
5134+
const ParsedAttr &Attr) {
5135+
checkForDuplicateAttribute<IntelFPGASimpleDualPortAttr>(S, D, Attr);
5136+
5137+
if (checkAttrMutualExclusion<IntelFPGARegisterAttr>(S, D, Attr))
5138+
return;
5139+
5140+
if (!D->hasAttr<IntelFPGAMemoryAttr>())
5141+
D->addAttr(IntelFPGAMemoryAttr::CreateImplicit(
5142+
S.Context, IntelFPGAMemoryAttr::Default));
5143+
5144+
D->addAttr(::new (S.Context)
5145+
IntelFPGASimpleDualPortAttr(Attr.getRange(), S.Context, 0));
5146+
}
5147+
5148+
static void handleIntelFPGAMaxReplicatesAttr(Sema &S, Decl *D,
5149+
const ParsedAttr &Attr) {
5150+
checkForDuplicateAttribute<IntelFPGAMaxReplicatesAttr>(S, D, Attr);
5151+
5152+
if (checkAttrMutualExclusion<IntelFPGARegisterAttr>(S, D, Attr))
5153+
return;
5154+
5155+
S.AddOneConstantValueAttr<IntelFPGAMaxReplicatesAttr>(
5156+
Attr.getRange(), D, Attr.getArgAsExpr(0),
5157+
Attr.getAttributeSpellingListIndex());
5158+
}
5159+
5160+
/// Handle the merge attribute.
5161+
/// This requires two string arguments. The first argument is a name, the
5162+
/// second is a direction. The direction must be "depth" or "width".
5163+
/// This is incompatible with the register attribute.
5164+
static void handleIntelFPGAMergeAttr(Sema &S, Decl *D, const ParsedAttr &Attr) {
5165+
checkForDuplicateAttribute<IntelFPGAMergeAttr>(S, D, Attr);
5166+
5167+
if (checkAttrMutualExclusion<IntelFPGARegisterAttr>(S, D, Attr))
5168+
return;
5169+
5170+
SmallVector<StringRef, 2> Results;
5171+
for (int I = 0; I < 2; I++) {
5172+
StringRef Str;
5173+
if (!S.checkStringLiteralArgumentAttr(Attr, I, Str))
5174+
return;
5175+
5176+
if (I == 1 && Str != "depth" && Str != "width") {
5177+
S.Diag(Attr.getLoc(), diag::err_intel_fpga_merge_dir_invalid) << Attr;
5178+
return;
5179+
}
5180+
Results.push_back(Str);
5181+
}
5182+
5183+
if (!D->hasAttr<IntelFPGAMemoryAttr>())
5184+
D->addAttr(IntelFPGAMemoryAttr::CreateImplicit(
5185+
S.Context, IntelFPGAMemoryAttr::Default));
5186+
5187+
D->addAttr(::new (S.Context) IntelFPGAMergeAttr(
5188+
Attr.getRange(), S.Context, Results[0], Results[1],
5189+
Attr.getAttributeSpellingListIndex()));
5190+
}
5191+
51275192
static void handleIntelFPGAMaxPrivateCopiesAttr(Sema &S, Decl *D,
51285193
const ParsedAttr &Attr) {
51295194
checkForDuplicateAttribute<IntelFPGAMaxPrivateCopiesAttr>(S, D, Attr);
@@ -7509,6 +7574,15 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
75097574
case ParsedAttr::AT_IntelFPGAMaxPrivateCopies:
75107575
handleIntelFPGAMaxPrivateCopiesAttr(S, D, AL);
75117576
break;
7577+
case ParsedAttr::AT_IntelFPGAMaxReplicates:
7578+
handleIntelFPGAMaxReplicatesAttr(S, D, AL);
7579+
break;
7580+
case ParsedAttr::AT_IntelFPGASimpleDualPort:
7581+
handleIntelFPGASimpleDualPortAttr(S, D, AL);
7582+
break;
7583+
case ParsedAttr::AT_IntelFPGAMerge:
7584+
handleIntelFPGAMergeAttr(S, D, AL);
7585+
break;
75127586

75137587
case ParsedAttr::AT_AnyX86NoCallerSavedRegisters:
75147588
handleSimpleAttribute<AnyX86NoCallerSavedRegistersAttr>(S, D, AL);

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,23 @@ class KernelBodyTransform : public TreeTransform<KernelBodyTransform> {
395395
auto NewDecl = MappingPair.second;
396396
return DeclRefExpr::Create(
397397
SemaRef.getASTContext(), DRE->getQualifierLoc(),
398-
DRE->getTemplateKeywordLoc(), NewDecl, false, DRE->getNameInfo(),
398+
DRE->getTemplateKeywordLoc(), NewDecl, false,
399+
DeclarationNameInfo(DRE->getNameInfo().getName(), SourceLocation(),
400+
DRE->getNameInfo().getInfo()),
399401
NewDecl->getType(), DRE->getValueKind());
400402
}
401403
return DRE;
402404
}
403405

406+
StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
407+
MultiStmtArg Statements,
408+
SourceLocation RBraceLoc,
409+
bool IsStmtExpr) {
410+
// Build a new compound statement but clear the source locations.
411+
return getSema().ActOnCompoundStmt(SourceLocation(), SourceLocation(),
412+
Statements, IsStmtExpr);
413+
}
414+
404415
private:
405416
std::pair<DeclaratorDecl *, DeclaratorDecl *> MappingPair;
406417
Sema &SemaRef;
@@ -530,8 +541,8 @@ static CompoundStmt *CreateOpenCLKernelBody(Sema &S,
530541
auto ME = MemberExpr::Create(
531542
S.Context, SpecialObjME, false, SourceLocation(),
532543
NestedNameSpecifierLoc(), SourceLocation(), InitMethod, MethodDAP,
533-
InitMethod->getNameInfo(), nullptr, InitMethod->getType(),
534-
VK_LValue, OK_Ordinary);
544+
DeclarationNameInfo(InitMethod->getDeclName(), SourceLocation()),
545+
nullptr, InitMethod->getType(), VK_LValue, OK_Ordinary);
535546

536547
// Not referenced -> not emitted
537548
S.MarkFunctionReferenced(SourceLocation(), InitMethod, true);
Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,38 @@
1-
// RUN: %clang --sycl %s -S -emit-llvm -g -o - | FileCheck %s --check-prefixes CHECK
1+
// RUN: %clang --sycl %s -S -I %S/Inputs -emit-llvm -g -o - | FileCheck %s
22
//
3-
// Verify the SYCL kernel routine is marked artificial.
3+
// Verify the SYCL kernel routine is marked artificial and has no source
4+
// correlation.
45
//
5-
// Since it has no source correlation of its own, the SYCL kernel needs to be
6-
// marked artificial or it will inherit source correlation from the surrounding
7-
// code.
6+
// The SYCL kernel should have no source correlation of its own, so it needs
7+
// to be marked artificial or it will inherit source correlation from the
8+
// surrounding code.
89
//
910

10-
template <typename Name, typename Func>
11-
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
11+
#include <sycl.hpp>
12+
13+
template <typename name, typename Func>
14+
__attribute__((sycl_kernel)) void kernel(Func kernelFunc) {
1215
kernelFunc();
1316
}
1417

1518
int main() {
16-
int value = 0;
17-
int* captured = &value;
18-
kernel_single_task<class kernel_function>([=]() {
19-
*captured = 1;
20-
});
19+
cl::sycl::sampler Sampler;
20+
kernel<class use_kernel_for_test>([=]() {
21+
Sampler.use();
22+
});
2123
return 0;
2224
}
2325

24-
25-
// CHECK: define{{.*}} spir_kernel {{.*}}void @_ZTSZ4mainE15kernel_function(i32 addrspace(1)*{{.*}}){{.*}} !dbg [[KERNEL:![0-9]+]] {{.*}}{
26+
// CHECK: define{{.*}} spir_kernel {{.*}}19use_kernel_for_test({{.*}}){{.*}} !dbg [[KERNEL:![0-9]+]] {{.*}}{
27+
// CHECK: getelementptr inbounds %"class.{{.*}}.anon"{{.*}} !dbg [[LINE_A0:![0-9]+]]
28+
// CHECK: call spir_func void {{.*}}6__init{{.*}} !dbg [[LINE_A0]]
29+
// CHECK: call spir_func void @"_ZZ4mainENK3$_0clEv"{{.*}} !dbg [[LINE_B0:![0-9]+]]
30+
// CHECK: ret void, !dbg [[LINE_A0]]
2631
// CHECK: [[FILE:![0-9]+]] = !DIFile(filename: "{{.*}}debug-info-srcpos-kernel.cpp"{{.*}})
27-
// CHECK: [[KERNEL]] = {{.*}}!DISubprogram(name: "_ZTSZ4mainE15kernel_function"
32+
// CHECK: [[KERNEL]] = {{.*}}!DISubprogram(name: "{{.*}}19use_kernel_for_test"
2833
// CHECK-SAME: scope: [[FILE]]
2934
// CHECK-SAME: file: [[FILE]]
3035
// CHECK-SAME: flags: DIFlagArtificial | DIFlagPrototyped
36+
// CHECK: [[LINE_A0]] = !DILocation(line: 0
37+
// CHECK: [[LINE_B0]] = !DILocation(line: 0
38+

0 commit comments

Comments
 (0)