Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Remove sycl address space #5

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions clang/include/clang/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,15 +486,12 @@ class Qualifiers {
/// Returns true if the address space in these qualifiers is equal to or
/// a superset of the address space in the argument qualifiers.
bool isAddressSpaceSupersetOf(Qualifiers other) const {

return
isAddressSpaceSupersetOf(getAddressSpace(), other.getAddressSpace()) ||
(!hasAddressSpace() &&
(other.getAddressSpace() == LangAS::sycl_private ||
other.getAddressSpace() == LangAS::sycl_local ||
other.getAddressSpace() == LangAS::sycl_global ||
other.getAddressSpace() == LangAS::sycl_constant ||
other.getAddressSpace() == LangAS::sycl_generic));
return isAddressSpaceSupersetOf(getAddressSpace(),
other.getAddressSpace()) ||
(!hasAddressSpace() &&
(other.getAddressSpace() == LangAS::opencl_private ||
other.getAddressSpace() == LangAS::opencl_local ||
other.getAddressSpace() == LangAS::opencl_global));
}

/// Determines if these qualifiers compatibly include another set.
Expand Down
8 changes: 0 additions & 8 deletions clang/include/clang/Basic/AddressSpaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ enum class LangAS : unsigned {
cuda_constant,
cuda_shared,

sycl_global,
sycl_local,
sycl_constant,
sycl_private,
// Likely never used, but useful in the future to reserve the spot in the
// enum.
sycl_generic,

// Pointer size and extension address spaces.
ptr32_sptr,
ptr32_uptr,
Expand Down
9 changes: 9 additions & 0 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,15 @@ def SYCLIntelMaxGlobalWorkDim : InheritableAttr {
let PragmaAttributeSupport = 0;
}

def SYCLIntelUsesGlobalWorkOffset : InheritableAttr {
let Spellings = [CXX11<"intelfpga","uses_global_work_offset">];
let Args = [BoolArgument<"Enabled">];
let LangOpts = [SYCLIsDevice, SYCLIsHost];
let Subjects = SubjectList<[Function], ErrorDiag>;
let Documentation = [SYCLIntelUsesGlobalWorkOffsetDocs];
let PragmaAttributeSupport = 0;
}

def C11NoReturn : InheritableAttr {
let Spellings = [Keyword<"_Noreturn">];
let Subjects = SubjectList<[Function], ErrorDiag>;
Expand Down
10 changes: 10 additions & 0 deletions clang/include/clang/Basic/AttrDocs.td
Original file line number Diff line number Diff line change
Expand Up @@ -2009,6 +2009,16 @@ device kernel, the attribute is ignored and it is not propagated to a kernel.
}];
}

def SYCLIntelUsesGlobalWorkOffsetDocs : Documentation {
let Category = DocCatFunction;
let Heading = "uses_global_work_offset (IntelFPGA)";
let Content = [{
Applies to a device function/lambda function or function call operator (of a
function object). If 0, compiler doesn't use the global work offset values for
the device function. Valid values are 0 and 1.
}];
}

def SYCLFPGAPipeDocs : Documentation {
let Category = DocCatStmt;
let Heading = "pipe (read_only, write_only)";
Expand Down
3 changes: 2 additions & 1 deletion clang/include/clang/Basic/AttributeCommonInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ class AttributeCommonInfo {
(ParsedAttr == AT_IntelReqdSubGroupSize && isCXX11Attribute()) ||
ParsedAttr == AT_SYCLIntelNumSimdWorkItems ||
ParsedAttr == AT_SYCLIntelMaxWorkGroupSize ||
ParsedAttr == AT_SYCLIntelMaxGlobalWorkDim)
ParsedAttr == AT_SYCLIntelMaxGlobalWorkDim ||
ParsedAttr == AT_SYCLIntelUsesGlobalWorkOffset)
return true;

return false;
Expand Down
4 changes: 3 additions & 1 deletion clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,10 @@ def NSReturnsMismatch : DiagGroup<"nsreturns-mismatch">;
def IndependentClassAttribute : DiagGroup<"IndependentClass-attribute">;
def UnknownAttributes : DiagGroup<"unknown-attributes">;
def IgnoredAttributes : DiagGroup<"ignored-attributes">;
def AdjustedAttributes : DiagGroup<"adjusted-attributes">;
def Attributes : DiagGroup<"attributes", [UnknownAttributes,
IgnoredAttributes]>;
IgnoredAttributes,
AdjustedAttributes]>;
def UnknownSanitizers : DiagGroup<"unknown-sanitizers">;
def UnnamedTypeTemplateArgs : DiagGroup<"unnamed-type-template-args",
[CXX98CompatUnnamedTypeTemplateArgs]>;
Expand Down
5 changes: 3 additions & 2 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -10292,8 +10292,6 @@ def err_builtin_launder_invalid_arg : Error<
"'__builtin_launder' is not allowed">;

// SYCL-specific diagnostics
def err_sycl_attribute_address_space_invalid : Error<
"address space is outside the valid range of values">;
def err_sycl_kernel_name_class_not_top_level : Error<
"kernel name class and its template argument classes' declarations can only "
"nest in a namespace: %0">;
Expand Down Expand Up @@ -10324,6 +10322,9 @@ def err_sycl_x_y_z_arguments_must_be_one : Error<
"%0 X-, Y- and Z- sizes must be 1 when %1 attribute is used with value 0">;
def err_intel_attribute_argument_is_not_in_range: Error<
"The value of %0 attribute must be in range from 0 to 3">;
def warn_boolean_attribute_argument_is_not_valid: Warning<
"The value of %0 attribute should be 0 or 1. Adjusted to 1">,
InGroup<AdjustedAttributes>;
def err_sycl_attibute_cannot_be_applied_here
: Error<"%0 attribute cannot be applied to a "
"%select{static function or function in an anonymous namespace"
Expand Down
18 changes: 0 additions & 18 deletions clang/include/clang/Sema/ParsedAttr.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,24 +534,6 @@ class ParsedAttr final
}
}

/// If this is an OpenCL addr space attribute returns its SYCL representation
/// in LangAS, otherwise returns default addr space.
LangAS asSYCLLangAS() const {
switch (getKind()) {
case ParsedAttr::AT_OpenCLConstantAddressSpace:
return LangAS::sycl_constant;
case ParsedAttr::AT_OpenCLGlobalAddressSpace:
return LangAS::sycl_global;
case ParsedAttr::AT_OpenCLLocalAddressSpace:
return LangAS::sycl_local;
case ParsedAttr::AT_OpenCLPrivateAddressSpace:
return LangAS::sycl_private;
case ParsedAttr::AT_OpenCLGenericAddressSpace:
default:
return LangAS::Default;
}
}

AttributeCommonInfo::Kind getKind() const { return getParsedKind(); }
};

Expand Down
26 changes: 24 additions & 2 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -12079,11 +12079,33 @@ class Sema final {
KernelCallDllimportFunction,
KernelCallVariadicFunction
};
DeviceDiagBuilder SYCLDiagIfDeviceCode(SourceLocation Loc, unsigned DiagID);
bool isKnownGoodSYCLDecl(const Decl *D);
void ConstructOpenCLKernel(FunctionDecl *KernelCallerFunc, MangleContext &MC);
void MarkDevice(void);
bool CheckSYCLCall(SourceLocation Loc, FunctionDecl *Callee);

/// Creates a DeviceDiagBuilder that emits the diagnostic if the current
/// context is "used as device code".
///
/// - If CurLexicalContext is a kernel function or it is known that the
/// function will be emitted for the device, emits the diagnostics
/// immediately.
/// - If CurLexicalContext is a function and we are compiling
/// for the device, but we don't know that this function will be codegen'ed
/// for devive yet, creates a diagnostic which is emitted if and when we
/// realize that the function will be codegen'ed.
///
/// Example usage:
///
/// Variables with thread storage duration are not allowed to be used in SYCL
/// device code
/// if (getLangOpts().SYCLIsDevice)
/// 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);
};

/// RAII object that enters a new expression evaluation context.
Expand Down
5 changes: 0 additions & 5 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,11 +836,6 @@ static const LangASMap *getAddressSpaceMap(const TargetInfo &T,
5, // cuda_device
6, // cuda_constant
7, // cuda_shared
1, // sycl_global
3, // sycl_local
2, // sycl_constant
0, // sycl_private
4, // sycl_generic
8, // ptr32_sptr
9, // ptr32_uptr
10 // ptr64
Expand Down
4 changes: 0 additions & 4 deletions clang/lib/AST/TypePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1792,16 +1792,12 @@ std::string Qualifiers::getAddrSpaceAsString(LangAS AS) {
case LangAS::Default:
return "";
case LangAS::opencl_global:
case LangAS::sycl_global:
return "__global";
case LangAS::opencl_local:
case LangAS::sycl_local:
return "__local";
case LangAS::opencl_private:
case LangAS::sycl_private:
return "__private";
case LangAS::opencl_constant:
case LangAS::sycl_constant:
return "__constant";
case LangAS::opencl_generic:
return "__generic";
Expand Down
10 changes: 0 additions & 10 deletions clang/lib/Basic/Targets/AMDGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ const LangASMap AMDGPUTargetInfo::AMDGPUDefIsGenMap = {
Global, // cuda_device
Constant, // cuda_constant
Local, // cuda_shared
Global, // sycl_global
Local, // sycl_local
Constant, // sycl_constant
Private, // sycl_private
Generic, // sycl_generic
Generic, // ptr32_sptr
Generic, // ptr32_uptr
Generic // ptr64
Expand All @@ -68,11 +63,6 @@ const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = {
Global, // cuda_device
Constant, // cuda_constant
Local, // cuda_shared
Global, // sycl_global
Local, // sycl_local
Constant, // sycl_constant
Private, // sycl_private
Generic, // sycl_generic
Generic, // ptr32_sptr
Generic, // ptr32_uptr
Generic // ptr64
Expand Down
6 changes: 0 additions & 6 deletions clang/lib/Basic/Targets/NVPTX.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ static const unsigned NVPTXAddrSpaceMap[] = {
1, // cuda_device
4, // cuda_constant
3, // cuda_shared
1, // sycl_global
3, // sycl_local
4, // sycl_constant
0, // sycl_private
// FIXME: generic has to be added to the target
0, // sycl_generic
0, // ptr32_sptr
0, // ptr32_uptr
0 // ptr64
Expand Down
18 changes: 3 additions & 15 deletions clang/lib/Basic/Targets/SPIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ static const unsigned SPIRAddrSpaceMap[] = {
0, // cuda_device
0, // cuda_constant
0, // cuda_shared
1, // sycl_global
3, // sycl_local
2, // sycl_constant
0, // sycl_private
4, // sycl_generic
0, // ptr32_sptr
0, // ptr32_uptr
0 // ptr64
Expand All @@ -53,11 +48,6 @@ static const unsigned SYCLAddrSpaceMap[] = {
0, // cuda_device
0, // cuda_constant
0, // cuda_shared
1, // sycl_global
3, // sycl_local
2, // sycl_constant
0, // sycl_private
4, // sycl_generic
0, // ptr32_sptr
0, // ptr32_uptr
0 // ptr64
Expand All @@ -70,11 +60,9 @@ class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public TargetInfo {
TLSSupported = false;
VLASupported = false;
LongWidth = LongAlign = 64;
if (Triple.getEnvironment() == llvm::Triple::SYCLDevice) {
AddrSpaceMap = &SYCLAddrSpaceMap;
} else {
AddrSpaceMap = &SPIRAddrSpaceMap;
}
AddrSpaceMap = (Triple.getEnvironment() == llvm::Triple::SYCLDevice)
? &SYCLAddrSpaceMap
: &SPIRAddrSpaceMap;
UseAddrSpaceMapMangling = true;
HasLegalHalfType = true;
HasFloat16 = true;
Expand Down
6 changes: 0 additions & 6 deletions clang/lib/Basic/Targets/TCE.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ static const unsigned TCEOpenCLAddrSpaceMap[] = {
0, // cuda_device
0, // cuda_constant
0, // cuda_shared
3, // sycl_global
4, // sycl_local
5, // sycl_constant
0, // sycl_private
// FIXME: generic has to be added to the target
0, // sycl_generic
0, // ptr32_sptr
0, // ptr32_uptr
0, // ptr64
Expand Down
5 changes: 0 additions & 5 deletions clang/lib/Basic/Targets/X86.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ static const unsigned X86AddrSpaceMap[] = {
0, // cuda_device
0, // cuda_constant
0, // cuda_shared
0, // sycl_global
0, // sycl_local
0, // sycl_constant
0, // sycl_private
0, // sycl_generic
270, // ptr32_sptr
271, // ptr32_uptr
272 // ptr64
Expand Down
11 changes: 11 additions & 0 deletions clang/lib/CodeGen/CodeGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,17 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD,
Fn->setMetadata("max_global_work_dim",
llvm::MDNode::get(Context, AttrMDArgs));
}

if (const SYCLIntelUsesGlobalWorkOffsetAttr *A =
FD->getAttr<SYCLIntelUsesGlobalWorkOffsetAttr>()) {
bool IsEnabled = A->getEnabled();
if (!IsEnabled) {
llvm::Metadata *AttrMDArgs[] = {
llvm::ConstantAsMetadata::get(Builder.getInt32(IsEnabled))};
Fn->setMetadata("uses_global_work_offset",
llvm::MDNode::get(Context, AttrMDArgs));
}
}
}

/// Determine whether the function F ends with a return stmt.
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Sema/Sema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,9 @@ Sema::DeviceDiagBuilder Sema::targetDiag(SourceLocation Loc, unsigned DiagID) {
if (getLangOpts().CUDA)
return getLangOpts().CUDAIsDevice ? CUDADiagIfDeviceCode(Loc, DiagID)
: CUDADiagIfHostCode(Loc, DiagID);
// TODO: analyze which usages of targetDiag could be reused for SYCL.
// if (getLangOpts().SYCLIsDevice)
// return SYCLDiagIfDeviceCode(Loc, DiagID);
return DeviceDiagBuilder(DeviceDiagBuilder::K_Immediate, Loc, DiagID,
getCurFunctionDecl(), *this);
}
Expand Down
27 changes: 27 additions & 0 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5166,6 +5166,26 @@ static bool checkForDuplicateAttribute(Sema &S, Decl *D,
return false;
}

static void handleUsesGlobalWorkOffsetAttr(Sema &S, Decl *D,
const ParsedAttr &Attr) {
if (S.LangOpts.SYCLIsHost)
return;

checkForDuplicateAttribute<SYCLIntelUsesGlobalWorkOffsetAttr>(S, D, Attr);

uint32_t Enabled;
const Expr *E = Attr.getArgAsExpr(0);
if (!checkUInt32Argument(S, Attr, E, Enabled, 0,
/*StrictlyUnsigned=*/true))
return;
if (Enabled > 1)
S.Diag(Attr.getLoc(), diag::warn_boolean_attribute_argument_is_not_valid)
<< Attr;

D->addAttr(::new (S.Context)
SYCLIntelUsesGlobalWorkOffsetAttr(S.Context, Attr, Enabled));
}

/// Handle the [[intelfpga::doublepump]] and [[intelfpga::singlepump]] attributes.
/// One but not both can be specified
/// Both are incompatible with the __register__ attribute.
Expand Down Expand Up @@ -7599,6 +7619,9 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
case ParsedAttr::AT_SYCLIntelMaxGlobalWorkDim:
handleMaxGlobalWorkDimAttr(S, D, AL);
break;
case ParsedAttr::AT_SYCLIntelUsesGlobalWorkOffset:
handleUsesGlobalWorkOffsetAttr(S, D, AL);
break;
case ParsedAttr::AT_VecTypeHint:
handleVecTypeHint(S, D, AL);
break;
Expand Down Expand Up @@ -8082,6 +8105,10 @@ void Sema::ProcessDeclAttributeList(Scope *S, Decl *D,
} else if (const auto *A = D->getAttr<SYCLIntelMaxWorkGroupSizeAttr>()) {
Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A;
D->setInvalidDecl();
} else if (const auto *A =
D->getAttr<SYCLIntelUsesGlobalWorkOffsetAttr>()) {
Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A;
D->setInvalidDecl();
} else if (const auto *A = D->getAttr<VecTypeHintAttr>()) {
Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A;
D->setInvalidDecl();
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14644,7 +14644,7 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
if (getLangOpts().CUDA && !CheckCUDACall(ConstructLoc, Constructor))
return ExprError();
if (getLangOpts().SYCLIsDevice)
CheckSYCLCall(ConstructLoc, Constructor);
checkSYCLDeviceFunction(ConstructLoc, Constructor);

return CXXConstructExpr::Create(
Context, DeclInitType, ConstructLoc, Constructor, Elidable,
Expand Down
Loading