Skip to content

Commit 044158c

Browse files
committed
[clang] Add isOffloadingTarget function to LangOpts
Signed-off-by: Sarnie, Nick <[email protected]>
1 parent c017cdf commit 044158c

File tree

6 files changed

+17
-19
lines changed

6 files changed

+17
-19
lines changed

clang/include/clang/Basic/LangOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,8 @@ class LangOptions : public LangOptionsBase {
636636
bool AtomicFineGrainedMemory = false;
637637
bool AtomicIgnoreDenormalMode = false;
638638

639+
bool IsOffloadingTarget = false;
640+
639641
LangOptions();
640642

641643
/// Set language defaults for the given input language and
@@ -838,6 +840,8 @@ class LangOptions : public LangOptionsBase {
838840
return FPExceptionModeKind::FPE_Ignore;
839841
return EM;
840842
}
843+
844+
bool isOffloadingTarget() const { return IsOffloadingTarget; }
841845
};
842846

843847
/// Floating point control options

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,9 +2613,8 @@ void CGOpenMPRuntime::emitDistributeStaticInit(
26132613
emitUpdateLocation(CGF, Loc, OMP_IDENT_WORK_DISTRIBUTE);
26142614
llvm::Value *ThreadId = getThreadID(CGF, Loc);
26152615
llvm::FunctionCallee StaticInitFunction;
2616-
bool isGPUDistribute =
2617-
CGM.getLangOpts().OpenMPIsTargetDevice &&
2618-
(CGM.getTriple().isAMDGCN() || CGM.getTriple().isNVPTX());
2616+
bool isGPUDistribute = CGM.getLangOpts().OpenMPIsTargetDevice &&
2617+
CGM.getLangOpts().isOffloadingTarget();
26192618
StaticInitFunction = OMPBuilder.createForStaticInitFunction(
26202619
Values.IVSize, Values.IVSigned, isGPUDistribute);
26212620

@@ -2645,7 +2644,7 @@ void CGOpenMPRuntime::emitForStaticFinish(CodeGenFunction &CGF,
26452644
auto DL = ApplyDebugLocation::CreateDefaultArtificial(CGF, Loc);
26462645
if (isOpenMPDistributeDirective(DKind) &&
26472646
CGM.getLangOpts().OpenMPIsTargetDevice &&
2648-
(CGM.getTriple().isAMDGCN() || CGM.getTriple().isNVPTX()))
2647+
CGM.getLangOpts().isOffloadingTarget())
26492648
CGF.EmitRuntimeCall(
26502649
OMPBuilder.getOrCreateRuntimeFunction(
26512650
CGM.getModule(), OMPRTL___kmpc_distribute_static_fini),

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ static void setVisibilityFromDLLStorageClass(const clang::LangOptions &LO,
843843
static bool isStackProtectorOn(const LangOptions &LangOpts,
844844
const llvm::Triple &Triple,
845845
clang::LangOptions::StackProtectorMode Mode) {
846-
if (Triple.isAMDGPU() || Triple.isNVPTX())
846+
if (LangOpts.isOffloadingTarget())
847847
return false;
848848
return LangOpts.getStackProtector() == Mode;
849849
}

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,8 +1078,7 @@ class CodeGenModule : public CodeGenTypeCache {
10781078
bool shouldEmitRTTI(bool ForEH = false) {
10791079
return (ForEH || getLangOpts().RTTI) && !getLangOpts().CUDAIsDevice &&
10801080
!(getLangOpts().OpenMP && getLangOpts().OpenMPIsTargetDevice &&
1081-
(getTriple().isNVPTX() || getTriple().isAMDGPU() ||
1082-
getTriple().isSPIRV()));
1081+
getLangOpts().isOffloadingTarget());
10831082
}
10841083

10851084
/// Get the address of the RTTI descriptor for the given type.

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4357,6 +4357,10 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
43574357
Opts.OpenACCMacroOverride = A->getValue();
43584358
}
43594359

4360+
Opts.IsOffloadingTarget =
4361+
(Opts.OpenMPIsTargetDevice || Opts.SYCLIsDevice || Opts.CUDAIsDevice) &&
4362+
(T.isNVPTX() || T.isAMDGCN() || T.isSPIROrSPIRV());
4363+
43604364
// FIXME: Eliminate this dependency.
43614365
unsigned Opt = getOptimizationLevel(Args, IK, Diags),
43624366
OptSize = getOptimizationLevelSize(Args);

clang/lib/Sema/SemaType.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,8 +1122,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
11221122
}
11231123
case DeclSpec::TST_int128:
11241124
if (!S.Context.getTargetInfo().hasInt128Type() &&
1125-
!(S.getLangOpts().SYCLIsDevice || S.getLangOpts().CUDAIsDevice ||
1126-
(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsTargetDevice)))
1125+
!(S.getLangOpts().isOffloadingTarget()))
11271126
S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
11281127
<< "__int128";
11291128
if (DS.getTypeSpecSign() == TypeSpecifierSign::Unsigned)
@@ -1168,8 +1167,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
11681167
break;
11691168
case DeclSpec::TST_float128:
11701169
if (!S.Context.getTargetInfo().hasFloat128Type() &&
1171-
!S.getLangOpts().SYCLIsDevice && !S.getLangOpts().CUDAIsDevice &&
1172-
!(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsTargetDevice))
1170+
!S.getLangOpts().isOffloadingTarget())
11731171
S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
11741172
<< "__float128";
11751173
Result = Context.Float128Ty;
@@ -8362,12 +8360,7 @@ static bool verifyValidIntegerConstantExpr(Sema &S, const ParsedAttr &Attr,
83628360
/// match one of the standard Neon vector types.
83638361
static void HandleNeonVectorTypeAttr(QualType &CurType, const ParsedAttr &Attr,
83648362
Sema &S, VectorKind VecKind) {
8365-
bool IsTargetCUDAAndHostARM = false;
8366-
if (S.getLangOpts().CUDAIsDevice) {
8367-
const TargetInfo *AuxTI = S.getASTContext().getAuxTargetInfo();
8368-
IsTargetCUDAAndHostARM =
8369-
AuxTI && (AuxTI->getTriple().isAArch64() || AuxTI->getTriple().isARM());
8370-
}
8363+
bool IsTargetOffloading = S.getLangOpts().isOffloadingTarget();
83718364

83728365
// Target must have NEON (or MVE, whose vectors are similar enough
83738366
// not to need a separate attribute)
@@ -8401,8 +8394,7 @@ static void HandleNeonVectorTypeAttr(QualType &CurType, const ParsedAttr &Attr,
84018394
return;
84028395

84038396
// Only certain element types are supported for Neon vectors.
8404-
if (!isPermittedNeonBaseType(CurType, VecKind, S) &&
8405-
!IsTargetCUDAAndHostARM) {
8397+
if (!isPermittedNeonBaseType(CurType, VecKind, S) && !IsTargetOffloading) {
84068398
S.Diag(Attr.getLoc(), diag::err_attribute_invalid_vector_type) << CurType;
84078399
Attr.setInvalid();
84088400
return;

0 commit comments

Comments
 (0)