@@ -56,36 +56,41 @@ class FixedPointSemantics {
5656
5757 // / Check if the Semantic follow the requirements of an older more limited
5858 // / version of this class
59- bool isValidLegacySema () const {
59+ [[nodiscard]] bool isValidLegacySema () const {
6060 return LsbWeight <= 0 && static_cast <int >(Width) >= -LsbWeight;
6161 }
62- unsigned getWidth () const { return Width; }
63- unsigned getScale () const { assert (isValidLegacySema ()); return -LsbWeight; }
64- int getLsbWeight () const { return LsbWeight; }
65- int getMsbWeight () const {
62+ [[nodiscard]] unsigned getWidth () const { return Width; }
63+ [[nodiscard]] unsigned getScale () const {
64+ assert (isValidLegacySema ());
65+ return -LsbWeight;
66+ }
67+ [[nodiscard]] int getLsbWeight () const { return LsbWeight; }
68+ [[nodiscard]] int getMsbWeight () const {
6669 return LsbWeight + Width - 1 /* Both lsb and msb are both part of width*/ ;
6770 }
68- bool isSigned () const { return IsSigned; }
69- bool isSaturated () const { return IsSaturated; }
70- bool hasUnsignedPadding () const { return HasUnsignedPadding; }
71+ [[nodiscard]] bool isSigned () const { return IsSigned; }
72+ [[nodiscard]] bool isSaturated () const { return IsSaturated; }
73+ [[nodiscard]] bool hasUnsignedPadding () const { return HasUnsignedPadding; }
7174
7275 void setSaturated (bool Saturated) { IsSaturated = Saturated; }
7376
7477 // / return true if the first bit doesn't have a strictly positive weight
75- bool hasSignOrPaddingBit () const { return IsSigned || HasUnsignedPadding; }
78+ [[nodiscard]] bool hasSignOrPaddingBit () const {
79+ return IsSigned || HasUnsignedPadding;
80+ }
7681
7782 // / Return the number of integral bits represented by these semantics. These
7883 // / are separate from the fractional bits and do not include the sign or
7984 // / padding bit.
80- unsigned getIntegralBits () const {
85+ [[nodiscard]] unsigned getIntegralBits () const {
8186 return std::max (getMsbWeight () + 1 - hasSignOrPaddingBit (), 0 );
8287 }
8388
8489 // / Return the FixedPointSemantics that allows for calculating the full
8590 // / precision semantic that can precisely represent the precision and ranges
8691 // / of both input values. This does not compute the resulting semantics for a
8792 // / given binary operation.
88- LLVM_ABI FixedPointSemantics
93+ [[nodiscard]] LLVM_ABI FixedPointSemantics
8994 getCommonSemantics (const FixedPointSemantics &Other) const ;
9095
9196 // / Print semantics for debug purposes
@@ -98,7 +103,8 @@ class FixedPointSemantics {
98103 // / minimum integer representation of 127 and -128, respectively. If both of
99104 // / these values can be represented (possibly inexactly) in the floating
100105 // / point semantic without overflowing, this returns true.
101- LLVM_ABI bool fitsInFloatSemantics (const fltSemantics &FloatSema) const ;
106+ [[nodiscard]] LLVM_ABI bool
107+ fitsInFloatSemantics (const fltSemantics &FloatSema) const ;
102108
103109 // / Return the FixedPointSemantics for an integer type.
104110 static FixedPointSemantics GetIntegerSemantics (unsigned Width,
@@ -119,7 +125,7 @@ class FixedPointSemantics {
119125 // / The result is dependent on the host endianness and not stable across LLVM
120126 // / versions. See getFromOpaqueInt() to convert it back to a
121127 // / FixedPointSemantics object.
122- LLVM_ABI uint32_t toOpaqueInt () const ;
128+ [[nodiscard]] LLVM_ABI uint32_t toOpaqueInt () const ;
123129 // / Create a FixedPointSemantics object from an integer created via
124130 // / toOpaqueInt().
125131 LLVM_ABI static FixedPointSemantics getFromOpaqueInt (uint32_t );
@@ -177,16 +183,18 @@ class APFixedPoint {
177183 APFixedPoint (const FixedPointSemantics &Sema) : APFixedPoint(0 , Sema) {}
178184
179185 APSInt getValue () const { return APSInt (Val, !Sema.isSigned ()); }
180- inline unsigned getWidth () const { return Sema.getWidth (); }
181- inline unsigned getScale () const { return Sema.getScale (); }
182- int getLsbWeight () const { return Sema.getLsbWeight (); }
183- int getMsbWeight () const { return Sema.getMsbWeight (); }
184- inline bool isSaturated () const { return Sema.isSaturated (); }
185- inline bool isSigned () const { return Sema.isSigned (); }
186- inline bool hasPadding () const { return Sema.hasUnsignedPadding (); }
187- FixedPointSemantics getSemantics () const { return Sema; }
186+ [[nodiscard]] inline unsigned getWidth () const { return Sema.getWidth (); }
187+ [[nodiscard]] inline unsigned getScale () const { return Sema.getScale (); }
188+ [[nodiscard]] int getLsbWeight () const { return Sema.getLsbWeight (); }
189+ [[nodiscard]] int getMsbWeight () const { return Sema.getMsbWeight (); }
190+ [[nodiscard]] inline bool isSaturated () const { return Sema.isSaturated (); }
191+ [[nodiscard]] inline bool isSigned () const { return Sema.isSigned (); }
192+ [[nodiscard]] inline bool hasPadding () const {
193+ return Sema.hasUnsignedPadding ();
194+ }
195+ [[nodiscard]] FixedPointSemantics getSemantics () const { return Sema; }
188196
189- bool getBoolValue () const { return Val.getBoolValue (); }
197+ [[nodiscard]] bool getBoolValue () const { return Val.getBoolValue (); }
190198
191199 // Convert this number to match the semantics provided. If the overflow
192200 // parameter is provided, set this value to true or false to indicate if this
@@ -244,10 +252,11 @@ class APFixedPoint {
244252
245253 // / Convert this fixed point number to a floating point value with the
246254 // / provided semantics.
247- LLVM_ABI APFloat convertToFloat (const fltSemantics &FloatSema) const ;
255+ [[nodiscard]] LLVM_ABI APFloat
256+ convertToFloat (const fltSemantics &FloatSema) const ;
248257
249258 LLVM_ABI void toString (SmallVectorImpl<char > &Str) const ;
250- std::string toString () const {
259+ [[nodiscard]] std::string toString () const {
251260 SmallString<40 > S;
252261 toString (S);
253262 return std::string (S);
@@ -260,7 +269,7 @@ class APFixedPoint {
260269#endif
261270
262271 // If LHS > RHS, return 1. If LHS == RHS, return 0. If LHS < RHS, return -1.
263- LLVM_ABI int compare (const APFixedPoint &Other) const ;
272+ [[nodiscard]] LLVM_ABI int compare (const APFixedPoint &Other) const ;
264273 bool operator ==(const APFixedPoint &Other) const {
265274 return compare (Other) == 0 ;
266275 }
0 commit comments