[compiler-rt] [llvm] [ctxprof] Handle musttail (PR #135121)

via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 9 19:43:51 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- compiler-rt/lib/ctx_profile/CtxInstrContextNode.h compiler-rt/lib/ctx_profile/CtxInstrProfiling.cpp compiler-rt/lib/ctx_profile/CtxInstrProfiling.h compiler-rt/lib/ctx_profile/RootAutoDetector.cpp compiler-rt/lib/ctx_profile/tests/CtxInstrProfilingTest.cpp llvm/include/llvm/ProfileData/CtxInstrContextNode.h llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/compiler-rt/lib/ctx_profile/CtxInstrProfiling.h b/compiler-rt/lib/ctx_profile/CtxInstrProfiling.h
index bda1e60ff..df23389d2 100644
--- a/compiler-rt/lib/ctx_profile/CtxInstrProfiling.h
+++ b/compiler-rt/lib/ctx_profile/CtxInstrProfiling.h
@@ -169,9 +169,7 @@ inline bool isScratch(const void *Ctx) {
   return (reinterpret_cast<uint64_t>(Ctx) & 1);
 }
 
-inline bool mustNotBeRoot(const ContextRoot* Ctx) {
-  return isScratch(Ctx);
-}
+inline bool mustNotBeRoot(const ContextRoot *Ctx) { return isScratch(Ctx); }
 
 } // namespace __ctx_profile
 
diff --git a/compiler-rt/lib/ctx_profile/RootAutoDetector.cpp b/compiler-rt/lib/ctx_profile/RootAutoDetector.cpp
index 871ca4e63..2256a2d0c 100644
--- a/compiler-rt/lib/ctx_profile/RootAutoDetector.cpp
+++ b/compiler-rt/lib/ctx_profile/RootAutoDetector.cpp
@@ -75,7 +75,7 @@ void RootAutoDetector::start() {
               Printf("[ctxprof] Root auto-detector selected a musttail "
                      "function for root (%p). Ignoring\n",
                      FD->EntryAddress);
-              }
+            }
           }
         }
         atomic_store_relaxed(&RAD->Self, 0);
diff --git a/llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp b/llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp
index f0e7ddd81..f99d7b9d0 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp
@@ -124,8 +124,8 @@ CtxInstrumentationLowerer::CtxInstrumentationLowerer(Module &M,
 #define _MUTEXDECL(_) SanitizerMutexType,
 
   FunctionDataTy = StructType::get(
-      M.getContext(),
-      {CTXPROF_FUNCTION_DATA(_PTRDECL, _CONTEXT_ROOT, _VOLATILE_PTRDECL, _MUTEXDECL)});
+      M.getContext(), {CTXPROF_FUNCTION_DATA(_PTRDECL, _CONTEXT_ROOT,
+                                             _VOLATILE_PTRDECL, _MUTEXDECL)});
 #undef _PTRDECL
 #undef _CONTEXT_ROOT
 #undef _VOLATILE_PTRDECL
@@ -146,75 +146,73 @@ CtxInstrumentationLowerer::CtxInstrumentationLowerer(Module &M,
 #undef _VOLATILE_PTRDECL
 #undef _MUTEXDECL
 
-      // The Context header.
-      ContextNodeTy =
-          StructType::get(M.getContext(), {
-                                              I64Ty,     /*Guid*/
-                                              PointerTy, /*Next*/
-                                              I32Ty,     /*NumCounters*/
-                                              I32Ty,     /*NumCallsites*/
-                                          });
-
-      // Define a global for each entrypoint. We'll reuse the entrypoint's name
-      // as prefix. We assume the entrypoint names to be unique.
-      for (const auto &Fname : ContextRoots) {
-        if (const auto *F = M.getFunction(Fname)) {
-          if (F->isDeclaration())
-            continue;
-          ContextRootSet.insert(F);
-          for (const auto &BB : *F)
-            for (const auto &I : BB)
-              if (const auto *CB = dyn_cast<CallBase>(&I))
-                if (CB->isMustTailCall()) {
-                  M.getContext().emitError("The function " + Fname +
-                                           " was indicated as a context root, "
-                                           "but it features musttail "
-                                           "calls, which is not supported.");
-                }
-        }
-      }
+  // The Context header.
+  ContextNodeTy = StructType::get(M.getContext(), {
+                                                      I64Ty,     /*Guid*/
+                                                      PointerTy, /*Next*/
+                                                      I32Ty,     /*NumCounters*/
+                                                      I32Ty, /*NumCallsites*/
+                                                  });
+
+  // Define a global for each entrypoint. We'll reuse the entrypoint's name
+  // as prefix. We assume the entrypoint names to be unique.
+  for (const auto &Fname : ContextRoots) {
+    if (const auto *F = M.getFunction(Fname)) {
+      if (F->isDeclaration())
+        continue;
+      ContextRootSet.insert(F);
+      for (const auto &BB : *F)
+        for (const auto &I : BB)
+          if (const auto *CB = dyn_cast<CallBase>(&I))
+            if (CB->isMustTailCall()) {
+              M.getContext().emitError("The function " + Fname +
+                                       " was indicated as a context root, "
+                                       "but it features musttail "
+                                       "calls, which is not supported.");
+            }
+    }
+  }
 
-      // Declare the functions we will call.
-      StartCtx = cast<Function>(
-          M.getOrInsertFunction(
-               CompilerRtAPINames::StartCtx,
-               FunctionType::get(PointerTy,
-                                 {PointerTy, /*FunctionData*/
-                                  I64Ty, /*Guid*/ I32Ty,
-                                  /*NumCounters*/ I32Ty /*NumCallsites*/},
-                                 false))
-              .getCallee());
-      GetCtx = cast<Function>(
-          M.getOrInsertFunction(CompilerRtAPINames::GetCtx,
-                                FunctionType::get(PointerTy,
-                                                  {PointerTy, /*FunctionData*/
-                                                   PointerTy, /*Callee*/
-                                                   I64Ty,     /*Guid*/
-                                                   I32Ty,     /*NumCounters*/
-                                                   I32Ty},    /*NumCallsites*/
-                                                  false))
-              .getCallee());
-      ReleaseCtx =
-          cast<Function>(M.getOrInsertFunction(
-                              CompilerRtAPINames::ReleaseCtx,
-                              FunctionType::get(Type::getVoidTy(M.getContext()),
-                                                {
-                                                    PointerTy, /*FunctionData*/
-                                                },
-                                                false))
-                             .getCallee());
-
-      // Declare the TLSes we will need to use.
-      CallsiteInfoTLS =
-          new GlobalVariable(M, PointerTy, false, GlobalValue::ExternalLinkage,
-                             nullptr, CompilerRtAPINames::CallsiteTLS);
-      CallsiteInfoTLS->setThreadLocal(true);
-      CallsiteInfoTLS->setVisibility(llvm::GlobalValue::HiddenVisibility);
-      ExpectedCalleeTLS =
-          new GlobalVariable(M, PointerTy, false, GlobalValue::ExternalLinkage,
-                             nullptr, CompilerRtAPINames::ExpectedCalleeTLS);
-      ExpectedCalleeTLS->setThreadLocal(true);
-      ExpectedCalleeTLS->setVisibility(llvm::GlobalValue::HiddenVisibility);
+  // Declare the functions we will call.
+  StartCtx = cast<Function>(
+      M.getOrInsertFunction(
+           CompilerRtAPINames::StartCtx,
+           FunctionType::get(PointerTy,
+                             {PointerTy, /*FunctionData*/
+                              I64Ty, /*Guid*/ I32Ty,
+                              /*NumCounters*/ I32Ty /*NumCallsites*/},
+                             false))
+          .getCallee());
+  GetCtx = cast<Function>(
+      M.getOrInsertFunction(CompilerRtAPINames::GetCtx,
+                            FunctionType::get(PointerTy,
+                                              {PointerTy, /*FunctionData*/
+                                               PointerTy, /*Callee*/
+                                               I64Ty,     /*Guid*/
+                                               I32Ty,     /*NumCounters*/
+                                               I32Ty},    /*NumCallsites*/
+                                              false))
+          .getCallee());
+  ReleaseCtx = cast<Function>(
+      M.getOrInsertFunction(CompilerRtAPINames::ReleaseCtx,
+                            FunctionType::get(Type::getVoidTy(M.getContext()),
+                                              {
+                                                  PointerTy, /*FunctionData*/
+                                              },
+                                              false))
+          .getCallee());
+
+  // Declare the TLSes we will need to use.
+  CallsiteInfoTLS =
+      new GlobalVariable(M, PointerTy, false, GlobalValue::ExternalLinkage,
+                         nullptr, CompilerRtAPINames::CallsiteTLS);
+  CallsiteInfoTLS->setThreadLocal(true);
+  CallsiteInfoTLS->setVisibility(llvm::GlobalValue::HiddenVisibility);
+  ExpectedCalleeTLS =
+      new GlobalVariable(M, PointerTy, false, GlobalValue::ExternalLinkage,
+                         nullptr, CompilerRtAPINames::ExpectedCalleeTLS);
+  ExpectedCalleeTLS->setThreadLocal(true);
+  ExpectedCalleeTLS->setVisibility(llvm::GlobalValue::HiddenVisibility);
 }
 
 PreservedAnalyses PGOCtxProfLoweringPass::run(Module &M,

``````````

</details>


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


More information about the llvm-commits mailing list