Skip to content

Commit ef47e71

Browse files
committed
Merge remote-tracking branch 'DiamondLovesYou/polly' into master
Topic-branch changes to src/librustc_codegen_llvm/back/write.rs and src/rustllvm/PassWrapper.cpp were ignored as the needed Refactorings would require a detailed understanding of rustc's LLVM backend. Further errors are expected.
2 parents 4bb4b96 + d51fa91 commit ef47e71

File tree

12 files changed

+347
-40
lines changed

12 files changed

+347
-40
lines changed

config.toml.example

+8
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,10 @@
400400
# Flag indicating whether tests are compiled with optimizations (the -O flag).
401401
#optimize-tests = true
402402

403+
# Flag indicating whether tests are optimized with Polly. If optimize-tests is false,
404+
# polly-tests will be false regardless of its value here.
405+
#polly-tests = false
406+
403407
# Flag indicating whether codegen tests will be run or not. If you get an error
404408
# saying that the FileCheck executable is missing, you may want to disable this.
405409
# Also see the target's llvm-filecheck option.
@@ -456,6 +460,10 @@
456460
# instead of LLVM's default of 100.
457461
#thin-lto-import-instr-limit = 100
458462

463+
# Use Polly on the rust compiler itself. If optimize is false, this will be
464+
# false as well.
465+
#polly-self = false
466+
459467
# Map debuginfo paths to `/rust/$sha/...`, generally only set for releases
460468
#remap-debuginfo = false
461469

src/bootstrap/bin/rustc.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ fn main() {
4545
("RUSTC_REAL", "RUSTC_LIBDIR")
4646
};
4747
let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set");
48+
let stage = usize::from_str(stage.as_str()).expect("RUSTC_STAGE not a usize");
4849
let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");
4950
let on_fail = env::var_os("RUSTC_ON_FAIL").map(Command::new);
5051

@@ -100,7 +101,7 @@ fn main() {
100101
// workaround undefined references to `rust_eh_unwind_resume` generated
101102
// otherwise, see issue https://github.com/rust-lang/rust/issues/43095.
102103
if crate_name == Some("panic_abort")
103-
|| crate_name == Some("compiler_builtins") && stage != "0"
104+
|| crate_name == Some("compiler_builtins") && stage != 0
104105
{
105106
cmd.arg("-C").arg("panic=abort");
106107
}
@@ -127,11 +128,19 @@ fn main() {
127128
cmd.arg("--remap-path-prefix").arg(&map);
128129
}
129130

131+
let use_polly = match env::var("RUSTC_USE_POLLY") {
132+
Ok(v) => v != "0",
133+
Err(_) => false,
134+
};
135+
if use_polly && stage >= 1 {
136+
cmd.arg("-Z").arg("polly");
137+
}
138+
130139
// Force all crates compiled by this compiler to (a) be unstable and (b)
131140
// allow the `rustc_private` feature to link to other unstable crates
132141
// also in the sysroot. We also do this for host crates, since those
133142
// may be proc macros, in which case we might ship them.
134-
if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() && (stage != "0" || target.is_some()) {
143+
if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() && (stage != 0 || target.is_some()) {
135144
cmd.arg("-Z").arg("force-unstable-if-unmarked");
136145
}
137146

src/bootstrap/builder.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,18 @@ impl<'a> Builder<'a> {
13231323
cargo.env("WINAPI_NO_BUNDLED_LIBRARIES", "1");
13241324
}
13251325

1326+
let use_polly = match cmd {
1327+
"test" | "bench" => {
1328+
self.config.rust_polly_tests
1329+
},
1330+
_ => self.config.rust_polly_self
1331+
};
1332+
if use_polly && stage > 1 {
1333+
cargo.env("RUSTC_USE_POLLY", "1");
1334+
} else {
1335+
cargo.env("RUSTC_USE_POLLY", "0");
1336+
}
1337+
13261338
for _ in 1..self.verbosity {
13271339
cargo.arg("-v");
13281340
}

src/bootstrap/config.rs

+16
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,14 @@ pub struct Config {
107107
pub rustc_parallel: bool,
108108
pub rustc_default_linker: Option<String>,
109109
pub rust_optimize_tests: bool,
110+
pub rust_polly_tests: bool,
110111
pub rust_dist_src: bool,
111112
pub rust_codegen_backends: Vec<Interned<String>>,
112113
pub rust_verify_llvm_ir: bool,
113114
pub rust_thin_lto_import_instr_limit: Option<u32>,
114115
pub rust_remap_debuginfo: bool,
115116
pub rust_new_symbol_mangling: bool,
117+
pub rust_polly_self: bool,
116118

117119
pub build: TargetSelection,
118120
pub hosts: Vec<TargetSelection>,
@@ -394,6 +396,7 @@ struct Rust {
394396
rpath: Option<bool>,
395397
verbose_tests: Option<bool>,
396398
optimize_tests: Option<bool>,
399+
polly_tests: Option<bool>,
397400
codegen_tests: Option<bool>,
398401
ignore_git: Option<bool>,
399402
dist_src: Option<bool>,
@@ -412,6 +415,7 @@ struct Rust {
412415
llvm_libunwind: Option<bool>,
413416
control_flow_guard: Option<bool>,
414417
new_symbol_mangling: Option<bool>,
418+
polly_self: Option<bool>,
415419
}
416420

417421
/// TOML representation of how each build target is configured.
@@ -641,6 +645,10 @@ impl Config {
641645
ignore_git = rust.ignore_git;
642646
set(&mut config.rust_new_symbol_mangling, rust.new_symbol_mangling);
643647
set(&mut config.rust_optimize_tests, rust.optimize_tests);
648+
set(&mut config.rust_polly_tests, rust.polly_tests);
649+
if !config.rust_optimize_tests {
650+
config.rust_polly_tests = false;
651+
}
644652
set(&mut config.codegen_tests, rust.codegen_tests);
645653
set(&mut config.rust_rpath, rust.rpath);
646654
set(&mut config.jemalloc, rust.jemalloc);
@@ -675,6 +683,10 @@ impl Config {
675683

676684
config.rust_codegen_units = rust.codegen_units.map(threads_from_config);
677685
config.rust_codegen_units_std = rust.codegen_units_std.map(threads_from_config);
686+
687+
config.rust_polly_self = rust
688+
.polly_self
689+
.unwrap_or(false);
678690
}
679691

680692
if let Some(ref t) = toml.target {
@@ -747,6 +759,10 @@ impl Config {
747759
config.rust_debuginfo_level_tools = with_defaults(debuginfo_level_tools);
748760
config.rust_debuginfo_level_tests = debuginfo_level_tests.unwrap_or(0);
749761

762+
if !config.rust_optimize {
763+
config.rust_polly_self = false;
764+
}
765+
750766
let default = config.channel == "dev";
751767
config.ignore_git = ignore_git.unwrap_or(default);
752768

src/bootstrap/native.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ impl Step for Llvm {
169169
.define("LLVM_INCLUDE_TESTS", "OFF")
170170
.define("LLVM_INCLUDE_DOCS", "OFF")
171171
.define("LLVM_INCLUDE_BENCHMARKS", "OFF")
172-
.define("WITH_POLLY", "OFF")
173172
.define("LLVM_ENABLE_TERMINFO", "OFF")
174173
.define("LLVM_ENABLE_LIBEDIT", "OFF")
175174
.define("LLVM_ENABLE_BINDINGS", "OFF")
@@ -178,6 +177,11 @@ impl Step for Llvm {
178177
.define("LLVM_TARGET_ARCH", target_native.split('-').next().unwrap())
179178
.define("LLVM_DEFAULT_TARGET_TRIPLE", target_native);
180179

180+
if !self.emscripten {
181+
let polly_src = builder.src.join("src/polly");
182+
cfg.define("LLVM_EXTERNAL_POLLY_SOURCE_DIR", polly_src);
183+
}
184+
181185
if !target.contains("netbsd") && target != "aarch64-apple-darwin" {
182186
cfg.define("LLVM_ENABLE_ZLIB", "ON");
183187
} else {

src/bootstrap/test.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,9 @@ impl Step for Compiletest {
10601060
flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
10611061
flags.push("-Zunstable-options".to_string());
10621062
flags.push(builder.config.cmd.rustc_args().join(" "));
1063+
if builder.config.rust_polly_self {
1064+
flags.push("-Zpolly".into());
1065+
}
10631066

10641067
// Don't use LLD here since we want to test that rustc finds and uses a linker by itself.
10651068
if let Some(linker) = builder.linker(target, false) {

src/librustc_codegen_llvm/back/lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ pub(crate) fn run_pass_manager(
659659
}
660660

661661
let pm = llvm::LLVMCreatePassManager();
662-
llvm::LLVMAddAnalysisPasses(module.module_llvm.tm, pm);
662+
llvm::LLVMAddAnalysisPasses(module.module_llvm.tm, pm, config.polly);
663663

664664
if config.verify_llvm_ir {
665665
let pass = llvm::LLVMRustFindAndCreatePass("verify\0".as_ptr().cast());

0 commit comments

Comments
 (0)