Skip to content

Commit

Permalink
Merge pull request #1137 from Mark-Simulacrum/llvm-ir
Browse files Browse the repository at this point in the history
LLVM IR emission option
  • Loading branch information
Mark-Simulacrum authored Jan 7, 2022
2 parents 2600686 + aceadf0 commit 7940e85
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
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 @@ -1082,8 +1082,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

0 comments on commit 7940e85

Please sign in to comment.