[llvm] Introduce CovMap in ObjectYAML (PR #127432)
Jessica Paquette via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 16 20:46:34 PST 2025
================
@@ -0,0 +1,385 @@
+//===- CovMap.h - ObjectYAML Interface for coverage map ---------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// - llvm::coverage::yaml
+//
+// Describes binary file formats and YAML structures of coverage map.
+//
+// - llvm::yaml
+//
+// Attachments for YAMLTraits.
+//
+// - llvm::covmap
+//
+// Provides YAML encoder and decoder for coverage map.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_OBJECTYAML_COVMAP_H
+#define LLVM_OBJECTYAML_COVMAP_H
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ObjectYAML/ELFYAML.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/YAMLTraits.h"
+#include <cstdint>
+#include <memory>
+#include <optional>
+#include <variant>
+
+namespace llvm {
+class InstrProfSymtab;
+class raw_ostream;
+} // namespace llvm
+
+namespace llvm::coverage::yaml {
+
+/// This works like vector container but can be replaced with
+/// MutableArrayRef. See also SequenceTraits<VectorOrRef>.
+template <typename T, typename Vec = std::vector<T>> class VectorOrRef {
+ using Ref = MutableArrayRef<T>;
+
+ /// Holds vector type initially.
+ std::variant<Vec, Ref> Array;
+
+public:
+ // FIXME: Iterator impl is minimal easy.
+ using iterator = T *;
+
+ iterator begin() {
+ if (auto *V = std::get_if<Vec>(&Array))
+ return &V->front();
+ else
+ return &std::get<Ref>(Array).front();
+ }
+
+ iterator end() {
+ if (auto *V = std::get_if<Vec>(&Array))
+ return &V->back() + 1;
+ else
+ return &std::get<Ref>(Array).back() + 1;
+ }
+
+ size_t size() const {
+ if (const auto *V = std::get_if<Vec>(&Array))
+ return V->size();
+ else
+ return std::get<Ref>(Array).size();
+ }
+
+ T &operator[](int Idx) {
+ if (auto *V = std::get_if<Vec>(&Array))
+ return (*V)[Idx];
+ else
----------------
ornata wrote:
https://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return
prefer
```
if ()
return ...
return ...
```
https://github.com/llvm/llvm-project/pull/127432
More information about the llvm-commits
mailing list