Skip to content

Conversation

@abidh
Copy link
Contributor

@abidh abidh commented Oct 22, 2025

No description provided.

@github-actions
Copy link

github-actions bot commented Oct 22, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/Transforms/IPO/OpenMPOpt.cpp

⚠️
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing origin/main to the base branch/commit you want to compare against.
⚠️

View the diff from clang-format here.
diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
index 4181c794c..6b888a4ca 100644
--- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -5001,28 +5001,28 @@ struct AAKernelInfoCallSite : AAKernelInfo {
           // won't be any change so we indicate a fixpoint.
           indicateOptimisticFixpoint();
         }
-      // If the callee is known and can be used in IPO, we will update the
-      // state based on the callee state in updateImpl.
-      return;
-    }
-    // Check if we have multiple possible callees. This usually indicates an
-    // indirect call where we don't know the target, requiring a pessimistic
-    // fixpoint. However, for callback functions, multiple edges are expected:
-    // one to the runtime function and edges through callback parameters. These
-    // are analyzable, so we exclude them from the pessimistic check.
-    if (NumCallees > 1 && !Callee->hasMetadata(LLVMContext::MD_callback)) {
-      LLVM_DEBUG(dbgs() << "[OpenMPOpt] Multiple callees found, forcing "
-                           "pessimistic fixpoint\n");
-      indicatePessimisticFixpoint();
-      return;
-    }
-    LLVM_DEBUG({
-      if (NumCallees > 1 && Callee->hasMetadata(LLVMContext::MD_callback)) {
-        dbgs() << "[OpenMPOpt] Allowing multiple callees for callback "
-                  "function: "
-               << Callee->getName() << "\n";
+        // If the callee is known and can be used in IPO, we will update the
+        // state based on the callee state in updateImpl.
+        return;
       }
-    });
+      // Check if we have multiple possible callees. This usually indicates an
+      // indirect call where we don't know the target, requiring a pessimistic
+      // fixpoint. However, for callback functions, multiple edges are expected:
+      // one to the runtime function and edges through callback parameters.
+      // These are analyzable, so we exclude them from the pessimistic check.
+      if (NumCallees > 1 && !Callee->hasMetadata(LLVMContext::MD_callback)) {
+        LLVM_DEBUG(dbgs() << "[OpenMPOpt] Multiple callees found, forcing "
+                             "pessimistic fixpoint\n");
+        indicatePessimisticFixpoint();
+        return;
+      }
+      LLVM_DEBUG({
+        if (NumCallees > 1 && Callee->hasMetadata(LLVMContext::MD_callback)) {
+          dbgs() << "[OpenMPOpt] Allowing multiple callees for callback "
+                    "function: "
+                 << Callee->getName() << "\n";
+        }
+      });
 
       RuntimeFunction RF = It->getSecond();
       switch (RF) {
@@ -5185,28 +5185,28 @@ struct AAKernelInfoCallSite : AAKernelInfo {
             A.getAAFor<AAKernelInfo>(*this, FnPos, DepClassTy::REQUIRED);
         if (!FnAA)
           return indicatePessimisticFixpoint();
-      if (getState() == FnAA->getState())
-        return ChangeStatus::UNCHANGED;
-      getState() = FnAA->getState();
-      return ChangeStatus::CHANGED;
-    }
-    // Check if we have multiple possible callees. This usually indicates an
-    // indirect call where we don't know the target, requiring a pessimistic
-    // fixpoint. However, for callback functions, multiple edges are expected:
-    // one to the runtime function and edges through callback parameters. These
-    // are analyzable, so we exclude them from the pessimistic check.
-    if (NumCallees > 1 && !F->hasMetadata(LLVMContext::MD_callback)) {
-      LLVM_DEBUG(dbgs() << "[OpenMPOpt] Multiple callees in update, forcing "
-                           "pessimistic fixpoint\n");
-      return indicatePessimisticFixpoint();
-    }
-    LLVM_DEBUG({
-      if (NumCallees > 1 && F->hasMetadata(LLVMContext::MD_callback)) {
-        dbgs() << "[OpenMPOpt] Allowing multiple callees for callback "
-                  "function in update: "
-               << F->getName() << "\n";
+        if (getState() == FnAA->getState())
+          return ChangeStatus::UNCHANGED;
+        getState() = FnAA->getState();
+        return ChangeStatus::CHANGED;
       }
-    });
+      // Check if we have multiple possible callees. This usually indicates an
+      // indirect call where we don't know the target, requiring a pessimistic
+      // fixpoint. However, for callback functions, multiple edges are expected:
+      // one to the runtime function and edges through callback parameters.
+      // These are analyzable, so we exclude them from the pessimistic check.
+      if (NumCallees > 1 && !F->hasMetadata(LLVMContext::MD_callback)) {
+        LLVM_DEBUG(dbgs() << "[OpenMPOpt] Multiple callees in update, forcing "
+                             "pessimistic fixpoint\n");
+        return indicatePessimisticFixpoint();
+      }
+      LLVM_DEBUG({
+        if (NumCallees > 1 && F->hasMetadata(LLVMContext::MD_callback)) {
+          dbgs() << "[OpenMPOpt] Allowing multiple callees for callback "
+                    "function in update: "
+                 << F->getName() << "\n";
+        }
+      });
 
       CallBase &CB = cast<CallBase>(getAssociatedValue());
       if (It->getSecond() == OMPRTL___kmpc_parallel_51) {

abidh added 10 commits October 22, 2025 17:46
Also set metadata in case it was not set (can happen with linked
library functions).
Get the information from the def file instead.
This commit improves the robustness and maintainability of callback
function analysis in OpenMPOpt by adding:

1. Defensive check for function declarations:
   - Skip analysis of declaration-only callbacks that cannot be analyzed
     interprocedurally
   - Prevents attempting to create AAKernelInfo for external functions
     without definitions

2. Explanatory comments for multiple callees handling:
   - Document why callback functions are excluded from pessimistic
     fixpoint when NumCallees > 1
   - Clarify that callbacks create expected multiple edges (to runtime
     function and through callback parameters) which are analyzable

3. Debug output for callback analysis:
   - Log when analyzing a callback function
   - Log when skipping declaration-only functions
   - Log decisions about allowing/forcing pessimistic fixpoints
   - Warn in debug builds when callback resolution fails

4. Verification in debug builds:
   - Assert expectations about callback resolution
   - Help catch logic errors early during development

These improvements make the code more robust against edge cases (like
linked library functions) and easier to debug when callback analysis
doesn't work as expected.

No functional changes for well-formed input - only improved error
handling and diagnostics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant