Skip to content

Commit

Permalink
[clang][NFC] Refactor CUDAFunctionTarget
Browse files Browse the repository at this point in the history
Refactor `CUDAFunctionTarget` into a scoped enum at namespace scope, so that it can be forward declared. This is done in preparation for `SemaCUDA`.
  • Loading branch information
Endilll committed Apr 12, 2024
1 parent 5fc8a19 commit c39df49
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 121 deletions.
29 changes: 15 additions & 14 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,14 @@ enum class CXXSpecialMemberKind {
Invalid
};

enum class CUDAFunctionTarget {
Device,
Global,
Host,
HostDevice,
InvalidTarget
};

/// Sema - This implements semantic analysis and AST building for C.
/// \nosubgrouping
class Sema final : public SemaBase {
Expand Down Expand Up @@ -3663,20 +3671,12 @@ class Sema final : public SemaBase {
InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D,
const InternalLinkageAttr &AL);

enum CUDAFunctionTarget {
CFT_Device,
CFT_Global,
CFT_Host,
CFT_HostDevice,
CFT_InvalidTarget
};

/// Check validaty of calling convention attribute \p attr. If \p FD
/// is not null pointer, use \p FD to determine the CUDA/HIP host/device
/// target. Otherwise, it is specified by \p CFT.
bool CheckCallingConvAttr(const ParsedAttr &attr, CallingConv &CC,
const FunctionDecl *FD = nullptr,
CUDAFunctionTarget CFT = CFT_InvalidTarget);
bool CheckCallingConvAttr(
const ParsedAttr &attr, CallingConv &CC, const FunctionDecl *FD = nullptr,
CUDAFunctionTarget CFT = CUDAFunctionTarget::InvalidTarget);

void AddParameterABIAttr(Decl *D, const AttributeCommonInfo &CI,
ParameterABI ABI);
Expand Down Expand Up @@ -12967,7 +12967,8 @@ class Sema final : public SemaBase {
/// Example usage:
///
/// // Variable-length arrays are not allowed in CUDA device code.
/// if (CUDADiagIfDeviceCode(Loc, diag::err_cuda_vla) << CurrentCUDATarget())
/// if (CUDADiagIfDeviceCode(Loc, diag::err_cuda_vla)
/// << llvm::to_underlying(CurrentCUDATarget()))
/// return ExprError();
/// // Otherwise, continue parsing as normal.
SemaDiagnosticBuilder CUDADiagIfDeviceCode(SourceLocation Loc,
Expand All @@ -12983,7 +12984,7 @@ class Sema final : public SemaBase {
/// function.
///
/// Use this rather than examining the function's attributes yourself -- you
/// will get it wrong. Returns CFT_Host if D is null.
/// will get it wrong. Returns CUDAFunctionTarget::Host if D is null.
CUDAFunctionTarget IdentifyCUDATarget(const FunctionDecl *D,
bool IgnoreImplicitHDAttr = false);
CUDAFunctionTarget IdentifyCUDATarget(const ParsedAttributesView &Attrs);
Expand All @@ -13008,7 +13009,7 @@ class Sema final : public SemaBase {
/// Define the current global CUDA host/device context where a function may be
/// called. Only used when a function is called outside of any functions.
struct CUDATargetContext {
CUDAFunctionTarget Target = CFT_HostDevice;
CUDAFunctionTarget Target = CUDAFunctionTarget::HostDevice;
CUDATargetContextKind Kind = CTCK_Unknown;
Decl *D = nullptr;
} CurCUDATargetCtx;
Expand Down

0 comments on commit c39df49

Please sign in to comment.