diff options
| author | Philip Reames <listmail@philipreames.com> | 2022-01-12 17:32:05 -0800 |
|---|---|---|
| committer | Philip Reames <listmail@philipreames.com> | 2022-01-12 17:34:17 -0800 |
| commit | 9979299705817c90ef7e4928ba1fb10243cecb67 (patch) | |
| tree | 30ec77af12a549696bfce57ba2c5babd83f3b369 /llvm/lib | |
| parent | aea27c3100396ec82412ad5b0254448f3fb0406b (diff) | |
| download | llvm-9979299705817c90ef7e4928ba1fb10243cecb67.zip llvm-9979299705817c90ef7e4928ba1fb10243cecb67.tar.gz llvm-9979299705817c90ef7e4928ba1fb10243cecb67.tar.bz2 | |
[Attributor] Simplify how we handle required alignment during heap-to-stack [NFC]
The existing code duplicated the same concern in two places, and (weirdly) changed the inference of the allocation size based on whether we could meet the alignment requirement. Instead, just directly check the allocation requirement.
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/IPO/AttributorAttributes.cpp | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp index d0534ed..33e567b 100644 --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -6022,10 +6022,7 @@ struct AAHeapToStackFunction final : public AAHeapToStack { return getAPInt(A, AA, *AI.CB->getArgOperand(0)); if (AI.Kind == AllocationInfo::AllocationKind::ALIGNED_ALLOC) - // Only if the alignment is also constant we return a size. - return getAPInt(A, AA, *AI.CB->getArgOperand(0)).hasValue() - ? getAPInt(A, AA, *AI.CB->getArgOperand(1)) - : llvm::None; + return getAPInt(A, AA, *AI.CB->getArgOperand(1)); assert(AI.Kind == AllocationInfo::AllocationKind::CALLOC && "Expected only callocs are left"); @@ -6267,23 +6264,24 @@ ChangeStatus AAHeapToStackFunction::updateImpl(Attributor &A) { if (AI.Status == AllocationInfo::INVALID) continue; - if (MaxHeapToStackSize == -1) { - if (AI.Kind == AllocationInfo::AllocationKind::ALIGNED_ALLOC) { - Value *Align = getAllocAlignment(AI.CB, TLI); - if (!Align || !getAPInt(A, *this, *Align)) { - LLVM_DEBUG(dbgs() << "[H2S] Unknown allocation alignment: " << *AI.CB - << "\n"); - AI.Status = AllocationInfo::INVALID; - Changed = ChangeStatus::CHANGED; - continue; - } + if (Value *Align = getAllocAlignment(AI.CB, TLI)) { + if (!getAPInt(A, *this, *Align)) { + // Can't generate an alloca which respects the required alignment + // on the allocation. + LLVM_DEBUG(dbgs() << "[H2S] Unknown allocation alignment: " << *AI.CB + << "\n"); + AI.Status = AllocationInfo::INVALID; + Changed = ChangeStatus::CHANGED; + continue; } - } else { + } + + if (MaxHeapToStackSize != -1) { Optional<APInt> Size = getSize(A, *this, AI); if (!Size.hasValue() || Size.getValue().ugt(MaxHeapToStackSize)) { LLVM_DEBUG({ if (!Size.hasValue()) - dbgs() << "[H2S] Unknown allocation size (or alignment): " << *AI.CB + dbgs() << "[H2S] Unknown allocation size: " << *AI.CB << "\n"; else dbgs() << "[H2S] Allocation size too large: " << *AI.CB << " vs. " |
