Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:23

0001 //===- MCDCTypes.h - Types related to MC/DC Coverage ------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // Types related to MC/DC Coverage.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_PROFILEDATA_COVERAGE_MCDCTYPES_H
0014 #define LLVM_PROFILEDATA_COVERAGE_MCDCTYPES_H
0015 
0016 #include <array>
0017 #include <cassert>
0018 #include <type_traits>
0019 #include <variant>
0020 
0021 namespace llvm::coverage::mcdc {
0022 
0023 /// The ID for MCDCBranch.
0024 using ConditionID = int16_t;
0025 using ConditionIDs = std::array<ConditionID, 2>;
0026 
0027 struct DecisionParameters {
0028   /// Byte Index of Bitmap Coverage Object for a Decision Region.
0029   unsigned BitmapIdx;
0030 
0031   /// Number of Conditions used for a Decision Region.
0032   uint16_t NumConditions;
0033 
0034   DecisionParameters() = delete;
0035   DecisionParameters(unsigned BitmapIdx, unsigned NumConditions)
0036       : BitmapIdx(BitmapIdx), NumConditions(NumConditions) {
0037     assert(NumConditions > 0);
0038   }
0039 };
0040 
0041 struct BranchParameters {
0042   /// IDs used to represent a branch region and other branch regions
0043   /// evaluated based on True and False branches.
0044   ConditionID ID;
0045   ConditionIDs Conds;
0046 
0047   BranchParameters() = delete;
0048   BranchParameters(ConditionID ID, const ConditionIDs &Conds)
0049       : ID(ID), Conds(Conds) {
0050     assert(ID >= 0);
0051   }
0052 };
0053 
0054 /// The type of MC/DC-specific parameters.
0055 using Parameters =
0056     std::variant<std::monostate, DecisionParameters, BranchParameters>;
0057 
0058 /// Check and get underlying params in MCDCParams.
0059 /// \tparam MaybeConstInnerParameters Type to get. May be const.
0060 /// \tparam MaybeConstMCDCParameters Expected inferred. May be const.
0061 /// \param MCDCParams May be const.
0062 template <class MaybeConstInnerParameters, class MaybeConstMCDCParameters>
0063 static auto &getParams(MaybeConstMCDCParameters &MCDCParams) {
0064   using InnerParameters =
0065       typename std::remove_const<MaybeConstInnerParameters>::type;
0066   MaybeConstInnerParameters *Params = std::get_if<InnerParameters>(&MCDCParams);
0067   assert(Params && "InnerParameters unavailable");
0068   return *Params;
0069 }
0070 
0071 } // namespace llvm::coverage::mcdc
0072 
0073 #endif // LLVM_PROFILEDATA_COVERAGE_MCDCTYPES_H