diff options
author | Chris Lattner <sabre@nondot.org> | 2008-12-08 07:11:56 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-12-08 07:11:56 +0000 |
commit | bedb8c1d35e420165fca7455d4025bf82913a38f (patch) | |
tree | b1eb6e902319b8ff413eaa496971e179e2251b6a /include/llvm/Target/TargetData.h | |
parent | 149cfc35197229d229c5737046210b5ade06e557 (diff) |
introduce a new RoundUpAlignment helper function, use it to
remove some more 64-bit divs and rems from the StructLayout
ctor.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60692 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Target/TargetData.h')
-rw-r--r-- | include/llvm/Target/TargetData.h | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/include/llvm/Target/TargetData.h b/include/llvm/Target/TargetData.h index fdb21c5ea1..c75d514dbf 100644 --- a/include/llvm/Target/TargetData.h +++ b/include/llvm/Target/TargetData.h @@ -178,12 +178,8 @@ public: /// that alloca reserves for this type. For example, returns 12 or 16 for /// x86_fp80, depending on alignment. uint64_t getABITypeSize(const Type* Ty) const { - // The alignment of a type is always a power of two. - unsigned char AlignMinusOne = getABITypeAlignment(Ty)-1; - // Round up to the next alignment boundary. - uint64_t RoundUp = getTypeStoreSize(Ty) + AlignMinusOne; - return RoundUp &= ~uint64_t(AlignMinusOne); + return RoundUpAlignment(getTypeStoreSize(Ty), getABITypeAlignment(Ty)); } /// getABITypeSizeInBits - Return the offset in bits between successive @@ -244,6 +240,16 @@ public: /// requested alignment (if the global has one). unsigned getPreferredAlignmentLog(const GlobalVariable *GV) const; + /// RoundUpAlignment - Round the specified value up to the next alignment + /// boundary specified by Alignment. For example, 7 rounded up to an + /// alignment boundary of 4 is 8. 8 rounded up to the alignment boundary of 4 + /// is 8 because it is already aligned. + template <typename UIntTy> + static UIntTy RoundUpAlignment(UIntTy Val, unsigned Alignment) { + assert((Alignment & (Alignment-1)) == 0 && "Alignment must be power of 2!"); + return (Val + (Alignment-1)) & ~UIntTy(Alignment-1); + } + static char ID; // Pass identification, replacement for typeid }; |