clang 23.0.0git
LUSummaryConsumer.h
Go to the documentation of this file.
1//===- LUSummaryConsumer.h --------------------------------------*- 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// LUSummaryConsumer constructs SummaryData objects by routing LUSummary entity
10// data to the corresponding SummaryDataBuilder objects.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_CORE_SUMMARYDATA_LUSUMMARYCONSUMER_H
15#define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_CORE_SUMMARYDATA_LUSUMMARYCONSUMER_H
16
20#include "llvm/ADT/ArrayRef.h"
21#include "llvm/Support/Error.h"
22#include <memory>
23#include <utility>
24
25namespace clang::ssaf {
26
27/// Consumes a LUSummary by dispatching its entity data to registered
28/// SummaryDataBuilders and returning the results in a SummaryDataStore.
29///
30/// Three consumption patterns are supported:
31/// - \c run() && — processes every analysis present in the
32/// LUSummary, silently skipping any whose data is
33/// absent or whose builder is not registered.
34/// Cannot fail, so it returns \c SummaryDataStore
35/// directly. Requires an rvalue consumer because
36/// this pattern exhausts all remaining data.
37/// - \c run(names) — processes a named subset; returns
38/// \c llvm::Expected<SummaryDataStore> and fails if
39/// any requested name has no data in the LUSummary
40/// or no registered builder.
41/// - \c run<DataTs...>() — type-safe variant of \c run(names) with the
42/// same error semantics and return type.
43///
44/// All patterns consume the underlying LUSummary data, so each analysis can
45/// only be retrieved once across all run() calls.
46class LUSummaryConsumer final {
47public:
48 explicit LUSummaryConsumer(std::unique_ptr<LUSummary> LU)
49 : LU(std::move(LU)) {}
50
51 /// Processes all registered analyses in LUSummary and returns the results.
52 /// Silently skips analyses with no data or no registered builder.
53 ///
54 /// Requires an rvalue consumer (call as \c std::move(Consumer).run()) because
55 /// this pattern exhausts all remaining LUSummary data.
56 [[nodiscard]] SummaryDataStore run() &&;
57
58 /// Processes the named analyses and returns the results.
59 ///
60 /// Returns an error if any name has no data in the LUSummary or no
61 /// registered builder.
64
65 /// Processes analyses for each of the given types and returns the results.
66 ///
67 /// Returns an error if any type has no data in the LUSummary or no
68 /// registered builder.
69 template <typename... DataTs>
71 return run({DataTs::summaryName()...});
72 }
73
74private:
75 std::unique_ptr<LUSummary> LU;
76
77 /// Iterator into LUSummary::Data — the map from SummaryName to entity data.
78 using LUDataIterator = decltype(std::declval<LUSummary &>().Data)::iterator;
79
80 /// Core build implementation. Instantiates the registered builder for the
81 /// analysis at \p It, delivers all entities, finalizes, and returns the
82 /// built data. Returns an error if no builder is registered. Erases the
83 /// LUSummary entry on success.
84 llvm::Expected<std::unique_ptr<SummaryData>> build(LUDataIterator It);
85
86 /// Looks up \p SN in the LUSummary and delegates to the iterator overload.
87 /// Returns an error if no data for \p SN exists or no builder is registered.
89};
90
91} // namespace clang::ssaf
92
93#endif // LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_CORE_SUMMARYDATA_LUSUMMARYCONSUMER_H
LUSummaryConsumer(std::unique_ptr< LUSummary > LU)
llvm::Expected< SummaryDataStore > run()
Processes analyses for each of the given types and returns the results.
Owns a collection of SummaryData objects keyed by SummaryName.
Uniquely identifies an analysis summary.
Definition SummaryName.h:22