[clang] [llvm] MC: Move BinutilsVersion from TargetOptions to MCTargetOptions (PR #221435)

Matt Arsenault via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 5 04:41:21 PDT 2026


https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/221435

BinutilsVersion has no codegen use and only used by MCAsmInfo to check
ELF assembler features.

Co-authored-by: Claude (claude-opus-4.8) <noreply at anthropic.com>

>From 71926efeebe6f917288262c14562e3e46535a64a Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Sat, 5 Sep 2026 13:08:40 +0200
Subject: [PATCH] MC: Move BinutilsVersion from TargetOptions to
 MCTargetOptions

BinutilsVersion has no codegen use and only used by MCAsmInfo to check
ELF assembler features.

Co-authored-by: Claude (claude-opus-4.8) <noreply at anthropic.com>
---
 clang/lib/CodeGen/BackendUtil.cpp             |  5 +++--
 llvm/include/llvm/MC/MCTargetOptions.h        |  8 ++++++++
 llvm/include/llvm/Target/TargetMachine.h      |  2 --
 llvm/include/llvm/Target/TargetOptions.h      |  4 ----
 llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp |  3 ---
 llvm/lib/MC/MCAsmInfo.cpp                     |  2 ++
 llvm/lib/MC/MCTargetOptions.cpp               | 10 ++++++++++
 llvm/lib/Target/TargetMachine.cpp             |  9 ---------
 llvm/tools/llc/llc.cpp                        |  4 ++--
 9 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index ed369d360c48b..c3624c486cc6d 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -40,6 +40,7 @@
 #include "llvm/IR/Verifier.h"
 #include "llvm/IRPrinter/IRPrintingPasses.h"
 #include "llvm/LTO/LTOBackend.h"
+#include "llvm/MC/MCTargetOptions.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Object/OffloadBinary.h"
 #include "llvm/Passes/PassBuilder.h"
@@ -403,8 +404,8 @@ static bool initTargetOptions(const CompilerInstance &CI,
     break;
   }
 
-  Options.BinutilsVersion =
-      llvm::TargetMachine::parseBinutilsVersion(CodeGenOpts.BinutilsVersion);
+  Options.MCOptions.BinutilsVersion =
+      llvm::MCTargetOptions::parseBinutilsVersion(CodeGenOpts.BinutilsVersion);
   Options.UseInitArray = CodeGenOpts.UseInitArray;
   Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS;
 
diff --git a/llvm/include/llvm/MC/MCTargetOptions.h b/llvm/include/llvm/MC/MCTargetOptions.h
index 1ef26da9afdbc..b7d3c7f46545f 100644
--- a/llvm/include/llvm/MC/MCTargetOptions.h
+++ b/llvm/include/llvm/MC/MCTargetOptions.h
@@ -14,6 +14,7 @@
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Compression.h"
 #include <string>
+#include <utility>
 #include <vector>
 
 namespace llvm {
@@ -80,6 +81,9 @@ class MCTargetOptions {
 
   int DwarfVersion = 0;
 
+  /// If greater than 0, overrides the default MCAsmInfo binutils version.
+  std::pair<int, int> BinutilsVersion = {0, 0};
+
   enum DwarfDirectory {
     // Force disable
     DisableDwarfDirectory,
@@ -128,6 +132,10 @@ class MCTargetOptions {
 
   LLVM_ABI MCTargetOptions();
 
+  /// Parse a binutils version string ("major[.minor]" or "none") into a
+  /// (major, minor) pair. "none" maps to {INT_MAX, INT_MAX}.
+  LLVM_ABI static std::pair<int, int> parseBinutilsVersion(StringRef Version);
+
   /// getABIName - If this returns a non-empty string this represents the
   /// textual name of the ABI that we want the backend to use, e.g. o32, or
   /// aapcs-linux.
diff --git a/llvm/include/llvm/Target/TargetMachine.h b/llvm/include/llvm/Target/TargetMachine.h
index a6b73d636dc27..57c35ed564616 100644
--- a/llvm/include/llvm/Target/TargetMachine.h
+++ b/llvm/include/llvm/Target/TargetMachine.h
@@ -475,8 +475,6 @@ class LLVM_ABI TargetMachine {
   static constexpr unsigned DefaultSjLjDataSize = 32;
   virtual unsigned getSjLjDataSize() const { return DefaultSjLjDataSize; }
 
-  static std::pair<int, int> parseBinutilsVersion(StringRef Version);
-
   /// getAddressSpaceForPseudoSourceKind - Given the kind of memory
   /// (e.g. stack) the target returns the corresponding address space.
   virtual unsigned getAddressSpaceForPseudoSourceKind(unsigned Kind) const {
diff --git a/llvm/include/llvm/Target/TargetOptions.h b/llvm/include/llvm/Target/TargetOptions.h
index f6c862e99b98f..30149e24255b1 100644
--- a/llvm/include/llvm/Target/TargetOptions.h
+++ b/llvm/include/llvm/Target/TargetOptions.h
@@ -150,10 +150,6 @@ class TargetOptions {
   /// function.
   LLVM_ABI bool FramePointerIsReserved(const MachineFunction &MF) const;
 
-  /// If greater than 0, override the default value of
-  /// MCAsmInfo::BinutilsVersion.
-  std::pair<int, int> BinutilsVersion{0, 0};
-
   /// NoTrappingFPMath - This flag is enabled when the
   /// -enable-no-trapping-fp-math is specified on the command line. This
   /// specifies that there are no trap handlers to handle exceptions.
diff --git a/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp b/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
index d869c123c2046..b27b916771201 100644
--- a/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
+++ b/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
@@ -69,9 +69,6 @@ void CodeGenTargetMachineImpl::initAsmInfo() {
                        "Make sure you include the correct TargetSelect.h"
                        "and that InitializeAllTargetMCs() is being invoked!");
 
-  if (Options.BinutilsVersion.first > 0)
-    TmpAsmInfo->setBinutilsVersion(Options.BinutilsVersion);
-
   if (Options.DisableIntegratedAS) {
     TmpAsmInfo->setUseIntegratedAssembler(false);
     // If there is explict option disable integratedAS, we can't use it for
diff --git a/llvm/lib/MC/MCAsmInfo.cpp b/llvm/lib/MC/MCAsmInfo.cpp
index 4cb2cf63ae9d7..8e07bc652419e 100644
--- a/llvm/lib/MC/MCAsmInfo.cpp
+++ b/llvm/lib/MC/MCAsmInfo.cpp
@@ -47,6 +47,8 @@ MCAsmInfo::MCAsmInfo(const MCTargetOptions &Options) : TargetOptions(Options) {
     SupportsExtendedDwarfLocDirective = DwarfExtendedLoc == Enable;
   if (UseLEB128Directives != cl::boolOrDefault::BOU_UNSET)
     HasLEB128Directives = UseLEB128Directives == cl::boolOrDefault::BOU_TRUE;
+  if (Options.BinutilsVersion.first > 0)
+    BinutilsVersion = Options.BinutilsVersion;
 }
 
 MCAsmInfo::~MCAsmInfo() = default;
diff --git a/llvm/lib/MC/MCTargetOptions.cpp b/llvm/lib/MC/MCTargetOptions.cpp
index 65270bc2d3a22..dc20019ccdf6d 100644
--- a/llvm/lib/MC/MCTargetOptions.cpp
+++ b/llvm/lib/MC/MCTargetOptions.cpp
@@ -8,6 +8,7 @@
 
 #include "llvm/MC/MCTargetOptions.h"
 #include "llvm/ADT/StringRef.h"
+#include <climits>
 
 using namespace llvm;
 
@@ -22,6 +23,15 @@ MCTargetOptions::MCTargetOptions()
       EmitCompactUnwindNonCanonical(false), EmitSFrameUnwind(false),
       PPCUseFullRegisterNames(false), LargeEHEncoding(false) {}
 
+std::pair<int, int> MCTargetOptions::parseBinutilsVersion(StringRef Version) {
+  if (Version == "none")
+    return {INT_MAX, INT_MAX}; // Make binutilsIsAtLeast() return true.
+  std::pair<int, int> Ret;
+  if (!Version.consumeInteger(10, Ret.first) && Version.consume_front("."))
+    Version.consumeInteger(10, Ret.second);
+  return Ret;
+}
+
 StringRef MCTargetOptions::getABIName() const {
   return ABIName;
 }
diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp
index 676c44495e798..abf3afcc6969b 100644
--- a/llvm/lib/Target/TargetMachine.cpp
+++ b/llvm/lib/Target/TargetMachine.cpp
@@ -321,15 +321,6 @@ TargetIRAnalysis TargetMachine::getTargetIRAnalysis() const {
       [this](const Function &F) { return this->getTargetTransformInfo(F); });
 }
 
-std::pair<int, int> TargetMachine::parseBinutilsVersion(StringRef Version) {
-  if (Version == "none")
-    return {INT_MAX, INT_MAX}; // Make binutilsIsAtLeast() return true.
-  std::pair<int, int> Ret;
-  if (!Version.consumeInteger(10, Ret.first) && Version.consume_front("."))
-    Version.consumeInteger(10, Ret.second);
-  return Ret;
-}
-
 StringRef TargetMachine::getTargetABIName(const Module &M) const {
   if (const auto *MD = cast_or_null<MDString>(M.getModuleFlag("target-abi")))
     return MD->getString();
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index 750ab0b1550ae..28cf80ee096e9 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -560,8 +560,8 @@ static int compileModule(char **argv, SmallVectorImpl<PassPlugin> &PluginList,
           << "X86 backend ignores --fp-contract setting; use IR fast-math "
              "flags instead.";
 
-    Options.BinutilsVersion =
-        TargetMachine::parseBinutilsVersion(BinutilsVersion);
+    Options.MCOptions.BinutilsVersion =
+        MCTargetOptions::parseBinutilsVersion(BinutilsVersion);
     Options.MCOptions.ShowMCEncoding = ShowMCEncoding;
     Options.MCOptions.AsmVerbose = AsmVerbose;
     Options.MCOptions.PreserveAsmComments = PreserveComments;



More information about the cfe-commits mailing list