authorgravatar for xavierb@gmail.comxavier <xavierb@gmail.com> 2020-10-07 20:27:35+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-10-07 18:43:05-04:00
logeb33394d14e29600d36280b6797de0d8f40076c1
treeb80904044e8207f2c9deaa00c5fd092867611255
parenta0a834a2f292eb7f4170d590833b5d56084c0468

notice more kinds of optimization flags and debug flags

Closes #6091

3 files changed, 78 insertions(+), 14 deletions(-)

src/clang_options_data.zig+34-6
......@@ -75,8 +75,22 @@ flagpd1("M"),
7575 .psl = false,
7676},
7777flagpd1("Mach"),
78flagpd1("O0"),
79flagpd1("O4"),
78.{
79 .name = "O0",
80 .syntax = .flag,
81 .zig_equivalent = .optimize,
82 .pd1 = true,
83 .pd2 = false,
84 .psl = false,
85},
86.{
87 .name = "O4",
88 .syntax = .flag,
89 .zig_equivalent = .optimize,
90 .pd1 = true,
91 .pd2 = false,
92 .psl = false,
93},
8094.{
8195 .name = "O",
8296 .syntax = .flag,
......@@ -2163,7 +2177,7 @@ flagpd1("fno-ident"),
21632177.{
21642178 .name = "Os",
21652179 .syntax = .flag,
2166 .zig_equivalent = .other,
2180 .zig_equivalent = .optimize,
21672181 .pd1 = true,
21682182 .pd2 = false,
21692183 .psl = true,
......@@ -3148,7 +3162,14 @@ flagpd1("fxray-link-deps"),
31483162flagpd1("fzero-initialized-in-bss"),
31493163flagpd1("fzvector"),
31503164flagpd1("g0"),
3151flagpd1("g1"),
3165.{
3166 .name = "g1",
3167 .syntax = .flag,
3168 .zig_equivalent = .debug,
3169 .pd1 = true,
3170 .pd2 = false,
3171 .psl = false,
3172},
31523173flagpd1("g2"),
31533174flagpd1("g3"),
31543175.{
......@@ -3189,7 +3210,14 @@ flagpd1("ggdb3"),
31893210flagpd1("ggnu-pubnames"),
31903211flagpd1("ginline-line-tables"),
31913212flagpd1("gline-directives-only"),
3192flagpd1("gline-tables-only"),
3213.{
3214 .name = "gline-tables-only",
3215 .syntax = .flag,
3216 .zig_equivalent = .debug,
3217 .pd1 = true,
3218 .pd2 = false,
3219 .psl = false,
3220},
31933221flagpd1("glldb"),
31943222flagpd1("gmlt"),
31953223flagpd1("gmodules"),
......@@ -5363,7 +5391,7 @@ jspd1("iquote"),
53635391joinpd1("weak-l"),
53645392.{
53655393 .name = "Ofast",
5366 .syntax = .joined,
5394 .syntax = .flag,
53675395 .zig_equivalent = .optimize,
53685396 .pd1 = true,
53695397 .pd2 = false,
src/main.zig+17-7
......@@ -992,15 +992,20 @@ fn buildOutputType(
992992 },
993993 .optimize => {
994994 // Alright, what release mode do they want?
995 if (mem.eql(u8, it.only_arg, "Os")) {
995 const level = if (it.only_arg.len >= 1 and it.only_arg[0] == 'O') it.only_arg[1..] else it.only_arg;
996 if (mem.eql(u8, level, "s") or
997 mem.eql(u8, level, "z"))
998 {
996999 optimize_mode = .ReleaseSmall;
997 } else if (mem.eql(u8, it.only_arg, "O2") or
998 mem.eql(u8, it.only_arg, "O3") or
999 mem.eql(u8, it.only_arg, "O4"))
1000 } else if (mem.eql(u8, level, "1") or
1001 mem.eql(u8, level, "2") or
1002 mem.eql(u8, level, "3") or
1003 mem.eql(u8, level, "4") or
1004 mem.eql(u8, level, "fast"))
10001005 {
10011006 optimize_mode = .ReleaseFast;
1002 } else if (mem.eql(u8, it.only_arg, "Og") or
1003 mem.eql(u8, it.only_arg, "O0"))
1007 } else if (mem.eql(u8, level, "g") or
1008 mem.eql(u8, level, "0"))
10041009 {
10051010 optimize_mode = .Debug;
10061011 } else {
......@@ -1009,8 +1014,13 @@ fn buildOutputType(
10091014 },
10101015 .debug => {
10111016 strip = false;
1012 if (mem.eql(u8, it.only_arg, "-g")) {
1017 if (mem.eql(u8, it.only_arg, "g")) {
10131018 // We handled with strip = false above.
1019 } else if (mem.eql(u8, it.only_arg, "g1") or
1020 mem.eql(u8, it.only_arg, "gline-tables-only"))
1021 {
1022 // We handled with strip = false above. but we also want reduced debug info.
1023 try clang_argv.append("-gline-tables-only");
10141024 } else {
10151025 try clang_argv.appendSlice(it.other_args);
10161026 }
tools/update_clang_options.zig+27-1
......@@ -130,6 +130,10 @@ const known_options = [_]KnownOpt{
130130 .name = "assemble",
131131 .ident = "asm_only",
132132 },
133 .{
134 .name = "O0",
135 .ident = "optimize",
136 },
133137 .{
134138 .name = "O1",
135139 .ident = "optimize",
......@@ -138,10 +142,20 @@ const known_options = [_]KnownOpt{
138142 .name = "O2",
139143 .ident = "optimize",
140144 },
145 // O3 is only detected from the joined "-O" option
146 .{
147 .name = "O4",
148 .ident = "optimize",
149 },
141150 .{
142151 .name = "Og",
143152 .ident = "optimize",
144153 },
154 .{
155 .name = "Os",
156 .ident = "optimize",
157 },
158 // Oz is only detected from the joined "-O" option
145159 .{
146160 .name = "O",
147161 .ident = "optimize",
......@@ -154,6 +168,14 @@ const known_options = [_]KnownOpt{
154168 .name = "optimize",
155169 .ident = "optimize",
156170 },
171 .{
172 .name = "g1",
173 .ident = "debug",
174 },
175 .{
176 .name = "gline-tables-only",
177 .ident = "debug",
178 },
157179 .{
158180 .name = "g",
159181 .ident = "debug",
......@@ -390,6 +412,10 @@ pub fn main() anyerror!void {
390412 // the only way.
391413 try stdout.print("flagpsl(\"{}\"),\n", .{name});
392414 } else if (knownOption(name)) |ident| {
415
416 // Workaround the fact that in 'Options.td' -Ofast is listed as 'joined'
417 const final_syntax = if (std.mem.eql(u8, name, "Ofast")) .flag else syntax;
418
393419 try stdout.print(
394420 \\.{{
395421 \\ .name = "{}",
......@@ -400,7 +426,7 @@ pub fn main() anyerror!void {
400426 \\ .psl = {},
401427 \\}},
402428 \\
403 , .{ name, syntax, ident, pd1, pd2, pslash });
429 , .{ name, final_syntax, ident, pd1, pd2, pslash });
404430 } else if (pd1 and !pd2 and !pslash and syntax == .flag) {
405431 try stdout.print("flagpd1(\"{}\"),\n", .{name});
406432 } else if (!pd1 and !pd2 and pslash and syntax == .flag) {