Skip to content

Commit c39df49

Browse files
committed
[clang][NFC] Refactor CUDAFunctionTarget
Refactor `CUDAFunctionTarget` into a scoped enum at namespace scope, so that it can be forward declared. This is done in preparation for `SemaCUDA`.
1 parent 5fc8a19 commit c39df49

File tree

9 files changed

+145
-121
lines changed

9 files changed

+145
-121
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,14 @@ enum class CXXSpecialMemberKind {
435435
Invalid
436436
};
437437

438+
enum class CUDAFunctionTarget {
439+
Device,
440+
Global,
441+
Host,
442+
HostDevice,
443+
InvalidTarget
444+
};
445+
438446
/// Sema - This implements semantic analysis and AST building for C.
439447
/// \nosubgrouping
440448
class Sema final : public SemaBase {
@@ -3663,20 +3671,12 @@ class Sema final : public SemaBase {
36633671
InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D,
36643672
const InternalLinkageAttr &AL);
36653673

3666-
enum CUDAFunctionTarget {
3667-
CFT_Device,
3668-
CFT_Global,
3669-
CFT_Host,
3670-
CFT_HostDevice,
3671-
CFT_InvalidTarget
3672-
};
3673-
36743674
/// Check validaty of calling convention attribute \p attr. If \p FD
36753675
/// is not null pointer, use \p FD to determine the CUDA/HIP host/device
36763676
/// target. Otherwise, it is specified by \p CFT.
3677-
bool CheckCallingConvAttr(const ParsedAttr &attr, CallingConv &CC,
3678-
const FunctionDecl *FD = nullptr,
3679-
CUDAFunctionTarget CFT = CFT_InvalidTarget);
3677+
bool CheckCallingConvAttr(
3678+
const ParsedAttr &attr, CallingConv &CC, const FunctionDecl *FD = nullptr,
3679+
CUDAFunctionTarget CFT = CUDAFunctionTarget::InvalidTarget);
36803680

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

0 commit comments

Comments
 (0)