[llvm] r367817 - [LLVM][Alignment] Introduce Alignment Type in DataLayout
Guillaume Chatelet via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 5 02:00:44 PDT 2019
Author: gchatelet
Date: Mon Aug 5 02:00:43 2019
New Revision: 367817
URL: http://llvm.org/viewvc/llvm-project?rev=367817&view=rev
Log:
[LLVM][Alignment] Introduce Alignment Type in DataLayout
Summary:
This is patch is part of a serie 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, jfb, jakehehrlich
Subscribers: hiraditya, dexonsmith, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65521
Make getFunctionPtrAlign() return MaybeAlign
Modified:
llvm/trunk/include/llvm/IR/DataLayout.h
llvm/trunk/lib/CodeGen/GlobalISel/CombinerHelper.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/trunk/lib/IR/DataLayout.cpp
llvm/trunk/lib/IR/Value.cpp
llvm/trunk/lib/Transforms/Utils/Local.cpp
llvm/trunk/unittests/IR/DataLayoutTest.cpp
Modified: llvm/trunk/include/llvm/IR/DataLayout.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DataLayout.h?rev=367817&r1=367816&r2=367817&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DataLayout.h (original)
+++ llvm/trunk/include/llvm/IR/DataLayout.h Mon Aug 5 02:00:43 2019
@@ -29,6 +29,7 @@
#include "llvm/Support/Casting.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
+#include "llvm/Support/Alignment.h"
#include <cassert>
#include <cstdint>
#include <string>
@@ -120,10 +121,10 @@ private:
bool BigEndian;
unsigned AllocaAddrSpace;
- unsigned StackNaturalAlign;
+ MaybeAlign StackNaturalAlign;
unsigned ProgramAddrSpace;
- unsigned FunctionPtrAlign;
+ MaybeAlign FunctionPtrAlign;
FunctionPtrAlignType TheFunctionPtrAlignType;
enum ManglingModeT {
@@ -261,17 +262,17 @@ public:
bool isIllegalInteger(uint64_t Width) const { return !isLegalInteger(Width); }
/// Returns true if the given alignment exceeds the natural stack alignment.
- bool exceedsNaturalStackAlignment(unsigned Align) const {
- return (StackNaturalAlign != 0) && (Align > StackNaturalAlign);
+ bool exceedsNaturalStackAlignment(llvm::Align Align) const {
+ return StackNaturalAlign && (Align > StackNaturalAlign);
}
- unsigned getStackAlignment() const { return StackNaturalAlign; }
+ unsigned getStackAlignment() const { return StackNaturalAlign ? StackNaturalAlign->value() : 0; }
unsigned getAllocaAddrSpace() const { return AllocaAddrSpace; }
/// Returns the alignment of function pointers, which may or may not be
/// related to the alignment of functions.
/// \see getFunctionPtrAlignType
- unsigned getFunctionPtrAlign() const { return FunctionPtrAlign; }
+ MaybeAlign getFunctionPtrAlign() const { return FunctionPtrAlign; }
/// Return the type of function pointer alignment.
/// \see getFunctionPtrAlign
Modified: llvm/trunk/lib/CodeGen/GlobalISel/CombinerHelper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/CombinerHelper.cpp?rev=367817&r1=367816&r2=367817&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/CombinerHelper.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/CombinerHelper.cpp Mon Aug 5 02:00:43 2019
@@ -698,7 +698,7 @@ bool CombinerHelper::optimizeMemcpy(Mach
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
if (!TRI->needsStackRealignment(MF))
while (NewAlign > Align &&
- DL.exceedsNaturalStackAlignment(NewAlign))
+ DL.exceedsNaturalStackAlignment(llvm::Align(NewAlign)))
NewAlign /= 2;
if (NewAlign > Align) {
@@ -804,7 +804,7 @@ bool CombinerHelper::optimizeMemmove(Mac
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
if (!TRI->needsStackRealignment(MF))
while (NewAlign > Align &&
- DL.exceedsNaturalStackAlignment(NewAlign))
+ DL.exceedsNaturalStackAlignment(llvm::Align(NewAlign)))
NewAlign /= 2;
if (NewAlign > Align) {
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=367817&r1=367816&r2=367817&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Mon Aug 5 02:00:43 2019
@@ -5804,7 +5804,7 @@ static SDValue getMemcpyLoadsAndStores(S
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
if (!TRI->needsStackRealignment(MF))
while (NewAlign > Align &&
- DL.exceedsNaturalStackAlignment(NewAlign))
+ DL.exceedsNaturalStackAlignment(llvm::Align(NewAlign)))
NewAlign /= 2;
if (NewAlign > Align) {
Modified: llvm/trunk/lib/IR/DataLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DataLayout.cpp?rev=367817&r1=367816&r2=367817&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DataLayout.cpp (original)
+++ llvm/trunk/lib/IR/DataLayout.cpp Mon Aug 5 02:00:43 2019
@@ -182,9 +182,9 @@ void DataLayout::reset(StringRef Desc) {
LayoutMap = nullptr;
BigEndian = false;
AllocaAddrSpace = 0;
- StackNaturalAlign = 0;
+ StackNaturalAlign.reset();
ProgramAddrSpace = 0;
- FunctionPtrAlign = 0;
+ FunctionPtrAlign.reset();
TheFunctionPtrAlignType = FunctionPtrAlignType::Independent;
ManglingMode = MM_None;
NonIntegralAddressSpaces.clear();
@@ -378,7 +378,7 @@ void DataLayout::parseSpecifier(StringRe
}
break;
case 'S': { // Stack natural alignment.
- StackNaturalAlign = inBytes(getInt(Tok));
+ StackNaturalAlign = MaybeAlign(inBytes(getInt(Tok)));
break;
}
case 'F': {
@@ -394,7 +394,7 @@ void DataLayout::parseSpecifier(StringRe
"datalayout string");
}
Tok = Tok.substr(1);
- FunctionPtrAlign = inBytes(getInt(Tok));
+ FunctionPtrAlign = MaybeAlign(inBytes(getInt(Tok)));
break;
}
case 'P': { // Function address space.
Modified: llvm/trunk/lib/IR/Value.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Value.cpp?rev=367817&r1=367816&r2=367817&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Value.cpp (original)
+++ llvm/trunk/lib/IR/Value.cpp Mon Aug 5 02:00:43 2019
@@ -681,11 +681,13 @@ unsigned Value::getPointerAlignment(cons
unsigned Align = 0;
if (auto *GO = dyn_cast<GlobalObject>(this)) {
if (isa<Function>(GO)) {
+ MaybeAlign FunctionPtrAlign = DL.getFunctionPtrAlign();
+ unsigned Align = FunctionPtrAlign ? FunctionPtrAlign->value() : 0;
switch (DL.getFunctionPtrAlignType()) {
case DataLayout::FunctionPtrAlignType::Independent:
- return DL.getFunctionPtrAlign();
+ return Align;
case DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign:
- return std::max(DL.getFunctionPtrAlign(), GO->getAlignment());
+ return std::max(Align, GO->getAlignment());
}
}
Align = GO->getAlignment();
Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=367817&r1=367816&r2=367817&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/Local.cpp Mon Aug 5 02:00:43 2019
@@ -1152,7 +1152,7 @@ static unsigned enforceKnownAlignment(Va
// If the preferred alignment is greater than the natural stack alignment
// then don't round up. This avoids dynamic stack realignment.
- if (DL.exceedsNaturalStackAlignment(PrefAlign))
+ if (DL.exceedsNaturalStackAlignment(llvm::Align(PrefAlign)))
return Align;
AI->setAlignment(PrefAlign);
return PrefAlign;
Modified: llvm/trunk/unittests/IR/DataLayoutTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/DataLayoutTest.cpp?rev=367817&r1=367816&r2=367817&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/DataLayoutTest.cpp (original)
+++ llvm/trunk/unittests/IR/DataLayoutTest.cpp Mon Aug 5 02:00:43 2019
@@ -14,15 +14,15 @@ using namespace llvm;
namespace {
TEST(DataLayoutTest, FunctionPtrAlign) {
- EXPECT_EQ(0U, DataLayout("").getFunctionPtrAlign());
- EXPECT_EQ(1U, DataLayout("Fi8").getFunctionPtrAlign());
- EXPECT_EQ(2U, DataLayout("Fi16").getFunctionPtrAlign());
- EXPECT_EQ(4U, DataLayout("Fi32").getFunctionPtrAlign());
- EXPECT_EQ(8U, DataLayout("Fi64").getFunctionPtrAlign());
- EXPECT_EQ(1U, DataLayout("Fn8").getFunctionPtrAlign());
- EXPECT_EQ(2U, DataLayout("Fn16").getFunctionPtrAlign());
- EXPECT_EQ(4U, DataLayout("Fn32").getFunctionPtrAlign());
- EXPECT_EQ(8U, DataLayout("Fn64").getFunctionPtrAlign());
+ EXPECT_EQ(MaybeAlign(0), DataLayout("").getFunctionPtrAlign());
+ EXPECT_EQ(MaybeAlign(1), DataLayout("Fi8").getFunctionPtrAlign());
+ EXPECT_EQ(MaybeAlign(2), DataLayout("Fi16").getFunctionPtrAlign());
+ EXPECT_EQ(MaybeAlign(4), DataLayout("Fi32").getFunctionPtrAlign());
+ EXPECT_EQ(MaybeAlign(8), DataLayout("Fi64").getFunctionPtrAlign());
+ EXPECT_EQ(MaybeAlign(1), DataLayout("Fn8").getFunctionPtrAlign());
+ EXPECT_EQ(MaybeAlign(2), DataLayout("Fn16").getFunctionPtrAlign());
+ EXPECT_EQ(MaybeAlign(4), DataLayout("Fn32").getFunctionPtrAlign());
+ EXPECT_EQ(MaybeAlign(8), DataLayout("Fn64").getFunctionPtrAlign());
EXPECT_EQ(DataLayout::FunctionPtrAlignType::Independent, \
DataLayout("").getFunctionPtrAlignType());
EXPECT_EQ(DataLayout::FunctionPtrAlignType::Independent, \
More information about the llvm-commits
mailing list