Skip to content

Commit

Permalink
Retire llvm::alignOf in favor of C++11 alignof.
Browse files Browse the repository at this point in the history
No functionality change intended.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284733 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
d0k committed Oct 20, 2016
1 parent 2913220 commit cb58e1e
Show file tree
Hide file tree
Showing 25 changed files with 73 additions and 98 deletions.
2 changes: 1 addition & 1 deletion include/llvm/ADT/IntervalMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ class IntervalMap {

public:
explicit IntervalMap(Allocator &a) : height(0), rootSize(0), allocator(a) {
assert((uintptr_t(data.buffer) & (alignOf<RootLeaf>() - 1)) == 0 &&
assert((uintptr_t(data.buffer) & (alignof(RootLeaf) - 1)) == 0 &&
"Insufficient alignment");
new(&rootLeaf()) RootLeaf();
}
Expand Down
2 changes: 1 addition & 1 deletion include/llvm/ADT/StringMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class StringMapEntry : public StringMapEntryBase {
// terminator.
unsigned AllocSize = static_cast<unsigned>(sizeof(StringMapEntry))+
KeyLength+1;
unsigned Alignment = alignOf<StringMapEntry>();
unsigned Alignment = alignof(StringMapEntry);

StringMapEntry *NewItem =
static_cast<StringMapEntry*>(Allocator.Allocate(AllocSize,Alignment));
Expand Down
1 change: 0 additions & 1 deletion include/llvm/CodeGen/LiveInterval.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include "llvm/ADT/IntEqClasses.h"
#include "llvm/CodeGen/SlotIndexes.h"
#include "llvm/Support/AlignOf.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Target/TargetRegisterInfo.h"
#include <cassert>
Expand Down
4 changes: 2 additions & 2 deletions include/llvm/CodeGen/SelectionDAG.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ class SelectionDAG {
/// The AllocatorType for allocating SDNodes. We use
/// pool allocation with recycling.
typedef RecyclingAllocator<BumpPtrAllocator, SDNode, sizeof(LargestSDNode),
AlignOf<MostAlignedSDNode>::Alignment>
NodeAllocatorType;
alignof(MostAlignedSDNode)>
NodeAllocatorType;

/// Pool allocation for nodes.
NodeAllocatorType NodeAllocator;
Expand Down
5 changes: 2 additions & 3 deletions include/llvm/CodeGen/SlotIndexes.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,8 @@ namespace llvm {

IndexListEntry* createEntry(MachineInstr *mi, unsigned index) {
IndexListEntry *entry =
static_cast<IndexListEntry*>(
ileAllocator.Allocate(sizeof(IndexListEntry),
alignOf<IndexListEntry>()));
static_cast<IndexListEntry *>(ileAllocator.Allocate(
sizeof(IndexListEntry), alignof(IndexListEntry)));

new (entry) IndexListEntry(mi, index);

Expand Down
2 changes: 1 addition & 1 deletion include/llvm/IR/DerivedTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class FunctionType : public Type {
return T->getTypeID() == FunctionTyID;
}
};
static_assert(AlignOf<FunctionType>::Alignment >= AlignOf<Type *>::Alignment,
static_assert(alignof(FunctionType) >= alignof(Type *),
"Alignment sufficient for objects appended to FunctionType");

bool Type::isFunctionVarArg() const {
Expand Down
5 changes: 2 additions & 3 deletions include/llvm/IR/User.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "llvm/ADT/iterator.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/AlignOf.h"
#include "llvm/Support/ErrorHandling.h"

namespace llvm {
Expand Down Expand Up @@ -250,9 +249,9 @@ class User : public Value {
}
};
// Either Use objects, or a Use pointer can be prepended to User.
static_assert(AlignOf<Use>::Alignment >= AlignOf<User>::Alignment,
static_assert(alignof(Use) >= alignof(User),
"Alignment is insufficient after objects prepended to User");
static_assert(AlignOf<Use *>::Alignment >= AlignOf<User>::Alignment,
static_assert(alignof(Use *) >= alignof(User),
"Alignment is insufficient after objects prepended to User");

template<> struct simplify_type<User::op_iterator> {
Expand Down
2 changes: 1 addition & 1 deletion include/llvm/Object/ELF.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ ELFFile<ELFT>::ELFFile(StringRef Object, std::error_code &EC)
return;
}

if (SectionTableOffset & (AlignOf<Elf_Shdr>::Alignment - 1)) {
if (SectionTableOffset & (alignof(Elf_Shdr) - 1)) {
// Invalid address alignment of section headers
EC = object_error::parse_failed;
return;
Expand Down
9 changes: 4 additions & 5 deletions include/llvm/Support/Allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#define LLVM_SUPPORT_ALLOCATOR_H

#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/AlignOf.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Memory.h"
Expand Down Expand Up @@ -74,7 +73,7 @@ template <typename DerivedT> class AllocatorBase {

/// \brief Allocate space for a sequence of objects without constructing them.
template <typename T> T *Allocate(size_t Num = 1) {
return static_cast<T *>(Allocate(Num * sizeof(T), AlignOf<T>::Alignment));
return static_cast<T *>(Allocate(Num * sizeof(T), alignof(T)));
}

/// \brief Deallocate space for a sequence of objects without constructing them.
Expand Down Expand Up @@ -381,7 +380,7 @@ template <typename T> class SpecificBumpPtrAllocator {
/// all memory allocated so far.
void DestroyAll() {
auto DestroyElements = [](char *Begin, char *End) {
assert(Begin == (char*)alignAddr(Begin, alignOf<T>()));
assert(Begin == (char *)alignAddr(Begin, alignof(T)));
for (char *Ptr = Begin; Ptr + sizeof(T) <= End; Ptr += sizeof(T))
reinterpret_cast<T *>(Ptr)->~T();
};
Expand All @@ -390,7 +389,7 @@ template <typename T> class SpecificBumpPtrAllocator {
++I) {
size_t AllocatedSlabSize = BumpPtrAllocator::computeSlabSize(
std::distance(Allocator.Slabs.begin(), I));
char *Begin = (char*)alignAddr(*I, alignOf<T>());
char *Begin = (char *)alignAddr(*I, alignof(T));
char *End = *I == Allocator.Slabs.back() ? Allocator.CurPtr
: (char *)*I + AllocatedSlabSize;

Expand All @@ -400,7 +399,7 @@ template <typename T> class SpecificBumpPtrAllocator {
for (auto &PtrAndSize : Allocator.CustomSizedSlabs) {
void *Ptr = PtrAndSize.first;
size_t Size = PtrAndSize.second;
DestroyElements((char*)alignAddr(Ptr, alignOf<T>()), (char *)Ptr + Size);
DestroyElements((char *)alignAddr(Ptr, alignof(T)), (char *)Ptr + Size);
}

Allocator.Reset();
Expand Down
5 changes: 2 additions & 3 deletions include/llvm/Support/ArrayRecycler.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ namespace llvm {
/// Arrays are allocated in a small number of fixed sizes. For each supported
/// array size, the ArrayRecycler keeps a free list of available arrays.
///
template<class T, size_t Align = AlignOf<T>::Alignment>
class ArrayRecycler {
template <class T, size_t Align = alignof(T)> class ArrayRecycler {
// The free list for a given array size is a simple singly linked list.
// We can't use iplist or Recycler here since those classes can't be copied.
struct FreeList {
FreeList *Next;
};

static_assert(Align >= AlignOf<FreeList>::Alignment, "Object underaligned");
static_assert(Align >= alignof(FreeList), "Object underaligned");
static_assert(sizeof(T) >= sizeof(FreeList), "Objects are too small");

// Keep a free list for each array size.
Expand Down
3 changes: 1 addition & 2 deletions include/llvm/Support/Endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#ifndef LLVM_SUPPORT_ENDIAN_H
#define LLVM_SUPPORT_ENDIAN_H

#include "llvm/Support/AlignOf.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/SwapByteOrder.h"

Expand All @@ -29,7 +28,7 @@ namespace detail {
/// \brief ::value is either alignment, or alignof(T) if alignment is 0.
template<class T, int alignment>
struct PickAlignment {
enum {value = alignment == 0 ? AlignOf<T>::Alignment : alignment};
enum { value = alignment == 0 ? alignof(T) : alignment };
};
} // end namespace detail

Expand Down
3 changes: 1 addition & 2 deletions include/llvm/Support/OnDiskHashTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#ifndef LLVM_SUPPORT_ONDISKHASHTABLE_H
#define LLVM_SUPPORT_ONDISKHASHTABLE_H

#include "llvm/Support/AlignOf.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/EndianStream.h"
Expand Down Expand Up @@ -208,7 +207,7 @@ template <typename Info> class OnDiskChainedHashTableGenerator {

// Pad with zeros so that we can start the hashtable at an aligned address.
offset_type TableOff = Out.tell();
uint64_t N = llvm::OffsetToAlignment(TableOff, alignOf<offset_type>());
uint64_t N = llvm::OffsetToAlignment(TableOff, alignof(offset_type));
TableOff += N;
while (N--)
LE.write<uint8_t>(0);
Expand Down
6 changes: 2 additions & 4 deletions include/llvm/Support/PointerLikeTypeTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#ifndef LLVM_SUPPORT_POINTERLIKETYPETRAITS_H
#define LLVM_SUPPORT_POINTERLIKETYPETRAITS_H

#include "llvm/Support/AlignOf.h"
#include "llvm/Support/DataTypes.h"
#include <type_traits>

namespace llvm {

Expand All @@ -42,9 +42,7 @@ template <typename T> class PointerLikeTypeTraits<T *> {
static inline void *getAsVoidPointer(T *P) { return P; }
static inline T *getFromVoidPointer(void *P) { return static_cast<T *>(P); }

enum {
NumLowBitsAvailable = detail::ConstantLog2<AlignOf<T>::Alignment>::value
};
enum { NumLowBitsAvailable = detail::ConstantLog2<alignof(T)>::value };
};

template <> class PointerLikeTypeTraits<void *> {
Expand Down
5 changes: 2 additions & 3 deletions include/llvm/Support/Recycler.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#define LLVM_SUPPORT_RECYCLER_H

#include "llvm/ADT/ilist.h"
#include "llvm/Support/AlignOf.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/ErrorHandling.h"
#include <cassert>
Expand All @@ -32,7 +31,7 @@ void PrintRecyclerStats(size_t Size, size_t Align, size_t FreeListSize);
/// and facilitates reusing deallocated memory in place of allocating
/// new memory.
///
template<class T, size_t Size = sizeof(T), size_t Align = AlignOf<T>::Alignment>
template <class T, size_t Size = sizeof(T), size_t Align = alignof(T)>
class Recycler {
struct FreeNode {
FreeNode *Next;
Expand Down Expand Up @@ -80,7 +79,7 @@ class Recycler {

template<class SubClass, class AllocatorType>
SubClass *Allocate(AllocatorType &Allocator) {
static_assert(AlignOf<SubClass>::Alignment <= Align,
static_assert(alignof(SubClass) <= Align,
"Recycler allocation alignment is less than object align!");
static_assert(sizeof(SubClass) <= Size,
"Recycler allocation size is less than object size!");
Expand Down
4 changes: 2 additions & 2 deletions include/llvm/Support/RecyclingAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ namespace llvm {
/// RecyclingAllocator - This class wraps an Allocator, adding the
/// functionality of recycling deleted objects.
///
template<class AllocatorType, class T,
size_t Size = sizeof(T), size_t Align = AlignOf<T>::Alignment>
template <class AllocatorType, class T, size_t Size = sizeof(T),
size_t Align = alignof(T)>
class RecyclingAllocator {
private:
/// Base - Implementation details.
Expand Down
28 changes: 11 additions & 17 deletions include/llvm/Support/TrailingObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace trailing_objects_internal {
template <typename First, typename... Rest> class AlignmentCalcHelper {
private:
enum {
FirstAlignment = AlignOf<First>::Alignment,
FirstAlignment = alignof(First),
RestAlignment = AlignmentCalcHelper<Rest...>::Alignment,
};

Expand All @@ -74,7 +74,7 @@ template <typename First, typename... Rest> class AlignmentCalcHelper {

template <typename First> class AlignmentCalcHelper<First> {
public:
enum { Alignment = AlignOf<First>::Alignment };
enum { Alignment = alignof(First) };
};

/// The base class for TrailingObjects* classes.
Expand Down Expand Up @@ -143,8 +143,7 @@ class TrailingObjectsImpl<Align, BaseTy, TopTrailingObj, PrevTy, NextTy,
ParentType;

struct RequiresRealignment {
static const bool value =
llvm::AlignOf<PrevTy>::Alignment < llvm::AlignOf<NextTy>::Alignment;
static const bool value = alignof(PrevTy) < alignof(NextTy);
};

static LLVM_CONSTEXPR bool requiresRealignment() {
Expand Down Expand Up @@ -174,7 +173,7 @@ class TrailingObjectsImpl<Align, BaseTy, TopTrailingObj, PrevTy, NextTy,

if (requiresRealignment())
return reinterpret_cast<const NextTy *>(
llvm::alignAddr(Ptr, llvm::alignOf<NextTy>()));
llvm::alignAddr(Ptr, alignof(NextTy)));
else
return reinterpret_cast<const NextTy *>(Ptr);
}
Expand All @@ -188,8 +187,7 @@ class TrailingObjectsImpl<Align, BaseTy, TopTrailingObj, PrevTy, NextTy,
Obj, TrailingObjectsBase::OverloadToken<PrevTy>());

if (requiresRealignment())
return reinterpret_cast<NextTy *>(
llvm::alignAddr(Ptr, llvm::alignOf<NextTy>()));
return reinterpret_cast<NextTy *>(llvm::alignAddr(Ptr, alignof(NextTy)));
else
return reinterpret_cast<NextTy *>(Ptr);
}
Expand All @@ -201,9 +199,8 @@ class TrailingObjectsImpl<Align, BaseTy, TopTrailingObj, PrevTy, NextTy,
size_t SizeSoFar, size_t Count1,
typename ExtractSecondType<MoreTys, size_t>::type... MoreCounts) {
return ParentType::additionalSizeToAllocImpl(
(requiresRealignment()
? llvm::alignTo<llvm::AlignOf<NextTy>::Alignment>(SizeSoFar)
: SizeSoFar) +
(requiresRealignment() ? llvm::alignTo<alignof(NextTy)>(SizeSoFar)
: SizeSoFar) +
sizeof(NextTy) * Count1,
MoreCounts...);
}
Expand All @@ -216,10 +213,9 @@ class TrailingObjectsImpl<Align, BaseTy, TopTrailingObj, PrevTy, NextTy,
static_assert(sizeof...(MoreTys) == sizeof...(MoreCounts),
"Number of counts do not match number of types");
static const size_t value = ParentType::template AdditionalSizeToAllocImpl<
(RequiresRealignment::value
? llvm::AlignTo<llvm::AlignOf<NextTy>::Alignment>::
template from_value<SizeSoFar>::value
: SizeSoFar) +
(RequiresRealignment::value ? llvm::AlignTo<alignof(NextTy)>::
template from_value<SizeSoFar>::value
: SizeSoFar) +
sizeof(NextTy) * Count1,
MoreCounts...>::value;
};
Expand Down Expand Up @@ -407,9 +403,7 @@ class TrailingObjects : private trailing_objects_internal::TrailingObjectsImpl<
enum {
Size = TotalSizeToAlloc<Tys...>::template with_counts<Counts...>::value
};
typedef llvm::AlignedCharArray<
llvm::AlignOf<BaseTy>::Alignment, Size
> type;
typedef llvm::AlignedCharArray<alignof(BaseTy), Size> type;
};
};

Expand Down
5 changes: 2 additions & 3 deletions include/llvm/Transforms/Utils/SSAUpdaterImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ class SSAUpdaterImpl {
if (Info->NumPreds == 0)
Info->Preds = nullptr;
else
Info->Preds = static_cast<BBInfo**>
(Allocator.Allocate(Info->NumPreds * sizeof(BBInfo*),
AlignOf<BBInfo*>::Alignment));
Info->Preds = static_cast<BBInfo **>(Allocator.Allocate(
Info->NumPreds * sizeof(BBInfo *), alignof(BBInfo *)));

for (unsigned p = 0; p != Info->NumPreds; ++p) {
BlkT *Pred = Preds[p];
Expand Down
2 changes: 1 addition & 1 deletion lib/Analysis/GlobalsModRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class GlobalsAAResult::FunctionInfo {
return (AlignedMap *)P;
}
enum { NumLowBitsAvailable = 3 };
static_assert(AlignOf<AlignedMap>::Alignment >= (1 << NumLowBitsAvailable),
static_assert(alignof(AlignedMap) >= (1 << NumLowBitsAvailable),
"AlignedMap insufficiently aligned to have enough low bits.");
};

Expand Down
1 change: 0 additions & 1 deletion lib/CodeGen/MachineSSAUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/Support/AlignOf.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
Expand Down
6 changes: 3 additions & 3 deletions lib/IR/Metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,15 +434,15 @@ StringRef MDString::getString() const {
// prepended to them.
#define HANDLE_MDNODE_LEAF(CLASS) \
static_assert( \
llvm::AlignOf<uint64_t>::Alignment >= llvm::AlignOf<CLASS>::Alignment, \
alignof(uint64_t) >= alignof(CLASS), \
"Alignment is insufficient after objects prepended to " #CLASS);
#include "llvm/IR/Metadata.def"

void *MDNode::operator new(size_t Size, unsigned NumOps) {
size_t OpSize = NumOps * sizeof(MDOperand);
// uint64_t is the most aligned type we need support (ensured by static_assert
// above)
OpSize = alignTo(OpSize, llvm::alignOf<uint64_t>());
OpSize = alignTo(OpSize, alignof(uint64_t));
void *Ptr = reinterpret_cast<char *>(::operator new(OpSize + Size)) + OpSize;
MDOperand *O = static_cast<MDOperand *>(Ptr);
for (MDOperand *E = O - NumOps; O != E; --O)
Expand All @@ -453,7 +453,7 @@ void *MDNode::operator new(size_t Size, unsigned NumOps) {
void MDNode::operator delete(void *Mem) {
MDNode *N = static_cast<MDNode *>(Mem);
size_t OpSize = N->NumOperands * sizeof(MDOperand);
OpSize = alignTo(OpSize, llvm::alignOf<uint64_t>());
OpSize = alignTo(OpSize, alignof(uint64_t));

MDOperand *O = static_cast<MDOperand *>(Mem);
for (MDOperand *E = O - N->NumOperands; O != E; --O)
Expand Down
6 changes: 3 additions & 3 deletions lib/IR/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ FunctionType *FunctionType::get(Type *ReturnType,
FunctionType *FT;

if (I == pImpl->FunctionTypes.end()) {
FT = (FunctionType*) pImpl->TypeAllocator.
Allocate(sizeof(FunctionType) + sizeof(Type*) * (Params.size() + 1),
AlignOf<FunctionType>::Alignment);
FT = (FunctionType *)pImpl->TypeAllocator.Allocate(
sizeof(FunctionType) + sizeof(Type *) * (Params.size() + 1),
alignof(FunctionType));
new (FT) FunctionType(ReturnType, Params, isVarArg);
pImpl->FunctionTypes.insert(FT);
} else {
Expand Down
Loading

0 comments on commit cb58e1e

Please sign in to comment.