[cfe-commits] r123868 - in /cfe/trunk: include/clang/AST/CharUnits.h lib/CodeGen/CGBlocks.cpp

Ken Dyck kd at kendyck.com
Wed Jan 19 17:59:55 PST 2011


Author: kjdyck
Date: Wed Jan 19 19:59:55 2011
New Revision: 123868

URL: http://llvm.org/viewvc/llvm-project?rev=123868&view=rev
Log:
Add CharUnits::RoundUpToAlignment() to simplify rounding in character units.

Modified:
    cfe/trunk/include/clang/AST/CharUnits.h
    cfe/trunk/lib/CodeGen/CGBlocks.cpp

Modified: cfe/trunk/include/clang/AST/CharUnits.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CharUnits.h?rev=123868&r1=123867&r2=123868&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/CharUnits.h (original)
+++ cfe/trunk/include/clang/AST/CharUnits.h Wed Jan 19 19:59:55 2011
@@ -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 @@
       /// 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

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=123868&r1=123867&r2=123868&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Wed Jan 19 19:59:55 2011
@@ -900,9 +900,7 @@
 
   // 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 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;





More information about the cfe-commits mailing list