Jlm
Loading...
Searching...
No Matches
ModRefSummary.hpp
Go to the documentation of this file.
1/*
2 * Copyright 2022 Nico Reißmann <nico.reissmann@gmail.com>
3 * Copyright 2025 Håvard Krogstie <krogstie.havard@gmail.com>
4 * See COPYING for terms of redistribution.
5 */
6
7#ifndef JLM_LLVM_OPT_ALIAS_ANALYSES_MODREFSUMMARY_HPP
8#define JLM_LLVM_OPT_ALIAS_ANALYSES_MODREFSUMMARY_HPP
9
11#include <jlm/rvsdg/gamma.hpp>
12#include <jlm/rvsdg/theta.hpp>
13#include <jlm/util/HashSet.hpp>
14
15#include <type_traits>
16#include <unordered_map>
17
18namespace jlm::llvm::aa
19{
20
26enum ModRefEffect : uint8_t
27{
28 // The set has no effect on the memory node
30
31 // The set represents possibly reading from the memory
32 RefOnly = 0b1,
33
34 // The set represents possibly storing to the memory
35 ModOnly = 0b10,
36
37 // The set represents both reading and writing to the memory
38 ModRef = 0b11
39};
40
44[[nodiscard]] inline bool
46{
47 // Bitwise AND checks for both RefOnly and ModRef
48 return effect & ModRefEffect::RefOnly;
49}
50
54[[nodiscard]] inline bool
56{
57 // Bitwise AND checks for both ModOnly and ModRef
58 return effect & ModRefEffect::ModOnly;
59}
60
67[[nodiscard]] inline ModRefEffect
69{
70 return static_cast<ModRefEffect>(
71 static_cast<std::underlying_type_t<ModRefEffect>>(a)
72 | static_cast<std::underlying_type_t<ModRefEffect>>(b));
73}
74
78inline ModRefEffect &
80{
81 return a = (a | b);
82}
83
91[[nodiscard]] inline bool
93{
94 return (subset | superset) == superset;
95}
96
114{
115public:
116 [[nodiscard]] const std::unordered_map<PointsToGraph::NodeIndex, ModRefEffect> &
118 {
119 return modRefNodes_;
120 }
121
122protected:
123 // Prevent users of the ModRefSummary base class from accidentally copying sets by value,
124 // or constructing empty ModRefSets. Instances should always be summarizer-specific subclasses.
125 ModRefSet() = default;
126 ModRefSet(const ModRefSet & other) = default;
127 ModRefSet(ModRefSet && other) = default;
128 ModRefSet &
129 operator=(const ModRefSet & other) = default;
130 ModRefSet &
131 operator=(ModRefSet && other) = default;
132
136 std::unordered_map<PointsToGraph::NodeIndex, ModRefEffect> modRefNodes_;
137};
138
144{
145public:
146 virtual ~ModRefSummary() noexcept = default;
147
148 [[nodiscard]] virtual const PointsToGraph &
149 GetPointsToGraph() const noexcept = 0;
150
165 [[nodiscard]] virtual const ModRefSet &
166 GetSimpleNodeModRef(const rvsdg::SimpleNode & node) const = 0;
167
173 [[nodiscard]] virtual const ModRefSet &
174 GetGammaEntryModRef(const rvsdg::GammaNode & gamma) const = 0;
175
181 [[nodiscard]] virtual const ModRefSet &
182 GetGammaExitModRef(const rvsdg::GammaNode & gamma) const = 0;
183
189 [[nodiscard]] virtual const ModRefSet &
190 GetThetaModRef(const rvsdg::ThetaNode & theta) const = 0;
191
197 [[nodiscard]] virtual const ModRefSet &
198 GetLambdaEntryModRef(const rvsdg::LambdaNode & lambda) const = 0;
199
205 [[nodiscard]] virtual const ModRefSet &
206 GetLambdaExitModRef(const rvsdg::LambdaNode & lambda) const = 0;
207};
208
209}
210
211#endif // JLM_LLVM_OPT_ALIAS_ANALYSES_MODREFSUMMARY_HPP
ModRefSet & operator=(const ModRefSet &other)=default
ModRefSet(ModRefSet &&other)=default
std::unordered_map< PointsToGraph::NodeIndex, ModRefEffect > modRefNodes_
ModRefSet & operator=(ModRefSet &&other)=default
const std::unordered_map< PointsToGraph::NodeIndex, ModRefEffect > & getModRefNodes() const
ModRefSet(const ModRefSet &other)=default
virtual const ModRefSet & GetGammaEntryModRef(const rvsdg::GammaNode &gamma) const =0
virtual const ModRefSet & GetThetaModRef(const rvsdg::ThetaNode &theta) const =0
virtual const ModRefSet & GetLambdaExitModRef(const rvsdg::LambdaNode &lambda) const =0
virtual const ModRefSet & GetLambdaEntryModRef(const rvsdg::LambdaNode &lambda) const =0
virtual const PointsToGraph & GetPointsToGraph() const noexcept=0
virtual const ModRefSet & GetGammaExitModRef(const rvsdg::GammaNode &gamma) const =0
virtual ~ModRefSummary() noexcept=default
virtual const ModRefSet & GetSimpleNodeModRef(const rvsdg::SimpleNode &node) const =0
bool isEffectSubset(ModRefEffect subset, ModRefEffect superset)
bool mayEffectModify(ModRefEffect effect)
ModRefEffect operator|(ModRefEffect a, ModRefEffect b)
bool mayEffectReference(ModRefEffect effect)
ModRefEffect & operator|=(ModRefEffect &a, ModRefEffect b)