Back port support for explicitly selectecting a variant of the
SPARC architecture and for setting the default to vis/-Av9a.
Needed for building base and xenocara on sparc64.
https://github.com/llvm/llvm-project/pull/125151
https://github.com/llvm/llvm-project/pull/130108

okay?

Index: Makefile
===================================================================
RCS file: /cvs/ports/devel/llvm/19/Makefile,v
diff -u -p -u -r1.10 Makefile
--- Makefile    2 Feb 2025 16:38:25 -0000       1.10
+++ Makefile    8 Mar 2025 23:12:51 -0000
@@ -2,7 +2,7 @@ LLVM_MAJOR =    19
 LLVM_VERSION = ${LLVM_MAJOR}.1.7
 LLVM_PKGSPEC = >=19,<20
 
-REVISION-main =        2
+REVISION-main =        3
 
 SHARED_LIBS += LLVM            0.0 \
                LTO             0.0 \
Index: patches/patch-clang_lib_Driver_ToolChains_Clang_cpp
===================================================================
RCS file: 
/cvs/ports/devel/llvm/19/patches/patch-clang_lib_Driver_ToolChains_Clang_cpp,v
diff -u -p -u -r1.1.1.1 patch-clang_lib_Driver_ToolChains_Clang_cpp
--- patches/patch-clang_lib_Driver_ToolChains_Clang_cpp 15 Nov 2024 11:18:28 
-0000      1.1.1.1
+++ patches/patch-clang_lib_Driver_ToolChains_Clang_cpp 8 Mar 2025 23:12:51 
-0000
@@ -37,7 +37,15 @@ Index: clang/lib/Driver/ToolChains/Clang
      BranchProtectionPAuthLR = false;
      GuardedControlStack = false;
    } else {
-@@ -2664,6 +2673,11 @@ static void CollectArgsForIntegratedAssembler(Compilat
+@@ -2574,6 +2583,7 @@ static void CollectArgsForIntegratedAssembler(Compilat
+   bool UseRelaxRelocations = C.getDefaultToolChain().useRelaxRelocations();
+   bool UseNoExecStack = false;
+   const char *MipsTargetFeature = nullptr;
++  llvm::SmallVector<const char *> SparcTargetFeatures;
+   StringRef ImplicitIt;
+   for (const Arg *A :
+        Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler,
+@@ -2664,6 +2674,11 @@ static void CollectArgsForIntegratedAssembler(Compilat
            CmdArgs.push_back("-soft-float");
            continue;
          }
@@ -49,7 +57,62 @@ Index: clang/lib/Driver/ToolChains/Clang
  
          MipsTargetFeature = llvm::StringSwitch<const char *>(Value)
                                  .Case("-mips1", "+mips1")
-@@ -5799,8 +5813,12 @@ void Clang::ConstructJob(Compilation &C, const JobActi
+@@ -2684,6 +2699,32 @@ static void CollectArgsForIntegratedAssembler(Compilat
+                                 .Default(nullptr);
+         if (MipsTargetFeature)
+           continue;
++        break;
++
++      case llvm::Triple::sparc:
++      case llvm::Triple::sparcel:
++      case llvm::Triple::sparcv9:
++        if (Value == "--undeclared-regs") {
++          // LLVM already allows undeclared use of G registers, so this option
++          // becomes a no-op. This solely exists for GNU compatibility.
++          // TODO implement --no-undeclared-regs
++          continue;
++        }
++        SparcTargetFeatures =
++            llvm::StringSwitch<llvm::SmallVector<const char *>>(Value)
++                .Case("-Av8", {"-v8plus"})
++                .Case("-Av8plus", {"+v8plus", "+v9"})
++                .Case("-Av8plusa", {"+v8plus", "+v9", "+vis"})
++                .Case("-Av8plusb", {"+v8plus", "+v9", "+vis", "+vis2"})
++                .Case("-Av8plusd", {"+v8plus", "+v9", "+vis", "+vis2", 
"+vis3"})
++                .Case("-Av9", {"+v9"})
++                .Case("-Av9a", {"+v9", "+vis"})
++                .Case("-Av9b", {"+v9", "+vis", "+vis2"})
++                .Case("-Av9d", {"+v9", "+vis", "+vis2", "+vis3"})
++                .Default({});
++        if (!SparcTargetFeatures.empty())
++          continue;
++        break;
+       }
+ 
+       if (Value == "-force_cpusubtype_ALL") {
+@@ -2791,6 +2832,21 @@ static void CollectArgsForIntegratedAssembler(Compilat
+     CmdArgs.push_back(MipsTargetFeature);
+   }
+ 
++  // Those OSes default to enabling VIS on 64-bit SPARC.
++  // See also the corresponding code for external assemblers in
++  // sparc::getSparcAsmModeForCPU().
++  bool IsSparcV9ATarget =
++      (C.getDefaultToolChain().getArch() == llvm::Triple::sparcv9) &&
++      (Triple.isOSLinux() || Triple.isOSFreeBSD() || Triple.isOSOpenBSD());
++  if (IsSparcV9ATarget && SparcTargetFeatures.empty()) {
++    CmdArgs.push_back("-target-feature");
++    CmdArgs.push_back("+vis");
++  }
++  for (const char *Feature : SparcTargetFeatures) {
++    CmdArgs.push_back("-target-feature");
++    CmdArgs.push_back(Feature);
++  }
++
+   // forward -fembed-bitcode to assmebler
+   if (C.getDriver().embedBitcodeEnabled() ||
+       C.getDriver().embedBitcodeMarkerOnly())
+@@ -5799,8 +5855,12 @@ void Clang::ConstructJob(Compilation &C, const JobActi
        OFastEnabled ? options::OPT_Ofast : options::OPT_fstrict_aliasing;
    // We turn strict aliasing off by default if we're Windows MSVC since MSVC
    // doesn't do any TBAA.
@@ -63,7 +126,7 @@ Index: clang/lib/Driver/ToolChains/Clang
      CmdArgs.push_back("-relaxed-aliasing");
    if (Args.hasFlag(options::OPT_fpointer_tbaa, options::OPT_fno_pointer_tbaa,
                     false))
-@@ -6844,7 +6862,8 @@ void Clang::ConstructJob(Compilation &C, const JobActi
+@@ -6844,7 +6904,8 @@ void Clang::ConstructJob(Compilation &C, const JobActi
                                        options::OPT_fno_strict_overflow)) {
      if (A->getOption().matches(options::OPT_fno_strict_overflow))
        CmdArgs.push_back("-fwrapv");
@@ -73,7 +136,7 @@ Index: clang/lib/Driver/ToolChains/Clang
  
    Args.AddLastArg(CmdArgs, options::OPT_ffinite_loops,
                    options::OPT_fno_finite_loops);
-@@ -6860,7 +6879,58 @@ void Clang::ConstructJob(Compilation &C, const JobActi
+@@ -6860,7 +6921,58 @@ void Clang::ConstructJob(Compilation &C, const JobActi
    Args.addOptInFlag(CmdArgs, options::OPT_mspeculative_load_hardening,
                      options::OPT_mno_speculative_load_hardening);
  
@@ -133,7 +196,7 @@ Index: clang/lib/Driver/ToolChains/Clang
    RenderSCPOptions(TC, Args, CmdArgs);
    RenderTrivialAutoVarInitOptions(D, TC, Args, CmdArgs);
  
-@@ -6938,6 +7008,11 @@ void Clang::ConstructJob(Compilation &C, const JobActi
+@@ -6938,6 +7050,11 @@ void Clang::ConstructJob(Compilation &C, const JobActi
    if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) {
      CmdArgs.push_back(
          Args.MakeArgString(Twine("-fcf-protection=") + A->getValue()));
@@ -145,7 +208,7 @@ Index: clang/lib/Driver/ToolChains/Clang
    }
  
    if (Arg *A = Args.getLastArg(options::OPT_mfunction_return_EQ))
-@@ -7466,6 +7541,18 @@ void Clang::ConstructJob(Compilation &C, const JobActi
+@@ -7466,6 +7583,18 @@ void Clang::ConstructJob(Compilation &C, const JobActi
                                       options::OPT_fno_rewrite_imports, false);
    if (RewriteImports)
      CmdArgs.push_back("-frewrite-imports");
Index: patches/patch-clang_test_Driver_sparc-ias-Wa_s
===================================================================
RCS file: patches/patch-clang_test_Driver_sparc-ias-Wa_s
diff -N patches/patch-clang_test_Driver_sparc-ias-Wa_s
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-clang_test_Driver_sparc-ias-Wa_s      8 Mar 2025 23:12:51 
-0000
@@ -0,0 +1,73 @@
+Index: clang/test/Driver/sparc-ias-Wa.s
+--- clang/test/Driver/sparc-ias-Wa.s.orig
++++ clang/test/Driver/sparc-ias-Wa.s
+@@ -0,0 +1,69 @@
++// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s -Wa,-Av8 
2>&1 | \
++// RUN:   FileCheck -check-prefix=V8 %s
++// V8: -cc1as
++// V8: "-target-feature" "-v8plus"
++
++// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s 
-Wa,-Av8plus 2>&1 | \
++// RUN:   FileCheck -check-prefix=V8PLUS %s
++// V8PLUS: -cc1as
++// V8PLUS: "-target-feature" "+v8plus"
++// V8PLUS: "-target-feature" "+v9"
++
++// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s 
-Wa,-Av8plusa 2>&1 | \
++// RUN:   FileCheck -check-prefix=V8PLUSA %s
++// V8PLUSA: -cc1as
++// V8PLUSA: "-target-feature" "+v8plus"
++// V8PLUSA: "-target-feature" "+v9"
++// V8PLUSA: "-target-feature" "+vis"
++
++// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s 
-Wa,-Av8plusb 2>&1 | \
++// RUN:   FileCheck -check-prefix=V8PLUSB %s
++// V8PLUSB: -cc1as
++// V8PLUSB: "-target-feature" "+v8plus"
++// V8PLUSB: "-target-feature" "+v9"
++// V8PLUSB: "-target-feature" "+vis"
++// V8PLUSB: "-target-feature" "+vis2"
++
++// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s 
-Wa,-Av8plusd 2>&1 | \
++// RUN:   FileCheck -check-prefix=V8PLUSD %s
++// V8PLUSD: -cc1as
++// V8PLUSD: "-target-feature" "+v8plus"
++// V8PLUSD: "-target-feature" "+v9"
++// V8PLUSD: "-target-feature" "+vis"
++// V8PLUSD: "-target-feature" "+vis2"
++// V8PLUSD: "-target-feature" "+vis3"
++
++// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s -Wa,-Av9 
2>&1 | \
++// RUN:   FileCheck -check-prefix=V9 %s
++// V9: -cc1as
++// V9: "-target-feature" "+v9"
++
++// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s -Wa,-Av9a 
2>&1 | \
++// RUN:   FileCheck -check-prefix=V9A %s
++// V9A: -cc1as
++// V9A: "-target-feature" "+v9"
++// V9A: "-target-feature" "+vis"
++
++// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s -Wa,-Av9b 
2>&1 | \
++// RUN:   FileCheck -check-prefix=V9B %s
++// V9B: -cc1as
++// V9B: "-target-feature" "+v9"
++// V9B: "-target-feature" "+vis"
++// V9B: "-target-feature" "+vis2"
++
++// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s -Wa,-Av9d 
2>&1 | \
++// RUN:   FileCheck -check-prefix=V9D %s
++// V9D: -cc1as
++// V9D: "-target-feature" "+v9"
++// V9D: "-target-feature" "+vis"
++// V9D: "-target-feature" "+vis2"
++// V9D: "-target-feature" "+vis3"
++
++// RUN: %clang --target=sparc64-linux-gnu -### -fintegrated-as -c %s 2>&1 | \
++// RUN:   FileCheck -check-prefix=VIS-DEFAULT %s
++// RUN: %clang --target=sparc64-freebsd -### -fintegrated-as -c %s 2>&1 | \
++// RUN:   FileCheck -check-prefix=VIS-DEFAULT %s
++// RUN: %clang --target=sparc64-openbsd -### -fintegrated-as -c %s 2>&1 | \
++// RUN:   FileCheck -check-prefix=VIS-DEFAULT %s
++// VIS-DEFAULT: -cc1as
++// VIS-DEFAULT: "-target-feature" "+vis"

Reply via email to