Skip to content

Commit aceadf0

Browse files
Add llvm-ir profiler
1 parent 77e110d commit aceadf0

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
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/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)