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

Add Polly Support #75615

Closed
wants to merge 2 commits into from
Closed
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
8 changes: 8 additions & 0 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@
# Flag indicating whether tests are compiled with optimizations (the -O flag).
#optimize-tests = true

# Flag indicating whether tests are optimized with Polly. If optimize-tests is false,
# polly-tests will be false regardless of its value here.
#polly-tests = false

# Flag indicating whether codegen tests will be run or not. If you get an error
# saying that the FileCheck executable is missing, you may want to disable this.
# Also see the target's llvm-filecheck option.
Expand Down Expand Up @@ -456,6 +460,10 @@
# instead of LLVM's default of 100.
#thin-lto-import-instr-limit = 100

# Use Polly on the rust compiler itself. If optimize is false, this will be
# false as well.
#polly-self = false

# Map debuginfo paths to `/rust/$sha/...`, generally only set for releases
#remap-debuginfo = false

Expand Down
13 changes: 11 additions & 2 deletions src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ fn main() {
("RUSTC_REAL", "RUSTC_LIBDIR")
};
let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set");
let stage = usize::from_str(stage.as_str()).expect("RUSTC_STAGE not a usize");
let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");
let on_fail = env::var_os("RUSTC_ON_FAIL").map(Command::new);

Expand Down Expand Up @@ -100,7 +101,7 @@ fn main() {
// workaround undefined references to `rust_eh_unwind_resume` generated
// otherwise, see issue https://github.com/rust-lang/rust/issues/43095.
if crate_name == Some("panic_abort")
|| crate_name == Some("compiler_builtins") && stage != "0"
|| crate_name == Some("compiler_builtins") && stage != 0
{
cmd.arg("-C").arg("panic=abort");
}
Expand All @@ -127,11 +128,19 @@ fn main() {
cmd.arg("--remap-path-prefix").arg(&map);
}

let use_polly = match env::var("RUSTC_USE_POLLY") {
Ok(v) => v != "0",
Err(_) => false,
};
if use_polly && stage >= 1 {
cmd.arg("-Z").arg("polly");
}

// Force all crates compiled by this compiler to (a) be unstable and (b)
// allow the `rustc_private` feature to link to other unstable crates
// also in the sysroot. We also do this for host crates, since those
// may be proc macros, in which case we might ship them.
if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() && (stage != "0" || target.is_some()) {
if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() && (stage != 0 || target.is_some()) {
cmd.arg("-Z").arg("force-unstable-if-unmarked");
}

Expand Down
12 changes: 12 additions & 0 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,18 @@ impl<'a> Builder<'a> {
cargo.env("WINAPI_NO_BUNDLED_LIBRARIES", "1");
}

let use_polly = match cmd {
"test" | "bench" => {
self.config.rust_polly_tests
},
_ => self.config.rust_polly_self
};
if use_polly && stage > 1 {
cargo.env("RUSTC_USE_POLLY", "1");
} else {
cargo.env("RUSTC_USE_POLLY", "0");
}

for _ in 1..self.verbosity {
cargo.arg("-v");
}
Expand Down
16 changes: 16 additions & 0 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ pub struct Config {
pub rustc_parallel: bool,
pub rustc_default_linker: Option<String>,
pub rust_optimize_tests: bool,
pub rust_polly_tests: bool,
pub rust_dist_src: bool,
pub rust_codegen_backends: Vec<Interned<String>>,
pub rust_verify_llvm_ir: bool,
pub rust_thin_lto_import_instr_limit: Option<u32>,
pub rust_remap_debuginfo: bool,
pub rust_new_symbol_mangling: bool,
pub rust_polly_self: bool,

pub build: TargetSelection,
pub hosts: Vec<TargetSelection>,
Expand Down Expand Up @@ -394,6 +396,7 @@ struct Rust {
rpath: Option<bool>,
verbose_tests: Option<bool>,
optimize_tests: Option<bool>,
polly_tests: Option<bool>,
codegen_tests: Option<bool>,
ignore_git: Option<bool>,
dist_src: Option<bool>,
Expand All @@ -412,6 +415,7 @@ struct Rust {
llvm_libunwind: Option<bool>,
control_flow_guard: Option<bool>,
new_symbol_mangling: Option<bool>,
polly_self: Option<bool>,
}

/// TOML representation of how each build target is configured.
Expand Down Expand Up @@ -641,6 +645,10 @@ impl Config {
ignore_git = rust.ignore_git;
set(&mut config.rust_new_symbol_mangling, rust.new_symbol_mangling);
set(&mut config.rust_optimize_tests, rust.optimize_tests);
set(&mut config.rust_polly_tests, rust.polly_tests);
if !config.rust_optimize_tests {
config.rust_polly_tests = false;
}
set(&mut config.codegen_tests, rust.codegen_tests);
set(&mut config.rust_rpath, rust.rpath);
set(&mut config.jemalloc, rust.jemalloc);
Expand Down Expand Up @@ -675,6 +683,10 @@ impl Config {

config.rust_codegen_units = rust.codegen_units.map(threads_from_config);
config.rust_codegen_units_std = rust.codegen_units_std.map(threads_from_config);

config.rust_polly_self = rust
.polly_self
.unwrap_or(false);
}

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

if !config.rust_optimize {
config.rust_polly_self = false;
}

let default = config.channel == "dev";
config.ignore_git = ignore_git.unwrap_or(default);

Expand Down
6 changes: 5 additions & 1 deletion src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ impl Step for Llvm {
.define("LLVM_INCLUDE_TESTS", "OFF")
.define("LLVM_INCLUDE_DOCS", "OFF")
.define("LLVM_INCLUDE_BENCHMARKS", "OFF")
.define("WITH_POLLY", "OFF")
.define("LLVM_ENABLE_TERMINFO", "OFF")
.define("LLVM_ENABLE_LIBEDIT", "OFF")
.define("LLVM_ENABLE_BINDINGS", "OFF")
Expand All @@ -178,6 +177,11 @@ impl Step for Llvm {
.define("LLVM_TARGET_ARCH", target_native.split('-').next().unwrap())
.define("LLVM_DEFAULT_TARGET_TRIPLE", target_native);

if !self.emscripten {
let polly_src = builder.src.join("src/polly");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Polly is included in LLVM checkout, why don't just use it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a minimal merge of the old patch into the current master. I already got rid of the Polly submodule, but I tried to not change the code to keep some separation between the updated base and the actual semantic changes that are needed to make this work.
It will use the LLVM submodule's Polly.

cfg.define("LLVM_EXTERNAL_POLLY_SOURCE_DIR", polly_src);
}

if !target.contains("netbsd") && target != "aarch64-apple-darwin" {
cfg.define("LLVM_ENABLE_ZLIB", "ON");
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,9 @@ impl Step for Compiletest {
flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
flags.push("-Zunstable-options".to_string());
flags.push(builder.config.cmd.rustc_args().join(" "));
if builder.config.rust_polly_self {
flags.push("-Zpolly".into());
}

// Don't use LLD here since we want to test that rustc finds and uses a linker by itself.
if let Some(linker) = builder.linker(target, false) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ pub(crate) fn run_pass_manager(
}

let pm = llvm::LLVMCreatePassManager();
llvm::LLVMAddAnalysisPasses(module.module_llvm.tm, pm);
llvm::LLVMAddAnalysisPasses(module.module_llvm.tm, pm, config.polly);

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