Skip to content

Commit fc7a1c3

Browse files
author
iclsrc
committed
Merge from 'sycl' to 'sycl-web' (#13)
2 parents 061ef02 + f9cbf2a commit fc7a1c3

29 files changed

+389
-56
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,6 +1735,13 @@ def IntelFPGASimpleDualPort : Attr {
17351735
let Documentation = [IntelFPGASimpleDualPortAttrDocs];
17361736
}
17371737

1738+
def SYCLFPGAPipe : TypeAttr {
1739+
let Spellings = [GNU<"pipe">];
1740+
let Args = [StringArgument<"Mode">];
1741+
let LangOpts = [SYCLIsDevice];
1742+
let Documentation = [SYCLFPGAPipeDocs];
1743+
}
1744+
17381745
def Naked : InheritableAttr {
17391746
let Spellings = [GCC<"naked">, Declspec<"naked">];
17401747
let Subjects = SubjectList<[Function]>;

clang/include/clang/Basic/AttrDocs.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,16 @@ function, and no effect otherwise.
18851885
}];
18861886
}
18871887

1888+
def SYCLFPGAPipeDocs : Documentation {
1889+
let Category = DocCatStmt;
1890+
let Heading = "pipe (read_only, write_only)";
1891+
let Content = [{
1892+
This attribute applies to a type to indicate that it is a pipe type.
1893+
It requires a string argument that specifies if the pipe is read only or
1894+
write only. Expected to be used only in SYCL headers.
1895+
}];
1896+
}
1897+
18881898
def SYCLIntelFPGAIVDepAttrDocs : Documentation {
18891899
let Category = DocCatVariable;
18901900
let Heading = "ivdep";

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ def err_sycl_loop_attr_duplication : Error<
137137
"duplicate %select{unroll|Intel FPGA}0 loop attribute '%1'">;
138138
def err_loop_unroll_compatibility : Error<
139139
"incompatible loop unroll instructions: '%0' and '%1'">;
140+
def err_pipe_attribute_arg_not_allowed : Error<
141+
"'%0' mode for pipe attribute is not supported. Allowed modes: 'read_only', 'write_only'">;
140142

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

clang/include/clang/Basic/TokenKinds.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,6 @@ KEYWORD(vec_step , KEYOPENCLC | KEYALTIVEC | KEYZVECTOR)
578578
KEYWORD(__builtin_omp_required_simd_align, KEYALL)
579579

580580
KEYWORD(pipe , KEYOPENCLC | KEYOPENCLCXX)
581-
KEYWORD(__pipe , KEYSYCL)
582581

583582
// Borland Extensions.
584583
KEYWORD(__pascal , KEYALL)

clang/lib/AST/TypePrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,10 @@ void TypePrinter::printAttributedAfter(const AttributedType *T,
15091509
// AttributedType nodes for them.
15101510
break;
15111511

1512+
case attr::SYCLFPGAPipe:
1513+
OS << "pipe";
1514+
break;
1515+
15121516
case attr::LifetimeBound:
15131517
case attr::TypeNonNull:
15141518
case attr::TypeNullable:

clang/lib/Driver/Driver.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3299,6 +3299,11 @@ class OffloadingActionBuilder final {
32993299
if (auto *IA = dyn_cast<InputAction>(HostAction)) {
33003300
SYCLDeviceActions.clear();
33013301

3302+
// Options that are considered LinkerInput are not valid input actions
3303+
// to the device tool chain.
3304+
if (IA->getInputArg().getOption().hasFlag(options::LinkerInput))
3305+
return ABRT_Inactive;
3306+
33023307
std::string InputName = IA->getInputArg().getAsString(Args);
33033308
// Objects should already be consumed with -foffload-static-lib
33043309
if (Args.hasArg(options::OPT_foffload_static_lib_EQ) &&
@@ -3319,6 +3324,11 @@ class OffloadingActionBuilder final {
33193324
if (auto *UA = dyn_cast<OffloadUnbundlingJobAction>(HostAction)) {
33203325
SYCLDeviceActions.clear();
33213326
if (auto *IA = dyn_cast<InputAction>(UA->getInputs().back())) {
3327+
// Options that are considered LinkerInput are not valid input actions
3328+
// to the device tool chain.
3329+
if (IA->getInputArg().getOption().hasFlag(options::LinkerInput))
3330+
return ABRT_Inactive;
3331+
33223332
std::string FileName = IA->getInputArg().getAsString(Args);
33233333
// Check if the type of the file is the same as the action. Do not
33243334
// unbundle it if it is not. Do not unbundle .so files, for example,
@@ -3772,6 +3782,7 @@ class OffloadingActionBuilder final {
37723782
// the input is not a bundle.
37733783
if (CanUseBundler && isa<InputAction>(HostAction) &&
37743784
InputArg->getOption().getKind() == llvm::opt::Option::InputClass &&
3785+
!InputArg->getOption().hasFlag(options::LinkerInput) &&
37753786
!types::isSrcFile(HostAction->getType())) {
37763787
std::string InputName = InputArg->getAsString(Args);
37773788
// Do not create an unbundling action for an object when we know a fat

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5649,12 +5649,17 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
56495649
// Host-side SYCL compilation receives the integration header file as
56505650
// Inputs[1]. Include the header with -include
56515651
if (!IsSYCLOffloadDevice && SYCLDeviceInput) {
5652+
SmallString<128> RealPath;
5653+
// Fixup the header path name in case there are discrepancies in the
5654+
// string used for the temporary directory environment variable and
5655+
// actual path expectations.
5656+
llvm::sys::fs::real_path(SYCLDeviceInput->getFilename(), RealPath);
56525657
CmdArgs.push_back("-include");
5653-
CmdArgs.push_back(SYCLDeviceInput->getFilename());
5658+
CmdArgs.push_back(Args.MakeArgString(RealPath));
56545659
// When creating dependency information, filter out the generated
56555660
// header file.
56565661
CmdArgs.push_back("-dependency-filter");
5657-
CmdArgs.push_back(SYCLDeviceInput->getFilename());
5662+
CmdArgs.push_back(Args.MakeArgString(RealPath));
56585663
// Let the FE know we are doing a SYCL offload compilation, but we are
56595664
// doing the host pass.
56605665
CmdArgs.push_back("-fsycl-is-host");

clang/lib/Parse/ParseDecl.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3830,11 +3830,6 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
38303830
}
38313831
isInvalid = DS.SetTypePipe(true, Loc, PrevSpec, DiagID, Policy);
38323832
break;
3833-
case tok::kw___pipe:
3834-
if (getLangOpts().SYCLIsDevice)
3835-
// __pipe keyword is defined only for SYCL kernel language
3836-
isInvalid = DS.SetTypePipe(true, Loc, PrevSpec, DiagID, Policy);
3837-
break;
38383833
#define GENERIC_IMAGE_TYPE(ImgType, Id) \
38393834
case tok::kw_##ImgType##_t: \
38403835
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, \
@@ -4967,9 +4962,8 @@ bool Parser::isDeclarationSpecifier(bool DisambiguatingWithExpression) {
49674962
default: return false;
49684963

49694964
case tok::kw_pipe:
4970-
case tok::kw___pipe:
49714965
return (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200) ||
4972-
getLangOpts().OpenCLCPlusPlus || getLangOpts().SYCLIsDevice;
4966+
getLangOpts().OpenCLCPlusPlus;
49734967

49744968
case tok::identifier: // foo::bar
49754969
// Unfortunate hack to support "Class.factoryMethod" notation.
@@ -5463,9 +5457,8 @@ static bool isPtrOperatorToken(tok::TokenKind Kind, const LangOptions &Lang,
54635457
if (Kind == tok::star || Kind == tok::caret)
54645458
return true;
54655459

5466-
if ((Kind == tok::kw_pipe || Kind == tok::kw___pipe) &&
5467-
((Lang.OpenCL && Lang.OpenCLVersion >= 200) || Lang.OpenCLCPlusPlus ||
5468-
Lang.SYCLIsDevice))
5460+
if ((Kind == tok::kw_pipe) &&
5461+
((Lang.OpenCL && Lang.OpenCLVersion >= 200) || Lang.OpenCLCPlusPlus))
54695462
return true;
54705463

54715464
if (!Lang.CPlusPlus)

clang/lib/Parse/ParseTentative.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,8 +1467,6 @@ Parser::isCXXDeclarationSpecifier(Parser::TPResult BracedCastResult,
14671467
case tok::kw___read_write:
14681468
// OpenCL pipe
14691469
case tok::kw_pipe:
1470-
// SYCL pipe
1471-
case tok::kw___pipe:
14721470

14731471
// GNU
14741472
case tok::kw_restrict:

clang/lib/Sema/SemaType.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6103,6 +6103,66 @@ static void HandleAddressSpaceTypeAttribute(QualType &Type,
61036103
}
61046104
}
61056105

6106+
static void HandleSYCLFPGAPipeAttribute(QualType &Type, const ParsedAttr &Attr,
6107+
TypeProcessingState &State) {
6108+
Sema &S = State.getSema();
6109+
ASTContext &Ctx = S.Context;
6110+
6111+
// Check the attribute arguments.
6112+
if (Attr.getNumArgs() != 1) {
6113+
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
6114+
<< Attr << 1;
6115+
Attr.setInvalid();
6116+
return;
6117+
}
6118+
6119+
if (!Attr.isArgExpr(0)) {
6120+
S.Diag(Attr.getLoc(), diag::err_attribute_argument_type)
6121+
<< Attr << AANT_ArgumentString;
6122+
Attr.setInvalid();
6123+
return;
6124+
}
6125+
6126+
StringRef Str;
6127+
if (auto *SL = dyn_cast<StringLiteral>(Attr.getArgAsExpr(0))) {
6128+
Str = SL->getString();
6129+
} else {
6130+
S.Diag(Attr.getLoc(), diag::err_attribute_argument_type)
6131+
<< Attr << AANT_ArgumentString;
6132+
Attr.setInvalid();
6133+
return;
6134+
}
6135+
6136+
bool isReadOnlyPipe;
6137+
if (Str == "write_only")
6138+
isReadOnlyPipe = false;
6139+
else if (Str == "read_only")
6140+
isReadOnlyPipe = true;
6141+
else {
6142+
S.Diag(Attr.getLoc(), diag::err_pipe_attribute_arg_not_allowed) << Str;
6143+
Attr.setInvalid();
6144+
return;
6145+
}
6146+
6147+
auto *PipeAttr = ::new (Ctx) SYCLFPGAPipeAttr(Ctx, Attr, Str);
6148+
6149+
// Apply pipe qualifiers just to the equivalent type, as the expression is not
6150+
// value dependent (not templated).
6151+
QualType EquivType = isReadOnlyPipe
6152+
? S.BuildReadPipeType(Type, Attr.getLoc())
6153+
: S.BuildWritePipeType(Type, Attr.getLoc());
6154+
if (EquivType.isNull()) {
6155+
Attr.setInvalid();
6156+
return;
6157+
}
6158+
6159+
QualType T = State.getAttributedType(PipeAttr, Type, EquivType);
6160+
if (!T.isNull())
6161+
Type = T;
6162+
else
6163+
Attr.setInvalid();
6164+
}
6165+
61066166
/// handleObjCOwnershipTypeAttr - Process an objc_ownership
61076167
/// attribute on the specified type.
61086168
///
@@ -7670,6 +7730,10 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type,
76707730
HandleOpenCLAccessAttr(type, attr, state.getSema());
76717731
attr.setUsedAsTypeAttr();
76727732
break;
7733+
case ParsedAttr::AT_SYCLFPGAPipe:
7734+
HandleSYCLFPGAPipeAttribute(type, attr, state);
7735+
attr.setUsedAsTypeAttr();
7736+
break;
76737737
case ParsedAttr::AT_LifetimeBound:
76747738
if (TAL == TAL_DeclChunk)
76757739
HandleLifetimeBoundAttr(state, type, attr);

clang/test/CodeGenSYCL/fpga_pipes.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %clang %s -S -emit-llvm --sycl -o - | FileCheck %s
2+
#include "CL/sycl.hpp"
3+
// CHECK: %opencl.pipe_wo_t
4+
// CHECK: %opencl.pipe_ro_t
5+
6+
class SomePipe;
7+
void foo() {
8+
using Pipe = cl::sycl::pipe<SomePipe, int>;
9+
// CHECK: %WPipe = alloca %opencl.pipe_wo_t
10+
Pipe::write(42);
11+
// CHECK: %RPipe = alloca %opencl.pipe_ro_t
12+
int a = Pipe::read();
13+
}
14+
15+
template <typename name, typename Func>
16+
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
17+
kernelFunc();
18+
}
19+
20+
int main() {
21+
kernel_single_task<class kernel_function>([]() {
22+
foo();
23+
});
24+
return 0;
25+
}
26+

clang/test/CodeGenSYCL/intel-restrict.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ int foo(int X) {
5353
cgh.single_task<class kernel_restrict_struct>(f);
5454
});
5555

56-
// CHECK: define {{.*}} spir_kernel {{.*}}kernel_restrict_other_params{{.*}}(i32 addrspace(1)* noalias %{{.*}} i32 addrspace(1)* noalias %{{.*}}, i32 %_arg_9)
56+
// CHECK: define {{.*}} spir_kernel {{.*}}kernel_restrict_other_params{{.*}}(i32 addrspace(1)* noalias %{{.*}} i32 addrspace(1)* noalias %{{.*}}, i32 %{{[^,]*}})
5757
int num = 42;
5858
Q.submit([&](cl::sycl::handler& cgh) {
5959
auto AccA = BufA.get_access<sycl_read_write, sycl_global_buffer>(cgh);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// REQUIRES: system-windows
2+
// Test the integration header file name generation. Name should match the
3+
// actual path name and not the environment variable setting
4+
// RUN: mkdir -p %t_DiRnAmE
5+
// invoke the compiler overriding output temp location
6+
// RUN: env TMP=%t_dirname \
7+
// RUN: %clang_cl -### -fsycl %s 2>&1 | \
8+
// RUN: FileCheck --check-prefix=CHECK-HEADER %s
9+
// RUN: env TMP=%t_dirname \
10+
// RUN: %clang -### -fsycl %s 2>&1 | \
11+
// RUN: FileCheck --check-prefix=CHECK-HEADER %s
12+
// CHECK-HEADER: clang{{.*}} "-fsycl-int-header=[[HEADER:.+\.h]]"
13+
// CHECK-HEADER-NOT: clang{{.*}} "-include" "[[HEADER]]"
14+
// CHECK-HEADER: clang{{.*}} "-include" "{{.*}}_DiRnAmE{{.+}}.h"

clang/test/Driver/sycl-offload.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@
182182
// CHK-PHASES-LIB: 15: clang-offload-wrapper, {14}, object, (device-sycl)
183183
// CHK-PHASES-LIB: 16: offload, "host-sycl (x86_64-unknown-linux-gnu)" {10}, "device-sycl (spir64-unknown-unknown-sycldevice)" {15}, image
184184

185+
/// Compilation check with -lstdc++ (treated differently than regular lib)
186+
// RUN: %clang -### -target x86_64-unknown-linux-gnu -lstdc++ -fsycl %s 2>&1 \
187+
// RUN: | FileCheck -check-prefix=CHK-LIB-STDCXX %s
188+
// CHK-LIB-STDCXX: ld{{.*}} "-lstdc++"
189+
// CHK-LIB-STDCXX-NOT: clang-offload-bundler{{.*}}
190+
// CHK-LIB-STDCXX-NOT: llvm-link{{.*}} "-lstdc++"
191+
185192
/// ###########################################################################
186193

187194
/// Check the phases when using and multiple source files

clang/test/SemaSYCL/fpga_pipes.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -x c++ -fsycl-is-device -std=c++11 -fsyntax-only -verify -pedantic %s
2+
3+
// no error expected
4+
using type1 = __attribute__((pipe("read_only"))) const int;
5+
6+
// no error expected
7+
using type2 = __attribute__((pipe("write_only"))) const int;
8+
9+
// expected-error@+1 {{'42' mode for pipe attribute is not supported. Allowed modes: 'read_only', 'write_only'}}
10+
using type3 = __attribute__((pipe("42"))) const int;
11+
12+
// expected-error@+1{{'pipe' attribute requires a string}}
13+
using type4 = __attribute__((pipe(0))) const int;
14+
15+
// expected-error@+1{{'pipe' attribute takes one argument}}
16+
using type5 = __attribute__((pipe)) const int;

clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
/// as input and creates wrapper bitcode file containing target binaries
1212
/// packaged as data. Wrapper bitcode also includes initialization code which
1313
/// registers target binaries in offloading runtime at program startup.
14-
/// TODO Add Windows support.
1514
///
1615
//===----------------------------------------------------------------------===//
1716

@@ -874,6 +873,9 @@ template <typename... Tys> class ListArgsSequencer {
874873
int Cur = -1;
875874

876875
/// Class IDs of all options from all lists. Filled in the constructor.
876+
/// Can also be seen as a map from command line position to the option class
877+
/// ID. If there is no option participating in one of the sequenced lists at
878+
/// given position, then it is mapped to -1 marker value.
877879
std::unique_ptr<std::vector<int>> OptListIDs;
878880

879881
using tuple_of_iters_t = std::tuple<typename Tys::iterator...>;
@@ -894,8 +896,11 @@ template <typename... Tys> class ListArgsSequencer {
894896
/// Args - the cl::list objects to sequence elements of
895897
ListArgsSequencer(size_t Sz, Tys &... Args)
896898
: Prevs(Args.end()...), Iters(Args.begin()...) {
897-
assert(Sz >= sizeof...(Tys));
899+
// make OptListIDs big enough to hold IDs of all options coming from the
900+
// command line and initialize all IDs to default class -1
898901
OptListIDs.reset(new std::vector<int>(Sz, -1));
902+
// map command line positions where sequenced options occur to appropriate
903+
// class IDs
899904
addLists<sizeof...(Tys) - 1, 0>(Args...);
900905
}
901906

@@ -942,9 +947,12 @@ template <typename... Tys> class ListArgsSequencer {
942947

943948
/// Does the actual sequencing of options found in given list.
944949
template <int ID, typename T> void addListImpl(T &L) {
950+
// iterate via all occurences of an option of given list class
945951
for (auto It = L.begin(); It != L.end(); It++) {
952+
// calculate its sequential position in the command line
946953
unsigned Pos = L.getPosition(It - L.begin());
947954
assert((*OptListIDs)[Pos] == -1);
955+
// ... and fill the corresponding spot in the list with the class ID
948956
(*OptListIDs)[Pos] = ID;
949957
}
950958
}

sycl/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ add_subdirectory( source )
178178
# SYCL toolchain builds all components: compiler, libraries, headers, etc.
179179
add_custom_target( sycl-toolchain
180180
DEPENDS ${SYCL_RT_LIBS}
181+
pi_opencl
181182
clang
182183
clang-offload-wrapper
183184
clang-offload-bundler
@@ -236,6 +237,7 @@ set( SYCL_TOOLCHAIN_DEPLOY_COMPONENTS
236237
opencl-headers
237238
sycl-headers
238239
sycl
240+
pi_opencl
239241
)
240242

241243
# Use it as fake dependency in order to force another command(s) to execute.

sycl/doc/GetStartedWithSYCLCompiler.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86" ^
8787
-DLLVM_ENABLE_PROJECTS="clang;llvm-spirv;sycl" ^
8888
-DLLVM_EXTERNAL_SYCL_SOURCE_DIR="%SYCL_HOME%\llvm\sycl" ^
8989
-DLLVM_EXTERNAL_LLVM_SPIRV_SOURCE_DIR="%SYCL_HOME%\llvm\llvm-spirv" ^
90-
-DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DCMAKE_C_FLAGS="/GS" ^
91-
-DCMAKE_CXX_FLAGS="/GS" -DCMAKE_EXE_LINKER_FLAGS="/NXCompat /DynamicBase" ^
92-
-DCMAKE_SHARED_LINKER_FLAGS="/NXCompat /DynamicBase" ^
90+
-DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl ^
9391
"%SYCL_HOME%\llvm\llvm"
9492
9593
ninja sycl-toolchain

0 commit comments

Comments
 (0)