[llvm] [FunctionAttrs] Switch readonly etc inference to use CaptureTracking (PR #201136)

Antonio Frighetto via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 4 01:29:38 PDT 2026


================
@@ -881,110 +881,73 @@ determinePointerAccessAttrs(Argument *A,
 
     Use *U = Worklist.pop_back_val();
     Instruction *I = cast<Instruction>(U->getUser());
+    if (isa<ReturnInst>(I))
+      continue;
 
-    switch (I->getOpcode()) {
-    case Instruction::BitCast:
-    case Instruction::GetElementPtr:
-    case Instruction::PHI:
-    case Instruction::Select:
-    case Instruction::AddrSpaceCast:
-      // The original value is not read/written via this if the new value isn't.
+    UseCaptureInfo Info = DetermineUseCaptureKind(*U, A);
+
+    // FIXME: This should really be part of CaptureTracking, but keep it here
+    // for now due to interference with isEscapeSource().
+    if (auto *CB = dyn_cast<CallBase>(I))
+      if (CB->onlyReadsMemory())
+        Info.UseCC &= CaptureComponents::Address;
+
+    if (capturesAnyProvenance(Info.UseCC)) {
+      // Handle indirect access via captured provenance.
+      if (!capturesReadProvenanceOnly(Info.UseCC))
+        return Attribute::None;
+      IsRead = true;
+    }
+
+    if (capturesAnyProvenance(Info.ResultCC)) {
       for (Use &UU : I->uses())
         if (Visited.insert(&UU).second)
           Worklist.push_back(&UU);
-      break;
+    }
 
-    case Instruction::Call:
-    case Instruction::Invoke: {
-      CallBase &CB = cast<CallBase>(*I);
-      if (CB.isCallee(U)) {
+    if (auto *CB = dyn_cast<CallBase>(I)) {
----------------
antoniofrighetto wrote:

Minor nit: you might prefer having a single `auto *CB = dyn_cast<CallBase>(I)` and reusing CB here for the time being.

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


More information about the llvm-commits mailing list