1 | //===- MCDCTypes.h - Types related to MC/DC Coverage ------------*- C++ -*-===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // Types related to MC/DC Coverage. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #ifndef LLVM_PROFILEDATA_COVERAGE_MCDCTYPES_H |
14 | #define LLVM_PROFILEDATA_COVERAGE_MCDCTYPES_H |
15 | |
16 | #include <array> |
17 | #include <cassert> |
18 | #include <type_traits> |
19 | #include <variant> |
20 | |
21 | namespace llvm::coverage::mcdc { |
22 | |
23 | /// The ID for MCDCBranch. |
24 | using ConditionID = int16_t; |
25 | using ConditionIDs = std::array<ConditionID, 2>; |
26 | |
27 | struct DecisionParameters { |
28 | /// Byte Index of Bitmap Coverage Object for a Decision Region. |
29 | unsigned BitmapIdx; |
30 | |
31 | /// Number of Conditions used for a Decision Region. |
32 | uint16_t NumConditions; |
33 | |
34 | DecisionParameters() = delete; |
35 | DecisionParameters(unsigned BitmapIdx, unsigned NumConditions) |
36 | : BitmapIdx(BitmapIdx), NumConditions(NumConditions) {} |
37 | }; |
38 | |
39 | struct BranchParameters { |
40 | /// IDs used to represent a branch region and other branch regions |
41 | /// evaluated based on True and False branches. |
42 | ConditionID ID; |
43 | ConditionIDs Conds; |
44 | |
45 | BranchParameters() = delete; |
46 | BranchParameters(ConditionID ID, const ConditionIDs &Conds) |
47 | : ID(ID), Conds(Conds) {} |
48 | }; |
49 | |
50 | /// The type of MC/DC-specific parameters. |
51 | using Parameters = |
52 | std::variant<std::monostate, DecisionParameters, BranchParameters>; |
53 | |
54 | /// Check and get underlying params in MCDCParams. |
55 | /// \tparam MaybeConstInnerParameters Type to get. May be const. |
56 | /// \tparam MaybeConstMCDCParameters Expected inferred. May be const. |
57 | /// \param MCDCParams May be const. |
58 | template <class MaybeConstInnerParameters, class MaybeConstMCDCParameters> |
59 | static auto &getParams(MaybeConstMCDCParameters &MCDCParams) { |
60 | using InnerParameters = |
61 | typename std::remove_const<MaybeConstInnerParameters>::type; |
62 | MaybeConstInnerParameters *Params = std::get_if<InnerParameters>(&MCDCParams); |
63 | assert(Params && "InnerParameters unavailable" ); |
64 | return *Params; |
65 | } |
66 | |
67 | } // namespace llvm::coverage::mcdc |
68 | |
69 | #endif // LLVM_PROFILEDATA_COVERAGE_MCDCTYPES_H |
70 | |