Skip to content

Commit 7940e85

Browse files
Merge pull request #1137 from Mark-Simulacrum/llvm-ir
LLVM IR emission option
2 parents 2600686 + aceadf0 commit 7940e85

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

collector/src/execute.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ pub enum Profiler {
181181
LlvmLines,
182182
MonoItems,
183183
DepGraph,
184+
LlvmIr,
184185
}
185186

186187
impl Profiler {
@@ -203,6 +204,7 @@ impl Profiler {
203204
"llvm-lines" => Ok(Profiler::LlvmLines),
204205
"mono-items" => Ok(Profiler::MonoItems),
205206
"dep-graph" => Ok(Profiler::DepGraph),
207+
"llvm-ir" => Ok(Profiler::LlvmIr),
206208
_ => Err(anyhow!("'{}' is not a known profiler", name)),
207209
}
208210
}
@@ -225,6 +227,7 @@ impl Profiler {
225227
Profiler::LlvmLines => "llvm-lines",
226228
Profiler::MonoItems => "mono-items",
227229
Profiler::DepGraph => "dep-graph",
230+
Profiler::LlvmIr => "llvm-ir",
228231
}
229232
}
230233

@@ -246,6 +249,7 @@ impl Profiler {
246249
| Profiler::Massif
247250
| Profiler::DepGraph
248251
| Profiler::MonoItems
252+
| Profiler::LlvmIr
249253
| Profiler::Eprintln => {
250254
if profile_kind == ProfileKind::Doc {
251255
Some("rustdoc")
@@ -275,6 +279,7 @@ impl Profiler {
275279
| Profiler::DHAT
276280
| Profiler::Massif
277281
| Profiler::MonoItems
282+
| Profiler::LlvmIr
278283
| Profiler::Eprintln => true,
279284
// only incremental
280285
Profiler::DepGraph => scenario_kind != ScenarioKind::Full,
@@ -1206,6 +1211,12 @@ impl<'a> Processor for ProfileProcessor<'a> {
12061211
fs::copy(&tmp_file, &output)?;
12071212
}
12081213

1214+
Profiler::LlvmIr => {
1215+
let tmp_file = filepath(data.cwd.as_ref(), "llvm-ir");
1216+
let output = filepath(self.output_dir, &out_file("llir"));
1217+
fs::copy(&tmp_file, &output)?;
1218+
}
1219+
12091220
// `cargo llvm-lines` writes its output to stdout. We copy that
12101221
// output into a file in the output dir.
12111222
Profiler::LlvmLines => {

collector/src/main.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,8 +1082,17 @@ fn main_result() -> anyhow::Result<i32> {
10821082
let rustdoc = sub_m.value_of("RUSTDOC");
10831083
check_installed("valgrind")?;
10841084
check_installed("cg_annotate")?;
1085-
check_installed("rustup-toolchain-install-master")?;
10861085
check_installed("rustfilt")?;
1086+
// Avoid just straight running rustup-toolchain-install-master which
1087+
// will install the current master commit (fetching quite a bit of
1088+
// data, including hitting GitHub)...
1089+
if Command::new("rustup-toolchain-install-master")
1090+
.arg("-V")
1091+
.output()
1092+
.is_err()
1093+
{
1094+
anyhow::bail!("rustup-toolchain-install-master is not installed but must be");
1095+
}
10871096

10881097
let id1 = rustc1.strip_prefix('+').unwrap_or("before");
10891098
let id2 = rustc2.strip_prefix('+').unwrap_or("after");

collector/src/rustc-fake.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,16 @@ fn main() {
323323
assert!(cmd.status().expect("failed to spawn").success());
324324
}
325325

326+
"llvm-ir" => {
327+
args.push("--emit=llvm-ir=./llvm-ir".into());
328+
args.push("-Cno-prepopulate-passes".into());
329+
args.push("-Cpasses=name-anon-globals".into());
330+
let mut cmd = Command::new(tool);
331+
cmd.args(args);
332+
determinism_env(&mut cmd);
333+
assert!(cmd.status().expect("failed to spawn").success());
334+
}
335+
326336
"mono-items" => {
327337
// Lazy item collection is the default (i.e., without this
328338
// option)

0 commit comments

Comments
 (0)