[PATCH] D69258: [Alignment][NFC] Add a helper function to DataLayout
Guillaume Chatelet via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 21 07:02:17 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc7a76d6bf011: [Alignment][NFC] Add a helper function to DataLayout (authored by gchatelet).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D69258/new/
https://reviews.llvm.org/D69258
Files:
llvm/include/llvm/IR/DataLayout.h
llvm/unittests/IR/DataLayoutTest.cpp
Index: llvm/unittests/IR/DataLayoutTest.cpp
===================================================================
--- llvm/unittests/IR/DataLayoutTest.cpp
+++ 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 @@
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
Index: llvm/include/llvm/IR/DataLayout.h
===================================================================
--- llvm/include/llvm/IR/DataLayout.h
+++ llvm/include/llvm/IR/DataLayout.h
@@ -504,6 +504,13 @@
/// 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69258.225875.patch
Type: text/x-patch
Size: 1738 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191021/c1ed6fc9/attachment.bin>
More information about the llvm-commits
mailing list