26#include "llvm/ADT/SmallVector.h"
35 if (
auto *A = D->
getAttr<AttrT>())
36 return !A->isImplicit();
41 assert(
getLangOpts().
CUDA &&
"Should only be called during CUDA compilation");
42 ForceHostDeviceDepth++;
46 assert(
getLangOpts().
CUDA &&
"Should only be called during CUDA compilation");
47 if (ForceHostDeviceDepth == 0)
49 ForceHostDeviceDepth--;
56 bool IsDeviceKernelCall =
false;
60 IsDeviceKernelCall =
true;
64 IsDeviceKernelCall =
true;
71 IsDeviceKernelCall =
false;
75 IsDeviceKernelCall =
false;
78 IsDeviceKernelCall =
false;
88 Diag(LLLLoc, diag::err_cuda_device_kernel_launch_not_supported));
98 if (IsDeviceKernelCall) {
109 SemaRef.MarkFunctionReferenced(LLLLoc, ConfigDecl);
111 if (IsDeviceKernelCall) {
118 SemaRef.Context.IntTy, LLLLoc));
122 SemaRef.Context.IntTy, LLLLoc));
124 llvm::append_range(Args, ExecConfig);
126 if (Args.size() < 4) {
127 llvm::APInt One(
SemaRef.Context.getTypeSize(
SemaRef.Context.IntTy), 1);
129 SemaRef.Context.IntTy, LLLLoc));
134 SemaRef.Context.IntTy, LLLLoc));
138 SemaRef.Context.NullPtrTy, LLLLoc));
139 return SemaRef.BuildCallExpr(S, ConfigDR, LLLLoc, Args, GGGLoc,
nullptr,
142 return SemaRef.BuildCallExpr(S, ConfigDR, LLLLoc, ExecConfig, GGGLoc,
nullptr,
147 bool HasHostAttr =
false;
148 bool HasDeviceAttr =
false;
149 bool HasGlobalAttr =
false;
150 bool HasInvalidTargetAttr =
false;
152 switch (AL.getKind()) {
153 case ParsedAttr::AT_CUDAGlobal:
154 HasGlobalAttr =
true;
156 case ParsedAttr::AT_CUDAHost:
159 case ParsedAttr::AT_CUDADevice:
160 HasDeviceAttr =
true;
162 case ParsedAttr::AT_CUDAInvalidTarget:
163 HasInvalidTargetAttr =
true;
170 if (HasInvalidTargetAttr)
176 if (HasHostAttr && HasDeviceAttr)
188 return isa<A>(Attribute) &&
189 !(IgnoreImplicitAttr && Attribute->isImplicit());
198 auto *VD = dyn_cast_or_null<VarDecl>(D);
199 if (VD && VD->hasGlobalStorage() && !VD->isStaticLocal()) {
206 S.CurCUDATargetCtx = {
Target, K, VD};
212 bool IgnoreImplicitHDAttr) {
223 if (D->
hasAttr<CUDAInvalidTargetAttr>())
226 if (D->
hasAttr<CUDAGlobalAttr>())
239 !IgnoreImplicitHDAttr) {
250 if (Var->
hasAttr<HIPManagedAttr>())
256 Var->
hasAttr<CUDAConstantAttr>() &&
259 if (Var->
hasAttr<CUDADeviceAttr>() || Var->
hasAttr<CUDAConstantAttr>() ||
260 Var->
hasAttr<CUDASharedAttr>() ||
313 assert(Callee &&
"Callee must be valid.");
344 if (CalleeTarget == CallerTarget ||
388 llvm_unreachable(
"All cases should've been handled by now.");
394 if (
auto *A = D->
getAttr<AttrT>())
395 return A->isImplicit();
402 return IsImplicitDevAttr && IsImplicitHostAttr;
412 if (Matches.size() <= 1)
415 using Pair = std::pair<DeclAccessPair, FunctionDecl *>;
418 auto GetCFP = [&](
const Pair &
Match) {
424 GetCFP(*llvm::max_element(Matches, [&](
const Pair &M1,
const Pair &M2) {
425 return GetCFP(M1) < GetCFP(M2);
429 llvm::erase_if(Matches,
430 [&](
const Pair &
Match) {
return GetCFP(
Match) < BestCFP; });
450 *ResolvedTarget = Target2;
452 *ResolvedTarget = Target1;
453 }
else if (Target1 != Target2) {
456 *ResolvedTarget = Target1;
471 bool HasH = MemberDecl->
hasAttr<CUDAHostAttr>();
472 bool HasD = MemberDecl->
hasAttr<CUDADeviceAttr>();
473 bool HasExplicitAttr =
474 (HasD && !MemberDecl->
getAttr<CUDADeviceAttr>()->isImplicit()) ||
475 (HasH && !MemberDecl->
getAttr<CUDAHostAttr>()->isImplicit());
476 if (!InClass || HasExplicitAttr)
479 std::optional<CUDAFunctionTarget> InferredTarget;
491 for (
const auto &B : ClassDecl->
bases()) {
492 if (!B.isVirtual()) {
498 llvm::append_range(Bases, llvm::make_pointer_range(ClassDecl->
vbases()));
500 for (
const auto *B : Bases) {
501 auto *BaseClassDecl = B->getType()->getAsCXXRecordDecl();
506 SemaRef.LookupSpecialMember(BaseClassDecl, CSM,
518 if (!InferredTarget) {
519 InferredTarget = BaseMethodTarget;
522 *InferredTarget, BaseMethodTarget, &*InferredTarget);
523 if (ResolutionError) {
526 diag::note_implicit_member_target_infer_collision)
527 << (
unsigned)CSM << *InferredTarget << BaseMethodTarget;
537 for (
const auto *F : ClassDecl->
fields()) {
538 if (F->isInvalidDecl()) {
548 SemaRef.LookupSpecialMember(FieldRecDecl, CSM,
549 ConstRHS && !F->isMutable(),
560 if (!InferredTarget) {
561 InferredTarget = FieldMethodTarget;
564 *InferredTarget, FieldMethodTarget, &*InferredTarget);
565 if (ResolutionError) {
568 diag::note_implicit_member_target_infer_collision)
569 << (
unsigned)CSM << *InferredTarget << FieldMethodTarget;
580 bool NeedsH =
true, NeedsD =
true;
581 if (InferredTarget) {
626 if (const CXXConstructExpr *CE =
627 dyn_cast<CXXConstructExpr>(CI->getInit()))
628 return isEmptyConstructor(Loc, CE->getConstructor());
670 if (CXXRecordDecl *RD = BS.getType()->getAsCXXRecordDecl())
671 return isEmptyDestructor(Loc, RD->getDestructor());
678 if (CXXRecordDecl *RD = Field->getType()
679 ->getBaseElementTypeUnsafe()
680 ->getAsCXXRecordDecl())
681 return isEmptyDestructor(Loc, RD->getDestructor());
690enum CUDAInitializerCheckKind {
691 CICK_DeviceOrConstant,
695bool IsDependentVar(
VarDecl *VD) {
699 return Init->isValueDependent();
712bool HasAllowedCUDADeviceStaticInitializer(
SemaCUDA &S, VarDecl *VD,
713 CUDAInitializerCheckKind CheckKind) {
715 assert(!IsDependentVar(VD) &&
"do not check dependent var");
717 auto IsEmptyInit = [&](
const Expr *
Init) {
720 if (
const auto *CE = dyn_cast<CXXConstructExpr>(
Init)) {
725 auto IsConstantInit = [&](
const Expr *
Init) {
727 ASTContext::CUDAConstantEvalContextRAII EvalCtx(S.
getASTContext(),
732 auto HasEmptyDtor = [&](VarDecl *VD) {
737 if (CheckKind == CICK_Shared)
738 return IsEmptyInit(
Init) && HasEmptyDtor(VD);
740 ((IsEmptyInit(
Init) || IsConstantInit(
Init)) && HasEmptyDtor(VD));
752 bool IsSharedVar = VD->
hasAttr<CUDASharedAttr>();
753 bool IsDeviceOrConstantVar =
755 (VD->
hasAttr<CUDADeviceAttr>() || VD->
hasAttr<CUDAConstantAttr>());
756 if ((IsSharedVar || IsDeviceOrConstantVar) &&
768 if (IsDeviceOrConstantVar || IsSharedVar) {
769 if (HasAllowedCUDADeviceStaticInitializer(
770 *
this, VD, IsSharedVar ? CICK_Shared : CICK_DeviceOrConstant))
773 IsSharedVar ? diag::err_shared_var_init : diag::err_dynamic_var_init)
774 <<
Init->getSourceRange();
791 diag::err_ref_bad_target_global_initializer)
792 << InitFnTarget << FD;
793 SCRef.
Diag(FD->getLocation(), diag::note_previous_decl) << FD;
802 if (
auto *VarD = dyn_cast<VarDecl>(DRE->
getDecl());
803 VarD && VarD->hasAttr<HIPManagedAttr>()) {
805 diag::err_cuda_invalid_use_of_managedvar);
807 diag::note_cuda_managed_var_in_glob_init);
810 void VisitCallExpr(
const CallExpr *CE) {
813 CheckForWrongSidedCall(InitFn);
814 Base::VisitCallExpr(CE);
820 CheckForWrongSidedCall(Ctor);
821 for (
auto *I : Ctor->
inits())
824 Base::VisitCXXConstructExpr(CE);
835 GlobVarInitChecker Checker(*
this, VD);
856 !
getASTContext().CUDAImplicitHostDeviceFunUsedByDevice.count(Caller))))
876 assert(
getLangOpts().
CUDA &&
"Should only be called during CUDA compilation");
878 if (ForceHostDeviceDepth > 0) {
879 if (!NewD->
hasAttr<CUDAHostAttr>())
881 if (!NewD->
hasAttr<CUDADeviceAttr>())
888 if (
getLangOpts().OffloadImplicitHostDeviceTemplates &&
889 !NewD->
hasAttr<CUDAHostAttr>() && !NewD->
hasAttr<CUDADeviceAttr>() &&
890 !NewD->
hasAttr<CUDAGlobalAttr>() &&
900 NewD->
hasAttr<CUDADeviceAttr>() || NewD->
hasAttr<CUDAGlobalAttr>())
905 auto IsMatchingDeviceFn = [&](
NamedDecl *D) {
907 D = Using->getTargetDecl();
909 return OldD && OldD->
hasAttr<CUDADeviceAttr>() &&
910 !OldD->
hasAttr<CUDAHostAttr>() &&
911 !
SemaRef.IsOverload(NewD, OldD,
915 auto It = llvm::find_if(
Previous, IsMatchingDeviceFn);
922 if (!
SemaRef.getSourceManager().isInSystemHeader(
Match->getLocation())) {
924 diag::err_cuda_unattributed_constexpr_cannot_overload_device)
927 diag::note_cuda_conflicting_device_function_declared_here);
943 !VD->
hasAttr<CUDASharedAttr>() &&
945 !IsDependentVar(VD) &&
947 HasAllowedCUDADeviceStaticInitializer(*
this, VD,
948 CICK_DeviceOrConstant))) {
955 assert(
getLangOpts().
CUDA &&
"Should only be called during CUDA compilation");
957 SemaRef.getCurFunctionDecl(
true);
958 SemaDiagnosticBuilder::Kind DiagKind = [&] {
960 return SemaDiagnosticBuilder::K_Nop;
964 return SemaDiagnosticBuilder::K_Immediate;
970 return SemaDiagnosticBuilder::K_Nop;
971 if (
SemaRef.IsLastErrorImmediate &&
973 return SemaDiagnosticBuilder::K_Immediate;
975 return SemaDiagnosticBuilder::K_Deferred;
976 return (
SemaRef.getEmissionStatus(CurFunContext) ==
978 ? SemaDiagnosticBuilder::K_ImmediateWithCallStack
979 : SemaDiagnosticBuilder::K_Deferred;
981 return SemaDiagnosticBuilder::K_Nop;
989 assert(
getLangOpts().
CUDA &&
"Should only be called during CUDA compilation");
991 SemaRef.getCurFunctionDecl(
true);
992 SemaDiagnosticBuilder::Kind DiagKind = [&] {
994 return SemaDiagnosticBuilder::K_Nop;
997 return SemaDiagnosticBuilder::K_Immediate;
1003 return SemaDiagnosticBuilder::K_Nop;
1004 if (
SemaRef.IsLastErrorImmediate &&
1006 return SemaDiagnosticBuilder::K_Immediate;
1007 return (
SemaRef.getEmissionStatus(CurFunContext) ==
1009 ? SemaDiagnosticBuilder::K_ImmediateWithCallStack
1010 : SemaDiagnosticBuilder::K_Deferred;
1012 return SemaDiagnosticBuilder::K_Nop;
1019 assert(
getLangOpts().
CUDA &&
"Should only be called during CUDA compilation");
1020 assert(Callee &&
"Callee may not be null.");
1022 const auto &ExprEvalCtx =
SemaRef.currentEvaluationContext();
1023 if (ExprEvalCtx.isUnevaluated() || ExprEvalCtx.isConstantEvaluated() ||
1024 ExprEvalCtx.isDiscardedStatementContext())
1041 bool CallerKnownEmitted =
SemaRef.getEmissionStatus(Caller) ==
1043 bool CallerIsImplicitHDExplicitInst =
1045 SemaDiagnosticBuilder::Kind DiagKind = [
this, Caller, Callee,
1047 CallerIsImplicitHDExplicitInst] {
1051 assert(Caller &&
"Never/wrongSide calls require a non-null caller");
1055 return (CallerKnownEmitted && !CallerIsImplicitHDExplicitInst)
1056 ? SemaDiagnosticBuilder::K_ImmediateWithCallStack
1057 : SemaDiagnosticBuilder::K_Deferred;
1059 return SemaDiagnosticBuilder::K_Nop;
1064 bool CallerHD = Caller && Caller->
hasAttr<CUDAHostAttr>() &&
1065 Caller->
hasAttr<CUDADeviceAttr>();
1066 bool CallerDiscard =
SemaRef.getEmissionStatus(Caller) ==
1068 bool RDC =
getLangOpts().GPURelocatableDeviceCode;
1069 if (IsDeviceKernelCall && !(CallerHD && CallerDiscard) && !RDC) {
1070 Diag(Loc, diag::err_cuda_device_kernel_launch_require_rdc);
1074 if (DiagKind == SemaDiagnosticBuilder::K_Nop) {
1077 Callee->hasAttr<CUDAGlobalAttr>() && !Callee->isDefined() &&
1096 if (!Callee->getBuiltinID())
1098 diag::note_previous_decl, Caller,
SemaRef)
1100 return DiagKind != SemaDiagnosticBuilder::K_Immediate &&
1101 DiagKind != SemaDiagnosticBuilder::K_ImmediateWithCallStack;
1132 bool CalleeIsDevice = Callee->hasAttr<CUDADeviceAttr>();
1134 !Caller->
hasAttr<CUDAGlobalAttr>() && !Caller->
hasAttr<CUDADeviceAttr>();
1135 bool ShouldCheck = CalleeIsDevice && CallerIsHost;
1138 auto DiagKind = SemaDiagnosticBuilder::K_Deferred;
1141 diag::err_capture_bad_target, Callee,
SemaRef)
1149 diag::warn_maybe_capture_bad_target_this_ptr, Callee,
1155 assert(
getLangOpts().
CUDA &&
"Should only be called during CUDA compilation");
1156 if (
Method->hasAttr<CUDAHostAttr>() ||
Method->hasAttr<CUDADeviceAttr>())
1164 assert(
getLangOpts().
CUDA &&
"Should only be called during CUDA compilation");
1177 if (NewTarget != OldTarget &&
1178 !
SemaRef.IsOverload(NewFD, OldFD,
false,
1181 !(
getLangOpts().OffloadImplicitHostDeviceTemplates &&
1185 !(
getLangOpts().OffloadImplicitHostDeviceTemplates &&
1191 << NewTarget << NewFD->
getDeclName() << OldTarget << OldFD;
1192 Diag(OldFD->getLocation(), diag::note_previous_declaration);
1201 << NewTarget << OldTarget;
1208template <
typename AttrTy>
1213 if (AttrTy *Attribute = TemplateFD.
getAttr<AttrTy>()) {
1214 AttrTy *Clone = Attribute->clone(S.
Context);
1215 Clone->setInherited(
true);
1230 return "__llvmPushCallConfiguration";
1233 return getLangOpts().HIPUseNewLaunchAPI ?
"__hipPushCallConfiguration"
1234 :
"hipConfigureCall";
1239 return "__cudaPushCallConfiguration";
1242 return "cudaConfigureCall";
1246 return "cudaGetParameterBuffer";
1250 return "cudaLaunchDevice";
1261 for (
unsigned I = 0; I < Arguments.size(); ++I) {
1262 auto *DeclRef = dyn_cast<DeclRefExpr>(Arguments[I]);
1265 auto *Variable = dyn_cast<VarDecl>(DeclRef->getDecl());
1266 if (!Variable || !Variable->isLocalVarDecl() || !Variable->isConstexpr())
1269 bool HostByValue =
false, HostByRef =
false;
1270 bool DeviceByValue =
false, DeviceByRef =
false;
1274 if (!Callee || I >= Callee->getNumParams())
1287 bool IsRef = Callee->getParamDecl(I)->getType()->isReferenceType();
1288 HostByValue |= CoversHost && !IsRef;
1289 HostByRef |= CoversHost && IsRef;
1290 DeviceByValue |= CoversDevice && !IsRef;
1291 DeviceByRef |= CoversDevice && IsRef;
1294 if ((HostByValue && DeviceByRef) || (HostByRef && DeviceByValue))
Defines the clang::ASTContext interface.
static bool hasImplicitAttr(const ValueDecl *decl)
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines the clang::Preprocessor interface.
static bool resolveCalleeCUDATargetConflict(CUDAFunctionTarget Target1, CUDAFunctionTarget Target2, CUDAFunctionTarget *ResolvedTarget)
When an implicitly-declared special member has to invoke more than one base/field special member,...
static bool hasAttr(const Decl *D, bool IgnoreImplicitAttr)
static void copyAttrIfPresent(Sema &S, FunctionDecl *FD, const FunctionDecl &TemplateFD)
static bool hasExplicitAttr(const VarDecl *D)
This file declares semantic analysis for CUDA constructs.
FunctionDecl * getcudaGetParameterBufferDecl()
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
llvm::SetVector< const ValueDecl * > CUDAExternalDeviceDeclODRUsedByHost
Keep track of CUDA/HIP external kernels or device variables ODR-used by host code.
llvm::DenseSet< const FunctionDecl * > CUDAImplicitHostDeviceFunUsedByDevice
Keep track of CUDA/HIP implicit host device functions used on device side in device compilation.
FunctionDecl * getcudaConfigureCallDecl()
FunctionDecl * getcudaLaunchDeviceDecl()
Attr - This represents one attribute.
Represents a base class of a C++ class.
Represents a call to a C++ constructor.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Represents a C++ constructor within a class.
Represents a C++ base or member initializer.
A default argument (C++ [dcl.fct.default]).
A use of a default initializer in a constructor or in aggregate initialization.
Expr * getExpr()
Get the initialization expression that will be used.
Represents a C++ destructor within a class.
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
The null pointer literal (C++11 [lex.nullptr])
Represents a C++ struct/union/class.
base_class_range vbases()
bool isAbstract() const
Determine whether this class has a pure virtual function.
bool isDynamicClass() const
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
ConstEvaluatedExprVisitor - This class visits 'const Expr *'s.
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
A reference to a declared variable, function, enum, etc.
SourceLocation getLocation() const
Decl - This represents one declaration (or definition), e.g.
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
bool isInvalidDecl() const
SourceLocation getLocation() const
DeclContext * getDeclContext()
This represents one expression.
Represents a member of a struct/union/class.
Represents a function declaration or definition.
bool hasTrivialBody() const
Returns whether the function has a trivial body that does not require any specific codegen.
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
bool isVariadic() const
Whether this function is variadic.
bool isTemplateInstantiation() const
Determines if the given function was instantiated from a function template.
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
bool isUserProvided() const
True if this method is user-declared and was not deleted or defaulted on its first declaration.
bool isImplicitHDExplicitInstantiation() const
True if both host and device are implicit attributes and this is (or is a member of) an explicit temp...
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
bool isDefined(const FunctionDecl *&Definition, bool CheckForPendingFriendDefinition=false) const
Returns true if the function has a definition that does not need to be instantiated.
Declaration of a template function.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Represents the results of name lookup.
This represents a decl that may have a name.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13....
ParsedAttr - Represents a syntactic attribute.
A (possibly-)qualified type.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
bool isConstQualified() const
Determine whether this type is const-qualified.
LangAS getAddressSpace() const
field_range fields() const
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Scope - A scope is a transient data structure that is used while parsing the program.
A generic diagnostic builder for errors which may or may not be deferred.
ASTContext & getASTContext() const
const LangOptions & getLangOpts() const
DiagnosticsEngine & getDiagnostics() const
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
std::string getLaunchDeviceFuncName() const
Return the name of the device kernel launch function.
void PushForceHostDevice()
Increments our count of the number of times we've seen a pragma forcing functions to be host device.
void checkAllowedInitializer(VarDecl *VD)
void RecordImplicitHostDeviceFuncUsedByDevice(const FunctionDecl *FD)
Record FD if it is a CUDA/HIP implicit host device function used on device side in device compilation...
std::string getConfigureFuncName() const
Returns the name of the launch configuration function.
bool PopForceHostDevice()
Decrements our count of the number of times we've seen a pragma forcing functions to be host device.
CUDAFunctionTarget IdentifyTarget(const FunctionDecl *D, bool IgnoreImplicitHDAttr=false)
Determines whether the given function is a CUDA device/host/kernel/etc.
static bool isImplicitHDExplicitInstantiation(const FunctionDecl *FD)
Null-tolerant wrapper for FunctionDecl::isImplicitHDExplicitInstantiation.
void maybeAddHostDeviceAttrs(FunctionDecl *FD, const LookupResult &Previous)
May add implicit CUDAHostAttr and CUDADeviceAttr attributes to FD, depending on FD and the current co...
ExprResult ActOnExecConfigExpr(Scope *S, SourceLocation LLLLoc, MultiExprArg ExecConfig, SourceLocation GGGLoc)
bool isEmptyConstructor(SourceLocation Loc, CXXConstructorDecl *CD)
std::string getGetParameterBufferFuncName() const
Return the name of the parameter buffer allocation function for the device kernel launch.
bool isEmptyDestructor(SourceLocation Loc, CXXDestructorDecl *CD)
void checkTargetOverload(FunctionDecl *NewFD, const LookupResult &Previous)
Check whether NewFD is a valid overload for CUDA.
CUDAFunctionTarget CurrentTarget()
Gets the CUDA target for the current context.
SemaDiagnosticBuilder DiagIfHostCode(SourceLocation Loc, unsigned DiagID)
Creates a SemaDiagnosticBuilder that emits the diagnostic if the current context is "used as host cod...
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 ...
struct clang::SemaCUDA::CUDATargetContext CurCUDATargetCtx
CUDATargetContextKind
Defines kinds of CUDA global host/device context where a function may be called.
@ CTCK_InitGlobalVar
Unknown context.
SemaDiagnosticBuilder DiagIfDeviceCode(SourceLocation Loc, unsigned DiagID)
Creates a SemaDiagnosticBuilder that emits the diagnostic if the current context is "used as device c...
llvm::DenseSet< FunctionDeclAndLoc > LocsWithCUDACallDiags
FunctionDecls and SourceLocations for which CheckCall has emitted a (maybe deferred) "bad call" diagn...
bool CheckCall(SourceLocation Loc, FunctionDecl *Callee)
Check whether we're allowed to call Callee from the current context.
void inheritTargetAttrs(FunctionDecl *FD, const FunctionTemplateDecl &TD)
Copies target attributes from the template TD to the function FD.
static bool isImplicitHostDeviceFunction(const FunctionDecl *D)
void CheckLambdaCapture(CXXMethodDecl *D, const sema::Capture &Capture)
void MaybeAddConstantAttr(VarDecl *VD)
May add implicit CUDAConstantAttr attribute to VD, depending on VD and current compilation settings.
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 function...
void SetLambdaAttrs(CXXMethodDecl *Method)
Set device or host device attributes on the given lambda operator() method.
CUDAFunctionPreference IdentifyPreference(const FunctionDecl *Caller, const FunctionDecl *Callee)
Identifies relative preference of a given Caller/Callee combination, based on their host/device attri...
void recordPotentialODRUsedVariable(MultiExprArg Args, OverloadCandidateSet &CandidateSet)
Record variables that are potentially ODR-used in CUDA/HIP.
@ 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.
SpecialMemberOverloadResult - The overloading result for a special member function.
CXXMethodDecl * getMethod() const
Sema - This implements semantic analysis and AST building for C.
Encodes a location in the source.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isReferenceType() const
bool isCUDADeviceBuiltinSurfaceType() const
Check if the type is the CUDA device builtin surface type.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool isCUDADeviceBuiltinTextureType() const
Check if the type is the CUDA device builtin texture type.
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Represents a variable declaration or definition.
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
bool isStaticDataMember() const
Determines whether this is a static data member.
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
const Expr * getInit() const
ValueDecl * getVariable() const
bool isVariableCapture() const
SourceLocation getLocation() const
Retrieve the location at which this variable was captured.
bool isThisCapture() const
bool isReferenceCapture() const
llvm::SmallPtrSet< VarDecl *, 4 > CUDAPotentialODRUsedVars
Variables that are potentially ODR-used in CUDA/HIP.
Defines the clang::TargetInfo interface.
Top level wrappers for InstallAPI frontend operations.
@ Match
This is not an overload because the signature exactly matches an existing declaration.
bool isa(CodeGen::Address addr)
MutableArrayRef< Expr * > MultiExprArg
bool CudaFeatureEnabled(llvm::VersionTuple, CudaFeature)
CXXSpecialMemberKind
Kinds of C++ special members.
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
ActionResult< Expr * > ExprResult
OverloadCandidate - A single candidate in an overload set (C++ 13.3).