Skip to content

Commit fe17ed5

Browse files
author
Alexander Zaitsev
committed
feat: add tests for debuginfo-for-profiling
- the test was ported from this commit: llvm/llvm-project@3009211
1 parent bcf9001 commit fe17ed5

2 files changed

Lines changed: 101 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Verify that additional discriminators are emitted for profiling with `-Zdebuginfo-for-profiling`:
2+
// - 0 discriminators are emitted without the flag in the test below
3+
// - at least 1 discriminator is emitted with the flag in the test below.
4+
// Actual count depends on the target
5+
//
6+
//
7+
//@ add-minicore
8+
//@ revisions: DEFAULT-X86 DEFAULT-AARCH64 DEBUGINFO-X86 DEBUGINFO-AARCH64
9+
//@ assembly-output: emit-asm
10+
//@ compile-flags: -Copt-level=2 -Cdebuginfo=line-tables-only
11+
//@ [DEFAULT-X86] compile-flags: --target=x86_64-unknown-linux-gnu
12+
//@ [DEFAULT-X86] needs-llvm-components: x86
13+
//@ [DEFAULT-AARCH64] compile-flags: --target=aarch64-unknown-linux-gnu
14+
//@ [DEFAULT-AARCH64] needs-llvm-components: aarch64
15+
//@ [DEBUGINFO-X86] compile-flags: -Zdebuginfo-for-profiling --target=x86_64-unknown-linux-gnu
16+
//@ [DEBUGINFO-X86] needs-llvm-components: x86
17+
//@ [DEBUGINFO-AARCH64] compile-flags: -Zdebuginfo-for-profiling --target=aarch64-unknown-linux-gnu
18+
//@ [DEBUGINFO-AARCH64] needs-llvm-components: aarch64
19+
// DEFAULT-X86-NOT: discriminator
20+
// DEFAULT-AARCH64-NOT: discriminator
21+
// DEBUGINFO-X86-COUNT-1: discriminator
22+
// DEBUGINFO-AARCH64-COUNT-1: discriminator
23+
24+
#![feature(no_core)]
25+
#![no_std]
26+
#![no_core]
27+
#![crate_type = "lib"]
28+
29+
extern crate minicore;
30+
use minicore::*;
31+
32+
extern "C" {
33+
fn add(_x: i32, _y: i32) -> i32;
34+
fn mul(_x: i32, _y: i32) -> i32;
35+
fn compute(_x: i32) -> i32;
36+
fn cond() -> bool;
37+
}
38+
39+
#[no_mangle]
40+
pub fn f(limit: i32) -> i32 {
41+
unsafe {
42+
let mut sum = 0;
43+
let mut i = 1;
44+
45+
while cond() {
46+
if cond() {
47+
sum = add(sum, compute(i));
48+
} else {
49+
sum = add(sum, mul(compute(i), 2));
50+
}
51+
i = add(i, 1);
52+
}
53+
54+
sum
55+
}
56+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Verify that additional discriminators are emitted for profiling with `-Zdebuginfo-for-profiling`:
2+
// - 0 discriminators are emitted without the flag in the test below
3+
// - at least 1 discriminator is emitted with the flag in the test below
4+
//
5+
//
6+
//@ add-minicore
7+
//@ revisions: DEFAULT DEBUGINFO
8+
//@ compile-flags: -Copt-level=2 -Cdebuginfo=line-tables-only
9+
//@ [DEBUGINFO] compile-flags: -Zdebuginfo-for-profiling
10+
// DEFAULT-NOT: discriminator
11+
// DEBUGINFO-COUNT-1: discriminator
12+
13+
#![feature(no_core)]
14+
#![no_std]
15+
#![no_core]
16+
#![crate_type = "lib"]
17+
18+
extern crate minicore;
19+
use minicore::*;
20+
21+
extern "C" {
22+
fn add(_x: i32, _y: i32) -> i32;
23+
fn mul(_x: i32, _y: i32) -> i32;
24+
fn compute(_x: i32) -> i32;
25+
fn cond() -> bool;
26+
}
27+
28+
#[no_mangle]
29+
pub fn f(limit: i32) -> i32 {
30+
unsafe {
31+
let mut sum = 0;
32+
let mut i = 1;
33+
34+
while cond() {
35+
if cond() {
36+
sum = add(sum, compute(i));
37+
} else {
38+
sum = add(sum, mul(compute(i), 2));
39+
}
40+
i = add(i, 1);
41+
}
42+
43+
sum
44+
}
45+
}

0 commit comments

Comments
 (0)