[llvm] r368000 - [LLVM][Alignment] Introduce Alignment In GlobalObject
Guillaume Chatelet via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 6 02:03:21 PDT 2019
Author: gchatelet
Date: Tue Aug 6 02:03:21 2019
New Revision: 368000
URL: http://llvm.org/viewvc/llvm-project?rev=368000&view=rev
Log:
[LLVM][Alignment] Introduce Alignment In GlobalObject
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: jfb
Subscribers: hiraditya, dexonsmith, llvm-commits, courbet
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65748
Address comments
Modified:
llvm/trunk/include/llvm/IR/GlobalObject.h
llvm/trunk/include/llvm/Support/Alignment.h
llvm/trunk/lib/IR/Globals.cpp
llvm/trunk/unittests/IR/ValueTest.cpp
llvm/trunk/unittests/Support/AlignmentTest.cpp
Modified: llvm/trunk/include/llvm/IR/GlobalObject.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/GlobalObject.h?rev=368000&r1=367999&r2=368000&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/GlobalObject.h (original)
+++ llvm/trunk/include/llvm/IR/GlobalObject.h Tue Aug 6 02:03:21 2019
@@ -17,6 +17,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/Value.h"
+#include "llvm/Support/Alignment.h"
#include <string>
#include <utility>
@@ -58,9 +59,13 @@ public:
unsigned getAlignment() const {
unsigned Data = getGlobalValueSubClassData();
unsigned AlignmentData = Data & AlignmentMask;
- return (1u << AlignmentData) >> 1;
+ MaybeAlign Align = decodeMaybeAlign(AlignmentData);
+ return Align ? Align->value() : 0;
}
+
+ /// FIXME: Remove this setter once the migration to MaybeAlign is over.
void setAlignment(unsigned Align);
+ void setAlignment(MaybeAlign Align);
unsigned getGlobalObjectSubClassData() const {
unsigned ValueData = getGlobalValueSubClassData();
Modified: llvm/trunk/include/llvm/Support/Alignment.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Alignment.h?rev=368000&r1=367999&r2=368000&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Alignment.h (original)
+++ llvm/trunk/include/llvm/Support/Alignment.h Tue Aug 6 02:03:21 2019
@@ -101,7 +101,7 @@ public:
explicit MaybeAlign(uint64_t Value) {
assert((Value == 0 || llvm::isPowerOf2_64(Value)) &&
- "Alignment is not 0 or a power of 2");
+ "Alignment is neither 0 nor a power of 2");
if (Value)
emplace(Value);
}
Modified: llvm/trunk/lib/IR/Globals.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Globals.cpp?rev=368000&r1=367999&r2=368000&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Globals.cpp (original)
+++ llvm/trunk/lib/IR/Globals.cpp Tue Aug 6 02:03:21 2019
@@ -114,13 +114,17 @@ unsigned GlobalValue::getAddressSpace()
}
void GlobalObject::setAlignment(unsigned Align) {
- assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
- assert(Align <= MaximumAlignment &&
- "Alignment is greater than MaximumAlignment!");
- unsigned AlignmentData = Log2_32(Align) + 1;
+ setAlignment(MaybeAlign(Align));
+}
+
+void GlobalObject::setAlignment(MaybeAlign Align) {
+ assert(!Align || Align <= MaximumAlignment &&
+ "Alignment is greater than MaximumAlignment!");
+ unsigned AlignmentData = encode(Align);
unsigned OldData = getGlobalValueSubClassData();
setGlobalValueSubClassData((OldData & ~AlignmentMask) | AlignmentData);
- assert(getAlignment() == Align && "Alignment representation error!");
+ assert(MaybeAlign(getAlignment()) == Align &&
+ "Alignment representation error!");
}
void GlobalObject::copyAttributesFrom(const GlobalObject *Src) {
Modified: llvm/trunk/unittests/IR/ValueTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/ValueTest.cpp?rev=368000&r1=367999&r2=368000&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/ValueTest.cpp (original)
+++ llvm/trunk/unittests/IR/ValueTest.cpp Tue Aug 6 02:03:21 2019
@@ -99,7 +99,8 @@ TEST(GlobalTest, AlignDeath) {
Constant::getAllOnesValue(Int32Ty), "var", nullptr,
GlobalVariable::NotThreadLocal, 1);
- EXPECT_DEATH(Var->setAlignment(536870913U), "Alignment is not a power of 2");
+ EXPECT_DEATH(Var->setAlignment(536870913U),
+ "Alignment is neither 0 nor a power of 2");
EXPECT_DEATH(Var->setAlignment(1073741824U),
"Alignment is greater than MaximumAlignment");
}
Modified: llvm/trunk/unittests/Support/AlignmentTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/AlignmentTest.cpp?rev=368000&r1=367999&r2=368000&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/AlignmentTest.cpp (original)
+++ llvm/trunk/unittests/Support/AlignmentTest.cpp Tue Aug 6 02:03:21 2019
@@ -256,7 +256,8 @@ TEST(AlignmentDeathTest, InvalidCTors) {
EXPECT_DEATH((Align(0)), "Value must not be 0");
for (uint64_t Value : getNonPowerOfTwo()) {
EXPECT_DEATH((Align(Value)), "Alignment is not a power of 2");
- EXPECT_DEATH((MaybeAlign(Value)), "Alignment is not 0 or a power of 2");
+ EXPECT_DEATH((MaybeAlign(Value)),
+ "Alignment is neither 0 nor a power of 2");
}
}
More information about the llvm-commits
mailing list