aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/APInt.cpp
diff options
context:
space:
mode:
authorGuillaume Chatelet <gchatelet@google.com>2023-06-26 13:58:30 +0000
committerGuillaume Chatelet <gchatelet@google.com>2023-06-27 09:27:47 +0000
commitb745c123857e0153d75f8793df79497c41f39bf5 (patch)
treecd7f89346801339e19e85960c81557bf3f4bc317 /llvm/lib/Support/APInt.cpp
parent956f5c5f6de88af7d0c9844ab40979bb45a51ad4 (diff)
downloadllvm-b745c123857e0153d75f8793df79497c41f39bf5.zip
llvm-b745c123857e0153d75f8793df79497c41f39bf5.tar.gz
llvm-b745c123857e0153d75f8793df79497c41f39bf5.tar.bz2
[Align] Add isAligned taking an APInt
This showed up in https://reviews.llvm.org/D153308 Reviewed By: courbet, nikic Differential Revision: https://reviews.llvm.org/D153356
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r--llvm/lib/Support/APInt.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index bd8358c..05b1526 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -19,6 +19,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/bit.h"
#include "llvm/Config/llvm-config.h"
+#include "llvm/Support/Alignment.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
@@ -164,6 +165,14 @@ void APInt::Profile(FoldingSetNodeID& ID) const {
ID.AddInteger(U.pVal[i]);
}
+bool APInt::isAligned(Align A) const {
+ if (isZero())
+ return true;
+ const unsigned TrailingZeroes = countr_zero();
+ const unsigned MinimumTrailingZeroes = Log2(A);
+ return TrailingZeroes >= MinimumTrailingZeroes;
+}
+
/// Prefix increment operator. Increments the APInt by one.
APInt& APInt::operator++() {
if (isSingleWord())