[llvm] 5d5d4d9 - [Attributor] Generalize heap to stack to any allocator with relevant properties
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 13 15:33:35 PST 2022
Author: Philip Reames
Date: 2022-01-13T15:33:24-08:00
New Revision: 5d5d4d94f0c405222628b57f78d2e8fdc9eea5d3
URL: https://github.com/llvm/llvm-project/commit/5d5d4d94f0c405222628b57f78d2e8fdc9eea5d3
DIFF: https://github.com/llvm/llvm-project/commit/5d5d4d94f0c405222628b57f78d2e8fdc9eea5d3.diff
LOG: [Attributor] Generalize heap to stack to any allocator with relevant properties
This completes removal of the isXLike queries, and depends on a whole series of earlier patches which have already landed.
Differential Revision: https://reviews.llvm.org/D117242
Added:
Modified:
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index cd68cd48546e..2cf725e04c79 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -5771,13 +5771,6 @@ struct AAHeapToStackFunction final : public AAHeapToStack {
/// The call that allocates the memory.
CallBase *const CB;
- /// The kind of allocation.
- const enum class AllocationKind {
- MALLOC,
- CALLOC,
- ALIGNED_ALLOC,
- } Kind;
-
/// The library function id for the allocation.
LibFunc LibraryFunctionId = NotLibFunc;
@@ -5834,20 +5827,17 @@ struct AAHeapToStackFunction final : public AAHeapToStack {
DeallocationInfos[CB] = new (A.Allocator) DeallocationInfo{CB};
return true;
}
- bool IsMalloc = isMallocLikeFn(CB, TLI);
- bool IsAlignedAllocLike = !IsMalloc && isAlignedAllocLikeFn(CB, TLI);
- bool IsCalloc =
- !IsMalloc && !IsAlignedAllocLike && isCallocLikeFn(CB, TLI);
- if (!IsMalloc && !IsAlignedAllocLike && !IsCalloc)
- return true;
- auto Kind =
- IsMalloc ? AllocationInfo::AllocationKind::MALLOC
- : (IsCalloc ? AllocationInfo::AllocationKind::CALLOC
- : AllocationInfo::AllocationKind::ALIGNED_ALLOC);
-
- AllocationInfo *AI = new (A.Allocator) AllocationInfo{CB, Kind};
- AllocationInfos[CB] = AI;
- TLI->getLibFunc(*CB, AI->LibraryFunctionId);
+ // To do heap to stack, we need to know that the allocation itself is
+ // removable once uses are rewritten, and that we can initialize the
+ // alloca to the same pattern as the original allocation result.
+ if (isAllocationFn(CB, TLI) && isAllocRemovable(CB, TLI)) {
+ auto *I8Ty = Type::getInt8Ty(CB->getParent()->getContext());
+ if (nullptr != getInitialValueOfAllocation(CB, TLI, I8Ty)) {
+ AllocationInfo *AI = new (A.Allocator) AllocationInfo{CB};
+ AllocationInfos[CB] = AI;
+ TLI->getLibFunc(*CB, AI->LibraryFunctionId);
+ }
+ }
return true;
};
More information about the llvm-commits
mailing list