]> git.proxmox.com Git - rustc.git/blob - compiler/rustc_codegen_ssa/src/coverageinfo/ffi.rs
New upstream version 1.49.0~beta.4+dfsg1
[rustc.git] / compiler / rustc_codegen_ssa / src / coverageinfo / ffi.rs
1 use rustc_middle::mir::coverage::{CounterValueReference, MappedExpressionIndex};
2
3 /// Aligns with [llvm::coverage::Counter::CounterKind](https://github.com/rust-lang/llvm-project/blob/rustc/10.0-2020-05-05/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L91)
4 #[derive(Copy, Clone, Debug)]
5 #[repr(C)]
6 pub enum CounterKind {
7 Zero = 0,
8 CounterValueReference = 1,
9 Expression = 2,
10 }
11
12 /// A reference to an instance of an abstract "counter" that will yield a value in a coverage
13 /// report. Note that `id` has different interpretations, depending on the `kind`:
14 /// * For `CounterKind::Zero`, `id` is assumed to be `0`
15 /// * For `CounterKind::CounterValueReference`, `id` matches the `counter_id` of the injected
16 /// instrumentation counter (the `index` argument to the LLVM intrinsic
17 /// `instrprof.increment()`)
18 /// * For `CounterKind::Expression`, `id` is the index into the coverage map's array of
19 /// counter expressions.
20 /// Aligns with [llvm::coverage::Counter](https://github.com/rust-lang/llvm-project/blob/rustc/10.0-2020-05-05/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L98-L99)
21 /// Important: The Rust struct layout (order and types of fields) must match its C++ counterpart.
22 #[derive(Copy, Clone, Debug)]
23 #[repr(C)]
24 pub struct Counter {
25 // Important: The layout (order and types of fields) must match its C++ counterpart.
26 pub kind: CounterKind,
27 pub id: u32,
28 }
29
30 impl Counter {
31 pub fn zero() -> Self {
32 Self { kind: CounterKind::Zero, id: 0 }
33 }
34
35 pub fn counter_value_reference(counter_id: CounterValueReference) -> Self {
36 Self { kind: CounterKind::CounterValueReference, id: counter_id.into() }
37 }
38
39 pub fn expression(mapped_expression_index: MappedExpressionIndex) -> Self {
40 Self { kind: CounterKind::Expression, id: mapped_expression_index.into() }
41 }
42 }
43
44 /// Aligns with [llvm::coverage::CounterExpression::ExprKind](https://github.com/rust-lang/llvm-project/blob/rustc/10.0-2020-05-05/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L146)
45 #[derive(Copy, Clone, Debug)]
46 #[repr(C)]
47 pub enum ExprKind {
48 Subtract = 0,
49 Add = 1,
50 }
51
52 /// Aligns with [llvm::coverage::CounterExpression](https://github.com/rust-lang/llvm-project/blob/rustc/10.0-2020-05-05/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L147-L148)
53 /// Important: The Rust struct layout (order and types of fields) must match its C++
54 /// counterpart.
55 #[derive(Copy, Clone, Debug)]
56 #[repr(C)]
57 pub struct CounterExpression {
58 pub kind: ExprKind,
59 pub lhs: Counter,
60 pub rhs: Counter,
61 }
62
63 impl CounterExpression {
64 pub fn new(lhs: Counter, kind: ExprKind, rhs: Counter) -> Self {
65 Self { kind, lhs, rhs }
66 }
67 }