@@ -235,24 +235,21 @@ inline bool operator<=(OperationCost l, OperationCost r) {
235235// / An alignment value, in eight-bit units.
236236class Alignment {
237237public:
238- using int_type = uint32_t ;
239-
240- constexpr Alignment () : Value(0 ) {}
241- constexpr explicit Alignment (int_type Value) : Value(Value) {}
242- explicit Alignment (clang::CharUnits value) : Value(value.getQuantity()) {}
238+ using int_type = uint64_t ;
243239
244- constexpr int_type getValue () const { return Value; }
245- constexpr int_type getMaskValue () const { return Value - 1 ; }
240+ constexpr Alignment () : Shift(0 ) {}
241+ explicit Alignment (int_type Value) : Shift(llvm::Log2_64(Value)) {
242+ assert (llvm::isPowerOf2_64 (Value));
243+ }
244+ explicit Alignment (clang::CharUnits value) : Alignment(value.getQuantity()) {}
246245
247- bool isOne () const { return Value == 1 ; }
248- bool isZero () const { return Value == 0 ; }
246+ constexpr int_type getValue () const { return int_type ( 1 ) << Shift ; }
247+ constexpr int_type getMaskValue () const { return getValue () - 1 ; }
249248
250249 Alignment alignmentAtOffset (Size S) const ;
251250 Size asSize () const ;
252251
253- unsigned log2 () const {
254- return llvm::Log2_64 (Value);
255- }
252+ unsigned log2 () const { return Shift; }
256253
257254 operator clang::CharUnits () const {
258255 return asCharUnits ();
@@ -261,19 +258,24 @@ class Alignment {
261258 return clang::CharUnits::fromQuantity (getValue ());
262259 }
263260
264- explicit operator bool () const { return Value != 0 ; }
261+ explicit operator llvm::MaybeAlign () const { return llvm::MaybeAlign ( getValue ()) ; }
265262
266- explicit operator llvm::MaybeAlign () const { return llvm::MaybeAlign (Value); }
263+ friend bool operator < (Alignment L, Alignment R){ return L.Shift < R.Shift ; }
264+ friend bool operator <=(Alignment L, Alignment R){ return L.Shift <= R.Shift ; }
265+ friend bool operator > (Alignment L, Alignment R){ return L.Shift > R.Shift ; }
266+ friend bool operator >=(Alignment L, Alignment R){ return L.Shift >= R.Shift ; }
267+ friend bool operator ==(Alignment L, Alignment R){ return L.Shift == R.Shift ; }
268+ friend bool operator !=(Alignment L, Alignment R){ return L.Shift != R.Shift ; }
267269
268- friend bool operator < (Alignment L, Alignment R){ return L. Value < R. Value ; }
269- friend bool operator <=( Alignment L, Alignment R){ return L. Value <= R. Value ; }
270- friend bool operator > ( Alignment L, Alignment R){ return L. Value > R. Value ; }
271- friend bool operator >=(Alignment L, Alignment R){ return L. Value >= R. Value ; }
272- friend bool operator ==(Alignment L, Alignment R){ return L. Value == R. Value ; }
273- friend bool operator !=(Alignment L, Alignment R){ return L. Value != R. Value ; }
270+ template < unsigned Value>
271+ static constexpr Alignment create () {
272+ Alignment result;
273+ result. Shift = llvm::CTLog2< Value>();
274+ return result;
275+ }
274276
275277private:
276- int_type Value ;
278+ unsigned char Shift ;
277279};
278280
279281// / A size value, in eight-bit units.
0 commit comments