summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Chatelet <gchatelet@google.com>2019-10-21 13:58:33 +0000
committerGuillaume Chatelet <gchatelet@google.com>2019-10-21 13:58:33 +0000
commitc7a76d6bf011754a0d3e9449c77b3cfa4bb01f6e (patch)
treed93608f74a7480ad429ef7b3659a22f116daad53
parentfe263c4f0f8b123ed335dc287524bc558eec0e16 (diff)
downloadbcm5719-llvm-c7a76d6bf011754a0d3e9449c77b3cfa4bb01f6e.tar.gz
bcm5719-llvm-c7a76d6bf011754a0d3e9449c77b3cfa4bb01f6e.zip
[Alignment][NFC] Add a helper function to DataLayout
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69258 llvm-svn: 375413
-rw-r--r--llvm/include/llvm/IR/DataLayout.h7
-rw-r--r--llvm/unittests/IR/DataLayoutTest.cpp12
2 files changed, 19 insertions, 0 deletions
diff --git a/llvm/include/llvm/IR/DataLayout.h b/llvm/include/llvm/IR/DataLayout.h
index 08fd269807a..8988f7d3c30 100644
--- a/llvm/include/llvm/IR/DataLayout.h
+++ b/llvm/include/llvm/IR/DataLayout.h
@@ -504,6 +504,13 @@ public:
/// Returns the minimum ABI-required alignment for the specified type.
unsigned getABITypeAlignment(Type *Ty) const;
+ /// Helper function to return `Alignment` if it's set or the result of
+ /// `getABITypeAlignment(Ty)`, in any case the result is a valid alignment.
+ inline Align getValueOrABITypeAlignment(MaybeAlign Alignment,
+ Type *Ty) const {
+ return Alignment ? *Alignment : Align(getABITypeAlignment(Ty));
+ }
+
/// Returns the minimum ABI-required alignment for an integer type of
/// the specified bitwidth.
Align getABIIntegerTypeAlignment(unsigned BitWidth) const;
diff --git a/llvm/unittests/IR/DataLayoutTest.cpp b/llvm/unittests/IR/DataLayoutTest.cpp
index e24e8e045db..de8ac253c45 100644
--- a/llvm/unittests/IR/DataLayoutTest.cpp
+++ b/llvm/unittests/IR/DataLayoutTest.cpp
@@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Type.h"
#include "gtest/gtest.h"
using namespace llvm;
@@ -44,4 +46,14 @@ TEST(DataLayoutTest, FunctionPtrAlign) {
EXPECT_EQ(a, c);
}
+TEST(DataLayoutTest, ValueOrABITypeAlignment) {
+ const DataLayout DL("Fi8");
+ LLVMContext Context;
+ Type *const FourByteAlignType = Type::getInt32Ty(Context);
+ EXPECT_EQ(Align(16),
+ DL.getValueOrABITypeAlignment(MaybeAlign(16), FourByteAlignType));
+ EXPECT_EQ(Align(4),
+ DL.getValueOrABITypeAlignment(MaybeAlign(), FourByteAlignType));
+}
+
} // anonymous namespace
OpenPOWER on IntegriCloud