clang 23.0.0git
AnalysisDriver.h
Go to the documentation of this file.
1//===- AnalysisDriver.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// Central orchestrator for whole-program analysis. Takes ownership of an
10// LUSummary, drives all registered analyses in topological dependency order,
11// and returns a WPASuite.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_CORE_WHOLEPROGRAMANALYSIS_ANALYSISDRIVER_H
16#define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_CORE_WHOLEPROGRAMANALYSIS_ANALYSISDRIVER_H
17
20#include "llvm/ADT/ArrayRef.h"
21#include "llvm/Support/Error.h"
22#include <memory>
23#include <vector>
24
25namespace clang::ssaf {
26
27class AnalysisBase;
30
31/// Orchestrates whole-program analysis over an LUSummary.
32///
33/// Three run() patterns are supported:
34/// - run() && -- all registered analyses in topological dependency
35/// order. Returns an error if any registered analysis
36/// has no matching entity data in the LUSummary.
37/// Requires an rvalue driver because this exhausts the
38/// LUSummary.
39/// - run(names) -- named subset plus transitive dependencies; returns
40/// Expected and fails if any listed name has no
41/// registered analysis or missing entity data.
42/// - run<ResultTs..> -- type-safe variant of run(names).
43class AnalysisDriver final {
44public:
45 explicit AnalysisDriver(std::unique_ptr<LUSummary> LU);
46
47 /// Runs all registered analyses in topological dependency order.
48 /// Returns an error if any registered analysis has no matching entity data
49 /// in the LUSummary.
50 ///
51 /// Requires an rvalue driver (std::move(Driver).run()) because this
52 /// exhausts all remaining LUSummary data.
53 [[nodiscard]] llvm::Expected<WPASuite> run() &&;
54
55 /// Runs only the named analyses (plus their transitive dependencies).
56 ///
57 /// Returns an error if any listed AnalysisName has no registered analysis
58 /// or if a required SummaryAnalysis has no matching entity data in the
59 /// LUSummary. The EntityIdTable is copied (not moved) so the driver remains
60 /// usable for subsequent calls.
61 [[nodiscard]] llvm::Expected<WPASuite>
63
64 /// Type-safe variant of run(names). Derives names from
65 /// ResultTs::analysisName().
66 template <typename... ResultTs>
67 [[nodiscard]] llvm::Expected<WPASuite> run() const {
68 return run({ResultTs::analysisName()...});
69 }
70
71private:
72 std::unique_ptr<LUSummary> LU;
73
74 /// Instantiates all analyses reachable from \p Roots (plus transitive
75 /// dependencies) and returns them in topological order via a single DFS.
76 /// Reports an error on unregistered names or cycles.
78 toposort(llvm::ArrayRef<AnalysisName> Roots);
79
80 /// Executes a topologically-sorted analysis list and returns a WPASuite.
81 /// \p IdTable is moved into the returned WPASuite.
83 execute(EntityIdTable IdTable,
84 llvm::ArrayRef<std::unique_ptr<AnalysisBase>> Sorted) const;
85
86 llvm::Error executeSummaryAnalysis(SummaryAnalysisBase &Summary,
87 WPASuite &Suite) const;
88
89 llvm::Error executeDerivedAnalysis(DerivedAnalysisBase &Derived,
90 WPASuite &Suite) const;
91};
92
93} // namespace clang::ssaf
94
95#endif // LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_CORE_WHOLEPROGRAMANALYSIS_ANALYSISDRIVER_H
Minimal common base for both analysis kinds.
llvm::Expected< WPASuite > run() const
Type-safe variant of run(names).
AnalysisDriver(std::unique_ptr< LUSummary > LU)
Type-erased base for derived analyses.
Manages entity name interning and provides efficient EntityId handles.
Type-erased base for summary analyses.
Bundles the EntityIdTable (moved from the LUSummary) and the analysis results produced by one Analysi...
Definition WPASuite.h:35