Skip to content

Commit 65ff20f

Browse files
committed
Back port support for explicitly selecting a variant of the
SPARC architecture and for setting the default to vis/-Av9a. Needed for building base and xenocara on sparc64. llvm/llvm-project#125151 llvm/llvm-project#130108
1 parent fc0efe3 commit 65ff20f

File tree

3 files changed

+143
-7
lines changed

3 files changed

+143
-7
lines changed

devel/llvm/19/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ LLVM_MAJOR = 19
22
LLVM_VERSION = ${LLVM_MAJOR}.1.7
33
LLVM_PKGSPEC = >=19,<20
44

5-
REVISION-main = 2
5+
REVISION-main = 3
66

77
SHARED_LIBS += LLVM 0.0 \
88
LTO 0.0 \

devel/llvm/19/patches/patch-clang_lib_Driver_ToolChains_Clang_cpp

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,15 @@ Index: clang/lib/Driver/ToolChains/Clang.cpp
3737
BranchProtectionPAuthLR = false;
3838
GuardedControlStack = false;
3939
} else {
40-
@@ -2664,6 +2673,11 @@ static void CollectArgsForIntegratedAssembler(Compilat
40+
@@ -2574,6 +2583,7 @@ static void CollectArgsForIntegratedAssembler(Compilat
41+
bool UseRelaxRelocations = C.getDefaultToolChain().useRelaxRelocations();
42+
bool UseNoExecStack = false;
43+
const char *MipsTargetFeature = nullptr;
44+
+ llvm::SmallVector<const char *> SparcTargetFeatures;
45+
StringRef ImplicitIt;
46+
for (const Arg *A :
47+
Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler,
48+
@@ -2664,6 +2674,11 @@ static void CollectArgsForIntegratedAssembler(Compilat
4149
CmdArgs.push_back("-soft-float");
4250
continue;
4351
}
@@ -49,7 +57,62 @@ Index: clang/lib/Driver/ToolChains/Clang.cpp
4957

5058
MipsTargetFeature = llvm::StringSwitch<const char *>(Value)
5159
.Case("-mips1", "+mips1")
52-
@@ -5799,8 +5813,12 @@ void Clang::ConstructJob(Compilation &C, const JobActi
60+
@@ -2684,6 +2699,32 @@ static void CollectArgsForIntegratedAssembler(Compilat
61+
.Default(nullptr);
62+
if (MipsTargetFeature)
63+
continue;
64+
+ break;
65+
+
66+
+ case llvm::Triple::sparc:
67+
+ case llvm::Triple::sparcel:
68+
+ case llvm::Triple::sparcv9:
69+
+ if (Value == "--undeclared-regs") {
70+
+ // LLVM already allows undeclared use of G registers, so this option
71+
+ // becomes a no-op. This solely exists for GNU compatibility.
72+
+ // TODO implement --no-undeclared-regs
73+
+ continue;
74+
+ }
75+
+ SparcTargetFeatures =
76+
+ llvm::StringSwitch<llvm::SmallVector<const char *>>(Value)
77+
+ .Case("-Av8", {"-v8plus"})
78+
+ .Case("-Av8plus", {"+v8plus", "+v9"})
79+
+ .Case("-Av8plusa", {"+v8plus", "+v9", "+vis"})
80+
+ .Case("-Av8plusb", {"+v8plus", "+v9", "+vis", "+vis2"})
81+
+ .Case("-Av8plusd", {"+v8plus", "+v9", "+vis", "+vis2", "+vis3"})
82+
+ .Case("-Av9", {"+v9"})
83+
+ .Case("-Av9a", {"+v9", "+vis"})
84+
+ .Case("-Av9b", {"+v9", "+vis", "+vis2"})
85+
+ .Case("-Av9d", {"+v9", "+vis", "+vis2", "+vis3"})
86+
+ .Default({});
87+
+ if (!SparcTargetFeatures.empty())
88+
+ continue;
89+
+ break;
90+
}
91+
92+
if (Value == "-force_cpusubtype_ALL") {
93+
@@ -2791,6 +2832,21 @@ static void CollectArgsForIntegratedAssembler(Compilat
94+
CmdArgs.push_back(MipsTargetFeature);
95+
}
96+
97+
+ // Those OSes default to enabling VIS on 64-bit SPARC.
98+
+ // See also the corresponding code for external assemblers in
99+
+ // sparc::getSparcAsmModeForCPU().
100+
+ bool IsSparcV9ATarget =
101+
+ (C.getDefaultToolChain().getArch() == llvm::Triple::sparcv9) &&
102+
+ (Triple.isOSLinux() || Triple.isOSFreeBSD() || Triple.isOSOpenBSD());
103+
+ if (IsSparcV9ATarget && SparcTargetFeatures.empty()) {
104+
+ CmdArgs.push_back("-target-feature");
105+
+ CmdArgs.push_back("+vis");
106+
+ }
107+
+ for (const char *Feature : SparcTargetFeatures) {
108+
+ CmdArgs.push_back("-target-feature");
109+
+ CmdArgs.push_back(Feature);
110+
+ }
111+
+
112+
// forward -fembed-bitcode to assmebler
113+
if (C.getDriver().embedBitcodeEnabled() ||
114+
C.getDriver().embedBitcodeMarkerOnly())
115+
@@ -5799,8 +5855,12 @@ void Clang::ConstructJob(Compilation &C, const JobActi
53116
OFastEnabled ? options::OPT_Ofast : options::OPT_fstrict_aliasing;
54117
// We turn strict aliasing off by default if we're Windows MSVC since MSVC
55118
// doesn't do any TBAA.
@@ -63,7 +126,7 @@ Index: clang/lib/Driver/ToolChains/Clang.cpp
63126
CmdArgs.push_back("-relaxed-aliasing");
64127
if (Args.hasFlag(options::OPT_fpointer_tbaa, options::OPT_fno_pointer_tbaa,
65128
false))
66-
@@ -6844,7 +6862,8 @@ void Clang::ConstructJob(Compilation &C, const JobActi
129+
@@ -6844,7 +6904,8 @@ void Clang::ConstructJob(Compilation &C, const JobActi
67130
options::OPT_fno_strict_overflow)) {
68131
if (A->getOption().matches(options::OPT_fno_strict_overflow))
69132
CmdArgs.push_back("-fwrapv");
@@ -73,7 +136,7 @@ Index: clang/lib/Driver/ToolChains/Clang.cpp
73136

74137
Args.AddLastArg(CmdArgs, options::OPT_ffinite_loops,
75138
options::OPT_fno_finite_loops);
76-
@@ -6860,7 +6879,58 @@ void Clang::ConstructJob(Compilation &C, const JobActi
139+
@@ -6860,7 +6921,58 @@ void Clang::ConstructJob(Compilation &C, const JobActi
77140
Args.addOptInFlag(CmdArgs, options::OPT_mspeculative_load_hardening,
78141
options::OPT_mno_speculative_load_hardening);
79142

@@ -133,7 +196,7 @@ Index: clang/lib/Driver/ToolChains/Clang.cpp
133196
RenderSCPOptions(TC, Args, CmdArgs);
134197
RenderTrivialAutoVarInitOptions(D, TC, Args, CmdArgs);
135198

136-
@@ -6938,6 +7008,11 @@ void Clang::ConstructJob(Compilation &C, const JobActi
199+
@@ -6938,6 +7050,11 @@ void Clang::ConstructJob(Compilation &C, const JobActi
137200
if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) {
138201
CmdArgs.push_back(
139202
Args.MakeArgString(Twine("-fcf-protection=") + A->getValue()));
@@ -145,7 +208,7 @@ Index: clang/lib/Driver/ToolChains/Clang.cpp
145208
}
146209

147210
if (Arg *A = Args.getLastArg(options::OPT_mfunction_return_EQ))
148-
@@ -7466,6 +7541,18 @@ void Clang::ConstructJob(Compilation &C, const JobActi
211+
@@ -7466,6 +7583,18 @@ void Clang::ConstructJob(Compilation &C, const JobActi
149212
options::OPT_fno_rewrite_imports, false);
150213
if (RewriteImports)
151214
CmdArgs.push_back("-frewrite-imports");
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
Index: clang/test/Driver/sparc-ias-Wa.s
2+
--- clang/test/Driver/sparc-ias-Wa.s.orig
3+
+++ clang/test/Driver/sparc-ias-Wa.s
4+
@@ -0,0 +1,69 @@
5+
+// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s -Wa,-Av8 2>&1 | \
6+
+// RUN: FileCheck -check-prefix=V8 %s
7+
+// V8: -cc1as
8+
+// V8: "-target-feature" "-v8plus"
9+
+
10+
+// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s -Wa,-Av8plus 2>&1 | \
11+
+// RUN: FileCheck -check-prefix=V8PLUS %s
12+
+// V8PLUS: -cc1as
13+
+// V8PLUS: "-target-feature" "+v8plus"
14+
+// V8PLUS: "-target-feature" "+v9"
15+
+
16+
+// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s -Wa,-Av8plusa 2>&1 | \
17+
+// RUN: FileCheck -check-prefix=V8PLUSA %s
18+
+// V8PLUSA: -cc1as
19+
+// V8PLUSA: "-target-feature" "+v8plus"
20+
+// V8PLUSA: "-target-feature" "+v9"
21+
+// V8PLUSA: "-target-feature" "+vis"
22+
+
23+
+// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s -Wa,-Av8plusb 2>&1 | \
24+
+// RUN: FileCheck -check-prefix=V8PLUSB %s
25+
+// V8PLUSB: -cc1as
26+
+// V8PLUSB: "-target-feature" "+v8plus"
27+
+// V8PLUSB: "-target-feature" "+v9"
28+
+// V8PLUSB: "-target-feature" "+vis"
29+
+// V8PLUSB: "-target-feature" "+vis2"
30+
+
31+
+// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s -Wa,-Av8plusd 2>&1 | \
32+
+// RUN: FileCheck -check-prefix=V8PLUSD %s
33+
+// V8PLUSD: -cc1as
34+
+// V8PLUSD: "-target-feature" "+v8plus"
35+
+// V8PLUSD: "-target-feature" "+v9"
36+
+// V8PLUSD: "-target-feature" "+vis"
37+
+// V8PLUSD: "-target-feature" "+vis2"
38+
+// V8PLUSD: "-target-feature" "+vis3"
39+
+
40+
+// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s -Wa,-Av9 2>&1 | \
41+
+// RUN: FileCheck -check-prefix=V9 %s
42+
+// V9: -cc1as
43+
+// V9: "-target-feature" "+v9"
44+
+
45+
+// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s -Wa,-Av9a 2>&1 | \
46+
+// RUN: FileCheck -check-prefix=V9A %s
47+
+// V9A: -cc1as
48+
+// V9A: "-target-feature" "+v9"
49+
+// V9A: "-target-feature" "+vis"
50+
+
51+
+// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s -Wa,-Av9b 2>&1 | \
52+
+// RUN: FileCheck -check-prefix=V9B %s
53+
+// V9B: -cc1as
54+
+// V9B: "-target-feature" "+v9"
55+
+// V9B: "-target-feature" "+vis"
56+
+// V9B: "-target-feature" "+vis2"
57+
+
58+
+// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s -Wa,-Av9d 2>&1 | \
59+
+// RUN: FileCheck -check-prefix=V9D %s
60+
+// V9D: -cc1as
61+
+// V9D: "-target-feature" "+v9"
62+
+// V9D: "-target-feature" "+vis"
63+
+// V9D: "-target-feature" "+vis2"
64+
+// V9D: "-target-feature" "+vis3"
65+
+
66+
+// RUN: %clang --target=sparc64-linux-gnu -### -fintegrated-as -c %s 2>&1 | \
67+
+// RUN: FileCheck -check-prefix=VIS-DEFAULT %s
68+
+// RUN: %clang --target=sparc64-freebsd -### -fintegrated-as -c %s 2>&1 | \
69+
+// RUN: FileCheck -check-prefix=VIS-DEFAULT %s
70+
+// RUN: %clang --target=sparc64-openbsd -### -fintegrated-as -c %s 2>&1 | \
71+
+// RUN: FileCheck -check-prefix=VIS-DEFAULT %s
72+
+// VIS-DEFAULT: -cc1as
73+
+// VIS-DEFAULT: "-target-feature" "+vis"

0 commit comments

Comments
 (0)