1//===---- MCDCState.h - Per-Function MC/DC state ----------------*- 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// Per-Function MC/DC state for PGO
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_CODEGEN_MCDCSTATE_H
14#define LLVM_CLANG_LIB_CODEGEN_MCDCSTATE_H
15
16#include "Address.h"
17#include "llvm/ADT/DenseMap.h"
18#include "llvm/ADT/SmallVector.h"
19#include "llvm/ProfileData/Coverage/MCDCTypes.h"
20#include <cassert>
21#include <limits>
22
23namespace clang {
24class Stmt;
25} // namespace clang
26
27namespace clang::CodeGen::MCDC {
28
29using namespace llvm::coverage::mcdc;
30
31/// Per-Function MC/DC state
32struct State {
33 unsigned BitmapBits = 0;
34
35 struct Decision {
36 using IndicesTy = llvm::SmallVector<std::array<int, 2>>;
37 static constexpr auto InvalidID = std::numeric_limits<unsigned>::max();
38
39 unsigned BitmapIdx;
40 IndicesTy Indices;
41 unsigned ID = InvalidID;
42 Address MCDCCondBitmapAddr = Address::invalid();
43
44 bool isValid() const { return ID != InvalidID; }
45
46 void update(unsigned I, IndicesTy &&X) {
47 assert(isValid());
48 BitmapIdx = I;
49 Indices = std::move(X);
50 }
51 };
52
53 llvm::DenseMap<const Stmt *, Decision> DecisionByStmt;
54
55 struct Branch {
56 ConditionID ID;
57 const Stmt *DecisionStmt;
58 };
59
60 llvm::DenseMap<const Stmt *, Branch> BranchByStmt;
61};
62
63} // namespace clang::CodeGen::MCDC
64
65#endif // LLVM_CLANG_LIB_CODEGEN_MCDCSTATE_H
66