clang  19.0.0git
Classes | Macros | Typedefs | Enumerations | Functions | Variables
SemaSYCL.cpp File Reference
#include "clang/Sema/SemaSYCL.h"
#include "TreeTransform.h"
#include "clang/AST/AST.h"
#include "clang/AST/Mangle.h"
#include "clang/AST/QualTypeNames.h"
#include "clang/AST/RecordLayout.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/TemplateArgumentVisitor.h"
#include "clang/AST/TypeVisitor.h"
#include "clang/Analysis/CallGraph.h"
#include "clang/Basic/Attributes.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/Version.h"
#include "clang/Sema/Initialization.h"
#include "clang/Sema/Sema.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include <array>
#include <functional>
#include <initializer_list>

Go to the source code of this file.

Classes

class  DiagDeviceFunction
 
class  DeviceFunctionTracker
 
class  SingleDeviceFunctionTracker
 
class  KernelBodyTransform
 
class  MarkWIScopeFnVisitor
 
class  SYCLKernelNameTypeVisitor
 
class  SYCLFwdDeclEmitter
 
class  SYCLKernelNameTypePrinter
 

Macros

#define KF_FOR_EACH(FUNC, Item, Qt)
 
#define KP_FOR_EACH(FUNC, Item, Qt)
 
#define CASE(x)
 

Typedefs

using KernelParamKind = SYCLIntegrationHeader::kernel_param_kind_t
 
using ParamDesc = std::tuple< QualType, IdentifierInfo *, TypeSourceInfo * >
 

Enumerations

enum  target {
  global_buffer = 2014 , constant_buffer , local , image ,
  host_buffer , host_image , image_array
}
 
enum  KernelInvocationKind { InvokeUnknown , InvokeSingleTask , InvokeParallelFor , InvokeParallelForWorkGroup }
 

Functions

static bool isSyclAccessorType (QualType Ty)
 
static bool isAccessorPropertyType (QualType Ty, SYCLTypeAttr::SYCLType TypeName)
 
static bool isSyclSpecialType (QualType Ty, SemaSYCL &S)
 
static bool IsSyclMathFunc (unsigned BuiltinID)
 
static bool isZeroSizedArray (SemaSYCL &S, QualType Ty)
 
static void checkSYCLType (SemaSYCL &S, QualType Ty, SourceRange Loc, llvm::DenseSet< QualType > Visited, SourceRange UsedAtLoc=SourceRange())
 
static bool isSYCLKernelBodyFunction (FunctionDecl *FD)
 
static bool isSYCLUndefinedAllowed (const FunctionDecl *Callee, const SourceManager &SrcMgr)
 
static void reportConflictingAttrs (SemaSYCL &S, FunctionDecl *F, const Attr *A1, const Attr *A2)
 
static int64_t getIntExprValue (const Expr *E, ASTContext &Ctx)
 Returns the signed constant integer value represented by given expression. More...
 
static void collectSYCLAttributes (SemaSYCL &S, FunctionDecl *FD, llvm::SmallVectorImpl< Attr * > &Attrs, bool DirectlyCalled)
 
static bool isDeclaredInSYCLNamespace (const Decl *D)
 This function checks whether given DeclContext contains a topmost namespace with name "sycl". More...
 
static ParamDesc makeParamDesc (const FieldDecl *Src, QualType Ty)
 Creates a kernel parameter descriptor. More...
 
static ParamDesc makeParamDesc (const ParmVarDecl *Src, QualType Ty)
 
static ParamDesc makeParamDesc (ASTContext &Ctx, StringRef Name, QualType Ty)
 
static void unsupportedFreeFunctionParamType ()
 
static bool isSYCLPrivateMemoryVar (VarDecl *VD)
 
static void addScopeAttrToLocalVars (CXXMethodDecl &F)
 
static CXXMethodDeclgetMethodByName (const CXXRecordDecl *CRD, StringRef MethodName)
 Return method by name. More...
 
static KernelInvocationKind getKernelInvocationKind (FunctionDecl *KernelCallerFunc)
 
static QualType GetSYCLKernelObjectType (const FunctionDecl *KernelCaller)
 
static target getAccessTarget (QualType FieldTy, const ClassTemplateSpecializationDecl *AccTy)
 
static bool isFreeFunction (SemaSYCL &SemaSYCLRef, const FunctionDecl *FD)
 
static std::pair< std::string, std::string > constructFreeFunctionKernelName (SemaSYCL &SemaSYCLRef, const FunctionDecl *FreeFunc, MangleContext &MC)
 
static QualType calculateKernelNameType (ASTContext &Ctx, const FunctionDecl *KernelCallerFunc)
 
static std::pair< std::string, std::string > constructKernelName (SemaSYCL &S, const FunctionDecl *KernelCallerFunc, MangleContext &MC)
 
static bool isDefaultSPIRArch (ASTContext &Context)
 
static ParmVarDeclgetSyclKernelHandlerArg (FunctionDecl *KernelCallerFunc)
 
static bool isReadOnlyAccessor (const TemplateArgument &AccessModeArg)
 
void ConstructFreeFunctionKernel (SemaSYCL &SemaSYCLRef, FunctionDecl *FD)
 
static std::pair< LangOptions::SubGroupSizeType, int64_t > CalcEffectiveSubGroup (ASTContext &Ctx, const LangOptions &LO, const FunctionDecl *FD)
 
static SourceLocation GetSubGroupLoc (const FunctionDecl *FD)
 
static void CheckSYCL2020SubGroupSizes (SemaSYCL &S, FunctionDecl *SYCLKernel, const FunctionDecl *FD)
 
static void CheckSYCL2020Attributes (SemaSYCL &S, FunctionDecl *SYCLKernel, FunctionDecl *KernelBody, const llvm::SmallPtrSetImpl< FunctionDecl * > &CalledFuncs)
 
static void PropagateAndDiagnoseDeviceAttr (SemaSYCL &S, const SingleDeviceFunctionTracker &Tracker, Attr *A, FunctionDecl *SYCLKernel, FunctionDecl *KernelBody)
 
static const char * paramKind2Str (KernelParamKind K)
 Returns a string ID of given parameter kind - used in header emission. More...
 
static void OutputStableNameChar (raw_ostream &O, char C)
 
static void OutputStableNameInChars (raw_ostream &O, StringRef Name)
 
template<typename BeforeFn , typename AfterFn >
static void PrintNSHelper (BeforeFn Before, AfterFn After, raw_ostream &OS, const DeclContext *DC)
 
static void PrintNamespaces (raw_ostream &OS, const DeclContext *DC)
 
static void PrintNSClosingBraces (raw_ostream &OS, const DeclContext *DC)
 
static std::string EmitShim (raw_ostream &OS, unsigned &ShimCounter, const std::string &LastShim, const NamespaceDecl *AnonNS)
 
static void EmitShims (raw_ostream &OS, unsigned &ShimCounter, const DeclContext *DC, std::string &NameForLastShim, PrintingPolicy &Policy)
 
static std::string EmitShims (raw_ostream &OS, unsigned &ShimCounter, PrintingPolicy &Policy, const VarDecl *VD)
 

Variables

static constexpr llvm::StringLiteral InitMethodName = "__init"
 
static constexpr llvm::StringLiteral InitESIMDMethodName = "__init_esimd"
 
static constexpr llvm::StringLiteral InitSpecConstantsBuffer
 
static constexpr llvm::StringLiteral FinalizeMethodName = "__finalize"
 
static constexpr llvm::StringLiteral LibstdcxxFailedAssertion
 
constexpr unsigned MaxKernelArgsSize = 2048
 

Macro Definition Documentation

◆ CASE

#define CASE (   x)
Value:
case SYCLIntegrationHeader::kind_##x: \
return "kind_" #x

◆ KF_FOR_EACH

#define KF_FOR_EACH (   FUNC,
  Item,
  Qt 
)
Value:
handleField( \
Item, Qt, \
std::bind(static_cast<bool (std::decay_t<decltype(Handlers)>::*)( \
bind_param_t<decltype(Item)>, QualType)>( \
&std::decay_t<decltype(Handlers)>::FUNC), \
std::ref(Handlers), _1, _2)...)
A (possibly-)qualified type.
Definition: Type.h:940
__inline void unsigned int _2
Definition: larchintrin.h:181

Definition at line 1253 of file SemaSYCL.cpp.

◆ KP_FOR_EACH

#define KP_FOR_EACH (   FUNC,
  Item,
  Qt 
)
Value:
handleParam( \
Item, Qt, \
std::bind(static_cast<bool (std::decay_t<decltype(Handlers)>::*)( \
bind_param_t<decltype(Item)>, QualType)>( \
&std::decay_t<decltype(Handlers)>::FUNC), \
std::ref(Handlers), _1, _2)...)

Definition at line 1276 of file SemaSYCL.cpp.

Typedef Documentation

◆ KernelParamKind

Definition at line 43 of file SemaSYCL.cpp.

◆ ParamDesc

using ParamDesc = std::tuple<QualType, IdentifierInfo *, TypeSourceInfo *>

Definition at line 55 of file SemaSYCL.cpp.

Enumeration Type Documentation

◆ KernelInvocationKind

Enumerator
InvokeUnknown 
InvokeSingleTask 
InvokeParallelFor 
InvokeParallelForWorkGroup 

Definition at line 57 of file SemaSYCL.cpp.

◆ target

enum target
Enumerator
global_buffer 
constant_buffer 
local 
image 
host_buffer 
host_image 
image_array 

Definition at line 45 of file SemaSYCL.cpp.

Function Documentation

◆ addScopeAttrToLocalVars()

static void addScopeAttrToLocalVars ( CXXMethodDecl F)
static

◆ CalcEffectiveSubGroup()

static std::pair<LangOptions::SubGroupSizeType, int64_t> CalcEffectiveSubGroup ( ASTContext Ctx,
const LangOptions LO,
const FunctionDecl FD 
)
static

◆ calculateKernelNameType()

static QualType calculateKernelNameType ( ASTContext Ctx,
const FunctionDecl KernelCallerFunc 
)
static

◆ CheckSYCL2020Attributes()

static void CheckSYCL2020Attributes ( SemaSYCL S,
FunctionDecl SYCLKernel,
FunctionDecl KernelBody,
const llvm::SmallPtrSetImpl< FunctionDecl * > &  CalledFuncs 
)
static

Definition at line 5133 of file SemaSYCL.cpp.

Referenced by clang::SemaSYCL::MarkDevices().

◆ CheckSYCL2020SubGroupSizes()

static void CheckSYCL2020SubGroupSizes ( SemaSYCL S,
FunctionDecl SYCLKernel,
const FunctionDecl FD 
)
static

Definition at line 5081 of file SemaSYCL.cpp.

◆ checkSYCLType()

static void checkSYCLType ( SemaSYCL S,
QualType  Ty,
SourceRange  Loc,
llvm::DenseSet< QualType Visited,
SourceRange  UsedAtLoc = SourceRange() 
)
static

Definition at line 405 of file SemaSYCL.cpp.

Referenced by clang::SemaSYCL::checkSYCLDeviceVarDecl().

◆ collectSYCLAttributes()

static void collectSYCLAttributes ( SemaSYCL S,
FunctionDecl FD,
llvm::SmallVectorImpl< Attr * > &  Attrs,
bool  DirectlyCalled 
)
static

Definition at line 527 of file SemaSYCL.cpp.

Referenced by clang::SemaSYCL::copySYCLKernelAttrs().

◆ ConstructFreeFunctionKernel()

void ConstructFreeFunctionKernel ( SemaSYCL SemaSYCLRef,
FunctionDecl FD 
)

◆ constructFreeFunctionKernelName()

static std::pair<std::string, std::string> constructFreeFunctionKernelName ( SemaSYCL SemaSYCLRef,
const FunctionDecl FreeFunc,
MangleContext MC 
)
static

Definition at line 1110 of file SemaSYCL.cpp.

References clang::MangleContext::mangleName().

Referenced by clang::SemaSYCL::SetSYCLKernelNames().

◆ constructKernelName()

static std::pair<std::string, std::string> constructKernelName ( SemaSYCL S,
const FunctionDecl KernelCallerFunc,
MangleContext MC 
)
static

◆ EmitShim()

static std::string EmitShim ( raw_ostream &  OS,
unsigned ShimCounter,
const std::string &  LastShim,
const NamespaceDecl AnonNS 
)
static

Definition at line 6347 of file SemaSYCL.cpp.

References clang::Decl::castToDeclContext(), PrintNamespaces(), and PrintNSClosingBraces().

Referenced by EmitShims().

◆ EmitShims() [1/2]

static void EmitShims ( raw_ostream &  OS,
unsigned ShimCounter,
const DeclContext DC,
std::string &  NameForLastShim,
PrintingPolicy Policy 
)
static

◆ EmitShims() [2/2]

static std::string EmitShims ( raw_ostream &  OS,
unsigned ShimCounter,
PrintingPolicy Policy,
const VarDecl VD 
)
static

◆ getAccessTarget()

static target getAccessTarget ( QualType  FieldTy,
const ClassTemplateSpecializationDecl AccTy 
)
static
Returns
the target of given SYCL accessor type

Definition at line 1064 of file SemaSYCL.cpp.

References clang::ClassTemplateSpecializationDecl::getTemplateArgs(), clang::SemaSYCL::isSyclType(), and local.

◆ getIntExprValue()

static int64_t getIntExprValue ( const Expr E,
ASTContext Ctx 
)
static

Returns the signed constant integer value represented by given expression.

Definition at line 522 of file SemaSYCL.cpp.

References clang::Expr::getIntegerConstantExpr().

Referenced by CalcEffectiveSubGroup().

◆ getKernelInvocationKind()

static KernelInvocationKind getKernelInvocationKind ( FunctionDecl KernelCallerFunc)
static

◆ getMethodByName()

static CXXMethodDecl* getMethodByName ( const CXXRecordDecl CRD,
StringRef  MethodName 
)
static

Return method by name.

Definition at line 1027 of file SemaSYCL.cpp.

References clang::CXXRecordDecl::methods().

◆ GetSubGroupLoc()

static SourceLocation GetSubGroupLoc ( const FunctionDecl FD)
static

Definition at line 5073 of file SemaSYCL.cpp.

References clang::Decl::getAttr().

◆ getSyclKernelHandlerArg()

static ParmVarDecl* getSyclKernelHandlerArg ( FunctionDecl KernelCallerFunc)
static

◆ GetSYCLKernelObjectType()

static QualType GetSYCLKernelObjectType ( const FunctionDecl KernelCaller)
static

◆ isAccessorPropertyType()

static bool isAccessorPropertyType ( QualType  Ty,
SYCLTypeAttr::SYCLType  TypeName 
)
static

Definition at line 99 of file SemaSYCL.cpp.

References clang::Type::getAsCXXRecordDecl(), Parent, and clang::TypeName.

◆ isDeclaredInSYCLNamespace()

static bool isDeclaredInSYCLNamespace ( const Decl D)
static

This function checks whether given DeclContext contains a topmost namespace with name "sycl".

Definition at line 738 of file SemaSYCL.cpp.

References clang::Decl::getDeclContext(), clang::DeclContext::getEnclosingNamespaceContext(), and Parent.

◆ isDefaultSPIRArch()

static bool isDefaultSPIRArch ( ASTContext Context)
static

Definition at line 1174 of file SemaSYCL.cpp.

◆ isFreeFunction()

static bool isFreeFunction ( SemaSYCL SemaSYCLRef,
const FunctionDecl FD 
)
static

◆ isReadOnlyAccessor()

static bool isReadOnlyAccessor ( const TemplateArgument AccessModeArg)
static

◆ isSyclAccessorType()

static bool isSyclAccessorType ( QualType  Ty)
static

Definition at line 90 of file SemaSYCL.cpp.

References clang::SemaSYCL::isSyclType().

◆ isSYCLKernelBodyFunction()

static bool isSYCLKernelBodyFunction ( FunctionDecl FD)
static

◆ IsSyclMathFunc()

static bool IsSyclMathFunc ( unsigned  BuiltinID)
static

Definition at line 320 of file SemaSYCL.cpp.

Referenced by DiagDeviceFunction::VisitCallExpr().

◆ isSYCLPrivateMemoryVar()

static bool isSYCLPrivateMemoryVar ( VarDecl VD)
static

Definition at line 1002 of file SemaSYCL.cpp.

References clang::ValueDecl::getType(), and clang::SemaSYCL::isSyclType().

Referenced by addScopeAttrToLocalVars().

◆ isSyclSpecialType()

static bool isSyclSpecialType ( QualType  Ty,
SemaSYCL S 
)
static

Definition at line 109 of file SemaSYCL.cpp.

◆ isSYCLUndefinedAllowed()

static bool isSYCLUndefinedAllowed ( const FunctionDecl Callee,
const SourceManager SrcMgr 
)
static

◆ isZeroSizedArray()

static bool isZeroSizedArray ( SemaSYCL S,
QualType  Ty 
)
static

Definition at line 399 of file SemaSYCL.cpp.

Referenced by clang::SemaSYCL::deepTypeCheckForDevice().

◆ makeParamDesc() [1/3]

static ParamDesc makeParamDesc ( ASTContext Ctx,
StringRef  Name,
QualType  Ty 
)
static

Definition at line 964 of file SemaSYCL.cpp.

◆ makeParamDesc() [2/3]

static ParamDesc makeParamDesc ( const FieldDecl Src,
QualType  Ty 
)
static

Creates a kernel parameter descriptor.

Parameters
Srcfield declaration to construct name from
Tythe desired parameter type
Returns
the constructed descriptor

Definition at line 951 of file SemaSYCL.cpp.

References clang::Decl::getASTContext().

◆ makeParamDesc() [3/3]

static ParamDesc makeParamDesc ( const ParmVarDecl Src,
QualType  Ty 
)
static

Definition at line 957 of file SemaSYCL.cpp.

References clang::Decl::getASTContext().

◆ OutputStableNameChar()

static void OutputStableNameChar ( raw_ostream &  O,
char  C 
)
static

Definition at line 5912 of file SemaSYCL.cpp.

◆ OutputStableNameInChars()

static void OutputStableNameInChars ( raw_ostream &  O,
StringRef  Name 
)
static

Definition at line 5921 of file SemaSYCL.cpp.

Referenced by clang::SYCLIntegrationHeader::emit().

◆ paramKind2Str()

static const char* paramKind2Str ( KernelParamKind  K)
static

Returns a string ID of given parameter kind - used in header emission.

Definition at line 5533 of file SemaSYCL.cpp.

References CASE.

Referenced by clang::SYCLIntegrationHeader::emit().

◆ PrintNamespaces()

static void PrintNamespaces ( raw_ostream &  OS,
const DeclContext DC 
)
static

◆ PrintNSClosingBraces()

static void PrintNSClosingBraces ( raw_ostream &  OS,
const DeclContext DC 
)
static

◆ PrintNSHelper()

template<typename BeforeFn , typename AfterFn >
static void PrintNSHelper ( BeforeFn  Before,
AfterFn  After,
raw_ostream &  OS,
const DeclContext DC 
)
static

◆ PropagateAndDiagnoseDeviceAttr()

static void PropagateAndDiagnoseDeviceAttr ( SemaSYCL S,
const SingleDeviceFunctionTracker Tracker,
Attr A,
FunctionDecl SYCLKernel,
FunctionDecl KernelBody 
)
static

Definition at line 5179 of file SemaSYCL.cpp.

Referenced by clang::SemaSYCL::MarkDevices().

◆ reportConflictingAttrs()

static void reportConflictingAttrs ( SemaSYCL S,
FunctionDecl F,
const Attr A1,
const Attr A2 
)
static

Definition at line 513 of file SemaSYCL.cpp.

◆ unsupportedFreeFunctionParamType()

static void unsupportedFreeFunctionParamType ( )
static

Definition at line 969 of file SemaSYCL.cpp.

Variable Documentation

◆ FinalizeMethodName

constexpr llvm::StringLiteral FinalizeMethodName = "__finalize"
staticconstexpr

Definition at line 68 of file SemaSYCL.cpp.

◆ InitESIMDMethodName

constexpr llvm::StringLiteral InitESIMDMethodName = "__init_esimd"
staticconstexpr

Definition at line 65 of file SemaSYCL.cpp.

◆ InitMethodName

constexpr llvm::StringLiteral InitMethodName = "__init"
staticconstexpr

Definition at line 64 of file SemaSYCL.cpp.

◆ InitSpecConstantsBuffer

constexpr llvm::StringLiteral InitSpecConstantsBuffer
staticconstexpr
Initial value:
=
"__init_specialization_constants_buffer"

Definition at line 66 of file SemaSYCL.cpp.

◆ LibstdcxxFailedAssertion

constexpr llvm::StringLiteral LibstdcxxFailedAssertion
staticconstexpr
Initial value:
=
"__failed_assertion"

Definition at line 69 of file SemaSYCL.cpp.

Referenced by isSYCLUndefinedAllowed().

◆ MaxKernelArgsSize

constexpr unsigned MaxKernelArgsSize = 2048
constexpr

Definition at line 71 of file SemaSYCL.cpp.