Skip to content

Commit b88c70b

Browse files
author
iclsrc
committed
Merge from 'sycl' to 'sycl-web' (#1)
2 parents ac052da + 478b7c0 commit b88c70b

File tree

79 files changed

+1993
-507
lines changed

Some content is hidden

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

79 files changed

+1993
-507
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,15 @@ def SYCLIntelMaxGlobalWorkDim : InheritableAttr {
11531153
let PragmaAttributeSupport = 0;
11541154
}
11551155

1156+
def SYCLIntelUsesGlobalWorkOffset : InheritableAttr {
1157+
let Spellings = [CXX11<"intelfpga","uses_global_work_offset">];
1158+
let Args = [BoolArgument<"Enabled">];
1159+
let LangOpts = [SYCLIsDevice, SYCLIsHost];
1160+
let Subjects = SubjectList<[Function], ErrorDiag>;
1161+
let Documentation = [SYCLIntelUsesGlobalWorkOffsetDocs];
1162+
let PragmaAttributeSupport = 0;
1163+
}
1164+
11561165
def C11NoReturn : InheritableAttr {
11571166
let Spellings = [Keyword<"_Noreturn">];
11581167
let Subjects = SubjectList<[Function], ErrorDiag>;
@@ -1730,12 +1739,12 @@ def IntelFPGANumBanks : Attr {
17301739
}];
17311740
}
17321741

1733-
def IntelFPGAMaxPrivateCopies : InheritableAttr {
1734-
let Spellings = [CXX11<"intelfpga","max_private_copies">];
1742+
def IntelFPGAPrivateCopies : InheritableAttr {
1743+
let Spellings = [CXX11<"intelfpga","private_copies">];
17351744
let Args = [ExprArgument<"Value">];
17361745
let LangOpts = [SYCLIsDevice, SYCLIsHost];
17371746
let Subjects = SubjectList<[IntelFPGALocalNonConstVar, Field], ErrorDiag>;
1738-
let Documentation = [IntelFPGAMaxPrivateCopiesAttrDocs];
1747+
let Documentation = [IntelFPGAPrivateCopiesAttrDocs];
17391748
let AdditionalMembers = [{
17401749
static unsigned getMinValue() {
17411750
return 0;

clang/include/clang/Basic/AttrDocs.td

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,9 +1876,9 @@ with N banks.
18761876
}];
18771877
}
18781878

1879-
def IntelFPGAMaxPrivateCopiesAttrDocs : Documentation {
1879+
def IntelFPGAPrivateCopiesAttrDocs : Documentation {
18801880
let Category = DocCatVariable;
1881-
let Heading = "max_private_copies (IntelFPGA)";
1881+
let Heading = "private_copies (IntelFPGA)";
18821882
let Content = [{
18831883
This attribute may be attached to a variable or struct member declaration and
18841884
instructs the backend to replicate the memory generated for the variable or
@@ -2009,6 +2009,16 @@ device kernel, the attribute is ignored and it is not propagated to a kernel.
20092009
}];
20102010
}
20112011

2012+
def SYCLIntelUsesGlobalWorkOffsetDocs : Documentation {
2013+
let Category = DocCatFunction;
2014+
let Heading = "uses_global_work_offset (IntelFPGA)";
2015+
let Content = [{
2016+
Applies to a device function/lambda function or function call operator (of a
2017+
function object). If 0, compiler doesn't use the global work offset values for
2018+
the device function. Valid values are 0 and 1.
2019+
}];
2020+
}
2021+
20122022
def SYCLFPGAPipeDocs : Documentation {
20132023
let Category = DocCatStmt;
20142024
let Heading = "pipe (read_only, write_only)";

clang/include/clang/Basic/AttributeCommonInfo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ class AttributeCommonInfo {
158158
(ParsedAttr == AT_IntelReqdSubGroupSize && isCXX11Attribute()) ||
159159
ParsedAttr == AT_SYCLIntelNumSimdWorkItems ||
160160
ParsedAttr == AT_SYCLIntelMaxWorkGroupSize ||
161-
ParsedAttr == AT_SYCLIntelMaxGlobalWorkDim)
161+
ParsedAttr == AT_SYCLIntelMaxGlobalWorkDim ||
162+
ParsedAttr == AT_SYCLIntelUsesGlobalWorkOffset)
162163
return true;
163164

164165
return false;

clang/include/clang/Basic/Builtins.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,7 @@ BUILTIN(__builtin_ms_va_copy, "vc*&c*&", "n")
15771577

15781578
// Builtins for Intel FPGA
15791579
BUILTIN(__builtin_intel_fpga_reg, "v.", "nt")
1580+
BUILTIN(__builtin_intel_fpga_mem, "v.", "nt")
15801581

15811582
#undef BUILTIN
15821583
#undef LIBBUILTIN

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,10 @@ def NSReturnsMismatch : DiagGroup<"nsreturns-mismatch">;
637637
def IndependentClassAttribute : DiagGroup<"IndependentClass-attribute">;
638638
def UnknownAttributes : DiagGroup<"unknown-attributes">;
639639
def IgnoredAttributes : DiagGroup<"ignored-attributes">;
640+
def AdjustedAttributes : DiagGroup<"adjusted-attributes">;
640641
def Attributes : DiagGroup<"attributes", [UnknownAttributes,
641-
IgnoredAttributes]>;
642+
IgnoredAttributes,
643+
AdjustedAttributes]>;
642644
def UnknownSanitizers : DiagGroup<"unknown-sanitizers">;
643645
def UnnamedTypeTemplateArgs : DiagGroup<"unnamed-type-template-args",
644646
[CXX98CompatUnnamedTypeTemplateArgs]>;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ def err_bankbits_numbanks_conflicting : Error<
143143
"the number of bank_bits must be equal to ceil(log2(numbanks))">;
144144
def err_bankbits_non_consecutive : Error<
145145
"bank_bits must be consecutive">;
146+
def err_intel_fpga_mem_limitations
147+
: Error<
148+
"illegal %select{pointer argument of type %1 |field in type pointed "
149+
"to by pointer argument}0 to __builtin_intel_fpga_mem. Only pointers "
150+
"to a first class lvalue or to an rvalue are allowed">;
151+
def err_intel_fpga_mem_arg_mismatch
152+
: Error<"builtin parameter must be %select{"
153+
"a pointer"
154+
"|a non-negative integer constant}0">;
146155

147156
// C99 variable-length arrays
148157
def ext_vla : Extension<"variable length arrays are a C99 feature">,
@@ -10338,8 +10347,10 @@ def err_sycl_virtual_types : Error<
1033810347
"No class with a vtable can be used in a SYCL kernel or any code included in the kernel">;
1033910348
def note_sycl_used_here : Note<"used here">;
1034010349
def note_sycl_recursive_function_declared_here: Note<"function implemented using recursion declared here">;
10350+
def err_sycl_non_trivially_copyable_type : Error<
10351+
"kernel parameter has non-trivially copyable class/struct type %0">;
1034110352
def err_sycl_non_std_layout_type : Error<
10342-
"kernel parameter has non-standard layout class/struct type">;
10353+
"kernel parameter has non-standard layout class/struct type %0">;
1034310354
def err_conflicting_sycl_kernel_attributes : Error<
1034410355
"conflicting attributes applied to a SYCL kernel">;
1034510356
def err_conflicting_sycl_function_attributes : Error<
@@ -10348,6 +10359,9 @@ def err_sycl_x_y_z_arguments_must_be_one : Error<
1034810359
"%0 X-, Y- and Z- sizes must be 1 when %1 attribute is used with value 0">;
1034910360
def err_intel_attribute_argument_is_not_in_range: Error<
1035010361
"The value of %0 attribute must be in range from 0 to 3">;
10362+
def warn_boolean_attribute_argument_is_not_valid: Warning<
10363+
"The value of %0 attribute should be 0 or 1. Adjusted to 1">,
10364+
InGroup<AdjustedAttributes>;
1035110365
def err_sycl_attibute_cannot_be_applied_here
1035210366
: Error<"%0 attribute cannot be applied to a "
1035310367
"%select{static function or function in an anonymous namespace"

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ LANGOPT(GPUMaxThreadsPerBlock, 32, 256, "default max threads per block for kerne
233233
LANGOPT(SYCLIsDevice , 1, 0, "Generate code for SYCL device")
234234
LANGOPT(SYCLIsHost , 1, 0, "SYCL host compilation")
235235
LANGOPT(SYCLAllowFuncPtr , 1, 0, "Allow function pointers in SYCL device code")
236+
LANGOPT(SYCLStdLayoutKernelParams, 1, 0, "Enable standard layout requirement for SYCL kernel parameters")
236237
LANGOPT(SYCLUnnamedLambda , 1, 0, "Allow unnamed lambda SYCL kernels")
237238

238239
LANGOPT(HIPUseNewLaunchAPI, 1, 0, "Use new kernel launching API for HIP")

clang/include/clang/Driver/CC1Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,8 @@ def fsycl_int_header : Separate<["-"], "fsycl-int-header">,
902902
HelpText<"Generate SYCL integration header into this file.">;
903903
def fsycl_int_header_EQ : Joined<["-"], "fsycl-int-header=">,
904904
Alias<fsycl_int_header>;
905+
def fsycl_std_layout_kernel_params: Flag<["-"], "fsycl-std-layout-kernel-params">,
906+
HelpText<"Enable standard layout requirement for SYCL kernel parameters.">;
905907
def fsycl_allow_func_ptr : Flag<["-"], "fsycl-allow-func-ptr">,
906908
HelpText<"Allow function pointers in SYCL device.">;
907909
def fno_sycl_allow_func_ptr : Flag<["-"], "fno-sycl-allow-func-ptr">;

clang/include/clang/Sema/Sema.h

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11715,7 +11715,8 @@ class Sema final {
1171511715
bool CheckX86BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
1171611716
bool CheckPPCBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
1171711717

11718-
bool CheckIntelFPGABuiltinFunctionCall(unsigned BuiltinID, CallExpr *Call);
11718+
bool CheckIntelFPGARegBuiltinFunctionCall(unsigned BuiltinID, CallExpr *Call);
11719+
bool CheckIntelFPGAMemBuiltinFunctionCall(CallExpr *Call);
1171911720

1172011721
bool SemaBuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall);
1172111722
bool SemaBuiltinVAStartARMMicrosoft(CallExpr *Call);
@@ -12093,11 +12094,33 @@ class Sema final {
1209312094
KernelCallDllimportFunction,
1209412095
KernelCallVariadicFunction
1209512096
};
12096-
DeviceDiagBuilder SYCLDiagIfDeviceCode(SourceLocation Loc, unsigned DiagID);
1209712097
bool isKnownGoodSYCLDecl(const Decl *D);
1209812098
void ConstructOpenCLKernel(FunctionDecl *KernelCallerFunc, MangleContext &MC);
1209912099
void MarkDevice(void);
12100-
bool CheckSYCLCall(SourceLocation Loc, FunctionDecl *Callee);
12100+
12101+
/// Creates a DeviceDiagBuilder that emits the diagnostic if the current
12102+
/// context is "used as device code".
12103+
///
12104+
/// - If CurLexicalContext is a kernel function or it is known that the
12105+
/// function will be emitted for the device, emits the diagnostics
12106+
/// immediately.
12107+
/// - If CurLexicalContext is a function and we are compiling
12108+
/// for the device, but we don't know that this function will be codegen'ed
12109+
/// for devive yet, creates a diagnostic which is emitted if and when we
12110+
/// realize that the function will be codegen'ed.
12111+
///
12112+
/// Example usage:
12113+
///
12114+
/// Variables with thread storage duration are not allowed to be used in SYCL
12115+
/// device code
12116+
/// if (getLangOpts().SYCLIsDevice)
12117+
/// SYCLDiagIfDeviceCode(Loc, diag::err_thread_unsupported);
12118+
DeviceDiagBuilder SYCLDiagIfDeviceCode(SourceLocation Loc, unsigned DiagID);
12119+
12120+
/// Checks if Callee function is a device function and emits
12121+
/// diagnostics if it is known that it is a device function, adds this
12122+
/// function to the DeviceCallGraph otherwise.
12123+
void checkSYCLDeviceFunction(SourceLocation Loc, FunctionDecl *Callee);
1210112124
};
1210212125

1210312126
/// RAII object that enters a new expression evaluation context.

clang/lib/AST/RecordLayoutBuilder.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,8 +2199,9 @@ static bool mustSkipTailPadding(TargetCXXABI ABI, const CXXRecordDecl *RD) {
21992199
llvm_unreachable("bad tail-padding use kind");
22002200
}
22012201

2202-
static bool isMsLayout(const ASTContext &Context) {
2203-
return Context.getTargetInfo().getCXXABI().isMicrosoft();
2202+
static bool isMsLayout(const ASTContext &Context, bool CheckAuxABI = false) {
2203+
return (CheckAuxABI) ? Context.getAuxTargetInfo()->getCXXABI().isMicrosoft()
2204+
: Context.getTargetInfo().getCXXABI().isMicrosoft();
22042205
}
22052206

22062207
// This section contains an implementation of struct layout that is, up to the
@@ -3025,6 +3026,9 @@ ASTContext::getASTRecordLayout(const RecordDecl *D) const {
30253026
// as soon as we begin to parse the definition. That definition is
30263027
// not a complete definition (which is what isDefinition() tests)
30273028
// until we *finish* parsing the definition.
3029+
bool CheckAuxABI = false;
3030+
if (getLangOpts().SYCLIsDevice && (getAuxTargetInfo() != nullptr))
3031+
CheckAuxABI = true;
30283032

30293033
if (D->hasExternalLexicalStorage() && !D->getDefinition())
30303034
getExternalSource()->CompleteType(const_cast<RecordDecl*>(D));
@@ -3042,7 +3046,7 @@ ASTContext::getASTRecordLayout(const RecordDecl *D) const {
30423046

30433047
const ASTRecordLayout *NewEntry = nullptr;
30443048

3045-
if (isMsLayout(*this)) {
3049+
if (isMsLayout(*this, CheckAuxABI)) {
30463050
MicrosoftRecordLayoutBuilder Builder(*this);
30473051
if (const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
30483052
Builder.cxxLayout(RD);

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4235,6 +4235,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
42354235
// SYCL
42364236
case Builtin::BI__builtin_intel_fpga_reg:
42374237
return EmitIntelFPGARegBuiltin(E, ReturnValue);
4238+
case Builtin::BI__builtin_intel_fpga_mem:
4239+
return EmitIntelFPGAMemBuiltin(E);
42384240
}
42394241

42404242
// If this is an alias for a lib function (e.g. __builtin_sin), emit
@@ -14994,3 +14996,32 @@ RValue CodeGenFunction::EmitIntelFPGARegBuiltin(const CallExpr *E,
1499414996

1499514997
return RValue::get(AnnotatedV);
1499614998
}
14999+
15000+
RValue CodeGenFunction::EmitIntelFPGAMemBuiltin(const CallExpr *E) {
15001+
// Arguments
15002+
const Expr *PtrArg = E->getArg(0);
15003+
Value *PtrVal = EmitScalarExpr(PtrArg);
15004+
15005+
// Create the pointer annotation
15006+
Function *F =
15007+
CGM.getIntrinsic(llvm::Intrinsic::ptr_annotation, PtrVal->getType());
15008+
SmallString<256> AnnotStr;
15009+
llvm::raw_svector_ostream Out(AnnotStr);
15010+
15011+
llvm::APSInt Params;
15012+
bool IsConst = E->getArg(1)->isIntegerConstantExpr(Params, getContext());
15013+
assert(IsConst && "Constant arg isn't actually constant?"); (void)IsConst;
15014+
Out << "{params:" << Params.toString(10) << "}";
15015+
15016+
llvm::APSInt CacheSize;
15017+
IsConst = E->getArg(2)->isIntegerConstantExpr(CacheSize, getContext());
15018+
assert(IsConst && "Constant arg isn't actually constant?"); (void)IsConst;
15019+
Out << "{cache-size:" << CacheSize.toString(10) << "}";
15020+
15021+
llvm::Value *Ann = EmitAnnotationCall(F, PtrVal, AnnotStr, SourceLocation());
15022+
15023+
cast<CallBase>(Ann)->addAttribute(llvm::AttributeList::FunctionIndex,
15024+
llvm::Attribute::ReadNone);
15025+
15026+
return RValue::get(Ann);
15027+
}

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,17 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD,
668668
Fn->setMetadata("max_global_work_dim",
669669
llvm::MDNode::get(Context, AttrMDArgs));
670670
}
671+
672+
if (const SYCLIntelUsesGlobalWorkOffsetAttr *A =
673+
FD->getAttr<SYCLIntelUsesGlobalWorkOffsetAttr>()) {
674+
bool IsEnabled = A->getEnabled();
675+
if (!IsEnabled) {
676+
llvm::Metadata *AttrMDArgs[] = {
677+
llvm::ConstantAsMetadata::get(Builder.getInt32(IsEnabled))};
678+
Fn->setMetadata("uses_global_work_offset",
679+
llvm::MDNode::get(Context, AttrMDArgs));
680+
}
681+
}
671682
}
672683

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

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3798,7 +3798,9 @@ class CodeGenFunction : public CodeGenTypeCache {
37983798
const CallExpr *E);
37993799
llvm::Value *EmitHexagonBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
38003800

3801-
RValue EmitIntelFPGARegBuiltin(const CallExpr *E, ReturnValueSlot ReturnValue);
3801+
RValue EmitIntelFPGARegBuiltin(const CallExpr *E,
3802+
ReturnValueSlot ReturnValue);
3803+
RValue EmitIntelFPGAMemBuiltin(const CallExpr *E);
38023804

38033805
private:
38043806
enum class MSVCIntrin;

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3981,9 +3981,9 @@ void CodeGenModule::generateIntelFPGAAnnotation(
39813981
llvm::APSInt BWAInt = BWA->getValue()->EvaluateKnownConstInt(getContext());
39823982
Out << '{' << BWA->getSpelling() << ':' << BWAInt << '}';
39833983
}
3984-
if (const auto *MCA = D->getAttr<IntelFPGAMaxPrivateCopiesAttr>()) {
3985-
llvm::APSInt MCAInt = MCA->getValue()->EvaluateKnownConstInt(getContext());
3986-
Out << '{' << MCA->getSpelling() << ':' << MCAInt << '}';
3984+
if (const auto *PCA = D->getAttr<IntelFPGAPrivateCopiesAttr>()) {
3985+
llvm::APSInt PCAInt = PCA->getValue()->EvaluateKnownConstInt(getContext());
3986+
Out << '{' << PCA->getSpelling() << ':' << PCAInt << '}';
39873987
}
39883988
if (const auto *NBA = D->getAttr<IntelFPGANumBanksAttr>()) {
39893989
llvm::APSInt NBAInt = NBA->getValue()->EvaluateKnownConstInt(getContext());

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4082,6 +4082,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
40824082

40834083
if (Arg *A = Args.getLastArg(options::OPT_sycl_std_EQ)) {
40844084
A->render(Args, CmdArgs);
4085+
CmdArgs.push_back("-fsycl-std-layout-kernel-params");
40854086
} else if (IsSYCL) {
40864087
// Ensure the default version in SYCL mode is 1.2.1
40874088
CmdArgs.push_back("-sycl-std=1.2.1");

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3140,6 +3140,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
31403140
Opts.SYCLIsHost = Args.hasArg(options::OPT_fsycl_is_host);
31413141
Opts.SYCLAllowFuncPtr = Args.hasFlag(options::OPT_fsycl_allow_func_ptr,
31423142
options::OPT_fno_sycl_allow_func_ptr, false);
3143+
Opts.SYCLStdLayoutKernelParams =
3144+
Args.hasArg(options::OPT_fsycl_std_layout_kernel_params);
31433145
Opts.SYCLUnnamedLambda = Args.hasArg(options::OPT_fsycl_unnamed_lambda);
31443146

31453147
// Set CUDA mode for OpenMP target NVPTX if specified in options

clang/lib/Sema/Sema.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,9 @@ Sema::DeviceDiagBuilder Sema::targetDiag(SourceLocation Loc, unsigned DiagID) {
16101610
if (getLangOpts().CUDA)
16111611
return getLangOpts().CUDAIsDevice ? CUDADiagIfDeviceCode(Loc, DiagID)
16121612
: CUDADiagIfHostCode(Loc, DiagID);
1613+
// TODO: analyze which usages of targetDiag could be reused for SYCL.
1614+
// if (getLangOpts().SYCLIsDevice)
1615+
// return SYCLDiagIfDeviceCode(Loc, DiagID);
16131616
return DeviceDiagBuilder(DeviceDiagBuilder::K_Immediate, Loc, DiagID,
16141617
getCurFunctionDecl(), *this);
16151618
}

0 commit comments

Comments
 (0)