Skip to content

Commit 3aa6cac

Browse files
author
iclsrc
committed
Merge from 'sycl' to 'sycl-web' (#10)
2 parents 98f64f0 + 9b7a317 commit 3aa6cac

File tree

102 files changed

+5283
-1195
lines changed

Some content is hidden

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

102 files changed

+5283
-1195
lines changed

CONTRIBUTING.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Contributing
22

33
## License
4-
Intel Project for LLVM* technology is licensed under the terms of the
4+
Intel Project for LLVM\* technology is licensed under the terms of the
55
Apache-2.0 with LLVM-exception license ([LICENSE.txt](llvm/LICENSE.TXT))
66
to ensure our ability to contribute this project to the LLVM project
77
under the same license.
@@ -70,11 +70,11 @@ commit automatically with `git commit -s`.
7070
### Development
7171

7272
- Create a personal fork of the project on GitHub
73-
- Use **sycl** branch as baseline for your changes
73+
- For the DPC++ Compiler project, use **sycl** branch as baseline for your
74+
changes. See [Get Started Guide](sycl/doc/GetStartedGuide.md).
7475
- Prepare your patch (follow
7576
[LLVM coding standards](https://llvm.org/docs/CodingStandards.html))
76-
- Build the project and run all tests (see
77-
[GetStartedWithSYCLCompiler.md](sycl/doc/GetStartedWithSYCLCompiler.md))
77+
- Build the project and run all tests
7878

7979
### Review and acceptance testing
8080

@@ -94,4 +94,8 @@ Project maintainers merge pull requests using one of the following options:
9494
- [Squash and merge] Used when there are multiple commits in the PR
9595
- Squashing is done to make sure that the project is buildable on any commit
9696
- [Create a merge commit] Used for LLVM pull-down PRs to preserve hashes of the
97-
commits pulled from the LLVM community repository
97+
commits pulled from the LLVM community repository
98+
99+
100+
*Other names and brands may be claimed as the property of others.
101+

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
# Intel Project for LLVM* technology
1+
# Intel Project for LLVM\* technology
22

33
## Introduction
44

55
Intel staging area for llvm.org contribution.
66
Home for Intel LLVM-based projects:
7-
- SYCL* Compiler and Runtimes - compiler and runtime libraries for SYCL ([https://www.khronos.org/sycl/](https://www.khronos.org/sycl/)). See **sycl** branch.
7+
- oneAPI Data Parallel C++ compiler - see **sycl** branch. More information on
8+
oneAPI and DPC++ is available at
9+
([https://www.oneapi.com/](https://www.oneapi.com/))
810

911
## License
1012
See [LICENSE.txt](sycl/LICENSE.TXT) for details.
1113

12-
1314
## Contributing
1415
See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
1516

1617
## Sub-projects Documentation
17-
- SYCL Compiler and Runtimes - See [GetStartedWithSYCLCompiler.md](sycl/doc/GetStartedWithSYCLCompiler.md)
18+
- oneAPI Data Parallel C++ compiler - See
19+
[GetStartedGuide.md](sycl/doc/GetStartedGuide.md)
1820

19-
*Other names and brands may be claimed as the property of others.
21+
## DPC++ extensions
2022

21-
## SYCL Extension Proposal Documents
23+
DPC++ is an open, cross-architecture language built upon the ISO C++ and Khronos
24+
SYCL\* standards. DPC++ extends these standards with a number of extensions,
25+
which can be found in [sycl/doc/extensions](sycl/doc/extensions) directory.
2226

23-
See [sycl/doc/extensions](sycl/doc/extensions)
27+
\*Other names and brands may be claimed as the property of others.
2428

buildbot/configure.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ def do_configure(args):
1010
llvm_dir = os.path.join(args.src_dir, "llvm")
1111
sycl_dir = os.path.join(args.src_dir, "sycl")
1212
spirv_dir = os.path.join(args.src_dir, "llvm-spirv")
13+
xpti_dir = os.path.join(args.src_dir, "xpti")
1314
ocl_header_dir = os.path.join(args.obj_dir, "OpenCL-Headers")
1415
icd_loader_lib = os.path.join(args.obj_dir, "OpenCL-ICD-Loader", "build")
1516
llvm_targets_to_build = 'X86'
16-
llvm_enable_projects = 'clang;llvm-spirv;sycl;opencl-aot'
17+
llvm_enable_projects = 'clang;llvm-spirv;sycl;opencl-aot;xpti'
1718
libclc_targets_to_build = ''
1819
sycl_build_pi_cuda = 'OFF'
1920
llvm_enable_assertions = 'ON'
@@ -44,9 +45,10 @@ def do_configure(args):
4445
"-DCMAKE_BUILD_TYPE={}".format(args.build_type),
4546
"-DLLVM_ENABLE_ASSERTIONS={}".format(llvm_enable_assertions),
4647
"-DLLVM_TARGETS_TO_BUILD={}".format(llvm_targets_to_build),
47-
"-DLLVM_EXTERNAL_PROJECTS=sycl;llvm-spirv;opencl-aot",
48+
"-DLLVM_EXTERNAL_PROJECTS=sycl;llvm-spirv;opencl-aot;xpti",
4849
"-DLLVM_EXTERNAL_SYCL_SOURCE_DIR={}".format(sycl_dir),
4950
"-DLLVM_EXTERNAL_LLVM_SPIRV_SOURCE_DIR={}".format(spirv_dir),
51+
"-DLLVM_EXTERNAL_XPTI_SOURCE_DIR={}".format(xpti_dir),
5052
"-DLLVM_ENABLE_PROJECTS={}".format(llvm_enable_projects),
5153
"-DLIBCLC_TARGETS_TO_BUILD={}".format(libclc_targets_to_build),
5254
"-DOpenCL_INCLUDE_DIR={}".format(ocl_header_dir),
@@ -57,6 +59,7 @@ def do_configure(args):
5759
"-DCMAKE_INSTALL_PREFIX={}".format(install_dir),
5860
"-DSYCL_INCLUDE_TESTS=ON", # Explicitly include all kinds of SYCL tests.
5961
"-DLLVM_ENABLE_DOXYGEN={}".format(llvm_enable_doxygen),
62+
"-DSYCL_ENABLE_XPTI_TRACING=ON", # Explicitly turn on XPTI tracing
6063
llvm_dir
6164
]
6265

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10648,7 +10648,9 @@ def err_sycl_restrict : Error<
1064810648
"|allocate storage"
1064910649
"|use inline assembly"
1065010650
"|call a dllimport function"
10651-
"|call a variadic function}0">;
10651+
"|call a variadic function"
10652+
"|call an undefined function without SYCL_EXTERNAL attribute"
10653+
"}0">;
1065210654
def err_sycl_virtual_types : Error<
1065310655
"No class with a vtable can be used in a SYCL kernel or any code included in the kernel">;
1065410656
def note_sycl_used_here : Note<"used here">;

clang/include/clang/Sema/Sema.h

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12316,11 +12316,13 @@ class Sema final {
1231612316
KernelAllocateStorage,
1231712317
KernelUseAssembly,
1231812318
KernelCallDllimportFunction,
12319-
KernelCallVariadicFunction
12320-
};
12319+
KernelCallVariadicFunction,
12320+
KernelCallUndefinedFunction
12321+
};
12322+
1232112323
bool isKnownGoodSYCLDecl(const Decl *D);
1232212324
void ConstructOpenCLKernel(FunctionDecl *KernelCallerFunc, MangleContext &MC);
12323-
void MarkDevice(void);
12325+
void MarkDevice();
1232412326

1232512327
/// Creates a DeviceDiagBuilder that emits the diagnostic if the current
1232612328
/// context is "used as device code".
@@ -12341,10 +12343,25 @@ class Sema final {
1234112343
/// SYCLDiagIfDeviceCode(Loc, diag::err_thread_unsupported);
1234212344
DeviceDiagBuilder SYCLDiagIfDeviceCode(SourceLocation Loc, unsigned DiagID);
1234312345

12344-
/// Checks if Callee function is a device function and emits
12345-
/// diagnostics if it is known that it is a device function, adds this
12346-
/// function to the DeviceCallGraph otherwise.
12347-
void checkSYCLDeviceFunction(SourceLocation Loc, FunctionDecl *Callee);
12346+
/// Check whether we're allowed to call Callee from the current context.
12347+
///
12348+
/// - If the call is never allowed in a semantically-correct program
12349+
/// emits an error and returns false.
12350+
///
12351+
/// - If the call is allowed in semantically-correct programs, but only if
12352+
/// it's never codegen'ed, creates a deferred diagnostic to be emitted if
12353+
/// and when the caller is codegen'ed, and returns true.
12354+
///
12355+
/// - Otherwise, returns true without emitting any diagnostics.
12356+
///
12357+
/// Adds Callee to DeviceCallGraph if we don't know if its caller will be
12358+
/// codegen'ed yet.
12359+
bool checkSYCLDeviceFunction(SourceLocation Loc, FunctionDecl *Callee);
12360+
12361+
/// Emit diagnostic that can't be emitted with deferred diagnostics mechanism.
12362+
/// At this step we imply that all device functions are marked with
12363+
/// sycl_device attribute.
12364+
void finalizeSYCLDelayedAnalysis();
1234812365
};
1234912366

1235012367
template <typename AttrType>

clang/lib/CodeGen/SYCLLowerIR/LowerWGScope.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -442,13 +442,15 @@ static void copyBetweenPrivateAndShadow(Value *L, GlobalVariable *Shadow,
442442
//
443443
static void materializeLocalsInWIScopeBlocksImpl(
444444
const DenseMap<BasicBlock *, std::unique_ptr<LocalsSet>> &BB2MatLocals,
445-
const DenseMap<AllocaInst *, GlobalVariable *> &Local2Shadow, const Triple &TT) {
445+
const DenseMap<AllocaInst *, GlobalVariable *> &Local2Shadow,
446+
const Triple &TT) {
446447
for (auto &P : BB2MatLocals) {
447448
// generate LeaderBB and private<->shadow copies in proper BBs
448449
BasicBlock *LeaderBB = P.first;
449450
BasicBlock *BB = LeaderBB->splitBasicBlock(&LeaderBB->front(), "LeaderMat");
450451
// Add a barrier to the original block:
451-
Instruction *At = spirv::genWGBarrier(*BB->getFirstNonPHI(), TT)->getNextNode();
452+
Instruction *At =
453+
spirv::genWGBarrier(*BB->getFirstNonPHI(), TT)->getNextNode();
452454

453455
for (AllocaInst *L : *P.second.get()) {
454456
auto MapEntry = Local2Shadow.find(L);
@@ -533,10 +535,9 @@ static bool localMustBeMaterialized(const AllocaInst *L, const BasicBlock &BB) {
533535
// have any noticible effect, though, as reading from Shadow always goes to a
534536
// register file anyway.
535537
//
536-
void materializeLocalsInWIScopeBlocks(
537-
SmallPtrSetImpl<AllocaInst *> &Locals,
538-
SmallPtrSetImpl<BasicBlock *> &WIScopeBBs,
539-
const Triple &TT) {
538+
void materializeLocalsInWIScopeBlocks(SmallPtrSetImpl<AllocaInst *> &Locals,
539+
SmallPtrSetImpl<BasicBlock *> &WIScopeBBs,
540+
const Triple &TT) {
540541
// maps local variable to its "shadow" workgroup-shared global:
541542
DenseMap<AllocaInst *, GlobalVariable *> Local2Shadow;
542543
// records which locals must be materialized at the beginning of a block:
@@ -718,8 +719,7 @@ static void shareByValParams(Function &F, const Triple &TT) {
718719
spirv::genWGBarrier(MergeBB->front(), TT);
719720
}
720721

721-
PreservedAnalyses SYCLLowerWGScopePass::run(Function &F,
722-
const llvm::Triple &TT,
722+
PreservedAnalyses SYCLLowerWGScopePass::run(Function &F, const llvm::Triple &TT,
723723
FunctionAnalysisManager &FAM) {
724724
if (!F.getMetadata(WG_SCOPE_MD))
725725
return PreservedAnalyses::all();
@@ -876,16 +876,16 @@ Value *spirv::genLinearLocalID(Instruction &Before, const Triple &TT) {
876876
IRBuilder<> Bld(Ctx);
877877
Bld.SetInsertPoint(&Before);
878878

879-
#define CREATE_CALLEE(NAME, FN_NAME) \
880-
FunctionCallee FnCallee##NAME = M.getOrInsertFunction(FN_NAME, RetTy); \
881-
assert(FnCallee##NAME && "spirv intrinsic creation failed"); \
879+
#define CREATE_CALLEE(NAME, FN_NAME) \
880+
FunctionCallee FnCallee##NAME = M.getOrInsertFunction(FN_NAME, RetTy); \
881+
assert(FnCallee##NAME && "spirv intrinsic creation failed"); \
882882
auto NAME = Bld.CreateCall(FnCallee##NAME, {});
883883

884-
CREATE_CALLEE(LocalInvocationId_X, "_Z27__spirv_LocalInvocationId_xv");
885-
CREATE_CALLEE(LocalInvocationId_Y, "_Z27__spirv_LocalInvocationId_yv");
886-
CREATE_CALLEE(LocalInvocationId_Z, "_Z27__spirv_LocalInvocationId_zv");
887-
CREATE_CALLEE(WorkgroupSize_Y, "_Z23__spirv_WorkgroupSize_yv");
888-
CREATE_CALLEE(WorkgroupSize_Z, "_Z23__spirv_WorkgroupSize_zv");
884+
CREATE_CALLEE(LocalInvocationId_X, "_Z27__spirv_LocalInvocationId_xv");
885+
CREATE_CALLEE(LocalInvocationId_Y, "_Z27__spirv_LocalInvocationId_yv");
886+
CREATE_CALLEE(LocalInvocationId_Z, "_Z27__spirv_LocalInvocationId_zv");
887+
CREATE_CALLEE(WorkgroupSize_Y, "_Z23__spirv_WorkgroupSize_yv");
888+
CREATE_CALLEE(WorkgroupSize_Z, "_Z23__spirv_WorkgroupSize_zv");
889889

890890
#undef CREATE_CALLEE
891891

@@ -894,12 +894,11 @@ Value *spirv::genLinearLocalID(Instruction &Before, const Triple &TT) {
894894
// 3: + (__spirv_WorkgroupSize_z() * __spirv_LocalInvocationId_y())
895895
// 4: + (__spirv_LocalInvocationId_z())
896896
return Bld.CreateAdd(
897-
Bld.CreateAdd(
898-
Bld.CreateMul(
899-
Bld.CreateMul(WorkgroupSize_Y, WorkgroupSize_Z), // 1
900-
LocalInvocationId_X), // 2
901-
Bld.CreateMul(WorkgroupSize_Z, LocalInvocationId_Y)), // 3
902-
LocalInvocationId_Z); // 4
897+
Bld.CreateAdd(
898+
Bld.CreateMul(Bld.CreateMul(WorkgroupSize_Y, WorkgroupSize_Z), // 1
899+
LocalInvocationId_X), // 2
900+
Bld.CreateMul(WorkgroupSize_Z, LocalInvocationId_Y)), // 3
901+
LocalInvocationId_Z); // 4
903902
} else {
904903
StringRef Name = "__spirv_BuiltInLocalInvocationIndex";
905904
GlobalVariable *G = M.getGlobalVariable(Name);

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4124,6 +4124,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
41244124
} else if (IsSYCL) {
41254125
// Ensure the default version in SYCL mode is 1.2.1
41264126
CmdArgs.push_back("-sycl-std=1.2.1");
4127+
// The user had not pass SYCL version, thus we'll employ no-sycl-strict
4128+
// to allow address-space unqualified pointers in function params/return
4129+
// along with marking the same function with explicit SYCL_EXTERNAL
4130+
CmdArgs.push_back("-Wno-sycl-strict");
41274131
}
41284132

41294133
if (IsOpenMPDevice) {

clang/lib/Sema/Sema.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,7 @@ void Sema::ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind) {
974974
if (SyclIntHeader != nullptr)
975975
SyclIntHeader->emit(getLangOpts().SYCLIntHeader);
976976
MarkDevice();
977+
finalizeSYCLDelayedAnalysis();
977978
}
978979

979980
// Finalize analysis of OpenMP-specific constructs.

clang/lib/Sema/SemaDecl.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18016,6 +18016,12 @@ Decl *Sema::getObjCDeclContext() const {
1801618016
}
1801718017

1801818018
Sema::FunctionEmissionStatus Sema::getEmissionStatus(FunctionDecl *FD) {
18019+
// Due to SYCL functions are template we check if they have appropriate
18020+
// attribute prior to checking if it is a template
18021+
if (LangOpts.SYCLIsDevice &&
18022+
(FD->hasAttr<SYCLDeviceAttr>() || FD->hasAttr<SYCLKernelAttr>()))
18023+
return FunctionEmissionStatus::Emitted;
18024+
1801918025
// Templates are emitted when they're instantiated.
1802018026
if (FD->isDependentContext())
1802118027
return FunctionEmissionStatus::TemplateDiscarded;
@@ -18080,6 +18086,23 @@ Sema::FunctionEmissionStatus Sema::getEmissionStatus(FunctionDecl *FD) {
1808018086
return FunctionEmissionStatus::Emitted;
1808118087
}
1808218088

18089+
if (getLangOpts().SYCLIsDevice) {
18090+
if (!FD->hasAttr<SYCLDeviceAttr>() && !FD->hasAttr<SYCLKernelAttr>())
18091+
return FunctionEmissionStatus::Unknown;
18092+
18093+
// Check whether this function is externally visible -- if so, it's
18094+
// known-emitted.
18095+
//
18096+
// We have to check the GVA linkage of the function's *definition* -- if we
18097+
// only have a declaration, we don't know whether or not the function will
18098+
// be emitted, because (say) the definition could include "inline".
18099+
FunctionDecl *Def = FD->getDefinition();
18100+
18101+
if (Def &&
18102+
!isDiscardableGVALinkage(getASTContext().GetGVALinkageForFunction(Def)))
18103+
return FunctionEmissionStatus::Emitted;
18104+
}
18105+
1808318106
// Otherwise, the function is known-emitted if it's in our set of
1808418107
// known-emitted functions.
1808518108
return (DeviceKnownEmittedFns.count(FD) > 0)

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2895,7 +2895,7 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr,
28952895
if (const auto *A = D->getAttr<SYCLIntelMaxGlobalWorkDimAttr>())
28962896
if (A->getNumber() == 0)
28972897
Result &= checkZeroDim(A, WGSize[0], WGSize[1], WGSize[2],
2898-
/*ReverseAttrs=*/ true);
2898+
/*ReverseAttrs=*/true);
28992899

29002900
if (const auto *A = D->getAttr<SYCLIntelMaxWorkGroupSizeAttr>()) {
29012901
if (!(WGSize[0] <= A->getXDim() && WGSize[1] <= A->getYDim() &&
@@ -2935,14 +2935,17 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
29352935
}
29362936
}
29372937

2938-
if (!checkWorkGroupSizeValues(S, D, AL, WGSize))
2939-
return;
2940-
2938+
// For a SYCLDevice WorkGroupAttr arguments are reversed
2939+
if (S.getLangOpts().SYCLIsDevice) {
2940+
std::swap(WGSize[0], WGSize[2]);
2941+
}
29412942
WorkGroupAttr *Existing = D->getAttr<WorkGroupAttr>();
2942-
if (Existing && !(Existing->getXDim() == WGSize[0] &&
2943-
Existing->getYDim() == WGSize[1] &&
2944-
Existing->getZDim() == WGSize[2]))
2943+
if (Existing &&
2944+
!(Existing->getXDim() == WGSize[0] && Existing->getYDim() == WGSize[1] &&
2945+
Existing->getZDim() == WGSize[2]))
29452946
S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
2947+
if (!checkWorkGroupSizeValues(S, D, AL, WGSize))
2948+
return;
29462949

29472950
D->addAttr(::new (S.Context)
29482951
WorkGroupAttr(S.Context, AL, WGSize[0], WGSize[1], WGSize[2]));

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14684,8 +14684,9 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
1468414684
MarkFunctionReferenced(ConstructLoc, Constructor);
1468514685
if (getLangOpts().CUDA && !CheckCUDACall(ConstructLoc, Constructor))
1468614686
return ExprError();
14687-
if (getLangOpts().SYCLIsDevice)
14688-
checkSYCLDeviceFunction(ConstructLoc, Constructor);
14687+
if (getLangOpts().SYCLIsDevice &&
14688+
!checkSYCLDeviceFunction(ConstructLoc, Constructor))
14689+
return ExprError();
1468914690

1469014691
return CXXConstructExpr::Create(
1469114692
Context, DeclInitType, ConstructLoc, Constructor, Elidable,

clang/lib/Sema/SemaExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs,
301301
if (getLangOpts().CUDA && !CheckCUDACall(Loc, FD))
302302
return true;
303303

304-
if (getLangOpts().SYCLIsDevice)
305-
checkSYCLDeviceFunction(Loc, FD);
304+
if (getLangOpts().SYCLIsDevice && !checkSYCLDeviceFunction(Loc, FD))
305+
return true;
306306
}
307307

308308
if (auto *MD = dyn_cast<CXXMethodDecl>(D)) {

0 commit comments

Comments
 (0)