Skip to content

Commit 417a6b0

Browse files
committed
add two flags
Signed-off-by: Sarnie, Nick <[email protected]>
1 parent 044158c commit 417a6b0

File tree

18 files changed

+40
-63
lines changed

18 files changed

+40
-63
lines changed

clang/include/clang/Basic/LangOptions.h

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

639-
bool IsOffloadingTarget = false;
640-
641639
LangOptions();
642640

643641
/// Set language defaults for the given input language and
@@ -841,7 +839,10 @@ class LangOptions : public LangOptionsBase {
841839
return EM;
842840
}
843841

844-
bool isOffloadingTarget() const { return IsOffloadingTarget; }
842+
/// True when compiling for an offloading target device.
843+
bool isTargetDevice() const {
844+
return OpenMPIsTargetDevice || CUDAIsDevice || SYCLIsDevice;
845+
}
845846
};
846847

847848
/// Floating point control options

clang/lib/AST/Decl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,7 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D,
810810
// functions as the host-callable kernel functions are emitted at codegen.
811811
if (Context.getLangOpts().OpenMP &&
812812
Context.getLangOpts().OpenMPIsTargetDevice &&
813-
((Context.getTargetInfo().getTriple().isAMDGPU() ||
814-
Context.getTargetInfo().getTriple().isNVPTX()) ||
813+
(Context.getTargetInfo().getTriple().isGPU() ||
815814
OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(Function)))
816815
LV.mergeVisibility(HiddenVisibility, /*newExplicit=*/false);
817816

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,8 +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 = CGM.getLangOpts().OpenMPIsTargetDevice &&
2617-
CGM.getLangOpts().isOffloadingTarget();
2616+
bool isGPUDistribute =
2617+
CGM.getLangOpts().OpenMPIsTargetDevice && CGM.getTriple().isGPU();
26182618
StaticInitFunction = OMPBuilder.createForStaticInitFunction(
26192619
Values.IVSize, Values.IVSigned, isGPUDistribute);
26202620

@@ -2643,8 +2643,7 @@ void CGOpenMPRuntime::emitForStaticFinish(CodeGenFunction &CGF,
26432643
getThreadID(CGF, Loc)};
26442644
auto DL = ApplyDebugLocation::CreateDefaultArtificial(CGF, Loc);
26452645
if (isOpenMPDistributeDirective(DKind) &&
2646-
CGM.getLangOpts().OpenMPIsTargetDevice &&
2647-
CGM.getLangOpts().isOffloadingTarget())
2646+
CGM.getLangOpts().OpenMPIsTargetDevice && CGM.getTriple().isGPU())
26482647
CGF.EmitRuntimeCall(
26492648
OMPBuilder.getOrCreateRuntimeFunction(
26502649
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 (LangOpts.isOffloadingTarget())
846+
if (Triple.isGPU())
847847
return false;
848848
return LangOpts.getStackProtector() == Mode;
849849
}

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,9 +1076,8 @@ class CodeGenModule : public CodeGenTypeCache {
10761076

10771077
// Return whether RTTI information should be emitted for this target.
10781078
bool shouldEmitRTTI(bool ForEH = false) {
1079-
return (ForEH || getLangOpts().RTTI) && !getLangOpts().CUDAIsDevice &&
1080-
!(getLangOpts().OpenMP && getLangOpts().OpenMPIsTargetDevice &&
1081-
getLangOpts().isOffloadingTarget());
1079+
return (ForEH || getLangOpts().RTTI) &&
1080+
(!getLangOpts().isTargetDevice() || !getTriple().isGPU());
10821081
}
10831082

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

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,8 +1101,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
11011101
if (JA.isDeviceOffloading(Action::OFK_OpenMP) &&
11021102
!Args.hasArg(options::OPT_nostdinc) &&
11031103
!Args.hasArg(options::OPT_nogpuinc) &&
1104-
(getToolChain().getTriple().isNVPTX() ||
1105-
getToolChain().getTriple().isAMDGCN())) {
1104+
getToolChain().getTriple().isGPU()) {
11061105
if (!Args.hasArg(options::OPT_nobuiltininc)) {
11071106
// Add openmp_wrappers/* to our system include path. This lets us wrap
11081107
// standard library headers.
@@ -1289,8 +1288,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
12891288
// Without an offloading language we will include these headers directly.
12901289
// Offloading languages will instead only use the declarations stored in
12911290
// the resource directory at clang/lib/Headers/llvm_libc_wrappers.
1292-
if ((getToolChain().getTriple().isNVPTX() ||
1293-
getToolChain().getTriple().isAMDGCN()) &&
1291+
if (getToolChain().getTriple().isGPU() &&
12941292
C.getActiveOffloadKinds() == Action::OFK_None) {
12951293
SmallString<128> P(llvm::sys::path::parent_path(D.Dir));
12961294
llvm::sys::path::append(P, "include");
@@ -6388,10 +6386,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
63886386
Args.AddLastArg(CmdArgs, options::OPT_fconvergent_functions,
63896387
options::OPT_fno_convergent_functions);
63906388

6391-
// NVPTX/AMDGCN doesn't support PGO or coverage. There's no runtime support
6389+
// GPUs don't support PGO or coverage. There's no runtime support
63926390
// for sampling, overhead of call arc collection is way too high and there's
63936391
// no way to collect the output.
6394-
if (!Triple.isNVPTX() && !Triple.isAMDGCN())
6392+
if (!Triple.isGPU())
63956393
addPGOAndCoverageFlags(TC, C, JA, Output, Args, SanitizeArgs, CmdArgs);
63966394

63976395
Args.AddLastArg(CmdArgs, options::OPT_fclang_abi_compat_EQ);

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ bool CompilerInstance::createTarget() {
116116
// Check whether AuxTarget exists, if not, then create TargetInfo for the
117117
// other side of CUDA/OpenMP/SYCL compilation.
118118
if (!getAuxTarget() &&
119-
(getLangOpts().CUDA || getLangOpts().OpenMPIsTargetDevice ||
120-
getLangOpts().SYCLIsDevice) &&
119+
(getLangOpts().CUDA || getLangOpts().isTargetDevice()) &&
121120
!getFrontendOpts().AuxTriple.empty()) {
122121
auto TO = std::make_shared<TargetOptions>();
123122
TO->Triple = llvm::Triple::normalize(getFrontendOpts().AuxTriple);

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4183,8 +4183,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
41834183
Opts.Blocks = Args.hasArg(OPT_fblocks) || (Opts.OpenCL
41844184
&& Opts.OpenCLVersion == 200);
41854185

4186-
bool HasConvergentOperations = Opts.OpenMPIsTargetDevice || Opts.OpenCL ||
4187-
Opts.CUDAIsDevice || Opts.SYCLIsDevice ||
4186+
bool HasConvergentOperations = Opts.isTargetDevice() || Opts.OpenCL ||
41884187
Opts.HLSL || T.isAMDGPU() || T.isNVPTX();
41894188
Opts.ConvergentFunctions =
41904189
Args.hasFlag(OPT_fconvergent_functions, OPT_fno_convergent_functions,
@@ -4357,10 +4356,6 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
43574356
Opts.OpenACCMacroOverride = A->getValue();
43584357
}
43594358

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

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,9 +1564,7 @@ void clang::InitializePreprocessor(Preprocessor &PP,
15641564
if (InitOpts.UsePredefines) {
15651565
// FIXME: This will create multiple definitions for most of the predefined
15661566
// macros. This is not the right way to handle this.
1567-
if ((LangOpts.CUDA || LangOpts.OpenMPIsTargetDevice ||
1568-
LangOpts.SYCLIsDevice) &&
1569-
PP.getAuxTargetInfo())
1567+
if ((LangOpts.CUDA || LangOpts.isTargetDevice()) && PP.getAuxTargetInfo())
15701568
InitializePredefinedMacros(*PP.getAuxTargetInfo(), LangOpts, FEOpts,
15711569
PP.getPreprocessorOpts(), Builder);
15721570

clang/lib/Sema/SemaDecl.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7854,8 +7854,7 @@ NamedDecl *Sema::ActOnVariableDeclarator(
78547854
diag::err_thread_non_global)
78557855
<< DeclSpec::getSpecifierName(TSCS);
78567856
else if (!Context.getTargetInfo().isTLSSupported()) {
7857-
if (getLangOpts().CUDA || getLangOpts().OpenMPIsTargetDevice ||
7858-
getLangOpts().SYCLIsDevice) {
7857+
if (getLangOpts().CUDA || getLangOpts().isTargetDevice()) {
78597858
// Postpone error emission until we've collected attributes required to
78607859
// figure out whether it's a host or device variable and whether the
78617860
// error should be ignored.
@@ -7986,8 +7985,7 @@ NamedDecl *Sema::ActOnVariableDeclarator(
79867985
if (const auto *TT = R->getAs<TypedefType>())
79877986
copyAttrFromTypedefToDecl<AllocSizeAttr>(*this, NewVD, TT);
79887987

7989-
if (getLangOpts().CUDA || getLangOpts().OpenMPIsTargetDevice ||
7990-
getLangOpts().SYCLIsDevice) {
7988+
if (getLangOpts().CUDA || getLangOpts().isTargetDevice()) {
79917989
if (EmitTLSUnsupportedError &&
79927990
((getLangOpts().CUDA && DeclAttrsMatchCUDAMode(getLangOpts(), NewVD)) ||
79937991
(getLangOpts().OpenMPIsTargetDevice &&
@@ -16554,9 +16552,8 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
1655416552
DiscardCleanupsInEvaluationContext();
1655516553
}
1655616554

16557-
if (FD && ((LangOpts.OpenMP && (LangOpts.OpenMPIsTargetDevice ||
16558-
!LangOpts.OMPTargetTriples.empty())) ||
16559-
LangOpts.CUDA || LangOpts.SYCLIsDevice)) {
16555+
if (FD && (LangOpts.isTargetDevice() || LangOpts.CUDA ||
16556+
(LangOpts.OpenMP && !LangOpts.OMPTargetTriples.empty()))) {
1656016557
auto ES = getEmissionStatus(FD);
1656116558
if (ES == Sema::FunctionEmissionStatus::Emitted ||
1656216559
ES == Sema::FunctionEmissionStatus::Unknown)

0 commit comments

Comments
 (0)