]> granicus.if.org Git - clang/commitdiff
Add CharUnits::RoundUpToAlignment() to simplify rounding in character units.
authorKen Dyck <kd@kendyck.com>
Thu, 20 Jan 2011 01:59:55 +0000 (01:59 +0000)
committerKen Dyck <kd@kendyck.com>
Thu, 20 Jan 2011 01:59:55 +0000 (01:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123868 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/CharUnits.h
lib/CodeGen/CGBlocks.cpp

index 1044fb742a5a61f7b3ee47a39b275397c69d94fb..cf909e88220f8d70fde68e6c89f632d8ae5771ca 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "llvm/ADT/DenseMapInfo.h"
 #include "llvm/Support/DataTypes.h"
+#include "llvm/Support/MathExtras.h"
 
 namespace clang {
   
@@ -142,6 +143,14 @@ namespace clang {
       /// getQuantity - Get the raw integer representation of this quantity.
       QuantityType getQuantity() const { return Quantity; }
 
+      /// RoundUpToAlignment - Returns the next integer (mod 2**64) that is
+      /// greater than or equal to this quantity and is a multiple of \arg
+      /// Align. Align must be non-zero.
+      CharUnits RoundUpToAlignment(const CharUnits &Align) {
+        return CharUnits(llvm::RoundUpToAlignment(Quantity, 
+                                                  Align.Quantity));
+      }
+
 
   }; // class CharUnit
 } // namespace clang
index 3cf128b8c654a812108a226be7146edf3424544a..a594a0bb9e2dc50bdcbc36c7528d3031131c7b81 100644 (file)
@@ -900,9 +900,7 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD, const BlockExpr *BExpr,
 
   // The runtime needs a minimum alignment of a void *.
   CharUnits MinAlign = getContext().getTypeAlignInChars(getContext().VoidPtrTy);
-  BlockOffset = CharUnits::fromQuantity(
-      llvm::RoundUpToAlignment(BlockOffset.getQuantity(), 
-                               MinAlign.getQuantity()));
+  BlockOffset = BlockOffset.RoundUpToAlignment(MinAlign);
 
   Info.BlockSize = BlockOffset;
   Info.BlockAlign = BlockAlign;
@@ -917,8 +915,7 @@ CharUnits BlockFunction::getBlockOffset(CharUnits Size, CharUnits Align) {
   CharUnits OldOffset = BlockOffset;
 
   // Ensure proper alignment, even if it means we have to have a gap
-  BlockOffset = CharUnits::fromQuantity(
-      llvm::RoundUpToAlignment(BlockOffset.getQuantity(), Align.getQuantity()));
+  BlockOffset = BlockOffset.RoundUpToAlignment(Align);
   BlockAlign = std::max(Align, BlockAlign);
 
   CharUnits Pad = BlockOffset - OldOffset;