Skip to content

Commit a704309

Browse files
committed
auto merge of #12084 : alexcrichton/rust/codegen-opts, r=cmr
Move them all behind a new -C switch. This migrates some -Z flags and some top-level flags behind this -C codegen option. The -C flag takes values of the form "-C name=value" where the "=value" is optional for some flags. Flags affected: * --llvm-args => -C llvm-args * --passes => -C passes * --ar => -C ar * --linker => -C linker * --link-args => -C link-args * --target-cpu => -C target-cpu * --target-feature => -C target-fature * --android-cross-path => -C android-cross-path * --save-temps => -C save-temps * --no-rpath => -C no-rpath * -Z no-prepopulate => -C no-prepopulate-passes * -Z no-vectorize-loops => -C no-vectorize-loops * -Z no-vectorize-slp => -C no-vectorize-slp * -Z soft-float => -C soft-float * -Z gen-crate-map => -C gen-crate-map * -Z prefer-dynamic => -C prefer-dynamic * -Z no-integrated-as => -C no-integrated-as As a bonus, this also promotes the -Z extra-debug-info flag to a first class -g or --debuginfo flag. * -Z debug-info => removed * -Z extra-debug-info => -g or --debuginfo Closes #9770 Closes #12000
2 parents a2290db + 682029d commit a704309

File tree

112 files changed

+394
-299
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+394
-299
lines changed

Makefile.in

+5-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ else
107107
$(info cfg: enabling more debugging (CFG_ENABLE_DEBUG))
108108
CFG_RUSTC_FLAGS += --cfg debug
109109
CFG_GCCISH_CFLAGS += -DRUST_DEBUG
110+
# NOTE: after stage0, move these up into CFG_RUSTC_FLAGS
111+
RUSTFLAGS_STAGE1 += -g
112+
RUSTFLAGS_STAGE2 += -g
113+
RUSTFLAGS_STAGE3 += -g
110114
endif
111115

112116
ifdef SAVE_TEMPS
@@ -141,7 +145,7 @@ endif
141145
# worry about the distribution of one file (with its native dynamic
142146
# dependencies)
143147
RUSTFLAGS_STAGE0 += -Z prefer-dynamic
144-
RUSTFLAGS_STAGE1 += -Z prefer-dynamic
148+
RUSTFLAGS_STAGE1 += -C prefer-dynamic
145149

146150
# platform-specific auto-configuration
147151
include $(CFG_SRC_DIR)mk/platform.mk

man/rustc.1

+76-22
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,15 @@ Display this message
2727
\fB\-L\fR PATH
2828
Add a directory to the library search path
2929
.TP
30-
\fB\-\-linker\fR LINKER
31-
Program to use for linking instead of the default
32-
.TP
33-
\fB\-\-link-args\fR FLAGS
34-
A space-separated list of flags passed to the linker
35-
.TP
3630
\fB\-\-ls\fR
3731
List the symbols defined by a library crate
3832
.TP
3933
\fB\-\-no\-trans\fR
4034
Run all passes except translation; no output
4135
.TP
36+
\fB\-g\fR, \fB\-\-debuginfo\fR
37+
Emit DWARF debug information into object files generated.
38+
.TP
4239
\fB\-O\fR
4340
Equivalent to \fI\-\-opt\-level=2\fR
4441
.TP
@@ -48,11 +45,6 @@ Write output to <filename>. Ignored if more than one --emit is specified.
4845
\fB\-\-opt\-level\fR LEVEL
4946
Optimize with possible levels 0-3
5047
.TP
51-
\fB\-\-passes\fR NAMES
52-
Comma- or space-separated list of optimization passes. Overrides
53-
the default passes for the optimization level. A value of 'list'
54-
will list the available passes.
55-
.TP
5648
\fB\-\-out\-dir\fR DIR
5749
Write output to compiler-chosen filename in <dir>. Ignored if -o is specified.
5850
(default the current directory)
@@ -66,9 +58,6 @@ Pretty-print the input instead of compiling; valid types are: normal
6658
expanded, with type annotations), or identified (fully parenthesized,
6759
AST nodes and blocks with IDs)
6860
.TP
69-
\fB\-\-save\-temps\fR
70-
Write intermediate files (.bc, .opt.bc, .o) in addition to normal output
71-
.TP
7261
\fB\-\-sysroot\fR PATH
7362
Override the system root
7463
.TP
@@ -80,12 +69,6 @@ Target triple cpu-manufacturer-kernel[-os] to compile for (see
8069
http://sources.redhat.com/autobook/autobook/autobook_17.html
8170
for details)
8271
.TP
83-
\fB\-\-target-feature\fR TRIPLE
84-
Target-specific attributes (see llc -mattr=help for details)
85-
.TP
86-
\fB\-\-android-cross-path\fR PATH
87-
The path to the Android NDK
88-
.TP
8972
\fB\-W\fR help
9073
Print 'lint' options and default settings
9174
.TP
@@ -104,9 +87,80 @@ Set lint forbidden
10487
\fB\-Z\fR FLAG
10588
Set internal debugging options. Use "-Z help" to print available options.
10689
.TP
90+
\fB\-C\fR FLAG[=VAL], \fB\-\-codegen\fR FLAG[=VAL]
91+
Set a codegen-related flag to the value specifie.d Use "-C help" to print
92+
available flags. See CODEGEN OPTIONS below
93+
.TP
10794
\fB\-v\fR, \fB\-\-version\fR
10895
Print version info and exit
10996

97+
.SH CODEGEN OPTIONS
98+
99+
.TP
100+
\fBar\fR=/path/to/ar
101+
Path to the archive utility to use when assembling archives.
102+
.TP
103+
\fBlinker\fR=/path/to/cc
104+
Path to the linker utility to use when linking libraries, executables, and
105+
objects.
106+
.TP
107+
\fBlink-args\fR='-flag1 -flag2'
108+
A space-separated list of extra arguments to pass to the linker when the linker
109+
is invoked.
110+
.TP
111+
\fBtarget-cpu\fR=help
112+
Selects a target processor. If the value is 'help', then a list of available
113+
cpus is printed.
114+
.TP
115+
\fBtarget-feature\fR='+feature1 -feature2'
116+
A space-separated list of features to enable or disable for the target. A
117+
preceding '+' enables a feature while a preceding '-' disables it. Available
118+
features can be discovered through target-cpu=help.
119+
.TP
120+
\fBpasses\fR=list
121+
A space-separated list of extra LLVM passes to run. A value of 'list' will
122+
cause rustc to print all known passes and exit. The passes specified are
123+
appended at the end of the normal pass manager.
124+
.TP
125+
\fBllvm-args\fR='-arg1 -arg2'
126+
A space-separted list of argument to pass through to LLVM.
127+
.TP
128+
\fBsave-temps\fR
129+
If specified, the compiler will save more files (.bc, .o, .no-opt.bc) generated
130+
throughout compilation in the output directory.
131+
.TP
132+
\fBandroid-cross-path\fR=path/to/ndk/bin
133+
Directory to find the Android NDK cross-compilation tools
134+
.TP
135+
\fBno-rpath\fR
136+
If specified, then the rpath value for dynamic libraries will not be set in
137+
either dynamic library or executable outputs.
138+
.TP
139+
\fBno-prepopulate-passes\fR
140+
Suppresses pre-population of the LLVM pass manager that is run over the module.
141+
.TP
142+
\fBno-vectorize-loops\fR
143+
Suppresses running the loop vectorization LLVM pass, regardless of optimization
144+
level.
145+
.TP
146+
\fBno-vectorize-slp\fR
147+
Suppresses running the LLVM SLP vectorization pass, regardless of optimization
148+
level.
149+
.TP
150+
\fBsoft-float\fR
151+
Generates software floating point library calls instead of hardware
152+
instructions.
153+
.TP
154+
\fBgen-crate-map\fR
155+
Forces generate of a toplevel crate map. May be required for logging to work
156+
when rust is embedded into another application.
157+
.TP
158+
\fBprefer-dynamic\fR
159+
Prefers dynamic linking to static linking.
160+
.TP
161+
\fBno-integrated-as\fR
162+
Force usage of an external assembler rather than LLVM's integrated one.
163+
110164
.SH "EXAMPLES"
111165
To build an executable from a source file with a main function:
112166
$ rustc -o hello hello.rs
@@ -117,8 +171,8 @@ To build a library from a source file:
117171
To build either with a crate (.rs) file:
118172
$ rustc hello.rs
119173

120-
To build an executable with debug info (experimental):
121-
$ rustc -Z debug-info -o hello hello.rs
174+
To build an executable with debug info:
175+
$ rustc -g -o hello hello.rs
122176

123177
.SH "SEE ALSO"
124178

mk/platform.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ CFG_PATH_MUNGE_arm-linux-androideabi := true
300300
CFG_LDPATH_arm-linux-androideabi :=
301301
CFG_RUN_arm-linux-androideabi=
302302
CFG_RUN_TARG_arm-linux-androideabi=
303-
RUSTC_FLAGS_arm-linux-androideabi :=--android-cross-path=$(CFG_ANDROID_CROSS_PATH)
304-
RUSTC_CROSS_FLAGS_arm-linux-androideabi :=--android-cross-path=$(CFG_ANDROID_CROSS_PATH)
303+
RUSTC_FLAGS_arm-linux-androideabi :=-C android-cross-path=$(CFG_ANDROID_CROSS_PATH)
304+
RUSTC_CROSS_FLAGS_arm-linux-androideabi :=-C android-cross-path=$(CFG_ANDROID_CROSS_PATH)
305305

306306
# arm-unknown-linux-gnueabihf configuration
307307
CROSS_PREFIX_arm-unknown-linux-gnueabihf=arm-linux-gnueabihf-

mk/tests.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ CTEST_RUSTC_FLAGS := $$(subst --cfg ndebug,,$$(CFG_RUSTC_FLAGS))
530530

531531
# There's no need our entire test suite to take up gigabytes of space on disk
532532
# including copies of libstd/libextra all over the place
533-
CTEST_RUSTC_FLAGS := $$(CTEST_RUSTC_FLAGS) -Z prefer-dynamic
533+
CTEST_RUSTC_FLAGS := $$(CTEST_RUSTC_FLAGS) -C prefer-dynamic
534534

535535
# The tests can not be optimized while the rest of the compiler is optimized, so
536536
# filter out the optimization (if any) from rustc and then figure out if we need

src/compiletest/runtest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ fn compile_test_and_save_bitcode(config: &config, props: &TestProps,
10541054
let aux_dir = aux_output_dir_name(config, testfile);
10551055
// FIXME (#9639): This needs to handle non-utf8 paths
10561056
let link_args = ~[~"-L", aux_dir.as_str().unwrap().to_owned()];
1057-
let llvm_args = ~[~"--emit=obj", ~"--crate-type=lib", ~"--save-temps"];
1057+
let llvm_args = ~[~"--emit=obj", ~"--crate-type=lib", ~"-C", ~"save-temps"];
10581058
let args = make_compile_args(config, props,
10591059
link_args + llvm_args,
10601060
|a, b| ThisFile(make_o_name(a, b)), testfile);

src/doc/rust.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3761,7 +3761,7 @@ dependencies will be used:
37613761
with the above limitations in dynamic and static libraries, it is required
37623762
for all upstream dependencies to be in the same format. The next question is
37633763
whether to prefer a dynamic or a static format. The compiler currently favors
3764-
static linking over dynamic linking, but this can be inverted with the `-Z
3764+
static linking over dynamic linking, but this can be inverted with the `-C
37653765
prefer-dynamic` flag to the compiler.
37663766

37673767
What this means is that first the compiler will attempt to find all upstream

src/librustc/back/link.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ pub mod write {
111111
fn target_feature<'a>(sess: &'a Session) -> &'a str {
112112
match sess.targ_cfg.os {
113113
abi::OsAndroid => {
114-
if "" == sess.opts.target_feature {
114+
if "" == sess.opts.cg.target_feature {
115115
"+v7"
116116
} else {
117-
sess.opts.target_feature.as_slice()
117+
sess.opts.cg.target_feature.as_slice()
118118
}
119119
}
120-
_ => sess.opts.target_feature.as_slice()
120+
_ => sess.opts.cg.target_feature.as_slice()
121121
}
122122
}
123123

@@ -130,7 +130,7 @@ pub mod write {
130130
unsafe {
131131
configure_llvm(sess);
132132

133-
if sess.opts.save_temps {
133+
if sess.opts.cg.save_temps {
134134
output.with_extension("no-opt.bc").with_c_str(|buf| {
135135
llvm::LLVMWriteBitcodeToFile(llmod, buf);
136136
})
@@ -142,7 +142,7 @@ pub mod write {
142142
session::Default => lib::llvm::CodeGenLevelDefault,
143143
session::Aggressive => lib::llvm::CodeGenLevelAggressive,
144144
};
145-
let use_softfp = sess.opts.debugging_opts & session::USE_SOFTFP != 0;
145+
let use_softfp = sess.opts.cg.soft_float;
146146

147147
// FIXME: #11906: Omitting frame pointers breaks retrieving the value of a parameter.
148148
// FIXME: #11954: mac64 unwinding may not work with fp elim
@@ -151,7 +151,7 @@ pub mod write {
151151
sess.targ_cfg.arch == abi::X86_64);
152152

153153
let tm = sess.targ_cfg.target_strs.target_triple.with_c_str(|T| {
154-
sess.opts.target_cpu.with_c_str(|CPU| {
154+
sess.opts.cg.target_cpu.with_c_str(|CPU| {
155155
target_feature(&sess).with_c_str(|Features| {
156156
llvm::LLVMRustCreateTargetMachine(
157157
T, CPU, Features,
@@ -180,13 +180,13 @@ pub mod write {
180180
};
181181
if !sess.no_verify() { assert!(addpass("verify")); }
182182

183-
if !sess.no_prepopulate_passes() {
183+
if !sess.opts.cg.no_prepopulate_passes {
184184
llvm::LLVMRustAddAnalysisPasses(tm, fpm, llmod);
185185
llvm::LLVMRustAddAnalysisPasses(tm, mpm, llmod);
186186
populate_llvm_passes(fpm, mpm, llmod, OptLevel);
187187
}
188188

189-
for pass in sess.opts.custom_passes.iter() {
189+
for pass in sess.opts.cg.passes.iter() {
190190
pass.with_c_str(|s| {
191191
if !llvm::LLVMRustAddPass(mpm, s) {
192192
sess.warn(format!("unknown pass {}, ignoring", *pass));
@@ -208,7 +208,7 @@ pub mod write {
208208
// emitting an rlib. Whenever an rlib is created, the bytecode is
209209
// inserted into the archive in order to allow LTO against it.
210210
let crate_types = sess.crate_types.borrow();
211-
if sess.opts.save_temps ||
211+
if sess.opts.cg.save_temps ||
212212
(crate_types.get().contains(&session::CrateTypeRlib) &&
213213
sess.opts.output_types.contains(&OutputTypeExe)) {
214214
output.temp_path(OutputTypeBitcode).with_c_str(|buf| {
@@ -220,7 +220,7 @@ pub mod write {
220220
time(sess.time_passes(), "all lto passes", (), |()|
221221
lto::run(sess, llmod, tm, trans.reachable));
222222

223-
if sess.opts.save_temps {
223+
if sess.opts.cg.save_temps {
224224
output.with_extension("lto.bc").with_c_str(|buf| {
225225
llvm::LLVMWriteBitcodeToFile(llmod, buf);
226226
})
@@ -353,10 +353,10 @@ pub mod write {
353353

354354
// Copy what clang does by turning on loop vectorization at O2 and
355355
// slp vectorization at O3
356-
let vectorize_loop = !sess.no_vectorize_loops() &&
356+
let vectorize_loop = !sess.opts.cg.no_vectorize_loops &&
357357
(sess.opts.optimize == session::Default ||
358358
sess.opts.optimize == session::Aggressive);
359-
let vectorize_slp = !sess.no_vectorize_slp() &&
359+
let vectorize_slp = !sess.opts.cg.no_vectorize_slp &&
360360
sess.opts.optimize == session::Aggressive;
361361

362362
let mut llvm_c_strs = ~[];
@@ -374,7 +374,7 @@ pub mod write {
374374
if sess.time_llvm_passes() { add("-time-passes"); }
375375
if sess.print_llvm_passes() { add("-debug-pass=Structure"); }
376376

377-
for arg in sess.opts.llvm_args.iter() {
377+
for arg in sess.opts.cg.llvm_args.iter() {
378378
add(*arg);
379379
}
380380

@@ -745,7 +745,7 @@ pub fn output_lib_filename(lm: &LinkMeta) -> ~str {
745745
}
746746

747747
pub fn get_cc_prog(sess: Session) -> ~str {
748-
match sess.opts.linker {
748+
match sess.opts.cg.linker {
749749
Some(ref linker) => return linker.to_owned(),
750750
None => {}
751751
}
@@ -763,7 +763,7 @@ pub fn get_cc_prog(sess: Session) -> ~str {
763763
}
764764

765765
pub fn get_ar_prog(sess: Session) -> ~str {
766-
match sess.opts.ar {
766+
match sess.opts.cg.ar {
767767
Some(ref ar) => return ar.to_owned(),
768768
None => {}
769769
}
@@ -773,7 +773,7 @@ pub fn get_ar_prog(sess: Session) -> ~str {
773773

774774
fn get_system_tool(sess: Session, tool: &str) -> ~str {
775775
match sess.targ_cfg.os {
776-
abi::OsAndroid => match sess.opts.android_cross_path {
776+
abi::OsAndroid => match sess.opts.cg.android_cross_path {
777777
Some(ref path) => {
778778
let tool_str = match tool {
779779
"cc" => "gcc",
@@ -813,7 +813,7 @@ pub fn link_binary(sess: Session,
813813
}
814814

815815
// Remove the temporary object file and metadata if we aren't saving temps
816-
if !sess.opts.save_temps {
816+
if !sess.opts.cg.save_temps {
817817
let obj_filename = outputs.temp_path(OutputTypeObject);
818818
if !sess.opts.output_types.contains(&OutputTypeObject) {
819819
remove(sess, &obj_filename);
@@ -969,7 +969,7 @@ fn link_rlib(sess: Session,
969969
// into the archive.
970970
let bc = obj_filename.with_extension("bc");
971971
a.add_file(&bc, false);
972-
if !sess.opts.save_temps &&
972+
if !sess.opts.cg.save_temps &&
973973
!sess.opts.output_types.contains(&OutputTypeBitcode) {
974974
remove(sess, &bc);
975975
}
@@ -1142,7 +1142,7 @@ fn link_args(sess: Session,
11421142
args.push(~"-dynamiclib");
11431143
args.push(~"-Wl,-dylib");
11441144
// FIXME (#9639): This needs to handle non-utf8 paths
1145-
if !sess.opts.no_rpath {
1145+
if !sess.opts.cg.no_rpath {
11461146
args.push(~"-Wl,-install_name,@rpath/" +
11471147
out_filename.filename_str().unwrap());
11481148
}
@@ -1163,13 +1163,13 @@ fn link_args(sess: Session,
11631163
// FIXME (#2397): At some point we want to rpath our guesses as to
11641164
// where extern libraries might live, based on the
11651165
// addl_lib_search_paths
1166-
if !sess.opts.no_rpath {
1166+
if !sess.opts.cg.no_rpath {
11671167
args.push_all(rpath::get_rpath_flags(sess, out_filename));
11681168
}
11691169

11701170
// Finally add all the linker arguments provided on the command line along
11711171
// with any #[link_args] attributes found inside the crate
1172-
args.push_all(sess.opts.linker_args);
1172+
args.push_all(sess.opts.cg.link_args);
11731173
let used_link_args = sess.cstore.get_used_link_args();
11741174
let used_link_args = used_link_args.borrow();
11751175
for arg in used_link_args.get().iter() {
@@ -1235,7 +1235,7 @@ fn add_upstream_rust_crates(args: &mut ~[~str], sess: Session,
12351235
}
12361236

12371237
let cstore = sess.cstore;
1238-
if !dylib && !sess.prefer_dynamic() {
1238+
if !dylib && !sess.opts.cg.prefer_dynamic {
12391239
// With an executable, things get a little interesting. As a limitation
12401240
// of the current implementation, we require that everything must be
12411241
// static or everything must be dynamic. The reasons for this are a

src/librustc/back/lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::libc;
1919

2020
pub fn run(sess: session::Session, llmod: ModuleRef,
2121
tm: TargetMachineRef, reachable: &[~str]) {
22-
if sess.prefer_dynamic() {
22+
if sess.opts.cg.prefer_dynamic {
2323
sess.err("cannot prefer dynamic linking when performing LTO");
2424
sess.note("only 'staticlib' and 'bin' outputs are supported with LTO");
2525
sess.abort_if_errors();

0 commit comments

Comments
 (0)