@@ -103,94 +103,85 @@ struct LatticeDomain : public std::variant<Top, L, Bottom> {
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- constexpr 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- constexpr bool operator ==(const LatticeDomain<L> &Lhs, const LL &Rhs) {
155- if (auto LVal = Lhs.getValueOrNull ()) {
156- return *LVal == Rhs;
156+ constexpr bool operator ==(Bottom /* Rhs*/ ) const noexcept {
157+ return this ->isBottom ();
157158 }
158- return false ;
159- }
160-
161- template <typename L>
162- constexpr bool operator ==(const LatticeDomain<L> &Lhs,
163- Bottom /* Rhs*/ ) noexcept {
164- return Lhs.isBottom ();
165- }
166-
167- template <typename L>
168- constexpr bool operator ==(const LatticeDomain<L> &Lhs, Top /* Rhs*/ ) noexcept {
169- return Lhs.isTop ();
170- }
171159
172- template <typename L>
173- constexpr bool operator <(const LatticeDomain<L> &Lhs,
174- const LatticeDomain<L> &Rhs) {
175- // / Top < (Lhs::L < Rhs::L) < Bottom
176- if (Rhs.isTop ()) {
177- return false ;
178- }
179- if (Lhs.isTop ()) {
180- return true ;
160+ constexpr bool operator ==(Top /* Rhs*/ ) const noexcept {
161+ return this ->isTop ();
181162 }
182- if (auto LhsPtr = Lhs.getValueOrNull ()) {
183- if (auto RhsPtr = Rhs.getValueOrNull ()) {
184- 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 ;
185168 }
186- } else if (Lhs.isBottom ()) {
187- return false ;
188- }
189- if (Rhs.isBottom ()) {
190- 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." );
191183 }
192- llvm_unreachable (" All comparison cases should be handled above." );
193- }
184+ };
194185
195186template <typename L> struct JoinLatticeTraits <LatticeDomain<L>> {
196187 using l_t = L;
0 commit comments