Skip to content

Commit 967dec4

Browse files
committed
[LLVM][Triple][NFCI] Add function to test for GPU offloading triples
Signed-off-by: Sarnie, Nick <[email protected]>
1 parent cb3498c commit 967dec4

File tree

11 files changed

+22
-24
lines changed

11 files changed

+22
-24
lines changed

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,9 +2624,8 @@ void CGOpenMPRuntime::emitDistributeStaticInit(
26242624
emitUpdateLocation(CGF, Loc, OMP_IDENT_WORK_DISTRIBUTE);
26252625
llvm::Value *ThreadId = getThreadID(CGF, Loc);
26262626
llvm::FunctionCallee StaticInitFunction;
2627-
bool isGPUDistribute =
2628-
CGM.getLangOpts().OpenMPIsTargetDevice &&
2629-
(CGM.getTriple().isAMDGCN() || CGM.getTriple().isNVPTX());
2627+
bool isGPUDistribute = CGM.getLangOpts().OpenMPIsTargetDevice &&
2628+
CGM.getTriple().isOffloadingTargetGPU();
26302629
StaticInitFunction = OMPBuilder.createForStaticInitFunction(
26312630
Values.IVSize, Values.IVSigned, isGPUDistribute);
26322631

@@ -2656,7 +2655,7 @@ void CGOpenMPRuntime::emitForStaticFinish(CodeGenFunction &CGF,
26562655
auto DL = ApplyDebugLocation::CreateDefaultArtificial(CGF, Loc);
26572656
if (isOpenMPDistributeDirective(DKind) &&
26582657
CGM.getLangOpts().OpenMPIsTargetDevice &&
2659-
(CGM.getTriple().isAMDGCN() || CGM.getTriple().isNVPTX()))
2658+
CGM.getTriple().isOffloadingTargetGPU())
26602659
CGF.EmitRuntimeCall(
26612660
OMPBuilder.getOrCreateRuntimeFunction(
26622661
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
@@ -842,7 +842,7 @@ static void setVisibilityFromDLLStorageClass(const clang::LangOptions &LO,
842842
static bool isStackProtectorOn(const LangOptions &LangOpts,
843843
const llvm::Triple &Triple,
844844
clang::LangOptions::StackProtectorMode Mode) {
845-
if (Triple.isAMDGPU() || Triple.isNVPTX())
845+
if (Triple.isOffloadingTargetGPU())
846846
return false;
847847
return LangOpts.getStackProtector() == Mode;
848848
}

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,8 +1067,7 @@ class CodeGenModule : public CodeGenTypeCache {
10671067
bool shouldEmitRTTI(bool ForEH = false) {
10681068
return (ForEH || getLangOpts().RTTI) && !getLangOpts().CUDAIsDevice &&
10691069
!(getLangOpts().OpenMP && getLangOpts().OpenMPIsTargetDevice &&
1070-
(getTriple().isNVPTX() || getTriple().isAMDGPU() ||
1071-
getTriple().isSPIRV()));
1070+
getTriple().isOffloadingTargetGPU());
10721071
}
10731072

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

clang/lib/Driver/Driver.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3351,10 +3351,9 @@ class OffloadingActionBuilder final {
33513351

33523352
const ToolChain *HostTC = C.getSingleOffloadToolChain<Action::OFK_Host>();
33533353
assert(HostTC && "No toolchain for host compilation.");
3354-
if (HostTC->getTriple().isNVPTX() ||
3355-
HostTC->getTriple().getArch() == llvm::Triple::amdgcn) {
3356-
// We do not support targeting NVPTX/AMDGCN for host compilation. Throw
3357-
// an error and abort pipeline construction early so we don't trip
3354+
if (HostTC->getTriple().isOffloadingTargetGPU()) {
3355+
// We do not support targeting offloading GPUs for host compilation.
3356+
// Throw an error and abort pipeline construction early so we don't trip
33583357
// asserts that assume device-side compilation.
33593358
C.getDriver().Diag(diag::err_drv_cuda_host_arch)
33603359
<< HostTC->getTriple().getArchName();

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,8 +1133,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
11331133
if (JA.isDeviceOffloading(Action::OFK_OpenMP) &&
11341134
!Args.hasArg(options::OPT_nostdinc) &&
11351135
!Args.hasArg(options::OPT_nogpuinc) &&
1136-
(getToolChain().getTriple().isNVPTX() ||
1137-
getToolChain().getTriple().isAMDGCN())) {
1136+
getToolChain().getTriple().isOffloadingTargetGPU()) {
11381137
if (!Args.hasArg(options::OPT_nobuiltininc)) {
11391138
// Add openmp_wrappers/* to our system include path. This lets us wrap
11401139
// standard library headers.
@@ -1321,8 +1320,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
13211320
// Without an offloading language we will include these headers directly.
13221321
// Offloading languages will instead only use the declarations stored in
13231322
// the resource directory at clang/lib/Headers/llvm_libc_wrappers.
1324-
if ((getToolChain().getTriple().isNVPTX() ||
1325-
getToolChain().getTriple().isAMDGCN()) &&
1323+
if (getToolChain().getTriple().isOffloadingTargetGPU() &&
13261324
C.getActiveOffloadKinds() == Action::OFK_None) {
13271325
SmallString<128> P(llvm::sys::path::parent_path(D.Dir));
13281326
llvm::sys::path::append(P, "include");

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2973,8 +2973,8 @@ void tools::addMCModel(const Driver &D, const llvm::opt::ArgList &Args,
29732973
} else if (Triple.getArch() == llvm::Triple::x86_64) {
29742974
Ok = llvm::is_contained({"small", "kernel", "medium", "large", "tiny"},
29752975
CM);
2976-
} else if (Triple.isNVPTX() || Triple.isAMDGPU() || Triple.isSPIRV()) {
2977-
// NVPTX/AMDGPU/SPIRV does not care about the code model and will accept
2976+
} else if (Triple.isOffloadingTargetGPU()) {
2977+
// Offloading GPU targets do not care about the code model and will accept
29782978
// whatever works for the host.
29792979
Ok = true;
29802980
} else if (Triple.isSPARC64()) {

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args) {
512512
CmdArgs.push_back(InputFile);
513513

514514
// If this is CPU offloading we copy the input libraries.
515-
if (!Triple.isAMDGPU() && !Triple.isNVPTX() && !Triple.isSPIRV()) {
515+
if (!Triple.isOffloadingTargetGPU()) {
516516
CmdArgs.push_back("-Wl,-Bsymbolic");
517517
CmdArgs.push_back("-shared");
518518
ArgStringList LinkerArgs;

llvm/include/llvm/TargetParser/Triple.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,11 @@ class Triple {
11091109
Env == llvm::Triple::EABIHF;
11101110
}
11111111

1112+
/// Tests if the target represents a GPU which can be offloaded to.
1113+
bool isOffloadingTargetGPU() const {
1114+
return isAMDGPU() || isNVPTX() || isSPIRV();
1115+
}
1116+
11121117
/// Tests whether the target supports comdat
11131118
bool supportsCOMDAT() const {
11141119
return !(isOSBinFormatMachO() || isOSBinFormatXCOFF() ||

llvm/include/llvm/Transforms/IPO/Attributor.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,9 +1338,7 @@ struct InformationCache {
13381338
bool stackIsAccessibleByOtherThreads() { return !targetIsGPU(); }
13391339

13401340
/// Return true if the target is a GPU.
1341-
bool targetIsGPU() {
1342-
return TargetTriple.isAMDGPU() || TargetTriple.isNVPTX();
1343-
}
1341+
bool targetIsGPU() { return TargetTriple.isOffloadingTargetGPU(); }
13441342

13451343
/// Return all functions that might be called indirectly, only valid for
13461344
/// closed world modules (see isClosedWorldModule).

llvm/lib/Transforms/IPO/Attributor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ ChangeStatus &llvm::operator&=(ChangeStatus &L, ChangeStatus R) {
199199

200200
bool AA::isGPU(const Module &M) {
201201
Triple T(M.getTargetTriple());
202-
return T.isAMDGPU() || T.isNVPTX();
202+
return T.isOffloadingTargetGPU();
203203
}
204204

205205
bool AA::isNoSyncInst(Attributor &A, const Instruction &I,
@@ -3296,7 +3296,7 @@ InformationCache::getIndirectlyCallableFunctions(Attributor &A) const {
32963296
}
32973297

32983298
std::optional<unsigned> InformationCache::getFlatAddressSpace() const {
3299-
if (TargetTriple.isAMDGPU() || TargetTriple.isNVPTX())
3299+
if (TargetTriple.isOffloadingTargetGPU())
33003300
return 0;
33013301
return std::nullopt;
33023302
}

0 commit comments

Comments
 (0)