]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_codegen_ssa/src/coverageinfo/ffi.rs
New upstream version 1.50.0+dfsg1
[rustc.git] / compiler / rustc_codegen_ssa / src / coverageinfo / ffi.rs
CommitLineData
3dfed10e
XL
1use rustc_middle::mir::coverage::{CounterValueReference, MappedExpressionIndex};
2
fc512014 3/// Aligns with [llvm::coverage::Counter::CounterKind](https://github.com/rust-lang/llvm-project/blob/rustc/11.0-2020-10-12/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L206-L222)
3dfed10e
XL
4#[derive(Copy, Clone, Debug)]
5#[repr(C)]
29967ef6 6pub enum CounterKind {
3dfed10e
XL
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.
fc512014 20/// Aligns with [llvm::coverage::Counter](https://github.com/rust-lang/llvm-project/blob/rustc/11.0-2020-10-12/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L99-L100)
3dfed10e
XL
21/// Important: The Rust struct layout (order and types of fields) must match its C++ counterpart.
22#[derive(Copy, Clone, Debug)]
23#[repr(C)]
24pub struct Counter {
25 // Important: The layout (order and types of fields) must match its C++ counterpart.
29967ef6
XL
26 pub kind: CounterKind,
27 pub id: u32,
3dfed10e
XL
28}
29
30impl 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
fc512014 44/// Aligns with [llvm::coverage::CounterExpression::ExprKind](https://github.com/rust-lang/llvm-project/blob/rustc/11.0-2020-10-12/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L147)
3dfed10e
XL
45#[derive(Copy, Clone, Debug)]
46#[repr(C)]
47pub enum ExprKind {
48 Subtract = 0,
49 Add = 1,
50}
51
fc512014 52/// Aligns with [llvm::coverage::CounterExpression](https://github.com/rust-lang/llvm-project/blob/rustc/11.0-2020-10-12/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L148-L149)
3dfed10e
XL
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)]
57pub struct CounterExpression {
29967ef6
XL
58 pub kind: ExprKind,
59 pub lhs: Counter,
60 pub rhs: Counter,
3dfed10e
XL
61}
62
63impl CounterExpression {
64 pub fn new(lhs: Counter, kind: ExprKind, rhs: Counter) -> Self {
65 Self { kind, lhs, rhs }
66 }
67}