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