@@ -67,17 +67,17 @@ template <typename L>
6767struct LatticeDomain : public std ::variant<Top, L, Bottom> {
6868 using std::variant<Top, L, Bottom>::variant;
6969
70- [[nodiscard]] inline bool isBottom () const noexcept {
70+ [[nodiscard]] constexpr bool isBottom () const noexcept {
7171 return std::holds_alternative<Bottom>(*this );
7272 }
73- [[nodiscard]] inline bool isTop () const noexcept {
73+ [[nodiscard]] constexpr bool isTop () const noexcept {
7474 return std::holds_alternative<Top>(*this );
7575 }
7676
77- [[nodiscard]] inline L *getValueOrNull () noexcept {
77+ [[nodiscard]] constexpr L *getValueOrNull () noexcept {
7878 return std::get_if<L>(this );
7979 }
80- [[nodiscard]] inline const L *getValueOrNull () const noexcept {
80+ [[nodiscard]] constexpr const L *getValueOrNull () const noexcept {
8181 return std::get_if<L>(this );
8282 }
8383
@@ -93,119 +93,95 @@ struct LatticeDomain : public std::variant<Top, L, Bottom> {
9393 return hash_value (std::get<L>(LD));
9494 }
9595
96- [[nodiscard]] inline L &assertGetValue () noexcept {
96+ [[nodiscard]] constexpr L &assertGetValue () noexcept {
9797 assert (std::holds_alternative<L>(*this ));
9898 return std::get<L>(*this );
9999 }
100- [[nodiscard]] inline const L &assertGetValue () const noexcept {
100+ [[nodiscard]] constexpr const L &assertGetValue () const noexcept {
101101 assert (std::holds_alternative<L>(*this ));
102102 return std::get<L>(*this );
103103 }
104104
105105 template <typename TransformFn, typename ... ArgsT>
106- void onValue (TransformFn Transform, ArgsT &&...Args) {
106+ constexpr void onValue (TransformFn Transform, ArgsT &&...Args) {
107107 if (auto *Val = getValueOrNull ()) {
108108 std::invoke (std::move (Transform), *Val, PSR_FWD (Args)...);
109109 }
110110 }
111- };
112111
113- template <typename L>
114- inline llvm::raw_ostream &operator <<(llvm::raw_ostream &OS,
115- const LatticeDomain<L> &LD) {
116- if (LD.isBottom ()) {
117- return OS << " Bottom" ;
118- }
119- if (LD.isTop ()) {
120- return OS << " Top" ;
112+ friend llvm::raw_ostream &operator <<(llvm::raw_ostream &OS,
113+ const LatticeDomain &LD) {
114+ if (LD.isBottom ()) {
115+ return OS << " Bottom" ;
116+ }
117+ if (LD.isTop ()) {
118+ return OS << " Top" ;
119+ }
120+
121+ const auto *Val = LD.getValueOrNull ();
122+ assert (Val && " Only alternative remaining is L" );
123+ if constexpr (is_llvm_printable_v<L>) {
124+ return OS << *Val;
125+ } else {
126+ return OS << PrettyPrinter{*Val};
127+ }
121128 }
122129
123- const auto *Val = LD.getValueOrNull ();
124- assert (Val && " Only alternative remaining is L" );
125- if constexpr (is_llvm_printable_v<L>) {
126- return OS << *Val;
127- } else {
128- return OS << PrettyPrinter{*Val};
130+ friend std::ostream &operator <<(std::ostream &OS, const LatticeDomain &LD) {
131+ llvm::raw_os_ostream ROS (OS);
132+ ROS << LD;
133+ return OS;
129134 }
130- }
131135
132- template <typename L>
133- inline std::ostream &operator <<(std::ostream &OS, const LatticeDomain<L> &LD) {
134- llvm::raw_os_ostream ROS (OS);
135- ROS << LD;
136- return OS;
137- }
136+ constexpr bool operator ==(const LatticeDomain &Rhs) const {
137+ if (this ->index () != Rhs.index ()) {
138+ return false ;
139+ }
140+ if (auto LhsPtr = this ->getValueOrNull ()) {
141+ // / No need to check whether Rhs is an L; the indices are already the same
142+ return *LhsPtr == *Rhs.getValueOrNull ();
143+ }
144+ return true ;
145+ }
138146
139- template <typename L>
140- inline bool operator ==(const LatticeDomain<L> &Lhs,
141- const LatticeDomain<L> &Rhs) {
142- if (Lhs.index () != Rhs.index ()) {
147+ template <typename LL>
148+ requires AreEqualityComparable<L, LL>
149+ constexpr bool operator ==(const LL &Rhs) const {
150+ if (auto LVal = this ->getValueOrNull ()) {
151+ return *LVal == Rhs;
152+ }
143153 return false ;
144154 }
145- if (auto LhsPtr = Lhs.getValueOrNull ()) {
146- // / No need to check whether Lhs is an L; the indices are already the same
147- return *LhsPtr == *Rhs.getValueOrNull ();
148- }
149- return true ;
150- }
151155
152- template <typename L, typename LL>
153- requires AreEqualityComparable<LL, L>
154- inline bool operator ==(const LL &Lhs, const LatticeDomain<L> &Rhs) {
155- if (auto RVal = Rhs.getValueOrNull ()) {
156- return Lhs == *RVal;
156+ constexpr bool operator ==(Bottom /* Rhs*/ ) const noexcept {
157+ return this ->isBottom ();
157158 }
158- return false ;
159- }
160-
161- template <typename L, typename LL>
162- requires AreEqualityComparable<LL, L>
163- inline bool operator ==(const LatticeDomain<L> &Lhs, const LL &Rhs) {
164- return Rhs == Lhs;
165- }
166159
167- template <typename L>
168- inline bool operator ==(const LatticeDomain<L> &Lhs, Bottom /* Rhs*/ ) noexcept {
169- return Lhs.isBottom ();
170- }
171-
172- template <typename L>
173- inline bool operator ==(const LatticeDomain<L> &Lhs, Top /* Rhs*/ ) noexcept {
174- return Lhs.isTop ();
175- }
176-
177- template <typename L>
178- inline bool operator ==(Bottom /* Lhs*/ , const LatticeDomain<L> &Rhs) noexcept {
179- return Rhs.isBottom ();
180- }
181-
182- template <typename L>
183- inline bool operator ==(Top /* Lhs*/ , const LatticeDomain<L> &Rhs) noexcept {
184- return Rhs.isTop ();
185- }
186-
187- template <typename L>
188- inline bool operator <(const LatticeDomain<L> &Lhs,
189- const LatticeDomain<L> &Rhs) {
190- // / Top < (Lhs::L < Rhs::L) < Bottom
191- if (Rhs.isTop ()) {
192- return false ;
160+ constexpr bool operator ==(Top /* Rhs*/ ) const noexcept {
161+ return this ->isTop ();
193162 }
194- if (Lhs.isTop ()) {
195- return true ;
196- }
197- if (auto LhsPtr = Lhs.getValueOrNull ()) {
198- if (auto RhsPtr = Rhs.getValueOrNull ()) {
199- return *LhsPtr < *RhsPtr;
163+
164+ constexpr bool operator <(const LatticeDomain &Rhs) const {
165+ // / Top < (Lhs::L < Rhs::L) < Bottom
166+ if (Rhs.isTop ()) {
167+ return false ;
200168 }
201- } else if (Lhs.isBottom ()) {
202- return false ;
203- }
204- if (Rhs.isBottom ()) {
205- return true ;
169+ if (this ->isTop ()) {
170+ return true ;
171+ }
172+ if (auto LhsPtr = this ->getValueOrNull ()) {
173+ if (auto RhsPtr = Rhs.getValueOrNull ()) {
174+ return *LhsPtr < *RhsPtr;
175+ }
176+ } else if (this ->isBottom ()) {
177+ return false ;
178+ }
179+ if (Rhs.isBottom ()) {
180+ return true ;
181+ }
182+ llvm_unreachable (" All comparison cases should be handled above." );
206183 }
207- llvm_unreachable (" All comparison cases should be handled above." );
208- }
184+ };
209185
210186template <typename L> struct JoinLatticeTraits <LatticeDomain<L>> {
211187 using l_t = L;
@@ -242,7 +218,7 @@ template <typename L>
242218struct NonTopBotValue <LatticeDomain<L>> {
243219 using type = L;
244220
245- static L unwrap (LatticeDomain<L> Value) noexcept (
221+ constexpr static L unwrap (LatticeDomain<L> Value) noexcept (
246222 std::is_nothrow_move_constructible_v<L>) {
247223 return std::get<L>(std::move (Value));
248224 }
0 commit comments