[llvm] 8e76720 - [Attributor] Reuse object size evaluation code [NFC]
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 12 16:59:32 PST 2022
Author: Philip Reames
Date: 2022-01-12T16:58:39-08:00
New Revision: 8e76720cf2c0fb230777e98ad5a41175efc4d404
URL: https://github.com/llvm/llvm-project/commit/8e76720cf2c0fb230777e98ad5a41175efc4d404
DIFF: https://github.com/llvm/llvm-project/commit/8e76720cf2c0fb230777e98ad5a41175efc4d404.diff
LOG: [Attributor] Reuse object size evaluation code [NFC]
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 d9cffa075776..26975f5e4a74 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -5943,15 +5943,15 @@ struct AAHeapToStackFunction final : public AAHeapToStack {
Optional<APInt> SizeAPI = getSize(A, *this, AI);
if (SizeAPI.hasValue()) {
Size = ConstantInt::get(AI.CB->getContext(), *SizeAPI);
- } else if (AI.Kind == AllocationInfo::AllocationKind::CALLOC) {
- auto *Num = AI.CB->getOperand(0);
- auto *SizeT = AI.CB->getOperand(1);
- IRBuilder<> B(AI.CB);
- Size = B.CreateMul(Num, SizeT, "h2s.calloc.size");
- } else if (AI.Kind == AllocationInfo::AllocationKind::ALIGNED_ALLOC) {
- Size = AI.CB->getOperand(1);
} else {
- Size = AI.CB->getOperand(0);
+ LLVMContext &Ctx = AI.CB->getContext();
+ auto &DL = A.getInfoCache().getDL();
+ ObjectSizeOpts Opts;
+ ObjectSizeOffsetEvaluator Eval(DL, TLI, Ctx, Opts);
+ SizeOffsetEvalType SizeOffsetPair = Eval.compute(AI.CB);
+ assert(SizeOffsetPair != ObjectSizeOffsetEvaluator::unknown() &&
+ cast<ConstantInt>(SizeOffsetPair.second)->isZero());
+ Size = SizeOffsetPair.first;
}
Align Alignment(1);
More information about the llvm-commits
mailing list