Skip to content

Commit 48b7530

Browse files
authored
[clang][flang][Triple][llvm] Add isOffload function to LangOpts and isGPU function to Triple (#126956)
I'm adding support for SPIR-V, so let's consolidate these checks. --------- Signed-off-by: Sarnie, Nick <[email protected]>
1 parent 4277255 commit 48b7530

File tree

20 files changed

+39
-64
lines changed

20 files changed

+39
-64
lines changed

clang/include/clang/Basic/LangOptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,11 @@ class LangOptions : public LangOptionsBase {
838838
return FPExceptionModeKind::FPE_Ignore;
839839
return EM;
840840
}
841+
842+
/// True when compiling for an offloading target device.
843+
bool isTargetDevice() const {
844+
return OpenMPIsTargetDevice || CUDAIsDevice || SYCLIsDevice;
845+
}
841846
};
842847

843848
/// 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: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,8 +2614,7 @@ void CGOpenMPRuntime::emitDistributeStaticInit(
26142614
llvm::Value *ThreadId = getThreadID(CGF, Loc);
26152615
llvm::FunctionCallee StaticInitFunction;
26162616
bool isGPUDistribute =
2617-
CGM.getLangOpts().OpenMPIsTargetDevice &&
2618-
(CGM.getTriple().isAMDGCN() || CGM.getTriple().isNVPTX());
2617+
CGM.getLangOpts().OpenMPIsTargetDevice && CGM.getTriple().isGPU();
26192618
StaticInitFunction = OMPBuilder.createForStaticInitFunction(
26202619
Values.IVSize, Values.IVSigned, isGPUDistribute);
26212620

@@ -2644,8 +2643,7 @@ void CGOpenMPRuntime::emitForStaticFinish(CodeGenFunction &CGF,
26442643
getThreadID(CGF, Loc)};
26452644
auto DL = ApplyDebugLocation::CreateDefaultArtificial(CGF, Loc);
26462645
if (isOpenMPDistributeDirective(DKind) &&
2647-
CGM.getLangOpts().OpenMPIsTargetDevice &&
2648-
(CGM.getTriple().isAMDGCN() || CGM.getTriple().isNVPTX()))
2646+
CGM.getLangOpts().OpenMPIsTargetDevice && CGM.getTriple().isGPU())
26492647
CGF.EmitRuntimeCall(
26502648
OMPBuilder.getOrCreateRuntimeFunction(
26512649
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 (Triple.isGPU())
847847
return false;
848848
return LangOpts.getStackProtector() == Mode;
849849
}

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,10 +1073,8 @@ class CodeGenModule : public CodeGenTypeCache {
10731073

10741074
// Return whether RTTI information should be emitted for this target.
10751075
bool shouldEmitRTTI(bool ForEH = false) {
1076-
return (ForEH || getLangOpts().RTTI) && !getLangOpts().CUDAIsDevice &&
1077-
!(getLangOpts().OpenMP && getLangOpts().OpenMPIsTargetDevice &&
1078-
(getTriple().isNVPTX() || getTriple().isAMDGPU() ||
1079-
getTriple().isSPIRV()));
1076+
return (ForEH || getLangOpts().RTTI) &&
1077+
(!getLangOpts().isTargetDevice() || !getTriple().isGPU());
10801078
}
10811079

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

clang/lib/CodeGen/CodeGenPGO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ void CodeGenPGO::setProfileVersion(llvm::Module &M) {
13571357

13581358
IRLevelVersionVariable->setVisibility(llvm::GlobalValue::HiddenVisibility);
13591359
llvm::Triple TT(M.getTargetTriple());
1360-
if (TT.isAMDGPU() || TT.isNVPTX())
1360+
if (TT.isGPU())
13611361
IRLevelVersionVariable->setVisibility(
13621362
llvm::GlobalValue::ProtectedVisibility);
13631363
if (TT.supportsCOMDAT()) {

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,8 +1100,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
11001100
if (JA.isDeviceOffloading(Action::OFK_OpenMP) &&
11011101
!Args.hasArg(options::OPT_nostdinc) &&
11021102
!Args.hasArg(options::OPT_nogpuinc) &&
1103-
(getToolChain().getTriple().isNVPTX() ||
1104-
getToolChain().getTriple().isAMDGCN())) {
1103+
getToolChain().getTriple().isGPU()) {
11051104
if (!Args.hasArg(options::OPT_nobuiltininc)) {
11061105
// Add openmp_wrappers/* to our system include path. This lets us wrap
11071106
// standard library headers.
@@ -1288,8 +1287,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
12881287
// Without an offloading language we will include these headers directly.
12891288
// Offloading languages will instead only use the declarations stored in
12901289
// the resource directory at clang/lib/Headers/llvm_libc_wrappers.
1291-
if ((getToolChain().getTriple().isNVPTX() ||
1292-
getToolChain().getTriple().isAMDGCN()) &&
1290+
if (getToolChain().getTriple().isGPU() &&
12931291
C.getActiveOffloadKinds() == Action::OFK_None) {
12941292
SmallString<128> P(llvm::sys::path::parent_path(D.Dir));
12951293
llvm::sys::path::append(P, "include");

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4191,8 +4191,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
41914191
Opts.Blocks = Args.hasArg(OPT_fblocks) || (Opts.OpenCL
41924192
&& Opts.OpenCLVersion == 200);
41934193

4194-
bool HasConvergentOperations = Opts.OpenMPIsTargetDevice || Opts.OpenCL ||
4195-
Opts.CUDAIsDevice || Opts.SYCLIsDevice ||
4194+
bool HasConvergentOperations = Opts.isTargetDevice() || Opts.OpenCL ||
41964195
Opts.HLSL || T.isAMDGPU() || T.isNVPTX();
41974196
Opts.ConvergentFunctions =
41984197
Args.hasFlag(OPT_fconvergent_functions, OPT_fno_convergent_functions,

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,9 +1568,7 @@ void clang::InitializePreprocessor(Preprocessor &PP,
15681568
if (InitOpts.UsePredefines) {
15691569
// FIXME: This will create multiple definitions for most of the predefined
15701570
// macros. This is not the right way to handle this.
1571-
if ((LangOpts.CUDA || LangOpts.OpenMPIsTargetDevice ||
1572-
LangOpts.SYCLIsDevice) &&
1573-
PP.getAuxTargetInfo())
1571+
if ((LangOpts.CUDA || LangOpts.isTargetDevice()) && PP.getAuxTargetInfo())
15741572
InitializePredefinedMacros(*PP.getAuxTargetInfo(), LangOpts, FEOpts,
15751573
PP.getPreprocessorOpts(), Builder);
15761574

0 commit comments

Comments
 (0)