Skip to content

Commit b250500

Browse files
committed
Retire llvm::alignOf in favor of C++11 alignof.
No functionality change intended. llvm-svn: 284733
1 parent 5d8cdb8 commit b250500

25 files changed

+73
-98
lines changed

llvm/include/llvm/ADT/IntervalMap.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ class IntervalMap {
10411041

10421042
public:
10431043
explicit IntervalMap(Allocator &a) : height(0), rootSize(0), allocator(a) {
1044-
assert((uintptr_t(data.buffer) & (alignOf<RootLeaf>() - 1)) == 0 &&
1044+
assert((uintptr_t(data.buffer) & (alignof(RootLeaf) - 1)) == 0 &&
10451045
"Insufficient alignment");
10461046
new(&rootLeaf()) RootLeaf();
10471047
}

llvm/include/llvm/ADT/StringMap.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class StringMapEntry : public StringMapEntryBase {
157157
// terminator.
158158
unsigned AllocSize = static_cast<unsigned>(sizeof(StringMapEntry))+
159159
KeyLength+1;
160-
unsigned Alignment = alignOf<StringMapEntry>();
160+
unsigned Alignment = alignof(StringMapEntry);
161161

162162
StringMapEntry *NewItem =
163163
static_cast<StringMapEntry*>(Allocator.Allocate(AllocSize,Alignment));

llvm/include/llvm/CodeGen/LiveInterval.h

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
#include "llvm/ADT/IntEqClasses.h"
2525
#include "llvm/CodeGen/SlotIndexes.h"
26-
#include "llvm/Support/AlignOf.h"
2726
#include "llvm/Support/Allocator.h"
2827
#include "llvm/Target/TargetRegisterInfo.h"
2928
#include <cassert>

llvm/include/llvm/CodeGen/SelectionDAG.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ class SelectionDAG {
183183
/// The AllocatorType for allocating SDNodes. We use
184184
/// pool allocation with recycling.
185185
typedef RecyclingAllocator<BumpPtrAllocator, SDNode, sizeof(LargestSDNode),
186-
AlignOf<MostAlignedSDNode>::Alignment>
187-
NodeAllocatorType;
186+
alignof(MostAlignedSDNode)>
187+
NodeAllocatorType;
188188

189189
/// Pool allocation for nodes.
190190
NodeAllocatorType NodeAllocator;

llvm/include/llvm/CodeGen/SlotIndexes.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,8 @@ namespace llvm {
346346

347347
IndexListEntry* createEntry(MachineInstr *mi, unsigned index) {
348348
IndexListEntry *entry =
349-
static_cast<IndexListEntry*>(
350-
ileAllocator.Allocate(sizeof(IndexListEntry),
351-
alignOf<IndexListEntry>()));
349+
static_cast<IndexListEntry *>(ileAllocator.Allocate(
350+
sizeof(IndexListEntry), alignof(IndexListEntry)));
352351

353352
new (entry) IndexListEntry(mi, index);
354353

llvm/include/llvm/IR/DerivedTypes.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class FunctionType : public Type {
138138
return T->getTypeID() == FunctionTyID;
139139
}
140140
};
141-
static_assert(AlignOf<FunctionType>::Alignment >= AlignOf<Type *>::Alignment,
141+
static_assert(alignof(FunctionType) >= alignof(Type *),
142142
"Alignment sufficient for objects appended to FunctionType");
143143

144144
bool Type::isFunctionVarArg() const {

llvm/include/llvm/IR/User.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "llvm/ADT/iterator.h"
2323
#include "llvm/ADT/iterator_range.h"
2424
#include "llvm/IR/Value.h"
25-
#include "llvm/Support/AlignOf.h"
2625
#include "llvm/Support/ErrorHandling.h"
2726

2827
namespace llvm {
@@ -250,9 +249,9 @@ class User : public Value {
250249
}
251250
};
252251
// Either Use objects, or a Use pointer can be prepended to User.
253-
static_assert(AlignOf<Use>::Alignment >= AlignOf<User>::Alignment,
252+
static_assert(alignof(Use) >= alignof(User),
254253
"Alignment is insufficient after objects prepended to User");
255-
static_assert(AlignOf<Use *>::Alignment >= AlignOf<User>::Alignment,
254+
static_assert(alignof(Use *) >= alignof(User),
256255
"Alignment is insufficient after objects prepended to User");
257256

258257
template<> struct simplify_type<User::op_iterator> {

llvm/include/llvm/Object/ELF.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ ELFFile<ELFT>::ELFFile(StringRef Object, std::error_code &EC)
337337
return;
338338
}
339339

340-
if (SectionTableOffset & (AlignOf<Elf_Shdr>::Alignment - 1)) {
340+
if (SectionTableOffset & (alignof(Elf_Shdr) - 1)) {
341341
// Invalid address alignment of section headers
342342
EC = object_error::parse_failed;
343343
return;

llvm/include/llvm/Support/Allocator.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#define LLVM_SUPPORT_ALLOCATOR_H
2323

2424
#include "llvm/ADT/SmallVector.h"
25-
#include "llvm/Support/AlignOf.h"
2625
#include "llvm/Support/DataTypes.h"
2726
#include "llvm/Support/MathExtras.h"
2827
#include "llvm/Support/Memory.h"
@@ -74,7 +73,7 @@ template <typename DerivedT> class AllocatorBase {
7473

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

8079
/// \brief Deallocate space for a sequence of objects without constructing them.
@@ -381,7 +380,7 @@ template <typename T> class SpecificBumpPtrAllocator {
381380
/// all memory allocated so far.
382381
void DestroyAll() {
383382
auto DestroyElements = [](char *Begin, char *End) {
384-
assert(Begin == (char*)alignAddr(Begin, alignOf<T>()));
383+
assert(Begin == (char *)alignAddr(Begin, alignof(T)));
385384
for (char *Ptr = Begin; Ptr + sizeof(T) <= End; Ptr += sizeof(T))
386385
reinterpret_cast<T *>(Ptr)->~T();
387386
};
@@ -390,7 +389,7 @@ template <typename T> class SpecificBumpPtrAllocator {
390389
++I) {
391390
size_t AllocatedSlabSize = BumpPtrAllocator::computeSlabSize(
392391
std::distance(Allocator.Slabs.begin(), I));
393-
char *Begin = (char*)alignAddr(*I, alignOf<T>());
392+
char *Begin = (char *)alignAddr(*I, alignof(T));
394393
char *End = *I == Allocator.Slabs.back() ? Allocator.CurPtr
395394
: (char *)*I + AllocatedSlabSize;
396395

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

406405
Allocator.Reset();

llvm/include/llvm/Support/ArrayRecycler.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ namespace llvm {
2626
/// Arrays are allocated in a small number of fixed sizes. For each supported
2727
/// array size, the ArrayRecycler keeps a free list of available arrays.
2828
///
29-
template<class T, size_t Align = AlignOf<T>::Alignment>
30-
class ArrayRecycler {
29+
template <class T, size_t Align = alignof(T)> class ArrayRecycler {
3130
// The free list for a given array size is a simple singly linked list.
3231
// We can't use iplist or Recycler here since those classes can't be copied.
3332
struct FreeList {
3433
FreeList *Next;
3534
};
3635

37-
static_assert(Align >= AlignOf<FreeList>::Alignment, "Object underaligned");
36+
static_assert(Align >= alignof(FreeList), "Object underaligned");
3837
static_assert(sizeof(T) >= sizeof(FreeList), "Objects are too small");
3938

4039
// Keep a free list for each array size.

llvm/include/llvm/Support/Endian.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#ifndef LLVM_SUPPORT_ENDIAN_H
1515
#define LLVM_SUPPORT_ENDIAN_H
1616

17-
#include "llvm/Support/AlignOf.h"
1817
#include "llvm/Support/Host.h"
1918
#include "llvm/Support/SwapByteOrder.h"
2019

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

llvm/include/llvm/Support/OnDiskHashTable.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#ifndef LLVM_SUPPORT_ONDISKHASHTABLE_H
1515
#define LLVM_SUPPORT_ONDISKHASHTABLE_H
1616

17-
#include "llvm/Support/AlignOf.h"
1817
#include "llvm/Support/Allocator.h"
1918
#include "llvm/Support/DataTypes.h"
2019
#include "llvm/Support/EndianStream.h"
@@ -208,7 +207,7 @@ template <typename Info> class OnDiskChainedHashTableGenerator {
208207

209208
// Pad with zeros so that we can start the hashtable at an aligned address.
210209
offset_type TableOff = Out.tell();
211-
uint64_t N = llvm::OffsetToAlignment(TableOff, alignOf<offset_type>());
210+
uint64_t N = llvm::OffsetToAlignment(TableOff, alignof(offset_type));
212211
TableOff += N;
213212
while (N--)
214213
LE.write<uint8_t>(0);

llvm/include/llvm/Support/PointerLikeTypeTraits.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#ifndef LLVM_SUPPORT_POINTERLIKETYPETRAITS_H
1616
#define LLVM_SUPPORT_POINTERLIKETYPETRAITS_H
1717

18-
#include "llvm/Support/AlignOf.h"
1918
#include "llvm/Support/DataTypes.h"
19+
#include <type_traits>
2020

2121
namespace llvm {
2222

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

45-
enum {
46-
NumLowBitsAvailable = detail::ConstantLog2<AlignOf<T>::Alignment>::value
47-
};
45+
enum { NumLowBitsAvailable = detail::ConstantLog2<alignof(T)>::value };
4846
};
4947

5048
template <> class PointerLikeTypeTraits<void *> {

llvm/include/llvm/Support/Recycler.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#define LLVM_SUPPORT_RECYCLER_H
1717

1818
#include "llvm/ADT/ilist.h"
19-
#include "llvm/Support/AlignOf.h"
2019
#include "llvm/Support/Allocator.h"
2120
#include "llvm/Support/ErrorHandling.h"
2221
#include <cassert>
@@ -32,7 +31,7 @@ void PrintRecyclerStats(size_t Size, size_t Align, size_t FreeListSize);
3231
/// and facilitates reusing deallocated memory in place of allocating
3332
/// new memory.
3433
///
35-
template<class T, size_t Size = sizeof(T), size_t Align = AlignOf<T>::Alignment>
34+
template <class T, size_t Size = sizeof(T), size_t Align = alignof(T)>
3635
class Recycler {
3736
struct FreeNode {
3837
FreeNode *Next;
@@ -80,7 +79,7 @@ class Recycler {
8079

8180
template<class SubClass, class AllocatorType>
8281
SubClass *Allocate(AllocatorType &Allocator) {
83-
static_assert(AlignOf<SubClass>::Alignment <= Align,
82+
static_assert(alignof(SubClass) <= Align,
8483
"Recycler allocation alignment is less than object align!");
8584
static_assert(sizeof(SubClass) <= Size,
8685
"Recycler allocation size is less than object size!");

llvm/include/llvm/Support/RecyclingAllocator.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ namespace llvm {
2222
/// RecyclingAllocator - This class wraps an Allocator, adding the
2323
/// functionality of recycling deleted objects.
2424
///
25-
template<class AllocatorType, class T,
26-
size_t Size = sizeof(T), size_t Align = AlignOf<T>::Alignment>
25+
template <class AllocatorType, class T, size_t Size = sizeof(T),
26+
size_t Align = alignof(T)>
2727
class RecyclingAllocator {
2828
private:
2929
/// Base - Implementation details.

llvm/include/llvm/Support/TrailingObjects.h

+11-17
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace trailing_objects_internal {
6262
template <typename First, typename... Rest> class AlignmentCalcHelper {
6363
private:
6464
enum {
65-
FirstAlignment = AlignOf<First>::Alignment,
65+
FirstAlignment = alignof(First),
6666
RestAlignment = AlignmentCalcHelper<Rest...>::Alignment,
6767
};
6868

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

7575
template <typename First> class AlignmentCalcHelper<First> {
7676
public:
77-
enum { Alignment = AlignOf<First>::Alignment };
77+
enum { Alignment = alignof(First) };
7878
};
7979

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

145145
struct RequiresRealignment {
146-
static const bool value =
147-
llvm::AlignOf<PrevTy>::Alignment < llvm::AlignOf<NextTy>::Alignment;
146+
static const bool value = alignof(PrevTy) < alignof(NextTy);
148147
};
149148

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

175174
if (requiresRealignment())
176175
return reinterpret_cast<const NextTy *>(
177-
llvm::alignAddr(Ptr, llvm::alignOf<NextTy>()));
176+
llvm::alignAddr(Ptr, alignof(NextTy)));
178177
else
179178
return reinterpret_cast<const NextTy *>(Ptr);
180179
}
@@ -188,8 +187,7 @@ class TrailingObjectsImpl<Align, BaseTy, TopTrailingObj, PrevTy, NextTy,
188187
Obj, TrailingObjectsBase::OverloadToken<PrevTy>());
189188

190189
if (requiresRealignment())
191-
return reinterpret_cast<NextTy *>(
192-
llvm::alignAddr(Ptr, llvm::alignOf<NextTy>()));
190+
return reinterpret_cast<NextTy *>(llvm::alignAddr(Ptr, alignof(NextTy)));
193191
else
194192
return reinterpret_cast<NextTy *>(Ptr);
195193
}
@@ -201,9 +199,8 @@ class TrailingObjectsImpl<Align, BaseTy, TopTrailingObj, PrevTy, NextTy,
201199
size_t SizeSoFar, size_t Count1,
202200
typename ExtractSecondType<MoreTys, size_t>::type... MoreCounts) {
203201
return ParentType::additionalSizeToAllocImpl(
204-
(requiresRealignment()
205-
? llvm::alignTo<llvm::AlignOf<NextTy>::Alignment>(SizeSoFar)
206-
: SizeSoFar) +
202+
(requiresRealignment() ? llvm::alignTo<alignof(NextTy)>(SizeSoFar)
203+
: SizeSoFar) +
207204
sizeof(NextTy) * Count1,
208205
MoreCounts...);
209206
}
@@ -216,10 +213,9 @@ class TrailingObjectsImpl<Align, BaseTy, TopTrailingObj, PrevTy, NextTy,
216213
static_assert(sizeof...(MoreTys) == sizeof...(MoreCounts),
217214
"Number of counts do not match number of types");
218215
static const size_t value = ParentType::template AdditionalSizeToAllocImpl<
219-
(RequiresRealignment::value
220-
? llvm::AlignTo<llvm::AlignOf<NextTy>::Alignment>::
221-
template from_value<SizeSoFar>::value
222-
: SizeSoFar) +
216+
(RequiresRealignment::value ? llvm::AlignTo<alignof(NextTy)>::
217+
template from_value<SizeSoFar>::value
218+
: SizeSoFar) +
223219
sizeof(NextTy) * Count1,
224220
MoreCounts...>::value;
225221
};
@@ -407,9 +403,7 @@ class TrailingObjects : private trailing_objects_internal::TrailingObjectsImpl<
407403
enum {
408404
Size = TotalSizeToAlloc<Tys...>::template with_counts<Counts...>::value
409405
};
410-
typedef llvm::AlignedCharArray<
411-
llvm::AlignOf<BaseTy>::Alignment, Size
412-
> type;
406+
typedef llvm::AlignedCharArray<alignof(BaseTy), Size> type;
413407
};
414408
};
415409

llvm/include/llvm/Transforms/Utils/SSAUpdaterImpl.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,8 @@ class SSAUpdaterImpl {
120120
if (Info->NumPreds == 0)
121121
Info->Preds = nullptr;
122122
else
123-
Info->Preds = static_cast<BBInfo**>
124-
(Allocator.Allocate(Info->NumPreds * sizeof(BBInfo*),
125-
AlignOf<BBInfo*>::Alignment));
123+
Info->Preds = static_cast<BBInfo **>(Allocator.Allocate(
124+
Info->NumPreds * sizeof(BBInfo *), alignof(BBInfo *)));
126125

127126
for (unsigned p = 0; p != Info->NumPreds; ++p) {
128127
BlkT *Pred = Preds[p];

llvm/lib/Analysis/GlobalsModRef.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class GlobalsAAResult::FunctionInfo {
7878
return (AlignedMap *)P;
7979
}
8080
enum { NumLowBitsAvailable = 3 };
81-
static_assert(AlignOf<AlignedMap>::Alignment >= (1 << NumLowBitsAvailable),
81+
static_assert(alignof(AlignedMap) >= (1 << NumLowBitsAvailable),
8282
"AlignedMap insufficiently aligned to have enough low bits.");
8383
};
8484

llvm/lib/CodeGen/MachineSSAUpdater.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "llvm/CodeGen/MachineInstr.h"
1919
#include "llvm/CodeGen/MachineInstrBuilder.h"
2020
#include "llvm/CodeGen/MachineRegisterInfo.h"
21-
#include "llvm/Support/AlignOf.h"
2221
#include "llvm/Support/Debug.h"
2322
#include "llvm/Support/ErrorHandling.h"
2423
#include "llvm/Support/raw_ostream.h"

llvm/lib/IR/Metadata.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -434,15 +434,15 @@ StringRef MDString::getString() const {
434434
// prepended to them.
435435
#define HANDLE_MDNODE_LEAF(CLASS) \
436436
static_assert( \
437-
llvm::AlignOf<uint64_t>::Alignment >= llvm::AlignOf<CLASS>::Alignment, \
437+
alignof(uint64_t) >= alignof(CLASS), \
438438
"Alignment is insufficient after objects prepended to " #CLASS);
439439
#include "llvm/IR/Metadata.def"
440440

441441
void *MDNode::operator new(size_t Size, unsigned NumOps) {
442442
size_t OpSize = NumOps * sizeof(MDOperand);
443443
// uint64_t is the most aligned type we need support (ensured by static_assert
444444
// above)
445-
OpSize = alignTo(OpSize, llvm::alignOf<uint64_t>());
445+
OpSize = alignTo(OpSize, alignof(uint64_t));
446446
void *Ptr = reinterpret_cast<char *>(::operator new(OpSize + Size)) + OpSize;
447447
MDOperand *O = static_cast<MDOperand *>(Ptr);
448448
for (MDOperand *E = O - NumOps; O != E; --O)
@@ -453,7 +453,7 @@ void *MDNode::operator new(size_t Size, unsigned NumOps) {
453453
void MDNode::operator delete(void *Mem) {
454454
MDNode *N = static_cast<MDNode *>(Mem);
455455
size_t OpSize = N->NumOperands * sizeof(MDOperand);
456-
OpSize = alignTo(OpSize, llvm::alignOf<uint64_t>());
456+
OpSize = alignTo(OpSize, alignof(uint64_t));
457457

458458
MDOperand *O = static_cast<MDOperand *>(Mem);
459459
for (MDOperand *E = O - N->NumOperands; O != E; --O)

llvm/lib/IR/Type.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ FunctionType *FunctionType::get(Type *ReturnType,
296296
FunctionType *FT;
297297

298298
if (I == pImpl->FunctionTypes.end()) {
299-
FT = (FunctionType*) pImpl->TypeAllocator.
300-
Allocate(sizeof(FunctionType) + sizeof(Type*) * (Params.size() + 1),
301-
AlignOf<FunctionType>::Alignment);
299+
FT = (FunctionType *)pImpl->TypeAllocator.Allocate(
300+
sizeof(FunctionType) + sizeof(Type *) * (Params.size() + 1),
301+
alignof(FunctionType));
302302
new (FT) FunctionType(ReturnType, Params, isVarArg);
303303
pImpl->FunctionTypes.insert(FT);
304304
} else {

0 commit comments

Comments
 (0)