Skip to content

Commit

Permalink
Merge from 'sycl' to 'sycl-web' (triSYCL#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
iclsrc committed Mar 11, 2020
2 parents 98f64f0 + 9b7a317 commit 3aa6cac
Show file tree
Hide file tree
Showing 102 changed files with 5,283 additions and 1,195 deletions.
14 changes: 9 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Contributing

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

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

### Review and acceptance testing

Expand All @@ -94,4 +94,8 @@ Project maintainers merge pull requests using one of the following options:
- [Squash and merge] Used when there are multiple commits in the PR
- Squashing is done to make sure that the project is buildable on any commit
- [Create a merge commit] Used for LLVM pull-down PRs to preserve hashes of the
commits pulled from the LLVM community repository
commits pulled from the LLVM community repository


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

18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
# Intel Project for LLVM* technology
# Intel Project for LLVM\* technology

## Introduction

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

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


## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md) for details.

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

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

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

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

7 changes: 5 additions & 2 deletions buildbot/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ def do_configure(args):
llvm_dir = os.path.join(args.src_dir, "llvm")
sycl_dir = os.path.join(args.src_dir, "sycl")
spirv_dir = os.path.join(args.src_dir, "llvm-spirv")
xpti_dir = os.path.join(args.src_dir, "xpti")
ocl_header_dir = os.path.join(args.obj_dir, "OpenCL-Headers")
icd_loader_lib = os.path.join(args.obj_dir, "OpenCL-ICD-Loader", "build")
llvm_targets_to_build = 'X86'
llvm_enable_projects = 'clang;llvm-spirv;sycl;opencl-aot'
llvm_enable_projects = 'clang;llvm-spirv;sycl;opencl-aot;xpti'
libclc_targets_to_build = ''
sycl_build_pi_cuda = 'OFF'
llvm_enable_assertions = 'ON'
Expand Down Expand Up @@ -44,9 +45,10 @@ def do_configure(args):
"-DCMAKE_BUILD_TYPE={}".format(args.build_type),
"-DLLVM_ENABLE_ASSERTIONS={}".format(llvm_enable_assertions),
"-DLLVM_TARGETS_TO_BUILD={}".format(llvm_targets_to_build),
"-DLLVM_EXTERNAL_PROJECTS=sycl;llvm-spirv;opencl-aot",
"-DLLVM_EXTERNAL_PROJECTS=sycl;llvm-spirv;opencl-aot;xpti",
"-DLLVM_EXTERNAL_SYCL_SOURCE_DIR={}".format(sycl_dir),
"-DLLVM_EXTERNAL_LLVM_SPIRV_SOURCE_DIR={}".format(spirv_dir),
"-DLLVM_EXTERNAL_XPTI_SOURCE_DIR={}".format(xpti_dir),
"-DLLVM_ENABLE_PROJECTS={}".format(llvm_enable_projects),
"-DLIBCLC_TARGETS_TO_BUILD={}".format(libclc_targets_to_build),
"-DOpenCL_INCLUDE_DIR={}".format(ocl_header_dir),
Expand All @@ -57,6 +59,7 @@ def do_configure(args):
"-DCMAKE_INSTALL_PREFIX={}".format(install_dir),
"-DSYCL_INCLUDE_TESTS=ON", # Explicitly include all kinds of SYCL tests.
"-DLLVM_ENABLE_DOXYGEN={}".format(llvm_enable_doxygen),
"-DSYCL_ENABLE_XPTI_TRACING=ON", # Explicitly turn on XPTI tracing
llvm_dir
]

Expand Down
4 changes: 3 additions & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -10648,7 +10648,9 @@ def err_sycl_restrict : Error<
"|allocate storage"
"|use inline assembly"
"|call a dllimport function"
"|call a variadic function}0">;
"|call a variadic function"
"|call an undefined function without SYCL_EXTERNAL attribute"
"}0">;
def err_sycl_virtual_types : Error<
"No class with a vtable can be used in a SYCL kernel or any code included in the kernel">;
def note_sycl_used_here : Note<"used here">;
Expand Down
31 changes: 24 additions & 7 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -12316,11 +12316,13 @@ class Sema final {
KernelAllocateStorage,
KernelUseAssembly,
KernelCallDllimportFunction,
KernelCallVariadicFunction
};
KernelCallVariadicFunction,
KernelCallUndefinedFunction
};

bool isKnownGoodSYCLDecl(const Decl *D);
void ConstructOpenCLKernel(FunctionDecl *KernelCallerFunc, MangleContext &MC);
void MarkDevice(void);
void MarkDevice();

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

/// Checks if Callee function is a device function and emits
/// diagnostics if it is known that it is a device function, adds this
/// function to the DeviceCallGraph otherwise.
void checkSYCLDeviceFunction(SourceLocation Loc, FunctionDecl *Callee);
/// Check whether we're allowed to call Callee from the current context.
///
/// - If the call is never allowed in a semantically-correct program
/// emits an error and returns false.
///
/// - If the call is allowed in semantically-correct programs, but only if
/// it's never codegen'ed, creates a deferred diagnostic to be emitted if
/// and when the caller is codegen'ed, and returns true.
///
/// - Otherwise, returns true without emitting any diagnostics.
///
/// Adds Callee to DeviceCallGraph if we don't know if its caller will be
/// codegen'ed yet.
bool checkSYCLDeviceFunction(SourceLocation Loc, FunctionDecl *Callee);

/// Emit diagnostic that can't be emitted with deferred diagnostics mechanism.
/// At this step we imply that all device functions are marked with
/// sycl_device attribute.
void finalizeSYCLDelayedAnalysis();
};

template <typename AttrType>
Expand Down
43 changes: 21 additions & 22 deletions clang/lib/CodeGen/SYCLLowerIR/LowerWGScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,15 @@ static void copyBetweenPrivateAndShadow(Value *L, GlobalVariable *Shadow,
//
static void materializeLocalsInWIScopeBlocksImpl(
const DenseMap<BasicBlock *, std::unique_ptr<LocalsSet>> &BB2MatLocals,
const DenseMap<AllocaInst *, GlobalVariable *> &Local2Shadow, const Triple &TT) {
const DenseMap<AllocaInst *, GlobalVariable *> &Local2Shadow,
const Triple &TT) {
for (auto &P : BB2MatLocals) {
// generate LeaderBB and private<->shadow copies in proper BBs
BasicBlock *LeaderBB = P.first;
BasicBlock *BB = LeaderBB->splitBasicBlock(&LeaderBB->front(), "LeaderMat");
// Add a barrier to the original block:
Instruction *At = spirv::genWGBarrier(*BB->getFirstNonPHI(), TT)->getNextNode();
Instruction *At =
spirv::genWGBarrier(*BB->getFirstNonPHI(), TT)->getNextNode();

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

PreservedAnalyses SYCLLowerWGScopePass::run(Function &F,
const llvm::Triple &TT,
PreservedAnalyses SYCLLowerWGScopePass::run(Function &F, const llvm::Triple &TT,
FunctionAnalysisManager &FAM) {
if (!F.getMetadata(WG_SCOPE_MD))
return PreservedAnalyses::all();
Expand Down Expand Up @@ -876,16 +876,16 @@ Value *spirv::genLinearLocalID(Instruction &Before, const Triple &TT) {
IRBuilder<> Bld(Ctx);
Bld.SetInsertPoint(&Before);

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

CREATE_CALLEE(LocalInvocationId_X, "_Z27__spirv_LocalInvocationId_xv");
CREATE_CALLEE(LocalInvocationId_Y, "_Z27__spirv_LocalInvocationId_yv");
CREATE_CALLEE(LocalInvocationId_Z, "_Z27__spirv_LocalInvocationId_zv");
CREATE_CALLEE(WorkgroupSize_Y, "_Z23__spirv_WorkgroupSize_yv");
CREATE_CALLEE(WorkgroupSize_Z, "_Z23__spirv_WorkgroupSize_zv");
CREATE_CALLEE(LocalInvocationId_X, "_Z27__spirv_LocalInvocationId_xv");
CREATE_CALLEE(LocalInvocationId_Y, "_Z27__spirv_LocalInvocationId_yv");
CREATE_CALLEE(LocalInvocationId_Z, "_Z27__spirv_LocalInvocationId_zv");
CREATE_CALLEE(WorkgroupSize_Y, "_Z23__spirv_WorkgroupSize_yv");
CREATE_CALLEE(WorkgroupSize_Z, "_Z23__spirv_WorkgroupSize_zv");

#undef CREATE_CALLEE

Expand All @@ -894,12 +894,11 @@ Value *spirv::genLinearLocalID(Instruction &Before, const Triple &TT) {
// 3: + (__spirv_WorkgroupSize_z() * __spirv_LocalInvocationId_y())
// 4: + (__spirv_LocalInvocationId_z())
return Bld.CreateAdd(
Bld.CreateAdd(
Bld.CreateMul(
Bld.CreateMul(WorkgroupSize_Y, WorkgroupSize_Z), // 1
LocalInvocationId_X), // 2
Bld.CreateMul(WorkgroupSize_Z, LocalInvocationId_Y)), // 3
LocalInvocationId_Z); // 4
Bld.CreateAdd(
Bld.CreateMul(Bld.CreateMul(WorkgroupSize_Y, WorkgroupSize_Z), // 1
LocalInvocationId_X), // 2
Bld.CreateMul(WorkgroupSize_Z, LocalInvocationId_Y)), // 3
LocalInvocationId_Z); // 4
} else {
StringRef Name = "__spirv_BuiltInLocalInvocationIndex";
GlobalVariable *G = M.getGlobalVariable(Name);
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4124,6 +4124,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
} else if (IsSYCL) {
// Ensure the default version in SYCL mode is 1.2.1
CmdArgs.push_back("-sycl-std=1.2.1");
// The user had not pass SYCL version, thus we'll employ no-sycl-strict
// to allow address-space unqualified pointers in function params/return
// along with marking the same function with explicit SYCL_EXTERNAL
CmdArgs.push_back("-Wno-sycl-strict");
}

if (IsOpenMPDevice) {
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Sema/Sema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,7 @@ void Sema::ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind) {
if (SyclIntHeader != nullptr)
SyclIntHeader->emit(getLangOpts().SYCLIntHeader);
MarkDevice();
finalizeSYCLDelayedAnalysis();
}

// Finalize analysis of OpenMP-specific constructs.
Expand Down
23 changes: 23 additions & 0 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18016,6 +18016,12 @@ Decl *Sema::getObjCDeclContext() const {
}

Sema::FunctionEmissionStatus Sema::getEmissionStatus(FunctionDecl *FD) {
// Due to SYCL functions are template we check if they have appropriate
// attribute prior to checking if it is a template
if (LangOpts.SYCLIsDevice &&
(FD->hasAttr<SYCLDeviceAttr>() || FD->hasAttr<SYCLKernelAttr>()))
return FunctionEmissionStatus::Emitted;

// Templates are emitted when they're instantiated.
if (FD->isDependentContext())
return FunctionEmissionStatus::TemplateDiscarded;
Expand Down Expand Up @@ -18080,6 +18086,23 @@ Sema::FunctionEmissionStatus Sema::getEmissionStatus(FunctionDecl *FD) {
return FunctionEmissionStatus::Emitted;
}

if (getLangOpts().SYCLIsDevice) {
if (!FD->hasAttr<SYCLDeviceAttr>() && !FD->hasAttr<SYCLKernelAttr>())
return FunctionEmissionStatus::Unknown;

// Check whether this function is externally visible -- if so, it's
// known-emitted.
//
// We have to check the GVA linkage of the function's *definition* -- if we
// only have a declaration, we don't know whether or not the function will
// be emitted, because (say) the definition could include "inline".
FunctionDecl *Def = FD->getDefinition();

if (Def &&
!isDiscardableGVALinkage(getASTContext().GetGVALinkageForFunction(Def)))
return FunctionEmissionStatus::Emitted;
}

// Otherwise, the function is known-emitted if it's in our set of
// known-emitted functions.
return (DeviceKnownEmittedFns.count(FD) > 0)
Expand Down
17 changes: 10 additions & 7 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2895,7 +2895,7 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr,
if (const auto *A = D->getAttr<SYCLIntelMaxGlobalWorkDimAttr>())
if (A->getNumber() == 0)
Result &= checkZeroDim(A, WGSize[0], WGSize[1], WGSize[2],
/*ReverseAttrs=*/ true);
/*ReverseAttrs=*/true);

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

if (!checkWorkGroupSizeValues(S, D, AL, WGSize))
return;

// For a SYCLDevice WorkGroupAttr arguments are reversed
if (S.getLangOpts().SYCLIsDevice) {
std::swap(WGSize[0], WGSize[2]);
}
WorkGroupAttr *Existing = D->getAttr<WorkGroupAttr>();
if (Existing && !(Existing->getXDim() == WGSize[0] &&
Existing->getYDim() == WGSize[1] &&
Existing->getZDim() == WGSize[2]))
if (Existing &&
!(Existing->getXDim() == WGSize[0] && Existing->getYDim() == WGSize[1] &&
Existing->getZDim() == WGSize[2]))
S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
if (!checkWorkGroupSizeValues(S, D, AL, WGSize))
return;

D->addAttr(::new (S.Context)
WorkGroupAttr(S.Context, AL, WGSize[0], WGSize[1], WGSize[2]));
Expand Down
5 changes: 3 additions & 2 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14684,8 +14684,9 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
MarkFunctionReferenced(ConstructLoc, Constructor);
if (getLangOpts().CUDA && !CheckCUDACall(ConstructLoc, Constructor))
return ExprError();
if (getLangOpts().SYCLIsDevice)
checkSYCLDeviceFunction(ConstructLoc, Constructor);
if (getLangOpts().SYCLIsDevice &&
!checkSYCLDeviceFunction(ConstructLoc, Constructor))
return ExprError();

return CXXConstructExpr::Create(
Context, DeclInitType, ConstructLoc, Constructor, Elidable,
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs,
if (getLangOpts().CUDA && !CheckCUDACall(Loc, FD))
return true;

if (getLangOpts().SYCLIsDevice)
checkSYCLDeviceFunction(Loc, FD);
if (getLangOpts().SYCLIsDevice && !checkSYCLDeviceFunction(Loc, FD))
return true;
}

if (auto *MD = dyn_cast<CXXMethodDecl>(D)) {
Expand Down
Loading

0 comments on commit 3aa6cac

Please sign in to comment.