Jlm
Loading...
Searching...
No Matches
DifferencePropagation.hpp
Go to the documentation of this file.
1/*
2 * Copyright 2024 HÃ¥vard Krogstie <krogstie.havard@gmail.com>
3 * See COPYING for terms of redistribution.
4 */
5
6#ifndef JLM_LLVM_OPT_ALIAS_ANALYSES_DIFFERENCEPROPAGATION_HPP
7#define JLM_LLVM_OPT_ALIAS_ANALYSES_DIFFERENCEPROPAGATION_HPP
8
10
11#include <vector>
12
13namespace jlm::llvm::aa
14{
15
17{
18
19public:
21 : Set_(set)
22 {}
23
27 void
35
36 [[nodiscard]] bool
37 IsInitialized() const noexcept
38 {
39 return NewPointees_.size() == Set_.NumPointerObjects();
40 }
41
46 void
48 {
51
52 NewPointees_[index].Clear();
53 NewPointeesTracked_[index] = true;
54 };
55
63 bool
65 {
68
69 // If pointees added to the superset are being tracked, use the tracking version
70 bool newPointee = Set_.AddToPointsToSet(pointer, pointee);
71 if (newPointee && NewPointeesTracked_[pointer])
72 return NewPointees_[pointer].insert(pointee);
73
74 return newPointee;
75 }
76
84 bool
86 {
89
90 // If pointees added to the superset are being tracked, use the tracking version
91 if (NewPointeesTracked_[superset])
92 return Set_.MakePointsToSetSuperset(superset, subset, NewPointees_[superset]);
93 else
94 return Set_.MakePointsToSetSuperset(superset, subset);
95 }
96
104 [[nodiscard]] const util::HashSet<PointerObjectIndex> &
106 {
109 if (NewPointeesTracked_[index])
110 return NewPointees_[index];
111 return Set_.GetPointsToSet(index);
112 }
113
118 void
120 {
121 NewPointeesTracked_[index] = false;
122 NewPointees_[index].Clear();
123 }
124
133 [[nodiscard]] bool
135 {
138 if (!Set_.IsPointingToExternal(index))
139 return false;
140 return !PointsToExternalFlagSeen_[index];
141 }
142
149 void
156
165 [[nodiscard]] bool
167 {
170 if (!Set_.HasPointeesEscaping(index))
171 return false;
172 return !PointeesEscapeFlagSeen_[index];
173 }
174
181 void
188
200 void
202 {
204
205 // After unification, forget everything about tracked differences in points-to sets
206 NewPointees_[nonRoot].Clear();
207 NewPointees_[root].Clear();
208 NewPointeesTracked_[root] = false;
209
214 }
215
216private:
218
219 // Only unification roots matter in these vectors
220
221 // Tracks all new pointees added to a unification root i,
222 // since ClearNewPointees(i) was last called.
223 std::vector<util::HashSet<PointerObjectIndex>> NewPointees_;
224 // Becomes true for a unification root i when CleanNewPointees(i) is called for the first time.
225 // Becomes false again when unification fully resets difference propagation
226 std::vector<bool> NewPointeesTracked_;
227
228 // These are set to true after the _IsNew have returned true
229 // When two PointerObjects a and b are unified, the flag only remains "seen",
230 // if the flag has already been "seen" on both a and b.
231 std::vector<bool> PointsToExternalFlagSeen_;
232 std::vector<bool> PointeesEscapeFlagSeen_;
233};
234
235}
236
237#endif // JLM_LLVM_OPT_ALIAS_ANALYSES_DIFFERENCEPROPAGATION_HPP
bool AddToPointsToSet(PointerObjectIndex pointer, PointerObjectIndex pointee)
bool PointeesEscapeIsNew(PointerObjectIndex index)
void OnPointerObjectsUnified(PointerObjectIndex root, PointerObjectIndex nonRoot)
bool PointsToExternalIsNew(PointerObjectIndex index)
const util::HashSet< PointerObjectIndex > & GetNewPointees(PointerObjectIndex index) const
void MarkPointsToExternalAsHandled(PointerObjectIndex index)
bool MakePointsToSetSuperset(PointerObjectIndex superset, PointerObjectIndex subset)
void MarkPointeesEscapeAsHandled(PointerObjectIndex index)
void OnRemoveAllPointees(PointerObjectIndex index)
void ClearNewPointees(PointerObjectIndex index)
std::vector< util::HashSet< PointerObjectIndex > > NewPointees_
const util::HashSet< PointerObjectIndex > & GetPointsToSet(PointerObjectIndex index) const
bool HasPointeesEscaping(PointerObjectIndex index) const noexcept
bool AddToPointsToSet(PointerObjectIndex pointer, PointerObjectIndex pointee)
bool IsPointingToExternal(PointerObjectIndex index) const noexcept
bool IsUnificationRoot(PointerObjectIndex index) const noexcept
size_t NumPointerObjects() const noexcept
bool MakePointsToSetSuperset(PointerObjectIndex superset, PointerObjectIndex subset)
#define JLM_ASSERT(x)
Definition common.hpp:16
uint32_t PointerObjectIndex