clang: clang::SemaCUDA Class Reference (original) (raw)
#include "[clang/Sema/SemaCUDA.h](SemaCUDA%5F8h%5Fsource.html)"
Classes | |
---|---|
struct | CUDATargetContext |
Define the current global CUDA host/device context where a function may be called. More... | |
struct | CUDATargetContextRAII |
struct | FunctionDeclAndLoc |
A pair of a canonical FunctionDecl and a SourceLocation. More... | |
Public Types | |
---|---|
enum | CUDAVariableTarget { CVT_Device, CVT_Host, CVT_Both, CVT_Unified } |
enum | CUDATargetContextKind { CTCK_Unknown, CTCK_InitGlobalVar } |
Defines kinds of CUDA global host/device context where a function may be called. More... | |
enum | CUDAFunctionPreference { CFP_Never, CFP_WrongSide, CFP_HostDevice, CFP_SameSide, CFP_Native } |
Public Member Functions | |
---|---|
SemaCUDA (Sema &S) | |
void | PushForceHostDevice () |
Increments our count of the number of times we've seen a pragma forcing functions to be host device. | |
bool | PopForceHostDevice () |
Decrements our count of the number of times we've seen a pragma forcing functions to be host device. | |
ExprResult | ActOnExecConfigExpr (Scope *S, SourceLocation LLLLoc, MultiExprArg ExecConfig, SourceLocation GGGLoc) |
SemaDiagnosticBuilder | DiagIfDeviceCode (SourceLocation Loc, unsigned DiagID) |
Creates a SemaDiagnosticBuilder that emits the diagnostic if the current context is "used as device code". | |
SemaDiagnosticBuilder | DiagIfHostCode (SourceLocation Loc, unsigned DiagID) |
Creates a SemaDiagnosticBuilder that emits the diagnostic if the current context is "used as host code". | |
CUDAFunctionTarget | IdentifyTarget (const FunctionDecl *D, bool IgnoreImplicitHDAttr=false) |
Determines whether the given function is a CUDA device/host/kernel/etc. | |
CUDAFunctionTarget | IdentifyTarget (const ParsedAttributesView &Attrs) |
CUDAVariableTarget | IdentifyTarget (const VarDecl *D) |
Determines whether the given variable is emitted on host or device side. | |
CUDAFunctionTarget | CurrentTarget () |
Gets the CUDA target for the current context. | |
CUDAFunctionPreference | IdentifyPreference (const FunctionDecl *Caller, const FunctionDecl *Callee) |
Identifies relative preference of a given Caller/Callee combination, based on their host/device attributes. | |
bool | IsAllowedCall (const FunctionDecl *Caller, const FunctionDecl *Callee) |
Determines whether Caller may invoke Callee, based on their CUDA host/device attributes. | |
void | maybeAddHostDeviceAttrs (FunctionDecl *FD, const LookupResult &Previous) |
May add implicit CUDAHostAttr and CUDADeviceAttr attributes to FD, depending on FD and the current compilation settings. | |
void | MaybeAddConstantAttr (VarDecl *VD) |
May add implicit CUDAConstantAttr attribute to VD, depending on VD and current compilation settings. | |
bool | CheckCall (SourceLocation Loc, FunctionDecl *Callee) |
Check whether we're allowed to call Callee from the current context. | |
void | CheckLambdaCapture (CXXMethodDecl *D, const sema::Capture &Capture) |
void | SetLambdaAttrs (CXXMethodDecl *Method) |
Set device or host device attributes on the given lambda operator() method. | |
void | RecordImplicitHostDeviceFuncUsedByDevice (const FunctionDecl *FD) |
Record FD if it is a CUDA/HIP implicit host device function used on device side in device compilation. | |
void | EraseUnwantedMatches (const FunctionDecl *Caller, llvm::SmallVectorImpl< std::pair< DeclAccessPair, FunctionDecl * > > &Matches) |
Finds a function in Matches with highest calling priority from Caller context and erases all functions with lower calling priority. | |
bool | inferTargetForImplicitSpecialMember (CXXRecordDecl *ClassDecl, CXXSpecialMemberKind CSM, CXXMethodDecl *MemberDecl, bool ConstRHS, bool Diagnose) |
Given a implicit special member, infer its CUDA target from the calls it needs to make to underlying base/field special members. | |
bool | isEmptyConstructor (SourceLocation Loc, CXXConstructorDecl *CD) |
bool | isEmptyDestructor (SourceLocation Loc, CXXDestructorDecl *CD) |
void | checkAllowedInitializer (VarDecl *VD) |
void | checkTargetOverload (FunctionDecl *NewFD, const LookupResult &Previous) |
Check whether NewFD is a valid overload for CUDA. | |
void | inheritTargetAttrs (FunctionDecl *FD, const FunctionTemplateDecl &TD) |
Copies target attributes from the template TD to the function FD. | |
std::string | getConfigureFuncName () const |
Returns the name of the launch configuration function. | |
![]() |
|
SemaBase (Sema &S) | |
ASTContext & | getASTContext () const |
DiagnosticsEngine & | getDiagnostics () const |
const LangOptions & | getLangOpts () const |
SemaDiagnosticBuilder | Diag (SourceLocation Loc, unsigned DiagID, bool DeferHint=false) |
Emit a diagnostic. | |
SemaDiagnosticBuilder | Diag (SourceLocation Loc, const PartialDiagnostic &PD, bool DeferHint=false) |
Emit a partial diagnostic. | |
PartialDiagnostic | PDiag (unsigned DiagID=0) |
Build a partial diagnostic. | |
Public Attributes | |
---|---|
llvm::DenseSet< FunctionDeclAndLoc > | LocsWithCUDACallDiags |
FunctionDecls and SourceLocations for which CheckCall has emitted a (maybe deferred) "bad call" diagnostic. | |
llvm::DenseMap< CanonicalDeclPtr< const FunctionDecl >, FunctionDeclAndLoc > | DeviceKnownEmittedFns |
An inverse call graph, mapping known-emitted functions to one of their known-emitted callers (plus the location of the call). | |
struct clang::SemaCUDA::CUDATargetContext | CurCUDATargetCtx |
![]() |
|
Sema & | SemaRef |
Definition at line 45 of file SemaCUDA.h.
◆ CUDAFunctionPreference
Enumerator |
---|
CFP_Never |
CFP_WrongSide |
CFP_HostDevice |
CFP_SameSide |
CFP_Native |
Definition at line 160 of file SemaCUDA.h.
◆ CUDATargetContextKind
Defines kinds of CUDA global host/device context where a function may be called.
Enumerator | |
---|---|
CTCK_Unknown | |
CTCK_InitGlobalVar | Unknown context. |
Definition at line 129 of file SemaCUDA.h.
◆ CUDAVariableTarget
Enumerator | |
---|---|
CVT_Device | |
CVT_Host | Emitted on device side with a shadow variable on host side. |
CVT_Both | Emitted on host side only. |
CVT_Unified | Emitted on both sides with different addresses. |
Definition at line 118 of file SemaCUDA.h.
SemaCUDA::SemaCUDA | ( | Sema & | S | ) |
---|
◆ ActOnExecConfigExpr()
◆ checkAllowedInitializer()
void SemaCUDA::checkAllowedInitializer | ( | VarDecl * | VD | ) |
---|
Definition at line 656 of file SemaCUDA.cpp.
References clang::SemaBase::Diag(), clang::Decl::getDeclContext(), clang::VarDecl::getInit(), clang::Decl::getLocation(), clang::Decl::hasAttr(), clang::VarDecl::hasGlobalStorage(), clang::VarDecl::hasInit(), clang::Host, clang::HostDevice, IdentifyTarget(), clang::Init, clang::DeclContext::isDependentContext(), clang::Decl::isInvalidDecl(), and clang::Decl::setInvalidDecl().
Referenced by clang::Sema::FinalizeDeclaration(), and clang::Sema::InstantiateVariableInitializer().
◆ CheckCall()
Check whether we're allowed to call Callee from the current context.
- If the call is never allowed in a semantically-correct program (CFP_Never), emits an error and returns false.
- If the call is allowed in semantically-correct programs, but only if it's never codegen'ed (CFP_WrongSide), creates a deferred diagnostic to be emitted if and when the caller is codegen'ed, and returns true.
Will only create deferred diagnostics for a given SourceLocation once, so you can safely call this multiple times without generating duplicate deferred errors. - Otherwise, returns true without emitting any diagnostics.
Definition at line 880 of file SemaCUDA.cpp.
References CFP_Never, CFP_WrongSide, clang::CUDA, clang::ASTContext::CUDAExternalDeviceDeclODRUsedByHost, clang::Sema::currentEvaluationContext(), clang::Sema::Emitted, clang::SemaBase::getASTContext(), clang::Sema::getCurFunctionDecl(), clang::FunctionDecl::getDescribedFunctionTemplate(), clang::Sema::getEmissionStatus(), clang::ASTContext::GetGVALinkageForFunction(), clang::SemaBase::getLangOpts(), clang::GVA_StrongExternal, IdentifyPreference(), Loc, LocsWithCUDACallDiags, and clang::SemaBase::SemaRef.
Referenced by clang::Sema::MarkFunctionReferenced().
◆ CheckLambdaCapture()
◆ checkTargetOverload()
Check whether NewFD is a valid overload for CUDA.
Emits diagnostics and invalidates NewFD if not.
Definition at line 1003 of file SemaCUDA.cpp.
References clang::CUDA, clang::Device, clang::SemaBase::Diag(), clang::Decl::getAsFunction(), clang::NamedDecl::getDeclName(), clang::SemaBase::getLangOpts(), clang::Decl::getLocation(), clang::Global, clang::Host, clang::HostDevice, IdentifyTarget(), isImplicitHostDeviceFunction(), clang::Sema::IsOverload(), Previous, clang::SemaBase::SemaRef, and clang::Decl::setInvalidDecl().
Referenced by clang::Sema::CheckFunctionDeclaration().
◆ CurrentTarget()
◆ DiagIfDeviceCode()
Creates a SemaDiagnosticBuilder that emits the diagnostic if the current context is "used as device code".
- If CurContext is a host function, does not emit any diagnostics unless
EmitOnBothSides
is true. - If CurContext is a device or global function, emits the diagnostics immediately.
- If CurContext is a host device function and we are compiling for the device, creates a diagnostic which is emitted if and when we realize that the function will be codegen'ed.
Example usage:
// Variable-length arrays are not allowed in CUDA device code. if (DiagIfDeviceCode(Loc, diag::err_cuda_vla) << CurrentTarget()) return ExprError(); // Otherwise, continue parsing as normal.
Definition at line 817 of file SemaCUDA.cpp.
References clang::CUDA, CurrentTarget(), clang::Device, clang::Sema::Emitted, clang::Sema::getCurFunctionDecl(), clang::SemaBase::getDiagnostics(), clang::Sema::getEmissionStatus(), clang::SemaBase::getLangOpts(), clang::Global, clang::HostDevice, clang::Sema::IsLastErrorImmediate, Loc, and clang::SemaBase::SemaRef.
Referenced by clang::Sema::ActOnCXXTryBlock(), clang::Sema::BuildCXXThrow(), and clang::SemaBase::Diag().
◆ DiagIfHostCode()
Creates a SemaDiagnosticBuilder that emits the diagnostic if the current context is "used as host code".
Same as DiagIfDeviceCode, with "host" and "device" switched.
Definition at line 849 of file SemaCUDA.cpp.
References clang::CUDA, CurrentTarget(), clang::Sema::Emitted, clang::Sema::getCurFunctionDecl(), clang::SemaBase::getDiagnostics(), clang::Sema::getEmissionStatus(), clang::SemaBase::getLangOpts(), clang::Host, clang::HostDevice, clang::Sema::IsLastErrorImmediate, Loc, and clang::SemaBase::SemaRef.
Referenced by clang::SemaBase::Diag(), and handleSharedAttr().
◆ EraseUnwantedMatches()
◆ getConfigureFuncName()
std::string SemaCUDA::getConfigureFuncName | ( | ) | const |
---|
◆ IdentifyPreference()
Identifies relative preference of a given Caller/Callee combination, based on their host/device attributes.
Parameters
Caller | function which needs address of Callee. nullptr in case of global context. |
---|---|
Callee | target function |
Returns
preference value for particular Caller/Callee combination.
Definition at line 225 of file SemaCUDA.cpp.
References CFP_HostDevice, CFP_Native, CFP_Never, CFP_SameSide, CFP_WrongSide, CTCK_InitGlobalVar, CurCUDATargetCtx, clang::Device, clang::SemaBase::getLangOpts(), clang::Global, clang::Host, clang::HostDevice, IdentifyTarget(), clang::InvalidTarget, clang::SemaCUDA::CUDATargetContext::Kind, and clang::SemaCUDA::CUDATargetContext::Target.
Referenced by clang::OverloadCandidateSet::BestViableFunction(), CheckCall(), EraseUnwantedMatches(), IsAllowedCall(), clang::isBetterOverloadCandidate(), and clang::Sema::isUsualDeallocationFunction().
◆ IdentifyTarget() [1/3]
Determines whether the given function is a CUDA device/host/kernel/etc.
IdentifyTarget - Determine the CUDA compilation target for this function.
function.
Use this rather than examining the function's attributes yourself – you will get it wrong. Returns CUDAFunctionTarget::Host if D is null.
Definition at line 134 of file SemaCUDA.cpp.
References CurCUDATargetCtx, D, clang::Device, clang::Global, clang::Decl::hasAttr(), clang::Host, clang::HostDevice, clang::InvalidTarget, clang::Decl::isImplicit(), and clang::SemaCUDA::CUDATargetContext::Target.
Referenced by clang::Sema::ActOnExplicitInstantiation(), clang::Sema::BuildVAArgExpr(), checkAllowedInitializer(), clang::Sema::CheckCallingConvAttr(), clang::Sema::CheckFunctionTemplateSpecialization(), checkTargetOverload(), CurrentTarget(), DiagnoseBadTarget(), getCCForDeclaratorChunk(), GetDeclSpecTypeForDeclarator(), clang::Sema::getEmissionStatus(), GetFullTypeForDeclarator(), handleCallConvAttr(), IdentifyPreference(), IdentifyTarget(), inferTargetForImplicitSpecialMember(), IsOverloadOrOverrideImpl(), MarkVarDeclODRUsed(), RecordImplicitHostDeviceFuncUsedByDevice(), and clang::Sema::shouldIgnoreInHostDeviceCheck().
◆ IdentifyTarget() [2/3]
◆ IdentifyTarget() [3/3]
Determines whether the given variable is emitted on host or device side.
IdentifyTarget - Determine the CUDA compilation target for this variable.
Definition at line 163 of file SemaCUDA.cpp.
References CVT_Both, CVT_Device, CVT_Host, CVT_Unified, clang::Device, clang::Decl::getDeclContext(), clang::ValueDecl::getType(), clang::Global, clang::Decl::hasAttr(), clang::HostDevice, IdentifyTarget(), clang::VarDecl::isConstexpr(), clang::QualType::isConstQualified(), clang::Type::isCUDADeviceBuiltinSurfaceType(), and clang::Type::isCUDADeviceBuiltinTextureType().
◆ inferTargetForImplicitSpecialMember()
Given a implicit special member, infer its CUDA target from the calls it needs to make to underlying base/field special members.
Parameters
ClassDecl | the class for which the member is being created. |
---|---|
CSM | the kind of special member. |
MemberDecl | the special member itself. |
ConstRHS | true if this is a copy operation with a const object on its RHS. |
Diagnose | true if this call should emit diagnostics. |
Returns
true if there was an error inferring. The result of this call is implicit CUDA target attribute(s) attached to the member declaration.
Definition at line 370 of file SemaCUDA.cpp.
References clang::Decl::addAttr(), clang::CXXRecordDecl::bases(), clang::Device, clang::SemaBase::Diag(), clang::RecordDecl::fields(), clang::Type::getAs(), clang::SemaBase::getASTContext(), clang::Decl::getAttr(), clang::ASTContext::getBaseElementType(), clang::RecordType::getDecl(), clang::DeclContext::getLexicalParent(), clang::Decl::getLocation(), clang::Sema::SpecialMemberOverloadResult::getMethod(), clang::CXXMethodDecl::getParent(), clang::Decl::hasAttr(), clang::Host, IdentifyTarget(), clang::CXXRecordDecl::isAbstract(), clang::Sema::LookupSpecialMember(), resolveCalleeCUDATargetConflict(), clang::SemaBase::SemaRef, and clang::CXXRecordDecl::vbases().
Referenced by clang::Sema::DeclareImplicitCopyAssignment(), clang::Sema::DeclareImplicitCopyConstructor(), clang::Sema::DeclareImplicitDefaultConstructor(), clang::Sema::DeclareImplicitDestructor(), clang::Sema::DeclareImplicitMoveAssignment(), clang::Sema::DeclareImplicitMoveConstructor(), DiagnoseBadTarget(), and clang::Sema::ShouldDeleteSpecialMember().
◆ inheritTargetAttrs()
◆ IsAllowedCall()
Determines whether Caller may invoke Callee, based on their CUDA host/device attributes.
Returns false if the call is not allowed.
Note: Will return true for CFP_WrongSide calls. These may appear in semantically correct CUDA programs, but only if they're never codegen'ed.
Definition at line 186 of file SemaCUDA.h.
References CFP_Never, and IdentifyPreference().
◆ isEmptyConstructor()
Returns
true if CD
can be considered empty according to CUDA (E.2.3.1 in CUDA 7.5 Programming guide).
Definition at line 510 of file SemaCUDA.cpp.
References clang::Redeclarable< decl_type >::getFirstDecl(), clang::FunctionDecl::getNumParams(), clang::CXXMethodDecl::getParent(), clang::FunctionDecl::hasTrivialBody(), clang::CXXConstructorDecl::inits(), clang::Sema::InstantiateFunctionDefinition(), clang::FunctionDecl::isDefined(), clang::CXXRecordDecl::isDynamicClass(), clang::FunctionDecl::isTemplateInstantiation(), clang::FunctionDecl::isTrivial(), clang::TagDecl::isUnion(), Loc, and clang::SemaBase::SemaRef.
◆ isEmptyDestructor()
Definition at line 548 of file SemaCUDA.cpp.
References clang::CXXRecordDecl::bases(), clang::RecordDecl::fields(), clang::Redeclarable< decl_type >::getFirstDecl(), clang::CXXMethodDecl::getParent(), clang::FunctionDecl::hasTrivialBody(), clang::Sema::InstantiateFunctionDefinition(), clang::FunctionDecl::isDefined(), clang::CXXRecordDecl::isDynamicClass(), clang::FunctionDecl::isTemplateInstantiation(), clang::FunctionDecl::isTrivial(), clang::TagDecl::isUnion(), Loc, and clang::SemaBase::SemaRef.
◆ isImplicitHostDeviceFunction()
◆ MaybeAddConstantAttr()
void SemaCUDA::MaybeAddConstantAttr | ( | VarDecl * | VD | ) |
---|
◆ maybeAddHostDeviceAttrs()
May add implicit CUDAHostAttr and CUDADeviceAttr attributes to FD, depending on FD and the current compilation settings.
Definition at line 738 of file SemaCUDA.cpp.
References clang::Decl::addAttr(), clang::CUDA, D, clang::SemaBase::Diag(), clang::Decl::getAsFunction(), clang::SemaBase::getASTContext(), clang::FunctionDecl::getDescribedFunctionTemplate(), clang::SemaBase::getLangOpts(), clang::Decl::getLocation(), clang::Sema::getSourceManager(), clang::Decl::hasAttr(), clang::FunctionDecl::isConstexpr(), clang::FunctionDecl::isFunctionTemplateSpecialization(), clang::SourceManager::isInSystemHeader(), clang::Sema::IsOverload(), clang::FunctionDecl::isVariadic(), Previous, and clang::SemaBase::SemaRef.
Referenced by clang::Sema::ActOnFunctionDeclarator().
◆ PopForceHostDevice()
bool SemaCUDA::PopForceHostDevice | ( | ) |
---|
Decrements our count of the number of times we've seen a pragma forcing functions to be host device.
Returns false if the count is 0 before incrementing, so you can emit an error.
Definition at line 44 of file SemaCUDA.cpp.
References clang::CUDA, and clang::SemaBase::getLangOpts().
◆ PushForceHostDevice()
void SemaCUDA::PushForceHostDevice | ( | ) |
---|
Increments our count of the number of times we've seen a pragma forcing functions to be host device.
So long as this count is greater than zero, all functions encountered will be host device.
Definition at line 39 of file SemaCUDA.cpp.
References clang::CUDA, and clang::SemaBase::getLangOpts().
◆ RecordImplicitHostDeviceFuncUsedByDevice()
void SemaCUDA::RecordImplicitHostDeviceFuncUsedByDevice | ( | const FunctionDecl * | FD | ) |
---|
◆ SetLambdaAttrs()
◆ ASTReader
◆ ASTWriter
◆ CurCUDATargetCtx
◆ DeviceKnownEmittedFns
An inverse call graph, mapping known-emitted functions to one of their known-emitted callers (plus the location of the call).
Functions that we can tell a priori must be emitted aren't added to this map.
Definition at line 82 of file SemaCUDA.h.
Referenced by emitCallStackNotes().
◆ LocsWithCUDACallDiags
FunctionDecls and SourceLocations for which CheckCall has emitted a (maybe deferred) "bad call" diagnostic.
We use this to avoid emitting the same deferred diag twice.
Definition at line 73 of file SemaCUDA.h.
Referenced by CheckCall().
The documentation for this class was generated from the following files:
- include/clang/Sema/SemaCUDA.h
- lib/Sema/SemaCUDA.cpp