Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions clang/include/clang/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,11 @@ class LangOptions : public LangOptionsBase {
return FPExceptionModeKind::FPE_Ignore;
return EM;
}

/// True when compiling for an offloading target device.
bool isTargetDevice() const {
return OpenMPIsTargetDevice || CUDAIsDevice || SYCLIsDevice;
}
};

/// Floating point control options
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,8 +810,7 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D,
// functions as the host-callable kernel functions are emitted at codegen.
if (Context.getLangOpts().OpenMP &&
Context.getLangOpts().OpenMPIsTargetDevice &&
((Context.getTargetInfo().getTriple().isAMDGPU() ||
Context.getTargetInfo().getTriple().isNVPTX()) ||
(Context.getTargetInfo().getTriple().isGPU() ||
OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(Function)))
LV.mergeVisibility(HiddenVisibility, /*newExplicit=*/false);

Expand Down
6 changes: 2 additions & 4 deletions clang/lib/CodeGen/CGOpenMPRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2614,8 +2614,7 @@ void CGOpenMPRuntime::emitDistributeStaticInit(
llvm::Value *ThreadId = getThreadID(CGF, Loc);
llvm::FunctionCallee StaticInitFunction;
bool isGPUDistribute =
CGM.getLangOpts().OpenMPIsTargetDevice &&
(CGM.getTriple().isAMDGCN() || CGM.getTriple().isNVPTX());
CGM.getLangOpts().OpenMPIsTargetDevice && CGM.getTriple().isGPU();
StaticInitFunction = OMPBuilder.createForStaticInitFunction(
Values.IVSize, Values.IVSigned, isGPUDistribute);

Expand Down Expand Up @@ -2644,8 +2643,7 @@ void CGOpenMPRuntime::emitForStaticFinish(CodeGenFunction &CGF,
getThreadID(CGF, Loc)};
auto DL = ApplyDebugLocation::CreateDefaultArtificial(CGF, Loc);
if (isOpenMPDistributeDirective(DKind) &&
CGM.getLangOpts().OpenMPIsTargetDevice &&
(CGM.getTriple().isAMDGCN() || CGM.getTriple().isNVPTX()))
CGM.getLangOpts().OpenMPIsTargetDevice && CGM.getTriple().isGPU())
CGF.EmitRuntimeCall(
OMPBuilder.getOrCreateRuntimeFunction(
CGM.getModule(), OMPRTL___kmpc_distribute_static_fini),
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ static void setVisibilityFromDLLStorageClass(const clang::LangOptions &LO,
static bool isStackProtectorOn(const LangOptions &LangOpts,
const llvm::Triple &Triple,
clang::LangOptions::StackProtectorMode Mode) {
if (Triple.isAMDGPU() || Triple.isNVPTX())
if (Triple.isGPU())
return false;
return LangOpts.getStackProtector() == Mode;
}
Expand Down
6 changes: 2 additions & 4 deletions clang/lib/CodeGen/CodeGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -1073,10 +1073,8 @@ class CodeGenModule : public CodeGenTypeCache {

// Return whether RTTI information should be emitted for this target.
bool shouldEmitRTTI(bool ForEH = false) {
return (ForEH || getLangOpts().RTTI) && !getLangOpts().CUDAIsDevice &&
!(getLangOpts().OpenMP && getLangOpts().OpenMPIsTargetDevice &&
(getTriple().isNVPTX() || getTriple().isAMDGPU() ||
getTriple().isSPIRV()));
return (ForEH || getLangOpts().RTTI) &&
(!getLangOpts().isTargetDevice() || !getTriple().isGPU());
}

/// Get the address of the RTTI descriptor for the given type.
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CodeGenPGO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ void CodeGenPGO::setProfileVersion(llvm::Module &M) {

IRLevelVersionVariable->setVisibility(llvm::GlobalValue::HiddenVisibility);
llvm::Triple TT(M.getTargetTriple());
if (TT.isAMDGPU() || TT.isNVPTX())
if (TT.isGPU())
IRLevelVersionVariable->setVisibility(
llvm::GlobalValue::ProtectedVisibility);
if (TT.supportsCOMDAT()) {
Expand Down
6 changes: 2 additions & 4 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1100,8 +1100,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
if (JA.isDeviceOffloading(Action::OFK_OpenMP) &&
!Args.hasArg(options::OPT_nostdinc) &&
!Args.hasArg(options::OPT_nogpuinc) &&
(getToolChain().getTriple().isNVPTX() ||
getToolChain().getTriple().isAMDGCN())) {
getToolChain().getTriple().isGPU()) {
if (!Args.hasArg(options::OPT_nobuiltininc)) {
// Add openmp_wrappers/* to our system include path. This lets us wrap
// standard library headers.
Expand Down Expand Up @@ -1288,8 +1287,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
// Without an offloading language we will include these headers directly.
// Offloading languages will instead only use the declarations stored in
// the resource directory at clang/lib/Headers/llvm_libc_wrappers.
if ((getToolChain().getTriple().isNVPTX() ||
getToolChain().getTriple().isAMDGCN()) &&
if (getToolChain().getTriple().isGPU() &&
C.getActiveOffloadKinds() == Action::OFK_None) {
SmallString<128> P(llvm::sys::path::parent_path(D.Dir));
llvm::sys::path::append(P, "include");
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/Frontend/CompilerInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ bool CompilerInstance::createTarget() {
// Check whether AuxTarget exists, if not, then create TargetInfo for the
// other side of CUDA/OpenMP/SYCL compilation.
if (!getAuxTarget() &&
(getLangOpts().CUDA || getLangOpts().OpenMPIsTargetDevice ||
getLangOpts().SYCLIsDevice) &&
(getLangOpts().CUDA || getLangOpts().isTargetDevice()) &&
!getFrontendOpts().AuxTriple.empty()) {
auto TO = std::make_shared<TargetOptions>();
TO->Triple = llvm::Triple::normalize(getFrontendOpts().AuxTriple);
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4191,8 +4191,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.Blocks = Args.hasArg(OPT_fblocks) || (Opts.OpenCL
&& Opts.OpenCLVersion == 200);

bool HasConvergentOperations = Opts.OpenMPIsTargetDevice || Opts.OpenCL ||
Opts.CUDAIsDevice || Opts.SYCLIsDevice ||
bool HasConvergentOperations = Opts.isTargetDevice() || Opts.OpenCL ||
Opts.HLSL || T.isAMDGPU() || T.isNVPTX();
Opts.ConvergentFunctions =
Args.hasFlag(OPT_fconvergent_functions, OPT_fno_convergent_functions,
Expand Down
4 changes: 1 addition & 3 deletions clang/lib/Frontend/InitPreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1564,9 +1564,7 @@ void clang::InitializePreprocessor(Preprocessor &PP,
if (InitOpts.UsePredefines) {
// FIXME: This will create multiple definitions for most of the predefined
// macros. This is not the right way to handle this.
if ((LangOpts.CUDA || LangOpts.OpenMPIsTargetDevice ||
LangOpts.SYCLIsDevice) &&
PP.getAuxTargetInfo())
if ((LangOpts.CUDA || LangOpts.isTargetDevice()) && PP.getAuxTargetInfo())
InitializePredefinedMacros(*PP.getAuxTargetInfo(), LangOpts, FEOpts,
PP.getPreprocessorOpts(), Builder);

Expand Down
11 changes: 4 additions & 7 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7860,8 +7860,7 @@ NamedDecl *Sema::ActOnVariableDeclarator(
diag::err_thread_non_global)
<< DeclSpec::getSpecifierName(TSCS);
else if (!Context.getTargetInfo().isTLSSupported()) {
if (getLangOpts().CUDA || getLangOpts().OpenMPIsTargetDevice ||
getLangOpts().SYCLIsDevice) {
if (getLangOpts().CUDA || getLangOpts().isTargetDevice()) {
// Postpone error emission until we've collected attributes required to
// figure out whether it's a host or device variable and whether the
// error should be ignored.
Expand Down Expand Up @@ -7994,8 +7993,7 @@ NamedDecl *Sema::ActOnVariableDeclarator(
if (const auto *TT = R->getAs<TypedefType>())
copyAttrFromTypedefToDecl<AllocSizeAttr>(*this, NewVD, TT);

if (getLangOpts().CUDA || getLangOpts().OpenMPIsTargetDevice ||
getLangOpts().SYCLIsDevice) {
if (getLangOpts().CUDA || getLangOpts().isTargetDevice()) {
if (EmitTLSUnsupportedError &&
((getLangOpts().CUDA && DeclAttrsMatchCUDAMode(getLangOpts(), NewVD)) ||
(getLangOpts().OpenMPIsTargetDevice &&
Expand Down Expand Up @@ -16586,9 +16584,8 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
DiscardCleanupsInEvaluationContext();
}

if (FD && ((LangOpts.OpenMP && (LangOpts.OpenMPIsTargetDevice ||
!LangOpts.OMPTargetTriples.empty())) ||
LangOpts.CUDA || LangOpts.SYCLIsDevice)) {
if (FD && (LangOpts.isTargetDevice() || LangOpts.CUDA ||
(LangOpts.OpenMP && !LangOpts.OMPTargetTriples.empty()))) {
auto ES = getEmissionStatus(FD);
if (ES == Sema::FunctionEmissionStatus::Emitted ||
ES == Sema::FunctionEmissionStatus::Unknown)
Expand Down
16 changes: 4 additions & 12 deletions clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,8 +1122,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
}
case DeclSpec::TST_int128:
if (!S.Context.getTargetInfo().hasInt128Type() &&
!(S.getLangOpts().SYCLIsDevice || S.getLangOpts().CUDAIsDevice ||
(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsTargetDevice)))
!(S.getLangOpts().isTargetDevice()))
S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
<< "__int128";
if (DS.getTypeSpecSign() == TypeSpecifierSign::Unsigned)
Expand Down Expand Up @@ -1168,8 +1167,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
break;
case DeclSpec::TST_float128:
if (!S.Context.getTargetInfo().hasFloat128Type() &&
!S.getLangOpts().SYCLIsDevice && !S.getLangOpts().CUDAIsDevice &&
!(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsTargetDevice))
!S.getLangOpts().isTargetDevice())
S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
<< "__float128";
Result = Context.Float128Ty;
Expand Down Expand Up @@ -8284,12 +8282,7 @@ static bool verifyValidIntegerConstantExpr(Sema &S, const ParsedAttr &Attr,
/// match one of the standard Neon vector types.
static void HandleNeonVectorTypeAttr(QualType &CurType, const ParsedAttr &Attr,
Sema &S, VectorKind VecKind) {
bool IsTargetCUDAAndHostARM = false;
if (S.getLangOpts().CUDAIsDevice) {
const TargetInfo *AuxTI = S.getASTContext().getAuxTargetInfo();
IsTargetCUDAAndHostARM =
AuxTI && (AuxTI->getTriple().isAArch64() || AuxTI->getTriple().isARM());
}
bool IsTargetOffloading = S.getLangOpts().isTargetDevice();

// Target must have NEON (or MVE, whose vectors are similar enough
// not to need a separate attribute)
Expand Down Expand Up @@ -8323,8 +8316,7 @@ static void HandleNeonVectorTypeAttr(QualType &CurType, const ParsedAttr &Attr,
return;

// Only certain element types are supported for Neon vectors.
if (!isPermittedNeonBaseType(CurType, VecKind, S) &&
!IsTargetCUDAAndHostARM) {
if (!isPermittedNeonBaseType(CurType, VecKind, S) && !IsTargetOffloading) {
S.Diag(Attr.getLoc(), diag::err_attribute_invalid_vector_type) << CurType;
Attr.setInvalid();
return;
Expand Down
2 changes: 1 addition & 1 deletion clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args) {
CmdArgs.push_back(InputFile);

// If this is CPU offloading we copy the input libraries.
if (!Triple.isAMDGPU() && !Triple.isNVPTX() && !Triple.isSPIRV()) {
if (!Triple.isGPU()) {
CmdArgs.push_back("-Wl,-Bsymbolic");
CmdArgs.push_back("-shared");
ArgStringList LinkerArgs;
Expand Down
16 changes: 4 additions & 12 deletions flang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,22 +1136,16 @@ static bool parseOpenMPArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
if (args.hasArg(clang::driver::options::OPT_no_offloadlib))
res.getLangOpts().NoGPULib = 1;
}

switch (llvm::Triple(res.getTargetOpts().triple).getArch()) {
case llvm::Triple::nvptx:
case llvm::Triple::nvptx64:
case llvm::Triple::amdgcn:
if (llvm::Triple(res.getTargetOpts().triple).isGPU()) {
if (!res.getLangOpts().OpenMPIsTargetDevice) {
const unsigned diagID = diags.getCustomDiagID(
clang::DiagnosticsEngine::Error,
"OpenMP AMDGPU/NVPTX is only prepared to deal with device code.");
"OpenMP GPU is only prepared to deal with device code.");
diags.Report(diagID);
}
res.getLangOpts().OpenMPIsGPU = 1;
break;
default:
} else {
res.getLangOpts().OpenMPIsGPU = 0;
break;
}

// Get the OpenMP target triples if any.
Expand All @@ -1173,10 +1167,8 @@ static bool parseOpenMPArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
if (tt.getArch() == llvm::Triple::UnknownArch ||
!(tt.getArch() == llvm::Triple::aarch64 || tt.isPPC() ||
tt.getArch() == llvm::Triple::systemz ||
tt.getArch() == llvm::Triple::nvptx ||
tt.getArch() == llvm::Triple::nvptx64 || tt.isAMDGCN() ||
tt.getArch() == llvm::Triple::x86 ||
tt.getArch() == llvm::Triple::x86_64))
tt.getArch() == llvm::Triple::x86_64 || tt.isGPU()))
diags.Report(clang::diag::err_drv_invalid_omp_target)
<< arg->getValue(i);
else if (getArchPtrSize(t) != getArchPtrSize(tt))
Expand Down
2 changes: 1 addition & 1 deletion flang/test/Lower/OpenMP/omp-is-gpu.f90
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
subroutine omp_subroutine()
end subroutine omp_subroutine

!FLANG-ERROR: error: OpenMP AMDGPU/NVPTX is only prepared to deal with device code.
!FLANG-ERROR: error: OpenMP GPU is only prepared to deal with device code.
!BBC-ERROR: FATAL: -fopenmp-is-gpu can only be set if -fopenmp-is-target-device is also set
3 changes: 3 additions & 0 deletions llvm/include/llvm/TargetParser/Triple.h
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,9 @@ class Triple {
/// Test whether target triples are compatible.
bool isCompatibleWith(const Triple &Other) const;

/// Test whether the target triple is for a GPU.
bool isGPU() const { return isSPIRV() || isNVPTX() || isAMDGPU(); }

/// Merge target triples.
std::string merge(const Triple &Other) const;

Expand Down
4 changes: 1 addition & 3 deletions llvm/include/llvm/Transforms/IPO/Attributor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1339,9 +1339,7 @@ struct InformationCache {
bool stackIsAccessibleByOtherThreads() { return !targetIsGPU(); }

/// Return true if the target is a GPU.
bool targetIsGPU() {
return TargetTriple.isAMDGPU() || TargetTriple.isNVPTX();
}
bool targetIsGPU() { return TargetTriple.isGPU(); }

/// Return all functions that might be called indirectly, only valid for
/// closed world modules (see isClosedWorldModule).
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ProfileData/InstrProf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ std::string getPGOFuncNameVarName(StringRef FuncName,

bool isGPUProfTarget(const Module &M) {
const Triple &T = M.getTargetTriple();
return T.isAMDGPU() || T.isNVPTX();
return T.isGPU();
}

void setPGOFuncVisibility(Module &M, GlobalVariable *FuncNameVar) {
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/IPO/Attributor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ ChangeStatus &llvm::operator&=(ChangeStatus &L, ChangeStatus R) {

bool AA::isGPU(const Module &M) {
Triple T(M.getTargetTriple());
return T.isAMDGPU() || T.isNVPTX();
return T.isGPU();
}

bool AA::isNoSyncInst(Attributor &A, const Instruction &I,
Expand Down Expand Up @@ -3300,7 +3300,7 @@ InformationCache::getIndirectlyCallableFunctions(Attributor &A) const {
}

std::optional<unsigned> InformationCache::getFlatAddressSpace() const {
if (TargetTriple.isAMDGPU() || TargetTriple.isNVPTX())
if (TargetTriple.isGPU())
return 0;
return std::nullopt;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ class SanitizerBinaryMetadata {
VersionStr(utostr(getVersion())), IRB(M.getContext()) {
// FIXME: Make it work with other formats.
assert(TargetTriple.isOSBinFormatELF() && "ELF only");
assert(!(TargetTriple.isNVPTX() || TargetTriple.isAMDGPU()) &&
"Device targets are not supported");
assert(!TargetTriple.isGPU() && "Device targets are not supported");
}

bool run();
Expand Down