clang 23.0.0git
LoanPropagation.h
Go to the documentation of this file.
1//===- LoanPropagation.h - Loan Propagation Analysis -----------*- 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 LoanPropagationAnalysis, a forward dataflow analysis
10// that tracks which loans each origin holds at each program point. Loans
11// represent borrows of storage locations and are propagated through the
12// program as pointers are copied or assigned.
13//
14//===----------------------------------------------------------------------===//
15#ifndef LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_LOAN_PROPAGATION_H
16#define LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_LOAN_PROPAGATION_H
17
20#include "clang/Analysis/CFG.h"
21#include "llvm/ADT/ImmutableMap.h"
22#include "llvm/ADT/ImmutableSet.h"
23
25
26// Using LLVM's immutable collections is efficient for dataflow analysis
27// as it avoids deep copies during state transitions.
28// TODO(opt): Consider using a bitset to represent the set of loans.
29using LoanSet = llvm::ImmutableSet<LoanID>;
30using OriginLoanMap = llvm::ImmutableMap<OriginID, LoanSet>;
31
33public:
35 OriginLoanMap::Factory &OriginLoanMapFactory,
36 LoanSet::Factory &LoanSetFactory);
38
40
41 /// Builds the chain of origins through which a loan has propagated.
42 ///
43 /// Starting from the last fact of the block containing StartPoint, this
44 /// function performs a DFS over CFG blocks to explore all reachable blocks.
45 /// Within each block, facts are processed in reverse order.
46 ///
47 /// The traversal follows OriginFlowFacts backwards to reconstruct the
48 /// sequence of origins through which the loan flowed, ending at the origin
49 /// where the loan was originally issued.
51 const OriginID StartOID,
52 const LoanID TargetLoan,
53 const CFG *Cfg) const;
54
56 const LoanID TargetLoan,
57 const CFG *Cfg) const;
58
59private:
60 class Impl;
61 std::unique_ptr<Impl> PImpl;
62};
63
64} // namespace clang::lifetimes::internal
65
66#endif // LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_LOAN_PROPAGATION_H
This file defines AnalysisDeclContext, a class that manages the analysis context data for context sen...
AnalysisDeclContext contains the context data for the function, method or block under analysis.
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt.
Definition CFG.h:1271
llvm::SmallVector< OriginID > buildOriginFlowChain(ProgramPoint StartPoint, const OriginID StartOID, const LoanID TargetLoan, const CFG *Cfg) const
Builds the chain of origins through which a loan has propagated.
LoanSet getLoans(OriginID OID, ProgramPoint P) const
LoanPropagationAnalysis(const CFG &C, AnalysisDeclContext &AC, FactManager &F, OriginLoanMap::Factory &OriginLoanMapFactory, LoanSet::Factory &LoanSetFactory)
const Fact * ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition Facts.h:95
llvm::ImmutableSet< LoanID > LoanSet
utils::ID< struct LoanTag > LoanID
Definition Loans.h:25
utils::ID< struct OriginTag > OriginID
Definition Origins.h:28
llvm::ImmutableMap< OriginID, LoanSet > OriginLoanMap