Jlm
Loading...
Searching...
No Matches
AliasAnalysisPrecisionEvaluator.hpp
Go to the documentation of this file.
1/*
2 * Copyright 2025 HÃ¥vard Krogstie <krogstie.havard@gmail.com>
3 * See COPYING for terms of redistribution.
4 */
5
6#ifndef JLM_LLVM_OPT_ALIAS_ANALYSES_ALIASANALYSISPRECISIONEVALUATOR_HPP
7#define JLM_LLVM_OPT_ALIAS_ANALYSES_ALIASANALYSISPRECISIONEVALUATOR_HPP
8
10#include <jlm/rvsdg/lambda.hpp>
14
15#include <unordered_map>
16
17namespace jlm::llvm::aa
18{
19
26{
28
29public:
31
33
42 void
43 SetLoadsConsideredClobbers(bool loadsConsideredClobbers) noexcept
44 {
45 LoadsConsideredClobbers_ = loadsConsideredClobbers;
46 }
47
48 [[nodiscard]] bool
50 {
52 }
53
61 void
62 SetDeduplicatePointers(bool deduplicatePointers) noexcept
63 {
64 DeduplicatePointers_ = deduplicatePointers;
65 }
66
67 [[nodiscard]] bool
68 IsDeduplicatingPointers() const noexcept
69 {
71 }
72
82 void
83 SetAliasingGraphEnabled(bool aliasingGraphEnabled) noexcept
84 {
85 AliasingGraphEnabled_ = aliasingGraphEnabled;
86 }
87
88 [[nodiscard]] bool
89 IsAliasingGraphEnabled() const noexcept
90 {
92 }
93
100 void
101 SetPerFunctionOutputEnabled(bool perFunctionOutputEnabled) noexcept
102 {
103 PerFunctionOutputEnabled_ = perFunctionOutputEnabled;
104 }
105
106 [[nodiscard]] bool
108 {
110 }
111
118 void
120 const rvsdg::RvsdgModule & rvsdgModule,
121 AliasAnalysis & aliasAnalysis,
123
124private:
125 void
126 EvaluateAllFunctions(const rvsdg::Region & region, AliasAnalysis & aliasAnalysis);
127
128 void
129 EvaluateFunction(const rvsdg::LambdaNode & function, AliasAnalysis & aliasAnalysis);
130
131 void
133
134 void
136
137 void
139
143 void
144 CollectPointer(const rvsdg::Output * value, size_t size, bool isClobber);
145
151 void
153
159 void
161
169 void
171 std::optional<util::FilePath> perFunctionOutput,
172 PrecisionStatistics & statistics) const;
173
183 void
185 const rvsdg::Output & p1,
186 size_t s1,
187 const rvsdg::Output & p2,
188 size_t s2,
190
191 // Alias analysis precision info for a set of pointer usages, such as in a function
193 {
195 {
196 // A single ClobberInfo can represent multiple identical clobbers.
197 // The multiplier should be applied to all the alias query response counters below,
198 // and when calculating the average of all clobbers, the multiplier is the weight.
199 uint64_t Multiplier = 1;
200
201 uint64_t NumNoAlias = 0;
202 uint64_t NumMayAlias = 0;
203 uint64_t NumMustAlias = 0;
204 };
205
210 std::vector<ClobberInfo> ClobberOperations;
211
217
221 uint64_t NumOperations = 0;
222 };
223
228 {
230
231 // Statistics about the average ClobberInfo. Sum to 1
235
236 // Total number of alias query responses
237 uint64_t TotalNoAlias = 0;
238 uint64_t TotalMayAlias = 0;
239 uint64_t TotalMustAlias = 0;
240 };
241
246 [[nodiscard]] static AggregatedClobberInfos
247 AggregateClobberInfos(const std::vector<PrecisionInfo::ClobberInfo> & clobberInfos);
248
254 static void
255 PrintAggregatedClobberInfos(const AggregatedClobberInfos & clobberInfos, std::ostream & out);
256
257 struct Context
258 {
259 // Output dot graph, only used if dumping a graph of alias analysis-response edges is enabled
261
262 // Precision info per function in the evaluated module
263 std::unordered_map<const rvsdg::LambdaNode *, PrecisionInfo> PerFunctionPrecision;
264
270 std::vector<std::tuple<const rvsdg::Output *, size_t, bool, size_t>> PointerOperations;
271 };
272
273 // Whether to consider loads as clobbers
275
276 // Whether to deduplicate pointers
278
279 // Whether to create an aliasing graph and write it to a file
281
282 // Whether to create a file containing aliasing statistics per function
284
285 // Data used during evaluation
287};
288
289}
290
291#endif // JLM_LLVM_OPT_ALIAS_ANALYSES_ALIASANALYSISPRECISIONEVALUATOR_HPP
void EvaluateAliasAnalysisClient(const rvsdg::RvsdgModule &rvsdgModule, AliasAnalysis &aliasAnalysis, util::StatisticsCollector &statisticsCollector)
void SetDeduplicatePointers(bool deduplicatePointers) noexcept
static void PrintAggregatedClobberInfos(const AggregatedClobberInfos &clobberInfos, std::ostream &out)
void SetAliasingGraphEnabled(bool aliasingGraphEnabled) noexcept
static AggregatedClobberInfos AggregateClobberInfos(const std::vector< PrecisionInfo::ClobberInfo > &clobberInfos)
void SetLoadsConsideredClobbers(bool loadsConsideredClobbers) noexcept
void EvaluateFunction(const rvsdg::LambdaNode &function, AliasAnalysis &aliasAnalysis)
void CalculateResults(std::optional< util::FilePath > perFunctionOutput, PrecisionStatistics &statistics) const
void CollectPointersFromStructuralNode(const rvsdg::StructuralNode &node)
void AddToAliasingGraph(const rvsdg::Output &p1, size_t s1, const rvsdg::Output &p2, size_t s2, AliasAnalysis::AliasQueryResponse response)
void CollectPointer(const rvsdg::Output *value, size_t size, bool isClobber)
void SetPerFunctionOutputEnabled(bool perFunctionOutputEnabled) noexcept
void EvaluateAllFunctions(const rvsdg::Region &region, AliasAnalysis &aliasAnalysis)
Represent acyclic RVSDG subgraphs.
Definition region.hpp:213
static util::StatisticsCollector statisticsCollector
std::unordered_map< const rvsdg::LambdaNode *, PrecisionInfo > PerFunctionPrecision
std::vector< std::tuple< const rvsdg::Output *, size_t, bool, size_t > > PointerOperations