Skip to content

Commit d51fa91

Browse files
Add Polly support. Use can be triggered via -Z polly, when rustc uses an LLVM which includes polly.
Force LLVM rebuild on buildbots.
1 parent e7f5d48 commit d51fa91

File tree

17 files changed

+170
-15
lines changed

17 files changed

+170
-15
lines changed

.gitmodules

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,7 @@
6464
path = src/tools/clang
6565
url = https://github.com/rust-lang-nursery/clang.git
6666
branch = rust-release-80-v1
67-
67+
[submodule "src/polly"]
68+
path = src/polly
69+
url = https://github.com/llvm-mirror/polly.git
70+
branch = master

config.toml.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@
337337
#optimize-tests = true
338338
#debuginfo-tests = true
339339

340+
# Flag indicating whether tests are optimized with Polly. If optimize-tests is false,
341+
# polly-tests will be false regardless of its value here.
342+
#polly-tests = false
343+
340344
# Flag indicating whether codegen tests will be run or not. If you get an error
341345
# saying that the FileCheck executable is missing, you may want to disable this.
342346
# Also see the target's llvm-filecheck option.
@@ -395,6 +399,10 @@
395399
# Whether to verify generated LLVM IR
396400
#verify-llvm-ir = false
397401

402+
# Use Polly on the rust compiler itself. If optimize is false, this will be
403+
# false as well.
404+
#polly-self = false
405+
398406
# Map all debuginfo paths for libstd and crates to `/rust/$sha/$crate/...`,
399407
# generally only set for releases
400408
#remap-debuginfo = false

src/bootstrap/bin/rustc.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ fn main() {
9191
("RUSTC_REAL", "RUSTC_LIBDIR")
9292
};
9393
let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set");
94+
let stage = usize::from_str(stage.as_str()).expect("RUSTC_STAGE not a usize");
9495
let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");
9596
let on_fail = env::var_os("RUSTC_ON_FAIL").map(|of| Command::new(of));
9697

@@ -159,7 +160,7 @@ fn main() {
159160
// workaround undefined references to `rust_eh_unwind_resume` generated
160161
// otherwise, see issue https://github.com/rust-lang/rust/issues/43095.
161162
if crate_name == "panic_abort" ||
162-
crate_name == "compiler_builtins" && stage != "0" {
163+
crate_name == "compiler_builtins" && stage != 0 {
163164
cmd.arg("-C").arg("panic=abort");
164165
}
165166

@@ -287,6 +288,14 @@ fn main() {
287288
cmd.arg("--cfg").arg("parallel_queries");
288289
}
289290

291+
let use_polly = match env::var("RUSTC_USE_POLLY") {
292+
Ok(v) => v != "0",
293+
Err(_) => false,
294+
};
295+
if use_polly && stage >= 1 {
296+
cmd.arg("-Z").arg("polly");
297+
}
298+
290299
if env::var_os("RUSTC_DENY_WARNINGS").is_some() && env::var_os("RUSTC_EXTERNAL_TOOL").is_none()
291300
{
292301
cmd.arg("-Dwarnings");

src/bootstrap/builder.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,18 @@ impl<'a> Builder<'a> {
11161116
cargo.env("WINAPI_NO_BUNDLED_LIBRARIES", "1");
11171117
}
11181118

1119+
let use_polly = match cmd {
1120+
"test" | "bench" => {
1121+
self.config.rust_polly_tests
1122+
},
1123+
_ => self.config.rust_polly_self
1124+
};
1125+
if use_polly && stage > 1 {
1126+
cargo.env("RUSTC_USE_POLLY", "1");
1127+
} else {
1128+
cargo.env("RUSTC_USE_POLLY", "0");
1129+
}
1130+
11191131
for _ in 1..self.verbosity {
11201132
cargo.arg("-v");
11211133
}

src/bootstrap/config.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@ pub struct Config {
104104
pub rustc_parallel_queries: bool,
105105
pub rustc_default_linker: Option<String>,
106106
pub rust_optimize_tests: bool,
107+
pub rust_polly_tests: bool,
107108
pub rust_debuginfo_tests: bool,
108109
pub rust_dist_src: bool,
109110
pub rust_codegen_backends: Vec<Interned<String>>,
110111
pub rust_codegen_backends_dir: String,
111112
pub rust_verify_llvm_ir: bool,
112113
pub rust_remap_debuginfo: bool,
114+
pub rust_polly_self: bool,
113115

114116
pub build: Interned<String>,
115117
pub hosts: Vec<Interned<String>>,
@@ -309,6 +311,7 @@ struct Rust {
309311
rpath: Option<bool>,
310312
optimize_tests: Option<bool>,
311313
debuginfo_tests: Option<bool>,
314+
polly_tests: Option<bool>,
312315
codegen_tests: Option<bool>,
313316
ignore_git: Option<bool>,
314317
debug: Option<bool>,
@@ -327,6 +330,7 @@ struct Rust {
327330
backtrace_on_ice: Option<bool>,
328331
verify_llvm_ir: Option<bool>,
329332
remap_debuginfo: Option<bool>,
333+
polly_self: Option<bool>,
330334
}
331335

332336
/// TOML representation of how each build target is configured.
@@ -541,6 +545,10 @@ impl Config {
541545
ignore_git = rust.ignore_git;
542546
debug_jemalloc = rust.debug_jemalloc;
543547
set(&mut config.rust_optimize_tests, rust.optimize_tests);
548+
set(&mut config.rust_polly_tests, rust.polly_tests);
549+
if !config.rust_optimize_tests {
550+
config.rust_polly_tests = false;
551+
}
544552
set(&mut config.rust_debuginfo_tests, rust.debuginfo_tests);
545553
set(&mut config.codegen_tests, rust.codegen_tests);
546554
set(&mut config.rust_rpath, rust.rpath);
@@ -580,6 +588,10 @@ impl Config {
580588
Some(n) => config.rust_codegen_units = Some(n),
581589
None => {}
582590
}
591+
592+
config.rust_polly_self = rust
593+
.polly_self
594+
.unwrap_or(false);
583595
}
584596

585597
if let Some(ref t) = toml.target {
@@ -644,6 +656,10 @@ impl Config {
644656
config.rust_debuginfo = debuginfo.unwrap_or(default);
645657
config.rust_debug_assertions = debug_assertions.unwrap_or(default);
646658

659+
if !config.rust_optimize {
660+
config.rust_polly_self = false;
661+
}
662+
647663
let default = config.channel == "dev";
648664
config.ignore_git = ignore_git.unwrap_or(default);
649665

src/bootstrap/native.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,17 @@ impl Step for Llvm {
148148
.define("LLVM_INCLUDE_DOCS", "OFF")
149149
.define("LLVM_INCLUDE_BENCHMARKS", "OFF")
150150
.define("LLVM_ENABLE_ZLIB", "OFF")
151-
.define("WITH_POLLY", "OFF")
152151
.define("LLVM_ENABLE_TERMINFO", "OFF")
153152
.define("LLVM_ENABLE_LIBEDIT", "OFF")
154153
.define("LLVM_PARALLEL_COMPILE_JOBS", builder.jobs().to_string())
155154
.define("LLVM_TARGET_ARCH", target.split('-').next().unwrap())
156155
.define("LLVM_DEFAULT_TARGET_TRIPLE", target);
157156

157+
if !self.emscripten {
158+
let polly_src = builder.src.join("src/polly");
159+
cfg.define("LLVM_EXTERNAL_POLLY_SOURCE_DIR", polly_src);
160+
}
161+
158162
if builder.config.llvm_thin_lto && !emscripten {
159163
cfg.define("LLVM_ENABLE_LTO", "Thin")
160164
.define("LLVM_ENABLE_LLD", "ON");

src/bootstrap/test.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,9 @@ impl Step for Compiletest {
10451045
}
10461046
flags.push("-Zunstable-options".to_string());
10471047
flags.push(builder.config.cmd.rustc_args().join(" "));
1048+
if builder.config.rust_polly_self {
1049+
flags.push("-Zpolly".into());
1050+
}
10481051

10491052
if let Some(linker) = builder.linker(target) {
10501053
cmd.arg("--linker").arg(linker);

src/ci/docker/dist-i686-linux/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ RUN ./build-headers.sh
8686
COPY scripts/sccache.sh /scripts/
8787
RUN sh /scripts/sccache.sh
8888

89+
# Polly needs `PATH_MAX`
90+
ENV CFLAGS="-DPATH_MAX=4096 ${CFLAGS}"
91+
ENV CXXFLAGS="-DPATH_MAX=4096 ${CXXFLAGS}"
92+
8993
ENV HOSTS=i686-unknown-linux-gnu
9094

9195
ENV RUST_CONFIGURE_ARGS \

src/ci/docker/dist-x86_64-linux/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ RUN ./build-headers.sh
8686
COPY scripts/sccache.sh /scripts/
8787
RUN sh /scripts/sccache.sh
8888

89+
# Polly needs `PATH_MAX`
90+
ENV CFLAGS="-DPATH_MAX=4096 ${CFLAGS}"
91+
ENV CXXFLAGS="-DPATH_MAX=4096 ${CXXFLAGS}"
92+
8993
ENV HOSTS=x86_64-unknown-linux-gnu
9094

9195
ENV RUST_CONFIGURE_ARGS \

src/librustc/session/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
13821382
"run the self profiler"),
13831383
profile_json: bool = (false, parse_bool, [UNTRACKED],
13841384
"output a json file with profiler results"),
1385+
polly: bool = (false, parse_bool, [UNTRACKED], "Run the Polly polyhedral \
1386+
model optimization passes."),
13851387
emit_stack_sizes: bool = (false, parse_bool, [UNTRACKED],
13861388
"emits a section containing stack size metadata"),
13871389
plt: Option<bool> = (None, parse_opt_bool, [TRACKED],

0 commit comments

Comments
 (0)