llvm.org GIT mirror llvm / cb58e1e
Retire llvm::alignOf in favor of C++11 alignof. No functionality change intended. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284733 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 3 years ago
25 changed file(s) with 78 addition(s) and 103 deletion(s). Raw diff Collapse all Expand all
10401040
10411041 public:
10421042 explicit IntervalMap(Allocator &a) : height(0), rootSize(0), allocator(a) {
1043 assert((uintptr_t(data.buffer) & (alignOf() - 1)) == 0 &&
1043 assert((uintptr_t(data.buffer) & (alignof(RootLeaf) - 1)) == 0 &&
10441044 "Insufficient alignment");
10451045 new(&rootLeaf()) RootLeaf();
10461046 }
156156 // terminator.
157157 unsigned AllocSize = static_cast(sizeof(StringMapEntry))+
158158 KeyLength+1;
159 unsigned Alignment = alignOf();
159 unsigned Alignment = alignof(StringMapEntry);
160160
161161 StringMapEntry *NewItem =
162162 static_cast(Allocator.Allocate(AllocSize,Alignment));
2222
2323 #include "llvm/ADT/IntEqClasses.h"
2424 #include "llvm/CodeGen/SlotIndexes.h"
25 #include "llvm/Support/AlignOf.h"
2625 #include "llvm/Support/Allocator.h"
2726 #include "llvm/Target/TargetRegisterInfo.h"
2827 #include
182182 /// The AllocatorType for allocating SDNodes. We use
183183 /// pool allocation with recycling.
184184 typedef RecyclingAllocator
185 AlignOf::Alignment>
186 NodeAllocatorType;
185 alignof(MostAlignedSDNode)>
186 NodeAllocatorType;
187187
188188 /// Pool allocation for nodes.
189189 NodeAllocatorType NodeAllocator;
345345
346346 IndexListEntry* createEntry(MachineInstr *mi, unsigned index) {
347347 IndexListEntry *entry =
348 static_cast(
349 ileAllocator.Allocate(sizeof(IndexListEntry),
350 alignOf()));
348 static_cast(ileAllocator.Allocate(
349 sizeof(IndexListEntry), alignof(IndexListEntry)));
351350
352351 new (entry) IndexListEntry(mi, index);
353352
137137 return T->getTypeID() == FunctionTyID;
138138 }
139139 };
140 static_assert(AlignOf::Alignment >= AlignOf::Alignment,
140 static_assert(alignof(FunctionType) >= alignof(Type *),
141141 "Alignment sufficient for objects appended to FunctionType");
142142
143143 bool Type::isFunctionVarArg() const {
2121 #include "llvm/ADT/iterator.h"
2222 #include "llvm/ADT/iterator_range.h"
2323 #include "llvm/IR/Value.h"
24 #include "llvm/Support/AlignOf.h"
2524 #include "llvm/Support/ErrorHandling.h"
2625
2726 namespace llvm {
249248 }
250249 };
251250 // Either Use objects, or a Use pointer can be prepended to User.
252 static_assert(AlignOf::Alignment >= AlignOf::Alignment,
251 static_assert(alignof(Use) >= alignof(User),
253252 "Alignment is insufficient after objects prepended to User");
254 static_assert(AlignOf::Alignment >= AlignOf::Alignment,
253 static_assert(alignof(Use *) >= alignof(User),
255254 "Alignment is insufficient after objects prepended to User");
256255
257256 template<> struct simplify_type {
336336 return;
337337 }
338338
339 if (SectionTableOffset & (AlignOf::Alignment - 1)) {
339 if (SectionTableOffset & (alignof(Elf_Shdr) - 1)) {
340340 // Invalid address alignment of section headers
341341 EC = object_error::parse_failed;
342342 return;
2121 #define LLVM_SUPPORT_ALLOCATOR_H
2222
2323 #include "llvm/ADT/SmallVector.h"
24 #include "llvm/Support/AlignOf.h"
2524 #include "llvm/Support/DataTypes.h"
2625 #include "llvm/Support/MathExtras.h"
2726 #include "llvm/Support/Memory.h"
7372
7473 /// \brief Allocate space for a sequence of objects without constructing them.
7574 template T *Allocate(size_t Num = 1) {
76 return static_cast(Allocate(Num * sizeof(T), AlignOf::Alignment));
75 return static_cast(Allocate(Num * sizeof(T), alignof(T)));
7776 }
7877
7978 /// \brief Deallocate space for a sequence of objects without constructing them.
380379 /// all memory allocated so far.
381380 void DestroyAll() {
382381 auto DestroyElements = [](char *Begin, char *End) {
383 assert(Begin == (char*)alignAddr(Begin, alignOf()));
382 assert(Begin == (char *)alignAddr(Begin, alignof(T)));
384383 for (char *Ptr = Begin; Ptr + sizeof(T) <= End; Ptr += sizeof(T))
385384 reinterpret_cast(Ptr)->~T();
386385 };
389388 ++I) {
390389 size_t AllocatedSlabSize = BumpPtrAllocator::computeSlabSize(
391390 std::distance(Allocator.Slabs.begin(), I));
392 char *Begin = (char*)alignAddr(*I, alignOf());
391 char *Begin = (char *)alignAddr(*I, alignof(T));
393392 char *End = *I == Allocator.Slabs.back() ? Allocator.CurPtr
394393 : (char *)*I + AllocatedSlabSize;
395394
399398 for (auto &PtrAndSize : Allocator.CustomSizedSlabs) {
400399 void *Ptr = PtrAndSize.first;
401400 size_t Size = PtrAndSize.second;
402 DestroyElements((char*)alignAddr(Ptr, alignOf()), (char *)Ptr + Size);
401 DestroyElements((char *)alignAddr(Ptr, alignof(T)), (char *)Ptr + Size);
403402 }
404403
405404 Allocator.Reset();
2525 /// Arrays are allocated in a small number of fixed sizes. For each supported
2626 /// array size, the ArrayRecycler keeps a free list of available arrays.
2727 ///
28 template::Alignment>
29 class ArrayRecycler {
28 template class ArrayRecycler {
3029 // The free list for a given array size is a simple singly linked list.
3130 // We can't use iplist or Recycler here since those classes can't be copied.
3231 struct FreeList {
3332 FreeList *Next;
3433 };
3534
36 static_assert(Align >= AlignOf::Alignment, "Object underaligned");
35 static_assert(Align >= alignof(FreeList), "Object underaligned");
3736 static_assert(sizeof(T) >= sizeof(FreeList), "Objects are too small");
3837
3938 // Keep a free list for each array size.
1313 #ifndef LLVM_SUPPORT_ENDIAN_H
1414 #define LLVM_SUPPORT_ENDIAN_H
1515
16 #include "llvm/Support/AlignOf.h"
1716 #include "llvm/Support/Host.h"
1817 #include "llvm/Support/SwapByteOrder.h"
1918
2827 /// \brief ::value is either alignment, or alignof(T) if alignment is 0.
2928 template
3029 struct PickAlignment {
31 enum {value = alignment == 0 ? AlignOf::Alignment : alignment};
30 enum { value = alignment == 0 ? alignof(T) : alignment };
3231 };
3332 } // end namespace detail
3433
1313 #ifndef LLVM_SUPPORT_ONDISKHASHTABLE_H
1414 #define LLVM_SUPPORT_ONDISKHASHTABLE_H
1515
16 #include "llvm/Support/AlignOf.h"
1716 #include "llvm/Support/Allocator.h"
1817 #include "llvm/Support/DataTypes.h"
1918 #include "llvm/Support/EndianStream.h"
207206
208207 // Pad with zeros so that we can start the hashtable at an aligned address.
209208 offset_type TableOff = Out.tell();
210 uint64_t N = llvm::OffsetToAlignment(TableOff, alignOf());
209 uint64_t N = llvm::OffsetToAlignment(TableOff, alignof(offset_type));
211210 TableOff += N;
212211 while (N--)
213212 LE.write(0);
1414 #ifndef LLVM_SUPPORT_POINTERLIKETYPETRAITS_H
1515 #define LLVM_SUPPORT_POINTERLIKETYPETRAITS_H
1616
17 #include "llvm/Support/AlignOf.h"
1817 #include "llvm/Support/DataTypes.h"
18 #include
1919
2020 namespace llvm {
2121
4141 static inline void *getAsVoidPointer(T *P) { return P; }
4242 static inline T *getFromVoidPointer(void *P) { return static_cast(P); }
4343
44 enum {
45 NumLowBitsAvailable = detail::ConstantLog2::Alignment>::value
46 };
44 enum { NumLowBitsAvailable = detail::ConstantLog2::value };
4745 };
4846
4947 template <> class PointerLikeTypeTraits {
1515 #define LLVM_SUPPORT_RECYCLER_H
1616
1717 #include "llvm/ADT/ilist.h"
18 #include "llvm/Support/AlignOf.h"
1918 #include "llvm/Support/Allocator.h"
2019 #include "llvm/Support/ErrorHandling.h"
2120 #include
3130 /// and facilitates reusing deallocated memory in place of allocating
3231 /// new memory.
3332 ///
34 template::Alignment>
33 template >
3534 class Recycler {
3635 struct FreeNode {
3736 FreeNode *Next;
7978
8079 template
8180 SubClass *Allocate(AllocatorType &Allocator) {
82 static_assert(AlignOf::Alignment <= Align,
81 static_assert(alignof(SubClass) <= Align,
8382 "Recycler allocation alignment is less than object align!");
8483 static_assert(sizeof(SubClass) <= Size,
8584 "Recycler allocation size is less than object size!");
2121 /// RecyclingAllocator - This class wraps an Allocator, adding the
2222 /// functionality of recycling deleted objects.
2323 ///
24 template
25 size_t Size = sizeof(T), size_t Align = AlignOf::Alignment>
24 template
25 size_t Align = alignof(T)>
2626 class RecyclingAllocator {
2727 private:
2828 /// Base - Implementation details.
6161 template class AlignmentCalcHelper {
6262 private:
6363 enum {
64 FirstAlignment = AlignOf::Alignment,
64 FirstAlignment = alignof(First),
6565 RestAlignment = AlignmentCalcHelper::Alignment,
6666 };
6767
7373
7474 template class AlignmentCalcHelper {
7575 public:
76 enum { Alignment = AlignOf::Alignment };
76 enum { Alignment = alignof(First) };
7777 };
7878
7979 /// The base class for TrailingObjects* classes.
142142 ParentType;
143143
144144 struct RequiresRealignment {
145 static const bool value =
146 llvm::AlignOf::Alignment < llvm::AlignOf::Alignment;
145 static const bool value = alignof(PrevTy) < alignof(NextTy);
147146 };
148147
149148 static LLVM_CONSTEXPR bool requiresRealignment() {
173172
174173 if (requiresRealignment())
175174 return reinterpret_cast(
176 llvm::alignAddr(Ptr, llvm::alignOf()));
175 llvm::alignAddr(Ptr, alignof(NextTy)));
177176 else
178177 return reinterpret_cast(Ptr);
179178 }
187186 Obj, TrailingObjectsBase::OverloadToken());
188187
189188 if (requiresRealignment())
190 return reinterpret_cast(
191 llvm::alignAddr(Ptr, llvm::alignOf()));
189 return reinterpret_cast(llvm::alignAddr(Ptr, alignof(NextTy)));
192190 else
193191 return reinterpret_cast(Ptr);
194192 }
200198 size_t SizeSoFar, size_t Count1,
201199 typename ExtractSecondType::type... MoreCounts) {
202200 return ParentType::additionalSizeToAllocImpl(
203 (requiresRealignment()
204 ? llvm::alignTo::Alignment>(SizeSoFar)
205 : SizeSoFar) +
201 (requiresRealignment() ? llvm::alignTo(SizeSoFar)
202 : SizeSoFar) +
206203 sizeof(NextTy) * Count1,
207204 MoreCounts...);
208205 }
215212 static_assert(sizeof...(MoreTys) == sizeof...(MoreCounts),
216213 "Number of counts do not match number of types");
217214 static const size_t value = ParentType::template AdditionalSizeToAllocImpl<
218 (RequiresRealignment::value
219 ? llvm::AlignTo::Alignment>::
220 template from_value::value
221 : SizeSoFar) +
215 (RequiresRealignment::value ? llvm::AlignTo::
216 template from_value::value
217 : SizeSoFar) +
222218 sizeof(NextTy) * Count1,
223219 MoreCounts...>::value;
224220 };
406402 enum {
407403 Size = TotalSizeToAlloc::template with_counts::value
408404 };
409 typedef llvm::AlignedCharArray<
410 llvm::AlignOf::Alignment, Size
411 > type;
405 typedef llvm::AlignedCharArray> type;
412406 };
413407 };
414408
119119 if (Info->NumPreds == 0)
120120 Info->Preds = nullptr;
121121 else
122 Info->Preds = static_cast
123 (Allocator.Allocate(Info->NumPreds * sizeof(BBInfo*),
124 AlignOf::Alignment));
122 Info->Preds = static_cast(Allocator.Allocate(
123 Info->NumPreds * sizeof(BBInfo *), alignof(BBInfo *)));
125124
126125 for (unsigned p = 0; p != Info->NumPreds; ++p) {
127126 BlkT *Pred = Preds[p];
7777 return (AlignedMap *)P;
7878 }
7979 enum { NumLowBitsAvailable = 3 };
80 static_assert(AlignOf::Alignment >= (1 << NumLowBitsAvailable),
80 static_assert(alignof(AlignedMap) >= (1 << NumLowBitsAvailable),
8181 "AlignedMap insufficiently aligned to have enough low bits.");
8282 };
8383
1717 #include "llvm/CodeGen/MachineInstr.h"
1818 #include "llvm/CodeGen/MachineInstrBuilder.h"
1919 #include "llvm/CodeGen/MachineRegisterInfo.h"
20 #include "llvm/Support/AlignOf.h"
2120 #include "llvm/Support/Debug.h"
2221 #include "llvm/Support/ErrorHandling.h"
2322 #include "llvm/Support/raw_ostream.h"
433433 // prepended to them.
434434 #define HANDLE_MDNODE_LEAF(CLASS) \
435435 static_assert( \
436 llvm::AlignOf::Alignment >= llvm::AlignOf::Alignment, \
436 alignof(uint64_t) >= alignof(CLASS), \
437437 "Alignment is insufficient after objects prepended to " #CLASS);
438438 #include "llvm/IR/Metadata.def"
439439
441441 size_t OpSize = NumOps * sizeof(MDOperand);
442442 // uint64_t is the most aligned type we need support (ensured by static_assert
443443 // above)
444 OpSize = alignTo(OpSize, llvm::alignOf());
444 OpSize = alignTo(OpSize, alignof(uint64_t));
445445 void *Ptr = reinterpret_cast(::operator new(OpSize + Size)) + OpSize;
446446 MDOperand *O = static_cast(Ptr);
447447 for (MDOperand *E = O - NumOps; O != E; --O)
452452 void MDNode::operator delete(void *Mem) {
453453 MDNode *N = static_cast(Mem);
454454 size_t OpSize = N->NumOperands * sizeof(MDOperand);
455 OpSize = alignTo(OpSize, llvm::alignOf());
455 OpSize = alignTo(OpSize, alignof(uint64_t));
456456
457457 MDOperand *O = static_cast(Mem);
458458 for (MDOperand *E = O - N->NumOperands; O != E; --O)
295295 FunctionType *FT;
296296
297297 if (I == pImpl->FunctionTypes.end()) {
298 FT = (FunctionType*) pImpl->TypeAllocator.
299 Allocate(sizeof(FunctionType) + sizeof(Type*) * (Params.size() + 1),
300 AlignOf::Alignment);
298 FT = (FunctionType *)pImpl->TypeAllocator.Allocate(
299 sizeof(FunctionType) + sizeof(Type *) * (Params.size() + 1),
300 alignof(FunctionType));
301301 new (FT) FunctionType(ReturnType, Params, isVarArg);
302302 pImpl->FunctionTypes.insert(FT);
303303 } else {
4242 void User::allocHungoffUses(unsigned N, bool IsPhi) {
4343 assert(HasHungOffUses && "alloc must have hung off uses");
4444
45 static_assert(AlignOf::Alignment >= AlignOf::Alignment,
45 static_assert(alignof(Use) >= alignof(Use::UserRef),
4646 "Alignment is insufficient for 'hung-off-uses' pieces");
47 static_assert(AlignOf::Alignment >=
48 AlignOf::Alignment,
47 static_assert(alignof(Use::UserRef) >= alignof(BasicBlock *),
4948 "Alignment is insufficient for 'hung-off-uses' pieces");
5049
5150 // Allocate the array of Uses, followed by a pointer (with bottom bit set) to
3030 // For safety, ensure that the alignment of a pointer is enough for an
3131 // MCSymbol. This also ensures we don't need padding between the name and
3232 // symbol.
33 static_assert((unsigned)AlignOf::Alignment <=
34 AlignOf::Alignment,
33 static_assert((unsigned)alignof(MCSymbol) <= alignof(NameEntryStorageTy),
3534 "Bad alignment of MCSymbol");
36 void *Storage = Ctx.allocate(Size, alignOf());
35 void *Storage = Ctx.allocate(Size, alignof(NameEntryStorageTy));
3736 NameEntryStorageTy *Start = static_cast(Storage);
3837 NameEntryStorageTy *End = Start + (Name ? 1 : 0);
3938 return End;
288288 if (CurrentPos + sizeof(RawInstrProf::Header) > End)
289289 return make_error(instrprof_error::malformed);
290290 // The writer ensures each profile is padded to start at an aligned address.
291 if (reinterpret_cast(CurrentPos) % alignOf())
291 if (reinterpret_cast(CurrentPos) % alignof(uint64_t))
292292 return make_error(instrprof_error::malformed);
293293 // The magic should have the same byte order as in the previous header.
294294 uint64_t Magic = *reinterpret_cast(CurrentPos);
111111 EXPECT_EQ(Class1::additionalSizeToAlloc(1), sizeof(short));
112112 EXPECT_EQ(Class1::additionalSizeToAlloc(3), sizeof(short) * 3);
113113
114 EXPECT_EQ(
115 llvm::alignOf(),
116 llvm::alignOf::with_counts<1>::type>());
114 EXPECT_EQ(alignof(Class1),
115 alignof(Class1::FixedSizeStorage::with_counts<1>::type));
117116 EXPECT_EQ(sizeof(Class1::FixedSizeStorage::with_counts<1>::type),
118 llvm::alignTo(Class1::totalSizeToAlloc(1),
119 llvm::alignOf()));
117 llvm::alignTo(Class1::totalSizeToAlloc(1), alignof(Class1)));
120118 EXPECT_EQ(Class1::totalSizeToAlloc(1), sizeof(Class1) + sizeof(short));
121119
122 EXPECT_EQ(
123 llvm::alignOf(),
124 llvm::alignOf::with_counts<3>::type>());
120 EXPECT_EQ(alignof(Class1),
121 alignof(Class1::FixedSizeStorage::with_counts<3>::type));
125122 EXPECT_EQ(sizeof(Class1::FixedSizeStorage::with_counts<3>::type),
126 llvm::alignTo(Class1::totalSizeToAlloc(3),
127 llvm::alignOf()));
123 llvm::alignTo(Class1::totalSizeToAlloc(3), alignof(Class1)));
128124 EXPECT_EQ(Class1::totalSizeToAlloc(3),
129125 sizeof(Class1) + sizeof(short) * 3);
130126
138134 Class2 *C1 = Class2::create(4);
139135 Class2 *C2 = Class2::create(0, 4.2);
140136
141 EXPECT_EQ(sizeof(Class2),
142 llvm::alignTo(sizeof(bool) * 2, llvm::alignOf()));
143 EXPECT_EQ(llvm::alignOf(), llvm::alignOf());
137 EXPECT_EQ(sizeof(Class2), llvm::alignTo(sizeof(bool) * 2, alignof(double)));
138 EXPECT_EQ(alignof(Class2), alignof(double));
144139
145140 EXPECT_EQ((Class2::additionalSizeToAlloc(1, 0)),
146141 sizeof(double));
150145 sizeof(double) * 3 + sizeof(short));
151146
152147 EXPECT_EQ(
153 llvm::alignOf(),
154 (llvm::alignOf<
155 Class2::FixedSizeStorage::with_counts<1, 1>::type>()));
148 alignof(Class2),
149 (alignof(
150 Class2::FixedSizeStorage::with_counts<1, 1>::type)));
156151 EXPECT_EQ(
157152 sizeof(Class2::FixedSizeStorage::with_counts<1, 1>::type),
158153 llvm::alignTo(Class2::totalSizeToAlloc(1, 1),
159 llvm::alignOf()));
154 alignof(Class2)));
160155 EXPECT_EQ((Class2::totalSizeToAlloc(1, 1)),
161156 sizeof(Class2) + sizeof(double) + sizeof(short));
162157
190185 TEST(TrailingObjects, ThreeArg) {
191186 EXPECT_EQ((Class3::additionalSizeToAlloc(1, 1, 3)),
192187 sizeof(double) + sizeof(short) + 3 * sizeof(bool));
193 EXPECT_EQ(sizeof(Class3), llvm::alignTo(1, llvm::alignOf()));
194
195 EXPECT_EQ(llvm::alignOf(),
196 (llvm::alignOf
197 double, short, bool>::with_counts<1, 1, 3>::type>()));
188 EXPECT_EQ(sizeof(Class3), llvm::alignTo(1, alignof(double)));
189
190 EXPECT_EQ(
191 alignof(Class3),
192 (alignof(Class3::FixedSizeStorage
193 bool>::with_counts<1, 1, 3>::type)));
198194 EXPECT_EQ(
199195 sizeof(Class3::FixedSizeStorage
200196 bool>::with_counts<1, 1, 3>::type),
201197 llvm::alignTo(Class3::totalSizeToAlloc(1, 1, 3),
202 llvm::alignOf()));
198 alignof(Class3)));
203199
204200 std::unique_ptr P(new char[1000]);
205201 Class3 *C = reinterpret_cast(P.get());
220216
221217 TEST(TrailingObjects, Realignment) {
222218 EXPECT_EQ((Class4::additionalSizeToAlloc(1, 1)),
223 llvm::alignTo(sizeof(long) + 1, llvm::alignOf()));
224 EXPECT_EQ(sizeof(Class4), llvm::alignTo(1, llvm::alignOf()));
225
226 EXPECT_EQ(
227 llvm::alignOf(),
228 (llvm::alignOf<
229 Class4::FixedSizeStorage::with_counts<1, 1>::type>()));
219 llvm::alignTo(sizeof(long) + 1, alignof(long)));
220 EXPECT_EQ(sizeof(Class4), llvm::alignTo(1, alignof(long)));
221
222 EXPECT_EQ(
223 alignof(Class4),
224 (alignof(Class4::FixedSizeStorage::with_counts<1, 1>::type)));
230225 EXPECT_EQ(
231226 sizeof(Class4::FixedSizeStorage::with_counts<1, 1>::type),
232227 llvm::alignTo(Class4::totalSizeToAlloc(1, 1),
233 llvm::alignOf()));
228 alignof(Class4)));
234229
235230 std::unique_ptr P(new char[1000]);
236231 Class4 *C = reinterpret_cast(P.get());
237232 EXPECT_EQ(C->getTrailingObjects(), reinterpret_cast(C + 1));
238233 EXPECT_EQ(C->getTrailingObjects(),
239234 reinterpret_cast(llvm::alignAddr(
240 reinterpret_cast(C + 1) + 1, llvm::alignOf())));
241 }
242 }
235 reinterpret_cast(C + 1) + 1, alignof(long))));
236 }
237 }