clang 22.0.0git
Facts.cpp
Go to the documentation of this file.
1//===- Facts.cpp - Lifetime Analysis Facts Implementation -------*- 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
10#include "clang/AST/Decl.h"
12
14
15void Fact::dump(llvm::raw_ostream &OS, const LoanManager &,
16 const OriginManager &) const {
17 OS << "Fact (Kind: " << static_cast<int>(K) << ")\n";
18}
19
20void IssueFact::dump(llvm::raw_ostream &OS, const LoanManager &LM,
21 const OriginManager &OM) const {
22 OS << "Issue (";
23 LM.getLoan(getLoanID()).dump(OS);
24 OS << ", ToOrigin: ";
25 OM.dump(getOriginID(), OS);
26 OS << ")\n";
27}
28
29void ExpireFact::dump(llvm::raw_ostream &OS, const LoanManager &LM,
30 const OriginManager &) const {
31 OS << "Expire (";
32 LM.getLoan(getLoanID()).dump(OS);
33 OS << ")\n";
34}
35
36void OriginFlowFact::dump(llvm::raw_ostream &OS, const LoanManager &,
37 const OriginManager &OM) const {
38 OS << "OriginFlow (Dest: ";
39 OM.dump(getDestOriginID(), OS);
40 OS << ", Src: ";
41 OM.dump(getSrcOriginID(), OS);
42 OS << (getKillDest() ? "" : ", Merge");
43 OS << ")\n";
44}
45
46void ReturnOfOriginFact::dump(llvm::raw_ostream &OS, const LoanManager &,
47 const OriginManager &OM) const {
48 OS << "ReturnOfOrigin (";
49 OM.dump(getReturnedOriginID(), OS);
50 OS << ")\n";
51}
52
53void UseFact::dump(llvm::raw_ostream &OS, const LoanManager &,
54 const OriginManager &OM) const {
55 OS << "Use (";
56 OM.dump(getUsedOrigin(OM), OS);
57 OS << ", " << (isWritten() ? "Write" : "Read") << ")\n";
58}
59
60void TestPointFact::dump(llvm::raw_ostream &OS, const LoanManager &,
61 const OriginManager &) const {
62 OS << "TestPoint (Annotation: \"" << getAnnotation() << "\")\n";
63}
64
65llvm::StringMap<ProgramPoint> FactManager::getTestPoints() const {
66 llvm::StringMap<ProgramPoint> AnnotationToPointMap;
67 for (const CFGBlock *Block : BlockToFactsMap.keys()) {
68 for (const Fact *F : getFacts(Block)) {
69 if (const auto *TPF = F->getAs<TestPointFact>()) {
70 StringRef PointName = TPF->getAnnotation();
71 assert(AnnotationToPointMap.find(PointName) ==
72 AnnotationToPointMap.end() &&
73 "more than one test points with the same name");
74 AnnotationToPointMap[PointName] = F;
75 }
76 }
77 }
78 return AnnotationToPointMap;
79}
80
81void FactManager::dump(const CFG &Cfg, AnalysisDeclContext &AC) const {
82 llvm::dbgs() << "==========================================\n";
83 llvm::dbgs() << " Lifetime Analysis Facts:\n";
84 llvm::dbgs() << "==========================================\n";
85 if (const Decl *D = AC.getDecl())
86 if (const auto *ND = dyn_cast<NamedDecl>(D))
87 llvm::dbgs() << "Function: " << ND->getQualifiedNameAsString() << "\n";
88 // Print blocks in the order as they appear in code for a stable ordering.
89 for (const CFGBlock *B : *AC.getAnalysis<PostOrderCFGView>()) {
90 llvm::dbgs() << " Block B" << B->getBlockID() << ":\n";
91 auto It = BlockToFactsMap.find(B);
92 if (It != BlockToFactsMap.end()) {
93 for (const Fact *F : It->second) {
94 llvm::dbgs() << " ";
95 F->dump(llvm::dbgs(), LoanMgr, OriginMgr);
96 }
97 }
98 llvm::dbgs() << " End of Block\n";
99 }
100}
101
102} // namespace clang::lifetimes::internal
AnalysisDeclContext contains the context data for the function, method or block under analysis.
Represents a single basic block in a source-level CFG.
Definition CFG.h:605
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt.
Definition CFG.h:1222
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
void dump(llvm::raw_ostream &OS, const LoanManager &LM, const OriginManager &) const override
Definition Facts.cpp:29
llvm::ArrayRef< const Fact * > getFacts(const CFGBlock *B) const
Definition Facts.h:187
llvm::StringMap< ProgramPoint > getTestPoints() const
Retrieves program points that were specially marked in the source code for testing.
Definition Facts.cpp:65
void dump(const CFG &Cfg, AnalysisDeclContext &AC) const
Definition Facts.cpp:81
An abstract base class for a single, atomic lifetime-relevant event.
Definition Facts.h:27
virtual void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &) const
Definition Facts.cpp:15
void dump(llvm::raw_ostream &OS, const LoanManager &LM, const OriginManager &OM) const override
Definition Facts.cpp:20
Manages the creation, storage and retrieval of loans.
Definition Loans.h:55
const Loan & getLoan(LoanID ID) const
Definition Loans.h:64
void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM) const override
Definition Facts.cpp:36
Manages the creation, storage, and retrieval of origins for pointer-like variables and expressions.
Definition Origins.h:57
void dump(OriginID OID, llvm::raw_ostream &OS) const
Definition Origins.cpp:13
void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM) const override
Definition Facts.cpp:46
A dummy-fact used to mark a specific point in the code for testing.
Definition Facts.h:170
void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &) const override
Definition Facts.cpp:60
void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM) const override
Definition Facts.cpp:53
OriginID getUsedOrigin(const OriginManager &OM) const
Definition Facts.h:156
void dump(llvm::raw_ostream &OS) const
Definition Loans.cpp:13