clang 23.0.0git
EntityLinker.h
Go to the documentation of this file.
1//===- EntityLinker.h - Class for linking entities --------------*- 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// This file defines the EntityLinker class that combines multiple TU summaries
10// into a unified LU summary by deduplicating entities and patching summaries.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_ANALYSIS_SCALABLE_ENTITYLINKER_ENTITYLINKER_H
15#define LLVM_CLANG_ANALYSIS_SCALABLE_ENTITYLINKER_ENTITYLINKER_H
16
18#include "llvm/Support/Error.h"
19#include <map>
20#include <memory>
21#include <set>
22#include <vector>
23
24namespace clang::ssaf {
25
27
29 LUSummaryEncoding Output;
30 std::set<BuildNamespace> ProcessedTUNamespaces;
31
32public:
33 /// Constructs an EntityLinker to link TU summaries into a LU summary.
34 ///
35 /// \param LUNamespace The namespace identifying this link unit.
36 explicit EntityLinker(NestedBuildNamespace LUNamespace)
37 : Output(std::move(LUNamespace)) {}
38
39 /// Links a TU summary into a LU summary.
40 ///
41 /// Deduplicates entities, patches entity ID references in the entity summary,
42 /// and merges them into a single data store.
43 ///
44 /// \param Summary The TU summary to link. Ownership is transferred.
45 /// \returns Error if the TU namespace has already been linked, success
46 /// otherwise. Corrupted summary data (missing linkage information,
47 /// duplicate entity IDs, etc.) triggers a fatal error.
48 llvm::Error link(std::unique_ptr<TUSummaryEncoding> Summary);
49
50 /// Returns the accumulated LU summary.
51 ///
52 /// \returns LU summary containing all the deduplicated and patched entity
53 /// summaries.
54 LUSummaryEncoding getOutput() && { return std::move(Output); }
55
56private:
57 /// Resolves a TU entity name to an LU entity name and ID.
58 ///
59 /// \param OldName The entity name in the TU namespace.
60 /// \param Linkage The linkage determining namespace resolution strategy.
61 /// \returns The resolved LU EntityId.
62 EntityId resolveEntity(const EntityName &OldName,
63 const EntityLinkage &Linkage);
64
65 /// Resolves each TU EntityId to its corresponding LU EntityId.
66 ///
67 /// \param Summary The TU summary whose entities are being resolved.
68 /// \returns A map from TU EntityIds to their corresponding LU EntityIds.
69 std::map<EntityId, EntityId> resolve(const TUSummaryEncoding &Summary);
70
71 /// Merges all summary data from a TU summary into the LU Summary.
72 ///
73 /// \param Summary The TU summary whose data is being merged.
74 /// \param EntityResolutionTable Map from TU EntityIds to LU EntityIds.
75 /// \returns Pointers to each EntitySummaryEncoding successfully merged.
76 std::vector<EntitySummaryEncoding *>
77 merge(TUSummaryEncoding &Summary,
78 const std::map<EntityId, EntityId> &EntityResolutionTable);
79
80 /// Patches EntityId references in merged summary data.
81 ///
82 /// \param PatchTargets Vector of summary encodings that need patching.
83 /// \param EntityResolutionTable Map from TU EntityIds to LU EntityIds.
84 void patch(const std::vector<EntitySummaryEncoding *> &PatchTargets,
85 const std::map<EntityId, EntityId> &EntityResolutionTable);
86};
87
88} // namespace clang::ssaf
89
90#endif // LLVM_CLANG_ANALYSIS_SCALABLE_ENTITYLINKER_ENTITYLINKER_H
Lightweight opaque handle representing an entity in an EntityIdTable.
Definition EntityId.h:31
Represents the linkage properties of an entity in the program model.
llvm::Error link(std::unique_ptr< TUSummaryEncoding > Summary)
Links a TU summary into a LU summary.
EntityLinker(NestedBuildNamespace LUNamespace)
Constructs an EntityLinker to link TU summaries into a LU summary.
LUSummaryEncoding getOutput() &&
Returns the accumulated LU summary.
Uniquely identifies an entity in a program.
Definition EntityName.h:28
Represents a link unit summary in its serialized encoding.
Represents a hierarchical sequence of build namespaces.
Represents a translation unit summary in its serialized encoding.
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
Definition Linkage.h:24