[clang] clang/Driver: Use struct type for BoundArch instead of StringRef (PR #204748)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 19 00:47:40 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-driver
Author: Matt Arsenault (arsenm)
<details>
<summary>Changes</summary>
Change BoundArch arguments in the clang driver from StringRef (or
sometimes const char*) to a dedicated struct type that contains both
the architecture string and a parsed OffloadArch enum field. In the
future it may be useful to contain other feature bits here.
Co-Authored-By: Claude Opus 4.6 <noreply@<!-- -->anthropic.com>
---
Patch is 190.73 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/204748.diff
90 Files Affected:
- (modified) clang/include/clang/Driver/Action.h (+23-23)
- (added) clang/include/clang/Driver/BoundArch.h (+49)
- (modified) clang/include/clang/Driver/Compilation.h (+11-10)
- (modified) clang/include/clang/Driver/Driver.h (+11-11)
- (modified) clang/include/clang/Driver/Job.h (+5-2)
- (modified) clang/include/clang/Driver/SanitizerArgs.h (+2-1)
- (modified) clang/include/clang/Driver/ToolChain.h (+14-13)
- (modified) clang/lib/Driver/Action.cpp (+12-14)
- (modified) clang/lib/Driver/Compilation.cpp (+7-7)
- (modified) clang/lib/Driver/Driver.cpp (+132-140)
- (modified) clang/lib/Driver/SanitizerArgs.cpp (+7-8)
- (modified) clang/lib/Driver/ToolChain.cpp (+12-15)
- (modified) clang/lib/Driver/ToolChains/AIX.cpp (+1-1)
- (modified) clang/lib/Driver/ToolChains/AIX.h (+1-2)
- (modified) clang/lib/Driver/ToolChains/AMDGPU.cpp (+23-22)
- (modified) clang/lib/Driver/ToolChains/AMDGPU.h (+6-8)
- (modified) clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp (+6-7)
- (modified) clang/lib/Driver/ToolChains/AMDGPUOpenMP.h (+2-3)
- (modified) clang/lib/Driver/ToolChains/AVR.cpp (+1-1)
- (modified) clang/lib/Driver/ToolChains/AVR.h (+1-2)
- (modified) clang/lib/Driver/ToolChains/BareMetal.cpp (+3-5)
- (modified) clang/lib/Driver/ToolChains/BareMetal.h (+2-3)
- (modified) clang/lib/Driver/ToolChains/CSKYToolChain.cpp (+1-1)
- (modified) clang/lib/Driver/ToolChains/CSKYToolChain.h (+1-2)
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+19-20)
- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+1-1)
- (modified) clang/lib/Driver/ToolChains/CrossWindows.cpp (+2-3)
- (modified) clang/lib/Driver/ToolChains/CrossWindows.h (+1-1)
- (modified) clang/lib/Driver/ToolChains/Cuda.cpp (+22-25)
- (modified) clang/lib/Driver/ToolChains/Cuda.h (+5-7)
- (modified) clang/lib/Driver/ToolChains/Darwin.cpp (+18-24)
- (modified) clang/lib/Driver/ToolChains/Darwin.h (+7-10)
- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+6-6)
- (modified) clang/lib/Driver/ToolChains/Flang.h (+3-6)
- (modified) clang/lib/Driver/ToolChains/FreeBSD.cpp (+2-3)
- (modified) clang/lib/Driver/ToolChains/FreeBSD.h (+1-1)
- (modified) clang/lib/Driver/ToolChains/Fuchsia.cpp (+5-6)
- (modified) clang/lib/Driver/ToolChains/Fuchsia.h (+3-4)
- (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+4-6)
- (modified) clang/lib/Driver/ToolChains/Gnu.h (+2-3)
- (modified) clang/lib/Driver/ToolChains/HIPAMD.cpp (+8-9)
- (modified) clang/lib/Driver/ToolChains/HIPAMD.h (+3-4)
- (modified) clang/lib/Driver/ToolChains/HIPSPV.cpp (+7-8)
- (modified) clang/lib/Driver/ToolChains/HIPSPV.h (+3-4)
- (modified) clang/lib/Driver/ToolChains/HIPUtility.cpp (+5-5)
- (modified) clang/lib/Driver/ToolChains/HLSL.cpp (+1-1)
- (modified) clang/lib/Driver/ToolChains/HLSL.h (+1-1)
- (modified) clang/lib/Driver/ToolChains/Haiku.cpp (+2-3)
- (modified) clang/lib/Driver/ToolChains/Haiku.h (+1-1)
- (modified) clang/lib/Driver/ToolChains/Hexagon.cpp (+1-1)
- (modified) clang/lib/Driver/ToolChains/Hexagon.h (+1-2)
- (modified) clang/lib/Driver/ToolChains/Linux.cpp (+6-7)
- (modified) clang/lib/Driver/ToolChains/Linux.h (+3-4)
- (modified) clang/lib/Driver/ToolChains/MSP430.cpp (+1-1)
- (modified) clang/lib/Driver/ToolChains/MSP430.h (+1-2)
- (modified) clang/lib/Driver/ToolChains/MSVC.cpp (+8-9)
- (modified) clang/lib/Driver/ToolChains/MSVC.h (+4-5)
- (modified) clang/lib/Driver/ToolChains/Managarm.cpp (+2-3)
- (modified) clang/lib/Driver/ToolChains/Managarm.h (+1-1)
- (modified) clang/lib/Driver/ToolChains/MinGW.cpp (+3-4)
- (modified) clang/lib/Driver/ToolChains/MinGW.h (+2-3)
- (modified) clang/lib/Driver/ToolChains/NetBSD.cpp (+3-4)
- (modified) clang/lib/Driver/ToolChains/NetBSD.h (+2-3)
- (modified) clang/lib/Driver/ToolChains/OHOS.cpp (+2-3)
- (modified) clang/lib/Driver/ToolChains/OHOS.h (+1-1)
- (modified) clang/lib/Driver/ToolChains/OpenBSD.cpp (+2-3)
- (modified) clang/lib/Driver/ToolChains/OpenBSD.h (+1-1)
- (modified) clang/lib/Driver/ToolChains/PS4CPU.cpp (+5-7)
- (modified) clang/lib/Driver/ToolChains/PS4CPU.h (+3-4)
- (modified) clang/lib/Driver/ToolChains/SPIRVOpenMP.cpp (+1-1)
- (modified) clang/lib/Driver/ToolChains/SPIRVOpenMP.h (+1-2)
- (modified) clang/lib/Driver/ToolChains/SYCL.cpp (+6-8)
- (modified) clang/lib/Driver/ToolChains/SYCL.h (+2-3)
- (modified) clang/lib/Driver/ToolChains/Serenity.cpp (+2-2)
- (modified) clang/lib/Driver/ToolChains/Serenity.h (+1-1)
- (modified) clang/lib/Driver/ToolChains/Solaris.cpp (+2-3)
- (modified) clang/lib/Driver/ToolChains/Solaris.h (+1-1)
- (modified) clang/lib/Driver/ToolChains/VEToolchain.cpp (+1-2)
- (modified) clang/lib/Driver/ToolChains/VEToolchain.h (+1-2)
- (modified) clang/lib/Driver/ToolChains/WebAssembly.cpp (+3-5)
- (modified) clang/lib/Driver/ToolChains/WebAssembly.h (+2-3)
- (modified) clang/lib/Driver/ToolChains/XCore.cpp (+1-2)
- (modified) clang/lib/Driver/ToolChains/XCore.h (+1-2)
- (modified) clang/lib/Driver/ToolChains/ZOS.cpp (+1-1)
- (modified) clang/lib/Driver/ToolChains/ZOS.h (+1-2)
- (modified) clang/test/Driver/hip-link-bundle-archive.hip (+6-6)
- (modified) clang/test/Driver/hip-phases.hip (+12-12)
- (modified) clang/test/Driver/hip-target-id.hip (+1-1)
- (modified) clang/test/Driver/hip-toolchain-no-rdc.hip (+4-4)
- (modified) clang/unittests/Driver/DXCModeTest.cpp (+6-5)
``````````diff
diff --git a/clang/include/clang/Driver/Action.h b/clang/include/clang/Driver/Action.h
index 67937b00f6bcf..16e598f0b63b3 100644
--- a/clang/include/clang/Driver/Action.h
+++ b/clang/include/clang/Driver/Action.h
@@ -10,6 +10,7 @@
#define LLVM_CLANG_DRIVER_ACTION_H
#include "clang/Basic/LLVM.h"
+#include "clang/Driver/BoundArch.h"
#include "clang/Driver/Types.h"
#include "clang/Driver/Util.h"
#include "llvm/ADT/ArrayRef.h"
@@ -131,7 +132,7 @@ class Action {
OffloadKind OffloadingDeviceKind = OFK_None;
/// The Offloading architecture associated with this action.
- const char *OffloadingArch = nullptr;
+ BoundArch OffloadingArch;
/// The Offloading toolchain associated with this device action.
const ToolChain *OffloadingToolChain = nullptr;
@@ -192,14 +193,14 @@ class Action {
/// Set the device offload info of this action and propagate it to its
/// dependences.
- void propagateDeviceOffloadInfo(OffloadKind OKind, const char *OArch,
+ void propagateDeviceOffloadInfo(OffloadKind OKind, BoundArch OArch,
const ToolChain *OToolChain);
/// Append the host offload info of this action and propagate it to its
/// dependences.
- void propagateHostOffloadInfo(unsigned OKinds, const char *OArch);
+ void propagateHostOffloadInfo(unsigned OKinds, BoundArch OArch);
- void setHostOffloadInfo(unsigned OKinds, const char *OArch) {
+ void setHostOffloadInfo(unsigned OKinds, BoundArch OArch) {
ActiveOffloadKindMask |= OKinds;
OffloadingArch = OArch;
}
@@ -213,7 +214,7 @@ class Action {
}
OffloadKind getOffloadingDeviceKind() const { return OffloadingDeviceKind; }
- const char *getOffloadingArch() const { return OffloadingArch; }
+ BoundArch getOffloadingArch() const { return OffloadingArch; }
const ToolChain *getOffloadingToolChain() const {
return OffloadingToolChain;
}
@@ -253,14 +254,14 @@ class InputAction : public Action {
class BindArchAction : public Action {
virtual void anchor();
- /// The architecture to bind, or 0 if the default architecture
+ /// The architecture to bind, or empty if the default architecture
/// should be bound.
- StringRef ArchName;
+ BoundArch ArchName;
public:
- BindArchAction(Action *Input, StringRef ArchName);
+ BindArchAction(Action *Input, BoundArch ArchName);
- StringRef getArchName() const { return ArchName; }
+ BoundArch getArch() const { return ArchName; }
static bool classof(const Action *A) {
return A->getKind() == BindArchClass;
@@ -279,7 +280,7 @@ class OffloadAction final : public Action {
class DeviceDependences final {
public:
using ToolChainList = SmallVector<const ToolChain *, 3>;
- using BoundArchList = SmallVector<const char *, 3>;
+ using BoundArchList = SmallVector<BoundArch, 3>;
using OffloadKindList = SmallVector<OffloadKind, 3>;
private:
@@ -303,12 +304,11 @@ class OffloadAction final : public Action {
public:
/// Add an action along with the associated toolchain, bound arch, and
/// offload kind.
- void add(Action &A, const ToolChain &TC, const char *BoundArch,
- OffloadKind OKind);
+ void add(Action &A, const ToolChain &TC, BoundArch BA, OffloadKind OKind);
/// Add an action along with the associated toolchain, bound arch, and
/// offload kinds.
- void add(Action &A, const ToolChain &TC, const char *BoundArch,
+ void add(Action &A, const ToolChain &TC, BoundArch BA,
unsigned OffloadKindMask);
/// Get each of the individual arrays.
@@ -330,29 +330,29 @@ class OffloadAction final : public Action {
const ToolChain &HostToolChain;
/// The architectures that should be used with this action.
- const char *HostBoundArch = nullptr;
+ BoundArch HostBoundArch;
/// The offload kind of each dependence.
unsigned HostOffloadKinds = 0u;
public:
- HostDependence(Action &A, const ToolChain &TC, const char *BoundArch,
+ HostDependence(Action &A, const ToolChain &TC, BoundArch BA,
const unsigned OffloadKinds)
- : HostAction(A), HostToolChain(TC), HostBoundArch(BoundArch),
+ : HostAction(A), HostToolChain(TC), HostBoundArch(BA),
HostOffloadKinds(OffloadKinds) {}
/// Constructor version that obtains the offload kinds from the device
/// dependencies.
- HostDependence(Action &A, const ToolChain &TC, const char *BoundArch,
+ HostDependence(Action &A, const ToolChain &TC, BoundArch BoundArch,
const DeviceDependences &DDeps);
Action *getAction() const { return &HostAction; }
const ToolChain *getToolChain() const { return &HostToolChain; }
- const char *getBoundArch() const { return HostBoundArch; }
+ BoundArch getBoundArch() const { return HostBoundArch; }
unsigned getOffloadKinds() const { return HostOffloadKinds; }
};
using OffloadActionWorkTy =
- llvm::function_ref<void(Action *, const ToolChain *, const char *)>;
+ llvm::function_ref<void(Action *, const ToolChain *, BoundArch)>;
private:
/// The host offloading toolchain that should be used with the action.
@@ -598,13 +598,13 @@ class OffloadUnbundlingJobAction final : public JobAction {
const ToolChain *DependentToolChain = nullptr;
/// The bound architecture of the dependent action.
- StringRef DependentBoundArch;
+ BoundArch DependentBoundArch;
/// The offload kind of the dependent action.
const OffloadKind DependentOffloadKind = OFK_None;
DependentActionInfo(const ToolChain *DependentToolChain,
- StringRef DependentBoundArch,
+ BoundArch DependentBoundArch,
const OffloadKind DependentOffloadKind)
: DependentToolChain(DependentToolChain),
DependentBoundArch(DependentBoundArch),
@@ -621,9 +621,9 @@ class OffloadUnbundlingJobAction final : public JobAction {
OffloadUnbundlingJobAction(Action *Input);
/// Register information about a dependent action.
- void registerDependentActionInfo(const ToolChain *TC, StringRef BoundArch,
+ void registerDependentActionInfo(const ToolChain *TC, BoundArch BA,
OffloadKind Kind) {
- DependentActionInfoArray.push_back({TC, BoundArch, Kind});
+ DependentActionInfoArray.push_back({TC, BA, Kind});
}
/// Return the information about all depending actions.
diff --git a/clang/include/clang/Driver/BoundArch.h b/clang/include/clang/Driver/BoundArch.h
new file mode 100644
index 0000000000000..7c1f730586289
--- /dev/null
+++ b/clang/include/clang/Driver/BoundArch.h
@@ -0,0 +1,49 @@
+//===--- BoundArch.h - Bound Architecture struct ----------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_DRIVER_BOUNDARCH_H
+#define LLVM_CLANG_DRIVER_BOUNDARCH_H
+
+#include "clang/Basic/OffloadArch.h"
+#include "llvm/ADT/StringRef.h"
+
+namespace clang {
+namespace driver {
+
+/// Represents a bound architecture for offload / multiple architecture
+/// compilation.
+struct BoundArch {
+ llvm::StringRef ArchName;
+
+ /// The parsed offload architecture enum.
+ /// Will be OffloadArch::Unknown if ArchName not recognized.
+ OffloadArch Arch = OffloadArch::Unused;
+
+ BoundArch() = default;
+ explicit BoundArch(llvm::StringRef Name)
+ : ArchName(Name),
+ Arch(Name.empty() ? OffloadArch::Unknown : StringToOffloadArch(Name)) {}
+
+ BoundArch(llvm::StringRef Name, OffloadArch A) : ArchName(Name), Arch(A) {}
+
+ bool empty() const { return ArchName.empty(); }
+ explicit operator bool() const { return Arch != OffloadArch::Unused; }
+
+ bool operator==(const BoundArch &Other) const {
+ return Arch == Other.Arch && ArchName == Other.ArchName;
+ }
+
+ bool operator<(const BoundArch &Other) const {
+ return std::tie(Arch, ArchName) < std::tie(Other.Arch, Other.ArchName);
+ }
+};
+
+} // namespace driver
+} // namespace clang
+
+#endif // LLVM_CLANG_DRIVER_BOUNDARCH_H
diff --git a/clang/include/clang/Driver/Compilation.h b/clang/include/clang/Driver/Compilation.h
index 4ad2dc34a1f85..aa0c3de574edc 100644
--- a/clang/include/clang/Driver/Compilation.h
+++ b/clang/include/clang/Driver/Compilation.h
@@ -11,6 +11,7 @@
#include "clang/Basic/LLVM.h"
#include "clang/Driver/Action.h"
+#include "clang/Driver/BoundArch.h"
#include "clang/Driver/Job.h"
#include "clang/Driver/Util.h"
#include "llvm/ADT/ArrayRef.h"
@@ -82,16 +83,16 @@ class Compilation {
/// architecture, and device offload kind.
struct TCArgsKey final {
const ToolChain *TC = nullptr;
- StringRef BoundArch;
+ BoundArch BoundArchitecture;
Action::OffloadKind DeviceOffloadKind = Action::OFK_None;
- TCArgsKey(const ToolChain *TC, StringRef BoundArch,
+ TCArgsKey(const ToolChain *TC, BoundArch BA,
Action::OffloadKind DeviceOffloadKind)
- : TC(TC), BoundArch(BoundArch), DeviceOffloadKind(DeviceOffloadKind) {}
+ : TC(TC), BoundArchitecture(BA), DeviceOffloadKind(DeviceOffloadKind) {}
bool operator<(const TCArgsKey &K) const {
- return std::tie(TC, BoundArch, DeviceOffloadKind) <
- std::tie(K.TC, K.BoundArch, K.DeviceOffloadKind);
+ return std::tie(TC, BoundArchitecture, DeviceOffloadKind) <
+ std::tie(K.TC, K.BoundArchitecture, K.DeviceOffloadKind);
}
};
std::map<TCArgsKey, llvm::opt::DerivedArgList *> TCArgs;
@@ -128,7 +129,7 @@ class Compilation {
/// The bound architecture currently being built, if any. Set around
/// ConstructJob calls so addCommand can stamp it onto each new Command.
- StringRef CurrentBoundArch;
+ BoundArch CurrentBoundArch;
public:
Compilation(const Driver &D, const ToolChain &DefaultToolChain,
@@ -220,8 +221,8 @@ class Compilation {
Jobs.addJob(std::move(Cmd));
}
- StringRef getCurrentBoundArch() const { return CurrentBoundArch; }
- void setCurrentBoundArch(StringRef Arch) { CurrentBoundArch = Arch; }
+ BoundArch getCurrentBoundArch() const { return CurrentBoundArch; }
+ void setCurrentBoundArch(BoundArch BA) { CurrentBoundArch = BA; }
llvm::opt::ArgStringList &getTempFiles() { return TempFiles; }
const llvm::opt::ArgStringList &getTempFiles() const { return TempFiles; }
@@ -248,11 +249,11 @@ class Compilation {
/// If a device offloading kind is specified, a translation specific for that
/// kind is performed, if any.
///
- /// \param BoundArch - The bound architecture name, or 0.
+ /// \param BA - The bound architecture.
/// \param DeviceOffloadKind - The offload device kind that should be used in
/// the translation, if any.
const llvm::opt::DerivedArgList &
- getArgsForToolChain(const ToolChain *TC, StringRef BoundArch,
+ getArgsForToolChain(const ToolChain *TC, BoundArch BA,
Action::OffloadKind DeviceOffloadKind);
/// addTempFile - Add a file to remove on exit, and returns its
diff --git a/clang/include/clang/Driver/Driver.h b/clang/include/clang/Driver/Driver.h
index 19a371163f050..81848cf587286 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -13,6 +13,7 @@
#include "clang/Basic/HeaderInclude.h"
#include "clang/Basic/LLVM.h"
#include "clang/Driver/Action.h"
+#include "clang/Driver/BoundArch.h"
#include "clang/Driver/DriverDiagnostic.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Phases.h"
@@ -523,7 +524,7 @@ class Driver {
/// Returns the set of bound architectures active for this offload kind.
/// If there are no bound architctures we return a set containing only the
/// empty string.
- llvm::SmallVector<StringRef>
+ llvm::SmallVector<BoundArch>
getOffloadArchs(Compilation &C, const llvm::opt::DerivedArgList &Args,
Action::OffloadKind Kind, const ToolChain &TC) const;
@@ -658,7 +659,7 @@ class Driver {
/// return an InputInfo for the result of running \p A. Will only construct
/// jobs for a given (Action, ToolChain, BoundArch, DeviceKind) tuple once.
InputInfoList BuildJobsForAction(
- Compilation &C, const Action *A, const ToolChain *TC, StringRef BoundArch,
+ Compilation &C, const Action *A, const ToolChain *TC, BoundArch BA,
bool AtTopLevel, bool MultipleArchs, const char *LinkingOutput,
std::map<std::pair<const Action *, std::string>, InputInfoList>
&CachedResults,
@@ -668,17 +669,16 @@ class Driver {
const char *getDefaultImageName() const;
/// Creates a temp file.
- /// 1. If \p MultipleArch is false or \p BoundArch is empty, the temp file is
+ /// 1. If \p MultipleArch is false or \p BA is empty, the temp file is
/// in the temporary directory with name $Prefix-%%%%%%.$Suffix.
- /// 2. If \p MultipleArch is true and \p BoundArch is not empty,
+ /// 2. If \p MultipleArch is true and \p BA is not empty,
/// 2a. If \p NeedUniqueDirectory is false, the temp file is in the
- /// temporary directory with name $Prefix-$BoundArch-%%%%%.$Suffix.
+ /// temporary directory with name $Prefix-$BA-%%%%%.$Suffix.
/// 2b. If \p NeedUniqueDirectory is true, the temp file is in a unique
/// subdiretory with random name under the temporary directory, and
- /// the temp file itself has name $Prefix-$BoundArch.$Suffix.
+ /// the temp file itself has name $Prefix-$BA.$Suffix.
const char *CreateTempFile(Compilation &C, StringRef Prefix, StringRef Suffix,
- bool MultipleArchs = false,
- StringRef BoundArch = {},
+ bool MultipleArchs = false, BoundArch BA = {},
bool NeedUniqueDirectory = false) const;
/// GetNamedOutputPath - Return the name to use for the output of
@@ -689,12 +689,12 @@ class Driver {
/// \param JA - The action of interest.
/// \param BaseInput - The original input file that this action was
/// triggered by.
- /// \param BoundArch - The bound architecture.
+ /// \param BA - The bound architecture.
/// \param AtTopLevel - Whether this is a "top-level" action.
/// \param MultipleArchs - Whether multiple -arch options were supplied.
/// \param NormalizedTriple - The normalized triple of the relevant target.
const char *GetNamedOutputPath(Compilation &C, const JobAction &JA,
- const char *BaseInput, StringRef BoundArch,
+ const char *BaseInput, BoundArch BA,
bool AtTopLevel, bool MultipleArchs,
StringRef NormalizedTriple) const;
@@ -785,7 +785,7 @@ class Driver {
/// jobs specifically for the given action, but will use the cache when
/// building jobs for the Action's inputs.
InputInfoList BuildJobsForActionNoCache(
- Compilation &C, const Action *A, const ToolChain *TC, StringRef BoundArch,
+ Compilation &C, const Action *A, const ToolChain *TC, BoundArch BA,
bool AtTopLevel, bool MultipleArchs, const char *LinkingOutput,
std::map<std::pair<const Action *, std::string>, InputInfoList>
&CachedResults,
diff --git a/clang/include/clang/Driver/Job.h b/clang/include/clang/Driver/Job.h
index 116254f79ae6f..a600064fe0a9e 100644
--- a/clang/include/clang/Driver/Job.h
+++ b/clang/include/clang/Driver/Job.h
@@ -10,6 +10,7 @@
#define LLVM_CLANG_DRIVER_JOB_H
#include "clang/Basic/LLVM.h"
+#include "clang/Driver/BoundArch.h"
#include "clang/Driver/InputInfo.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"
@@ -195,8 +196,10 @@ class Command {
const Tool &getCreator() const { return Creator; }
/// Return the bound architecture for this command, if any.
- StringRef getBoundArch() const { return BoundArch; }
- void setBoundArch(StringRef Arch) { BoundArch = std::string(Arch); }
+ driver::BoundArch getBoundArch() const {
+ return driver::BoundArch(BoundArch);
+ }
+ void setBoundArch(driver::BoundArch BA) { BoundArch = BA.ArchName.str(); }
/// Returns the kind of response file supported by the current invocation.
const ResponseFileSupport &getResponseFileSupport() {
diff --git a/clang/include/clang/Driver/SanitizerArgs.h b/clang/include/clang/Driver/SanitizerArgs.h
index d4ee17802fd8e..702209fbdbe72 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -10,6 +10,7 @@
#include "clang/Basic/Sanitizers.h"
#include "clang/Driver/Action.h"
+#include "clang/Driver/BoundArch.h"
#include "clang/Driver/Types.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
@@ -87,7 +88,7 @@ class SanitizerArgs {
/// Parses the sanitizer arguments from an argument list.
SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
bool DiagnoseErrors = true, bool DiagnoseBoundArchErrors = true,
- StringRef BoundArch = "",
+ BoundArch BA = {},
Action::OffloadKind DeviceOffloadKind = Action::OFK_None);
bool needsSharedRt() const { return SharedRuntime; }
diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h
index 8953c299268df..50e2752b5e16d 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -13,6 +13,7 @@
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/Sanitizers.h"
#include "clang/Driver/Action.h"
+#include "clang/Driver/BoundArch.h"
#include "clang/Driver/Multilib.h"
#include "clang/Driver/Types.h"
#include "llvm/ADT/APFloat.h"
@@ -347,7 +348,7 @@ class ToolChain {
Multilib::flags_list getMultilibFlags(const llvm::opt::ArgList &) const;
SanitizerArgs getSanitizerArgs(
- const llvm::opt::ArgList &JobArgs, StringRef BoundArch = "",
+ const llvm::opt::ArgList &JobArgs, BoundArch BA = {},
Action::OffloadKind DeviceOffloadKind = Action::OFK_None) const;
/// Returns the feature requirement for a sanitizer on a specific arch for
@@ -355,7 +356,7 @@ class ToolChain {
/// the sanitizer is generally supported but requires a specific feature for
/// the given BoundArch, or an empty StringRef otherwise.
virtual StringRef getSanitizerRequirement(SanitizerMask Kinds,
- StringRef BoundArch) const {
+ BoundArch BA) const {
return {};
}
@@ -393,11 +394,11 @@ class ToolChain {
/// specific translations are needed. If \p DeviceOffloadKind is specified
/// the translation specific for that offload kind is performed.
///
- /// \param BoundArch - The bound architecture name, or 0.
+ /// \param BA - The bound architecture.
/// \param DeviceOffloadKind - The device offload kind used for the
/// translation.
virtual llvm::opt::DerivedArgList *
- TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
+ TranslateArgs(const llvm::opt::DerivedArgList &Args, BoundArch BA,
Action::OffloadKind DeviceOffloadKind) const {
return nullptr;
}
@@ -421,7 +422,7 @@ class ToolChain {
/// a null pointer, otherwise return a DerivedArgList containing the
/// translated arguments.
virtual llvm::opt::DerivedArgList *
- TranslateXarchArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
+ TranslateXarchArgs(const llvm::opt::DerivedArgList &Args, BoundArch BA,
Action::OffloadKind DeviceOffloadKind,
SmallVectorImpl<llvm::opt::Arg *> *AllocatedArgs) const;
@@ -715,7 +716,7 @@ class ToolChain {
/// ComputeLLVMTriple - Return the LLVM target triple to use, after taking
/// command line arguments into account.
virtual std::string
- ComputeLLVMTriple(const llvm::opt::ArgList &Args, StringRef BoundArch = {},
+ ComputeLLVMTriple(const llvm::opt::ArgList &Args, BoundArch BA = {},
types::ID InputType = types::TY_INVALID) const;
/// ComputeEffectiveClangTriple - Return the Clang triple to use for this
@@ -724,8 +725,7 @@ class ToolChain {
/// sets the deployment target) determines the version in the...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/204748
More information about the cfe-commits
mailing list