[llvm] r368002 - [LLVM][Alignment] Introduce Alignment In Attributes
Guillaume Chatelet via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 6 02:16:34 PDT 2019
Author: gchatelet
Date: Tue Aug 6 02:16:33 2019
New Revision: 368002
URL: http://llvm.org/viewvc/llvm-project?rev=368002&view=rev
Log:
[LLVM][Alignment] Introduce Alignment In Attributes
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/D65742
Modified:
llvm/trunk/include/llvm/IR/Attributes.h
llvm/trunk/lib/IR/Attributes.cpp
Modified: llvm/trunk/include/llvm/IR/Attributes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Attributes.h?rev=368002&r1=368001&r2=368002&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Attributes.h (original)
+++ llvm/trunk/include/llvm/IR/Attributes.h Tue Aug 6 02:16:33 2019
@@ -22,6 +22,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Config/llvm-config.h"
+#include "llvm/Support/Alignment.h"
#include "llvm/Support/PointerLikeTypeTraits.h"
#include <bitset>
#include <cassert>
@@ -705,8 +706,8 @@ template <> struct DenseMapInfo<Attribut
class AttrBuilder {
std::bitset<Attribute::EndAttrKinds> Attrs;
std::map<std::string, std::string> TargetDepAttrs;
- uint64_t Alignment = 0;
- uint64_t StackAlignment = 0;
+ MaybeAlign Alignment;
+ MaybeAlign StackAlignment;
uint64_t DerefBytes = 0;
uint64_t DerefOrNullBytes = 0;
uint64_t AllocSizeArgs = 0;
@@ -773,10 +774,12 @@ public:
bool hasAlignmentAttr() const;
/// Retrieve the alignment attribute, if it exists.
- uint64_t getAlignment() const { return Alignment; }
+ uint64_t getAlignment() const { return Alignment ? Alignment->value() : 0; }
/// Retrieve the stack alignment attribute, if it exists.
- uint64_t getStackAlignment() const { return StackAlignment; }
+ uint64_t getStackAlignment() const {
+ return StackAlignment ? StackAlignment->value() : 0;
+ }
/// Retrieve the number of dereferenceable bytes, if the
/// dereferenceable attribute exists (zero is returned otherwise).
Modified: llvm/trunk/lib/IR/Attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Attributes.cpp?rev=368002&r1=368001&r2=368002&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Attributes.cpp (original)
+++ llvm/trunk/lib/IR/Attributes.cpp Tue Aug 6 02:16:33 2019
@@ -1438,7 +1438,9 @@ AttrBuilder::AttrBuilder(AttributeSet AS
void AttrBuilder::clear() {
Attrs.reset();
TargetDepAttrs.clear();
- Alignment = StackAlignment = DerefBytes = DerefOrNullBytes = 0;
+ Alignment.reset();
+ StackAlignment.reset();
+ DerefBytes = DerefOrNullBytes = 0;
AllocSizeArgs = 0;
ByValType = nullptr;
}
@@ -1462,9 +1464,9 @@ AttrBuilder &AttrBuilder::addAttribute(A
Attrs[Kind] = true;
if (Kind == Attribute::Alignment)
- Alignment = Attr.getAlignment();
+ Alignment = MaybeAlign(Attr.getAlignment());
else if (Kind == Attribute::StackAlignment)
- StackAlignment = Attr.getStackAlignment();
+ StackAlignment = MaybeAlign(Attr.getStackAlignment());
else if (Kind == Attribute::ByVal)
ByValType = Attr.getValueAsType();
else if (Kind == Attribute::Dereferenceable)
@@ -1486,9 +1488,9 @@ AttrBuilder &AttrBuilder::removeAttribut
Attrs[Val] = false;
if (Val == Attribute::Alignment)
- Alignment = 0;
+ Alignment.reset();
else if (Val == Attribute::StackAlignment)
- StackAlignment = 0;
+ StackAlignment.reset();
else if (Val == Attribute::ByVal)
ByValType = nullptr;
else if (Val == Attribute::Dereferenceable)
@@ -1517,23 +1519,25 @@ std::pair<unsigned, Optional<unsigned>>
return unpackAllocSizeArgs(AllocSizeArgs);
}
-AttrBuilder &AttrBuilder::addAlignmentAttr(unsigned Align) {
- if (Align == 0) return *this;
+AttrBuilder &AttrBuilder::addAlignmentAttr(unsigned A) {
+ MaybeAlign Align(A);
+ if (!Align)
+ return *this;
- assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
- assert(Align <= 0x40000000 && "Alignment too large.");
+ assert(*Align <= 0x40000000 && "Alignment too large.");
Attrs[Attribute::Alignment] = true;
Alignment = Align;
return *this;
}
-AttrBuilder &AttrBuilder::addStackAlignmentAttr(unsigned Align) {
+AttrBuilder &AttrBuilder::addStackAlignmentAttr(unsigned A) {
+ MaybeAlign Align(A);
// Default alignment, allow the target to define how to align it.
- if (Align == 0) return *this;
+ if (!Align)
+ return *this;
- assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
- assert(Align <= 0x100 && "Alignment too large.");
+ assert(*Align <= 0x100 && "Alignment too large.");
Attrs[Attribute::StackAlignment] = true;
StackAlignment = Align;
@@ -1610,10 +1614,10 @@ AttrBuilder &AttrBuilder::merge(const At
AttrBuilder &AttrBuilder::remove(const AttrBuilder &B) {
// FIXME: What if both have alignments, but they don't match?!
if (B.Alignment)
- Alignment = 0;
+ Alignment.reset();
if (B.StackAlignment)
- StackAlignment = 0;
+ StackAlignment.reset();
if (B.DerefBytes)
DerefBytes = 0;
More information about the llvm-commits
mailing list