Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate codegen-related compiler flags #12084

Merged
merged 1 commit into from
Feb 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ endif
# worry about the distribution of one file (with its native dynamic
# dependencies)
RUSTFLAGS_STAGE0 += -Z prefer-dynamic
RUSTFLAGS_STAGE1 += -Z prefer-dynamic
RUSTFLAGS_STAGE1 += -C prefer-dynamic

# platform-specific auto-configuration
include $(CFG_SRC_DIR)mk/platform.mk
Expand Down
98 changes: 76 additions & 22 deletions man/rustc.1
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,15 @@ Display this message
\fB\-L\fR PATH
Add a directory to the library search path
.TP
\fB\-\-linker\fR LINKER
Program to use for linking instead of the default
.TP
\fB\-\-link-args\fR FLAGS
A space-separated list of flags passed to the linker
.TP
\fB\-\-ls\fR
List the symbols defined by a library crate
.TP
\fB\-\-no\-trans\fR
Run all passes except translation; no output
.TP
\fB\-g\fR, \fB\-\-debuginfo\fR
Emit DWARF debug information into object files generated.
.TP
\fB\-O\fR
Equivalent to \fI\-\-opt\-level=2\fR
.TP
Expand All @@ -48,11 +45,6 @@ Write output to <filename>. Ignored if more than one --emit is specified.
\fB\-\-opt\-level\fR LEVEL
Optimize with possible levels 0-3
.TP
\fB\-\-passes\fR NAMES
Comma- or space-separated list of optimization passes. Overrides
the default passes for the optimization level. A value of 'list'
will list the available passes.
.TP
\fB\-\-out\-dir\fR DIR
Write output to compiler-chosen filename in <dir>. Ignored if -o is specified.
(default the current directory)
Expand All @@ -66,9 +58,6 @@ Pretty-print the input instead of compiling; valid types are: normal
expanded, with type annotations), or identified (fully parenthesized,
AST nodes and blocks with IDs)
.TP
\fB\-\-save\-temps\fR
Write intermediate files (.bc, .opt.bc, .o) in addition to normal output
.TP
\fB\-\-sysroot\fR PATH
Override the system root
.TP
Expand All @@ -80,12 +69,6 @@ Target triple cpu-manufacturer-kernel[-os] to compile for (see
http://sources.redhat.com/autobook/autobook/autobook_17.html
for details)
.TP
\fB\-\-target-feature\fR TRIPLE
Target-specific attributes (see llc -mattr=help for details)
.TP
\fB\-\-android-cross-path\fR PATH
The path to the Android NDK
.TP
\fB\-W\fR help
Print 'lint' options and default settings
.TP
Expand All @@ -104,9 +87,80 @@ Set lint forbidden
\fB\-Z\fR FLAG
Set internal debugging options. Use "-Z help" to print available options.
.TP
\fB\-C\fR FLAG[=VAL], \fB\-\-codegen\fR FLAG[=VAL]
Set a codegen-related flag to the value specifie.d Use "-C help" to print
available flags. See CODEGEN OPTIONS below
.TP
\fB\-v\fR, \fB\-\-version\fR
Print version info and exit

.SH CODEGEN OPTIONS

.TP
\fBar\fR=/path/to/ar
Path to the archive utility to use when assembling archives.
.TP
\fBlinker\fR=/path/to/cc
Path to the linker utility to use when linking libraries, executables, and
objects.
.TP
\fBlink-args\fR='-flag1 -flag2'
A space-separated list of extra arguments to pass to the linker when the linker
is invoked.
.TP
\fBtarget-cpu\fR=help
Selects a target processor. If the value is 'help', then a list of available
cpus is printed.
.TP
\fBtarget-feature\fR='+feature1 -feature2'
A space-separated list of features to enable or disable for the target. A
preceding '+' enables a feature while a preceding '-' disables it. Available
features can be discovered through target-cpu=help.
.TP
\fBpasses\fR=list
A space-separated list of extra LLVM passes to run. A value of 'list' will
cause rustc to print all known passes and exit. The passes specified are
appended at the end of the normal pass manager.
.TP
\fBllvm-args\fR='-arg1 -arg2'
A space-separted list of argument to pass through to LLVM.
.TP
\fBsave-temps\fR
If specified, the compiler will save more files (.bc, .o, .no-opt.bc) generated
throughout compilation in the output directory.
.TP
\fBandroid-cross-path\fR=path/to/ndk/bin
Directory to find the Android NDK cross-compilation tools
.TP
\fBno-rpath\fR
If specified, then the rpath value for dynamic libraries will not be set in
either dynamic library or executable outputs.
.TP
\fBno-prepopulate-passes\fR
Suppresses pre-population of the LLVM pass manager that is run over the module.
.TP
\fBno-vectorize-loops\fR
Suppresses running the loop vectorization LLVM pass, regardless of optimization
level.
.TP
\fBno-vectorize-slp\fR
Suppresses running the LLVM SLP vectorization pass, regardless of optimization
level.
.TP
\fBsoft-float\fR
Generates software floating point library calls instead of hardware
instructions.
.TP
\fBgen-crate-map\fR
Forces generate of a toplevel crate map. May be required for logging to work
when rust is embedded into another application.
.TP
\fBprefer-dynamic\fR
Prefers dynamic linking to static linking.
.TP
\fBno-integrated-as\fR
Force usage of an external assembler rather than LLVM's integrated one.

.SH "EXAMPLES"
To build an executable from a source file with a main function:
$ rustc -o hello hello.rs
Expand All @@ -117,8 +171,8 @@ To build a library from a source file:
To build either with a crate (.rs) file:
$ rustc hello.rs

To build an executable with debug info (experimental):
$ rustc -Z debug-info -o hello hello.rs
To build an executable with debug info:
$ rustc -g -o hello hello.rs

.SH "SEE ALSO"

Expand Down
4 changes: 2 additions & 2 deletions mk/platform.mk
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ CFG_PATH_MUNGE_arm-linux-androideabi := true
CFG_LDPATH_arm-linux-androideabi :=
CFG_RUN_arm-linux-androideabi=
CFG_RUN_TARG_arm-linux-androideabi=
RUSTC_FLAGS_arm-linux-androideabi :=--android-cross-path=$(CFG_ANDROID_CROSS_PATH)
RUSTC_CROSS_FLAGS_arm-linux-androideabi :=--android-cross-path=$(CFG_ANDROID_CROSS_PATH)
RUSTC_FLAGS_arm-linux-androideabi :=-C android-cross-path=$(CFG_ANDROID_CROSS_PATH)
RUSTC_CROSS_FLAGS_arm-linux-androideabi :=-C android-cross-path=$(CFG_ANDROID_CROSS_PATH)

# arm-unknown-linux-gnueabihf configuration
CROSS_PREFIX_arm-unknown-linux-gnueabihf=arm-linux-gnueabihf-
Expand Down
2 changes: 1 addition & 1 deletion mk/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ CTEST_RUSTC_FLAGS := $$(subst --cfg ndebug,,$$(CFG_RUSTC_FLAGS))

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

# The tests can not be optimized while the rest of the compiler is optimized, so
# filter out the optimization (if any) from rustc and then figure out if we need
Expand Down
6 changes: 3 additions & 3 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
let args = split_maybe_args(&config.rustcflags);
let mut tool_path:~str = ~"";
for arg in args.iter() {
if arg.contains("--android-cross-path=") {
tool_path = arg.replace("--android-cross-path=","");
if arg.contains("android-cross-path=") {
tool_path = arg.replace("android-cross-path=","");
break;
}
}
Expand Down Expand Up @@ -1054,7 +1054,7 @@ fn compile_test_and_save_bitcode(config: &config, props: &TestProps,
let aux_dir = aux_output_dir_name(config, testfile);
// FIXME (#9639): This needs to handle non-utf8 paths
let link_args = ~[~"-L", aux_dir.as_str().unwrap().to_owned()];
let llvm_args = ~[~"--emit=obj", ~"--crate-type=lib", ~"--save-temps"];
let llvm_args = ~[~"--emit=obj", ~"--crate-type=lib", ~"-C", ~"save-temps"];
let args = make_compile_args(config, props,
link_args + llvm_args,
|a, b| ThisFile(make_o_name(a, b)), testfile);
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -3761,7 +3761,7 @@ dependencies will be used:
with the above limitations in dynamic and static libraries, it is required
for all upstream dependencies to be in the same format. The next question is
whether to prefer a dynamic or a static format. The compiler currently favors
static linking over dynamic linking, but this can be inverted with the `-Z
static linking over dynamic linking, but this can be inverted with the `-C
prefer-dynamic` flag to the compiler.

What this means is that first the compiler will attempt to find all upstream
Expand Down
46 changes: 23 additions & 23 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ pub mod write {
fn target_feature<'a>(sess: &'a Session) -> &'a str {
match sess.targ_cfg.os {
abi::OsAndroid => {
if "" == sess.opts.target_feature {
if "" == sess.opts.cg.target_feature {
"+v7"
} else {
sess.opts.target_feature.as_slice()
sess.opts.cg.target_feature.as_slice()
}
}
_ => sess.opts.target_feature.as_slice()
_ => sess.opts.cg.target_feature.as_slice()
}
}

Expand All @@ -130,7 +130,7 @@ pub mod write {
unsafe {
configure_llvm(sess);

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

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

let tm = sess.targ_cfg.target_strs.target_triple.with_c_str(|T| {
sess.opts.target_cpu.with_c_str(|CPU| {
sess.opts.cg.target_cpu.with_c_str(|CPU| {
target_feature(&sess).with_c_str(|Features| {
llvm::LLVMRustCreateTargetMachine(
T, CPU, Features,
Expand Down Expand Up @@ -180,13 +180,13 @@ pub mod write {
};
if !sess.no_verify() { assert!(addpass("verify")); }

if !sess.no_prepopulate_passes() {
if !sess.opts.cg.no_prepopulate_passes {
llvm::LLVMRustAddAnalysisPasses(tm, fpm, llmod);
llvm::LLVMRustAddAnalysisPasses(tm, mpm, llmod);
populate_llvm_passes(fpm, mpm, llmod, OptLevel);
}

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

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

// Copy what clang does by turning on loop vectorization at O2 and
// slp vectorization at O3
let vectorize_loop = !sess.no_vectorize_loops() &&
let vectorize_loop = !sess.opts.cg.no_vectorize_loops &&
(sess.opts.optimize == session::Default ||
sess.opts.optimize == session::Aggressive);
let vectorize_slp = !sess.no_vectorize_slp() &&
let vectorize_slp = !sess.opts.cg.no_vectorize_slp &&
sess.opts.optimize == session::Aggressive;

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

for arg in sess.opts.llvm_args.iter() {
for arg in sess.opts.cg.llvm_args.iter() {
add(*arg);
}

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

pub fn get_cc_prog(sess: Session) -> ~str {
match sess.opts.linker {
match sess.opts.cg.linker {
Some(ref linker) => return linker.to_owned(),
None => {}
}
Expand All @@ -763,7 +763,7 @@ pub fn get_cc_prog(sess: Session) -> ~str {
}

pub fn get_ar_prog(sess: Session) -> ~str {
match sess.opts.ar {
match sess.opts.cg.ar {
Some(ref ar) => return ar.to_owned(),
None => {}
}
Expand All @@ -773,7 +773,7 @@ pub fn get_ar_prog(sess: Session) -> ~str {

fn get_system_tool(sess: Session, tool: &str) -> ~str {
match sess.targ_cfg.os {
abi::OsAndroid => match sess.opts.android_cross_path {
abi::OsAndroid => match sess.opts.cg.android_cross_path {
Some(ref path) => {
let tool_str = match tool {
"cc" => "gcc",
Expand All @@ -783,7 +783,7 @@ fn get_system_tool(sess: Session, tool: &str) -> ~str {
}
None => {
sess.fatal(format!("need Android NDK path for the '{}' tool \
(--android-cross-path)", tool))
(-C android-cross-path)", tool))
}
},
_ => tool.to_owned(),
Expand Down Expand Up @@ -813,7 +813,7 @@ pub fn link_binary(sess: Session,
}

// Remove the temporary object file and metadata if we aren't saving temps
if !sess.opts.save_temps {
if !sess.opts.cg.save_temps {
let obj_filename = outputs.temp_path(OutputTypeObject);
if !sess.opts.output_types.contains(&OutputTypeObject) {
remove(sess, &obj_filename);
Expand Down Expand Up @@ -969,7 +969,7 @@ fn link_rlib(sess: Session,
// into the archive.
let bc = obj_filename.with_extension("bc");
a.add_file(&bc, false);
if !sess.opts.save_temps &&
if !sess.opts.cg.save_temps &&
!sess.opts.output_types.contains(&OutputTypeBitcode) {
remove(sess, &bc);
}
Expand Down Expand Up @@ -1142,7 +1142,7 @@ fn link_args(sess: Session,
args.push(~"-dynamiclib");
args.push(~"-Wl,-dylib");
// FIXME (#9639): This needs to handle non-utf8 paths
if !sess.opts.no_rpath {
if !sess.opts.cg.no_rpath {
args.push(~"-Wl,-install_name,@rpath/" +
out_filename.filename_str().unwrap());
}
Expand All @@ -1163,13 +1163,13 @@ fn link_args(sess: Session,
// FIXME (#2397): At some point we want to rpath our guesses as to
// where extern libraries might live, based on the
// addl_lib_search_paths
if !sess.opts.no_rpath {
if !sess.opts.cg.no_rpath {
args.push_all(rpath::get_rpath_flags(sess, out_filename));
}

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

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