[llvm] [Attributor] New attribute to identify what byte ranges are alive for an allocation (PR #66148)

Shilei Tian via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 18 17:03:32 PDT 2023


================
@@ -12658,6 +12669,268 @@ struct AAAddressSpaceCallSiteArgument final : AAAddressSpaceImpl {
 };
 } // namespace
 
+/// ----------- Allocation Info ----------
+namespace {
+struct AAAllocationInfoImpl : public AAAllocationInfo {
+  AAAllocationInfoImpl(const IRPosition &IRP, Attributor &A)
+      : AAAllocationInfo(IRP, A) {}
+
+  std::optional<TypeSize> getAllocatedSize() const override {
+    assert(isValidState() && "the AA is invalid");
+    return AssumedAllocatedSize;
+  }
+
+  bool isaMallocInst(Instruction *I) {
+    CallInst *Call = dyn_cast<CallInst>(I);
+    auto CallName = Call->getCalledFunction()->getName();
+    if (CallName.str() == "malloc")
+      return true;
+
+    return false;
+  };
+
+  ChangeStatus updateImpl(Attributor &A) override {
+
+    Instruction *I = getIRPosition().getCtxI();
+
+    const IRPosition &IRP = getIRPosition();
+
+    if (!(isa<AllocaInst>(I) || isaMallocInst(I)))
----------------
shiltian wrote:

If we want to use this in `OpenMPOpt`, this test needs to be extended to include functions like `__kmpc_alloc_shared`. IIRC TLI has a function to check if it is allocation.

https://github.com/llvm/llvm-project/pull/66148


More information about the llvm-commits mailing list