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; DecisionParametersDecisionParameters35 DecisionParameters(unsigned BitmapIdx, unsigned NumConditions) 36 : BitmapIdx(BitmapIdx), NumConditions(NumConditions) { 37 assert(NumConditions > 0); 38 } 39 }; 40 41 struct BranchParameters { 42 /// IDs used to represent a branch region and other branch regions 43 /// evaluated based on True and False branches. 44 ConditionID ID; 45 ConditionIDs Conds; 46 47 BranchParameters() = delete; BranchParametersBranchParameters48 BranchParameters(ConditionID ID, const ConditionIDs &Conds) 49 : ID(ID), Conds(Conds) { 50 assert(ID >= 0); 51 } 52 }; 53 54 /// The type of MC/DC-specific parameters. 55 using Parameters = 56 std::variant<std::monostate, DecisionParameters, BranchParameters>; 57 58 /// Check and get underlying params in MCDCParams. 59 /// \tparam MaybeConstInnerParameters Type to get. May be const. 60 /// \tparam MaybeConstMCDCParameters Expected inferred. May be const. 61 /// \param MCDCParams May be const. 62 template <class MaybeConstInnerParameters, class MaybeConstMCDCParameters> getParams(MaybeConstMCDCParameters & MCDCParams)63static auto &getParams(MaybeConstMCDCParameters &MCDCParams) { 64 using InnerParameters = 65 typename std::remove_const<MaybeConstInnerParameters>::type; 66 MaybeConstInnerParameters *Params = std::get_if<InnerParameters>(&MCDCParams); 67 assert(Params && "InnerParameters unavailable"); 68 return *Params; 69 } 70 71 } // namespace llvm::coverage::mcdc 72 73 #endif // LLVM_PROFILEDATA_COVERAGE_MCDCTYPES_H 74