summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKen Dyck <kd@kendyck.com>2011-01-20 01:59:55 +0000
committerKen Dyck <kd@kendyck.com>2011-01-20 01:59:55 +0000
commit7d381c48fec57b35c3ce2e400ce53f68c456eabd (patch)
treeeab7d7b1190c4de8a2434f53efd1e9418b259e40
parent2bbfba0f0c135203f0676dcb882322dd3c334ed9 (diff)
downloadbcm5719-llvm-7d381c48fec57b35c3ce2e400ce53f68c456eabd.tar.gz
bcm5719-llvm-7d381c48fec57b35c3ce2e400ce53f68c456eabd.zip
Add CharUnits::RoundUpToAlignment() to simplify rounding in character units.
llvm-svn: 123868
-rw-r--r--clang/include/clang/AST/CharUnits.h9
-rw-r--r--clang/lib/CodeGen/CGBlocks.cpp7
2 files changed, 11 insertions, 5 deletions
diff --git a/clang/include/clang/AST/CharUnits.h b/clang/include/clang/AST/CharUnits.h
index 1044fb742a5..cf909e88220 100644
--- a/clang/include/clang/AST/CharUnits.h
+++ b/clang/include/clang/AST/CharUnits.h
@@ -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
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 3cf128b8c65..a594a0bb9e2 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -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;
OpenPOWER on IntegriCloud