Skip to content

LLVM IR emission option #1137

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

Merged
merged 2 commits into from
Jan 7, 2022
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
11 changes: 11 additions & 0 deletions collector/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ pub enum Profiler {
LlvmLines,
MonoItems,
DepGraph,
LlvmIr,
}

impl Profiler {
Expand All @@ -203,6 +204,7 @@ impl Profiler {
"llvm-lines" => Ok(Profiler::LlvmLines),
"mono-items" => Ok(Profiler::MonoItems),
"dep-graph" => Ok(Profiler::DepGraph),
"llvm-ir" => Ok(Profiler::LlvmIr),
_ => Err(anyhow!("'{}' is not a known profiler", name)),
}
}
Expand All @@ -225,6 +227,7 @@ impl Profiler {
Profiler::LlvmLines => "llvm-lines",
Profiler::MonoItems => "mono-items",
Profiler::DepGraph => "dep-graph",
Profiler::LlvmIr => "llvm-ir",
}
}

Expand All @@ -246,6 +249,7 @@ impl Profiler {
| Profiler::Massif
| Profiler::DepGraph
| Profiler::MonoItems
| Profiler::LlvmIr
| Profiler::Eprintln => {
if profile_kind == ProfileKind::Doc {
Some("rustdoc")
Expand Down Expand Up @@ -275,6 +279,7 @@ impl Profiler {
| Profiler::DHAT
| Profiler::Massif
| Profiler::MonoItems
| Profiler::LlvmIr
| Profiler::Eprintln => true,
// only incremental
Profiler::DepGraph => scenario_kind != ScenarioKind::Full,
Expand Down Expand Up @@ -1206,6 +1211,12 @@ impl<'a> Processor for ProfileProcessor<'a> {
fs::copy(&tmp_file, &output)?;
}

Profiler::LlvmIr => {
let tmp_file = filepath(data.cwd.as_ref(), "llvm-ir");
let output = filepath(self.output_dir, &out_file("llir"));
fs::copy(&tmp_file, &output)?;
}

// `cargo llvm-lines` writes its output to stdout. We copy that
// output into a file in the output dir.
Profiler::LlvmLines => {
Expand Down
11 changes: 10 additions & 1 deletion collector/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1062,8 +1062,17 @@ fn main_result() -> anyhow::Result<i32> {
let rustdoc = sub_m.value_of("RUSTDOC");
check_installed("valgrind")?;
check_installed("cg_annotate")?;
check_installed("rustup-toolchain-install-master")?;
check_installed("rustfilt")?;
// Avoid just straight running rustup-toolchain-install-master which
// will install the current master commit (fetching quite a bit of
// data, including hitting GitHub)...
if Command::new("rustup-toolchain-install-master")
.arg("-V")
.output()
.is_err()
{
anyhow::bail!("rustup-toolchain-install-master is not installed but must be");
}

let id1 = rustc1.strip_prefix('+').unwrap_or("before");
let id2 = rustc2.strip_prefix('+').unwrap_or("after");
Expand Down
10 changes: 10 additions & 0 deletions collector/src/rustc-fake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,16 @@ fn main() {
assert!(cmd.status().expect("failed to spawn").success());
}

"llvm-ir" => {
args.push("--emit=llvm-ir=./llvm-ir".into());
args.push("-Cno-prepopulate-passes".into());
args.push("-Cpasses=name-anon-globals".into());
let mut cmd = Command::new(tool);
cmd.args(args);
determinism_env(&mut cmd);
assert!(cmd.status().expect("failed to spawn").success());
}

"mono-items" => {
// Lazy item collection is the default (i.e., without this
// option)
Expand Down