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_SCALABLESTATICANALYSIS_CORE_ENTITYLINKER_ENTITYLINKER_H
15#define LLVM_CLANG_SCALABLESTATICANALYSIS_CORE_ENTITYLINKER_ENTITYLINKER_H
16
18#include "llvm/Support/Error.h"
19#include "llvm/TargetParser/Triple.h"
20#include <map>
21#include <memory>
22#include <set>
23#include <vector>
24
25namespace clang::ssaf {
26
28
30 LUSummaryEncoding Output;
31 std::set<BuildNamespace> ProcessedTUNamespaces;
32
33public:
34 /// Constructs an EntityLinker to link TU summaries into a LU summary.
35 ///
36 /// \param TargetTriple The target triple of the link unit. Every linked TU
37 /// must report the same triple.
38 /// \param LUNamespace The namespace identifying this link unit.
39 EntityLinker(llvm::Triple TargetTriple, NestedBuildNamespace LUNamespace)
40 : Output(std::move(TargetTriple), std::move(LUNamespace)) {}
41
42 /// Links a TU summary into a LU summary.
43 ///
44 /// Deduplicates entities, patches entity ID references in the entity summary,
45 /// and merges them into a single data store.
46 ///
47 /// \param Summary The TU summary to link. Ownership is transferred.
48 /// \returns Error if the TU namespace has already been linked or if patching
49 /// fails, success otherwise. Corrupted summary data (missing linkage
50 /// information, duplicate entity IDs, etc.) triggers a fatal error.
51 llvm::Error link(std::unique_ptr<TUSummaryEncoding> Summary);
52
53 /// Returns the accumulated LU summary.
54 ///
55 /// \returns LU summary containing all the deduplicated and patched entity
56 /// summaries.
57 LUSummaryEncoding takeOutput() && { return std::move(Output); }
58
59private:
60 /// Resolves a TU entity name to an LU entity name and ID.
61 ///
62 /// \param OldName The entity name in the TU namespace.
63 /// \param Linkage The linkage determining namespace resolution strategy.
64 /// \returns The resolved LU EntityId.
65 EntityId resolveEntity(const EntityName &OldName,
67 const NestedBuildNamespace &TUNamespace);
68
69 /// Resolves each TU EntityId to its corresponding LU EntityId.
70 ///
71 /// \param Summary The TU summary whose entities are being resolved.
72 /// \returns A map from TU EntityIds to their corresponding LU EntityIds.
73 std::map<EntityId, EntityId> resolve(const TUSummaryEncoding &Summary);
74
75 /// Merges all summary data from a TU summary into the LU Summary.
76 ///
77 /// \param Summary The TU summary whose data is being merged.
78 /// \param EntityResolutionTable Map from TU EntityIds to LU EntityIds.
79 /// \returns Pointers to each EntitySummaryEncoding successfully merged.
80 std::vector<EntitySummaryEncoding *>
81 merge(TUSummaryEncoding &Summary,
82 const std::map<EntityId, EntityId> &EntityResolutionTable);
83
84 /// Patches EntityId references in merged summary data.
85 ///
86 /// \param PatchTargets Vector of summary encodings that need patching.
87 /// \param EntityResolutionTable Map from TU EntityIds to LU EntityIds.
88 /// \returns Error if patching any encoding fails, success otherwise.
89 llvm::Error patch(const std::vector<EntitySummaryEncoding *> &PatchTargets,
90 const std::map<EntityId, EntityId> &EntityResolutionTable);
91};
92
93} // namespace clang::ssaf
94
95#endif // LLVM_CLANG_SCALABLESTATICANALYSIS_CORE_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.
EntityLinker(llvm::Triple TargetTriple, NestedBuildNamespace LUNamespace)
Constructs an EntityLinker to link TU summaries into a LU summary.
llvm::Error link(std::unique_ptr< TUSummaryEncoding > Summary)
Links a TU summary into a LU summary.
LUSummaryEncoding takeOutput() &&
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