comparison llvm/lib/Support/OptimizedStructLayout.cpp @ 236:c4bab56944e8 llvm-original

LLVM 16
author kono
date Wed, 09 Nov 2022 17:45:10 +0900
parents 0572611fdcc8
children 1f2b6ac9f198
comparison
equal deleted inserted replaced
232:70dce7da266c 236:c4bab56944e8
348 auto tryAddFillerFromQueue = [&](AlignmentQueue *Queue, 348 auto tryAddFillerFromQueue = [&](AlignmentQueue *Queue,
349 uint64_t StartOffset, 349 uint64_t StartOffset,
350 Optional<uint64_t> EndOffset) -> bool { 350 Optional<uint64_t> EndOffset) -> bool {
351 assert(Queue->Head); 351 assert(Queue->Head);
352 assert(StartOffset == alignTo(LastEnd, Queue->Alignment)); 352 assert(StartOffset == alignTo(LastEnd, Queue->Alignment));
353 assert(!EndOffset || StartOffset < *EndOffset);
353 354
354 // Figure out the maximum size that a field can be, and ignore this 355 // Figure out the maximum size that a field can be, and ignore this
355 // queue if there's nothing in it that small. 356 // queue if there's nothing in it that small.
356 auto MaxViableSize = 357 auto MaxViableSize =
357 (EndOffset ? *EndOffset - StartOffset : ~(uint64_t)0); 358 (EndOffset ? *EndOffset - StartOffset : ~(uint64_t)0);
370 }; 371 };
371 372
372 // Helper function to find the "best" flexible-offset field according 373 // Helper function to find the "best" flexible-offset field according
373 // to the criteria described above. 374 // to the criteria described above.
374 auto tryAddBestField = [&](Optional<uint64_t> BeforeOffset) -> bool { 375 auto tryAddBestField = [&](Optional<uint64_t> BeforeOffset) -> bool {
376 assert(!BeforeOffset || LastEnd < *BeforeOffset);
375 auto QueueB = FlexibleFieldsByAlignment.begin(); 377 auto QueueB = FlexibleFieldsByAlignment.begin();
376 auto QueueE = FlexibleFieldsByAlignment.end(); 378 auto QueueE = FlexibleFieldsByAlignment.end();
377 379
378 // Start by looking for the most-aligned queue that doesn't need any 380 // Start by looking for the most-aligned queue that doesn't need any
379 // leading padding after LastEnd. 381 // leading padding after LastEnd.
401 // If we started from the first queue, we're done. 403 // If we started from the first queue, we're done.
402 if (FirstQueueToSearch == QueueB) 404 if (FirstQueueToSearch == QueueB)
403 return false; 405 return false;
404 406
405 // Otherwise, scan backwards to find the most-aligned queue that 407 // Otherwise, scan backwards to find the most-aligned queue that
406 // still has minimal leading padding after LastEnd. 408 // still has minimal leading padding after LastEnd. If that
409 // minimal padding is already at or past the end point, we're done.
407 --FirstQueueToSearch; 410 --FirstQueueToSearch;
408 Offset = alignTo(LastEnd, FirstQueueToSearch->Alignment); 411 Offset = alignTo(LastEnd, FirstQueueToSearch->Alignment);
412 if (BeforeOffset && Offset >= *BeforeOffset)
413 return false;
409 while (FirstQueueToSearch != QueueB && 414 while (FirstQueueToSearch != QueueB &&
410 Offset == alignTo(LastEnd, FirstQueueToSearch[-1].Alignment)) 415 Offset == alignTo(LastEnd, FirstQueueToSearch[-1].Alignment))
411 --FirstQueueToSearch; 416 --FirstQueueToSearch;
412 } 417 }
413 }; 418 };
414 419
415 // Phase 1: fill the gaps between fixed-offset fields with the best 420 // Phase 1: fill the gaps between fixed-offset fields with the best
416 // flexible-offset field that fits. 421 // flexible-offset field that fits.
417 for (auto I = Fields.begin(); I != FirstFlexible; ++I) { 422 for (auto I = Fields.begin(); I != FirstFlexible; ++I) {
423 assert(LastEnd <= I->Offset);
418 while (LastEnd != I->Offset) { 424 while (LastEnd != I->Offset) {
419 if (!tryAddBestField(I->Offset)) 425 if (!tryAddBestField(I->Offset))
420 break; 426 break;
421 } 427 }
422 Layout.push_back(*I); 428 Layout.push_back(*I);