11#include "llvm/Support/ErrorHandling.h"
22 Lattice() : LiveOrigins(
nullptr) {};
27 return LiveOrigins ==
Other.LiveOrigins;
32 void dump(llvm::raw_ostream &OS,
const OriginManager &OM)
const {
33 if (LiveOrigins.isEmpty())
35 for (
const auto &Entry : LiveOrigins) {
37 const LivenessInfo &Info = Entry.second;
49 llvm_unreachable(
"liveness kind of live origins should not be dead.");
51 OS <<
" live at this point\n";
63 AnalysisImpl(
const CFG &
C, AnalysisDeclContext &AC, FactManager &F,
64 LivenessMap::Factory &SF)
65 : DataflowAnalysis(
C, AC, F), FactMgr(F), Factory(SF) {}
68 StringRef getAnalysisName()
const {
return "LiveOrigins"; }
70 Lattice getInitialState() {
return Lattice(Factory.getEmptyMap()); }
75 Lattice join(Lattice L1, Lattice L2)
const {
78 auto CombineUseFact = [](
const UseFact &A,
79 const UseFact &B) ->
const UseFact * {
80 return A.getUseExpr()->getExprLoc() < B.getUseExpr()->getExprLoc() ? &A
92 auto CombineLivenessInfo = [&](
const LivenessInfo *L1,
93 const LivenessInfo *L2) -> LivenessInfo {
94 assert((L1 || L2) &&
"unexpectedly merging 2 empty sets");
100 CombineUseFact(*L1->CausingUseFact, *L2->CausingUseFact),
101 CombineLivenessKind(L1->Kind, L2->Kind));
104 L1.LiveOrigins, L2.LiveOrigins, Factory, CombineLivenessInfo,
113 Lattice
transfer(Lattice In,
const UseFact &UF) {
114 OriginID OID = UF.getUsedOrigin(FactMgr.getOriginMgr());
117 return Lattice(Factory.remove(
In.LiveOrigins, OID));
119 return Lattice(Factory.add(
In.LiveOrigins, OID,
124 Lattice
transfer(Lattice In,
const IssueFact &IF) {
125 return Lattice(Factory.remove(
In.LiveOrigins, IF.getOriginID()));
130 Lattice
transfer(Lattice In,
const OriginFlowFact &OF) {
131 if (!OF.getKillDest())
133 return Lattice(Factory.remove(
In.LiveOrigins, OF.getDestOriginID()));
137 return getState(P).LiveOrigins;
141 void dump(llvm::raw_ostream &OS,
142 llvm::StringMap<ProgramPoint> TestPoints)
const {
143 llvm::dbgs() <<
"==========================================\n";
144 llvm::dbgs() << getAnalysisName() <<
" results:\n";
145 llvm::dbgs() <<
"==========================================\n";
146 for (
const auto &Entry : TestPoints) {
147 OS <<
"TestPoint: " << Entry.getKey() <<
"\n";
148 getState(Entry.getValue()).dump(OS, FactMgr.getOriginMgr());
153 FactManager &FactMgr;
154 LivenessMap::Factory &Factory;
160 using AnalysisImpl::AnalysisImpl;
165 LivenessMap::Factory &SF)
166 : PImpl(
std::make_unique<
Impl>(
C, AC, F, SF)) {
173 return PImpl->getLiveOriginsAt(P);
177 llvm::StringMap<ProgramPoint> TestPoints)
const {
178 PImpl->dump(OS, TestPoints);
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
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.
A generic, policy-based driver for dataflow analyses.
void dump(llvm::raw_ostream &OS, llvm::StringMap< ProgramPoint > TestPoints) const
LiveOriginsAnalysis(const CFG &C, AnalysisDeclContext &AC, FactManager &F, LivenessMap::Factory &SF)
LivenessMap getLiveOriginsAt(ProgramPoint P) const
Returns the set of origins that are live at a specific program point, along with the the details of t...
void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env, Environment::ValueModel &Model)
Evaluates S and updates Env accordingly.
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
@ Symmetric
A symmetric join applies the JoinValues operation to keys unique to either map, ensuring that values ...
static llvm::ImmutableSet< T > join(llvm::ImmutableSet< T > A, llvm::ImmutableSet< T > B, typename llvm::ImmutableSet< T >::Factory &F)
Computes the union of two ImmutableSets.
const Fact * ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
utils::ID< struct OriginTag > OriginID
llvm::ImmutableMap< OriginID, LivenessInfo > LivenessMap
bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
bool operator!=(CanQual< T > x, CanQual< U > y)
@ Other
Other implicit parameter.