From c170edb60bbc53b46c1dcaf6ae21d9b37c11499d Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Thu, 13 Apr 2017 04:59:11 +0000 Subject: [PATCH] [APInt] Reorder fields to avoid a hole in the middle of the class Summary: APInt is currently implemented with an unsigned BitWidth field first and then a uint_64/pointer union. Due to the 64-bit size of the union there is a hole after the bitwidth. Putting the union first allows the class to be packed. Making it 12 bytes instead of 16 bytes. An APSInt goes from 20 bytes to 16 bytes. This shows a 4k reduction on the size of the opt binary on my local x86-64 build. So this enables some other improvement to the code as well. Reviewers: dblaikie, RKSimon, hans, davide Reviewed By: davide Subscribers: davide, llvm-commits Differential Revision: https://reviews.llvm.org/D32001 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300171 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/APInt.h | 10 +++++----- lib/Support/APInt.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h index fb883aa061e..9179d9c96d1 100644 --- a/include/llvm/ADT/APInt.h +++ b/include/llvm/ADT/APInt.h @@ -79,8 +79,6 @@ public: }; private: - unsigned BitWidth; ///< The number of bits in this APInt. - /// This union is used to store the integer value. When the /// integer bit-width <= 64, it uses VAL, otherwise it uses pVal. union { @@ -88,13 +86,15 @@ private: uint64_t *pVal; ///< Used to store the >64 bits integer value. }; + unsigned BitWidth; ///< The number of bits in this APInt. + friend struct DenseMapAPIntKeyInfo; /// \brief Fast internal constructor /// /// This constructor is used only internally for speed of construction of /// temporaries. It is unsafe for general use so it is not public. - APInt(uint64_t *val, unsigned bits) : BitWidth(bits), pVal(val) {} + APInt(uint64_t *val, unsigned bits) : pVal(val), BitWidth(bits) {} /// \brief Determine if this APInt just has one word to store value. /// @@ -290,7 +290,7 @@ public: } /// \brief Move Constructor. - APInt(APInt &&that) : BitWidth(that.BitWidth), VAL(that.VAL) { + APInt(APInt &&that) : VAL(that.VAL), BitWidth(that.BitWidth) { that.BitWidth = 0; } @@ -305,7 +305,7 @@ public: /// /// This is useful for object deserialization (pair this with the static /// method Read). - explicit APInt() : BitWidth(1), VAL(0) {} + explicit APInt() : VAL(0), BitWidth(1) {} /// \brief Returns whether this instance allocated memory. bool needsCleanup() const { return !isSingleWord(); } diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp index 8733028a9b6..4fe14641032 100644 --- a/lib/Support/APInt.cpp +++ b/lib/Support/APInt.cpp @@ -120,7 +120,7 @@ APInt::APInt(unsigned numBits, unsigned numWords, const uint64_t bigVal[]) } APInt::APInt(unsigned numbits, StringRef Str, uint8_t radix) - : BitWidth(numbits), VAL(0) { + : VAL(0), BitWidth(numbits) { assert(BitWidth && "Bitwidth too small"); fromString(numbits, Str, radix); } -- 2.50.1