[Attributor] Use getFreedOperand() (NFC)
authorNikita Popov <npopov@redhat.com>
Thu, 21 Jul 2022 12:25:54 +0000 (14:25 +0200)
committerNikita Popov <npopov@redhat.com>
Thu, 21 Jul 2022 12:26:47 +0000 (14:26 +0200)
Track which operand is actually freed, to avoid the implicit
assumption that it is the first call argument.

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

index 0f87d10..6ea8b7c 100644 (file)
@@ -5798,6 +5798,8 @@ struct AAHeapToStackFunction final : public AAHeapToStack {
   struct DeallocationInfo {
     /// The call that deallocates the memory.
     CallBase *const CB;
+    /// The value freed by the call.
+    Value *FreedOp;
 
     /// Flag to indicate if we don't know all objects this deallocation might
     /// free.
@@ -5829,8 +5831,8 @@ struct AAHeapToStackFunction final : public AAHeapToStack {
       CallBase *CB = dyn_cast<CallBase>(&I);
       if (!CB)
         return true;
-      if (isFreeCall(CB, TLI)) {
-        DeallocationInfos[CB] = new (A.Allocator) DeallocationInfo{CB};
+      if (Value *FreedOp = getFreedOperand(CB, TLI)) {
+        DeallocationInfos[CB] = new (A.Allocator) DeallocationInfo{CB, FreedOp};
         return true;
       }
       // To do heap to stack, we need to know that the allocation itself is
@@ -6104,7 +6106,7 @@ ChangeStatus AAHeapToStackFunction::updateImpl(Attributor &A) {
         continue;
 
       // Use the non-optimistic version to get the freed object.
-      Value *Obj = getUnderlyingObject(DI.CB->getArgOperand(0));
+      Value *Obj = getUnderlyingObject(DI.FreedOp);
       if (!Obj) {
         LLVM_DEBUG(dbgs() << "[H2S] Unknown underlying object for free!\n");
         DI.MightFreeUnknownObjects = true;