[llvm] [RFC][Attributor] change argument privatization to size-based type selection (PR #181716)

via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 16 10:22:52 PST 2026


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 origin/main HEAD --extensions cpp,h -- llvm/include/llvm/Transforms/IPO/Attributor.h llvm/lib/Transforms/IPO/AttributorAttributes.cpp --diff_from_common_commit
``````````

:warning:
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.
:warning:

</details>

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

``````````diff
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 17b9b9308..26fd1afc7 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -7382,9 +7382,8 @@ struct AAPrivatizablePtrArgument final : public AAPrivatizablePtrImpl {
     }
 
     // Get alignment information for choosing optimal type
-    const auto *AlignAA =
-        A.getAAFor<AAAlign>(*this, IRPosition::value(getAssociatedValue()),
-                            DepClassTy::OPTIONAL);
+    const auto *AlignAA = A.getAAFor<AAAlign>(
+        *this, IRPosition::value(getAssociatedValue()), DepClassTy::OPTIONAL);
     Align Alignment = AlignAA ? AlignAA->getAssumedAlign() : Align(1);
 
     // Get TTI for target-specific type selection
@@ -7532,9 +7531,9 @@ struct AAPrivatizablePtrArgument final : public AAPrivatizablePtrImpl {
   /// 2. Up to vector register size: use vector of integers
   /// 3. Otherwise: use array of integers sized to alignment
   static Type *getPrivatizableReplacementType(uint64_t Size, Align Alignment,
-                                               const DataLayout &DL,
-                                               LLVMContext &Ctx,
-                                               const TargetTransformInfo *TTI) {
+                                              const DataLayout &DL,
+                                              LLVMContext &Ctx,
+                                              const TargetTransformInfo *TTI) {
     // Strategy 1: If size fits in pointer, use integer type
     uint64_t PointerSizeInBits = DL.getPointerSizeInBits();
     if (Size * 8 <= PointerSizeInBits)
@@ -7574,10 +7573,11 @@ struct AAPrivatizablePtrArgument final : public AAPrivatizablePtrImpl {
     return ArrayType::get(ElementTy, NumElements);
   }
 
-  /// Initialize \p Base with the replacement value argument at position \p ArgNo.
-  /// Stores the value argument into the alloca.
-  static void createInitialization(Type *ReplacementTy, Value &Base, Function &F,
-                                   unsigned ArgNo, BasicBlock::iterator IP) {
+  /// Initialize \p Base with the replacement value argument at position \p
+  /// ArgNo. Stores the value argument into the alloca.
+  static void createInitialization(Type *ReplacementTy, Value &Base,
+                                   Function &F, unsigned ArgNo,
+                                   BasicBlock::iterator IP) {
     assert(ReplacementTy && "Expected valid replacement type!");
 
     // The argument is a value - store it into the alloca
@@ -7603,7 +7603,8 @@ struct AAPrivatizablePtrArgument final : public AAPrivatizablePtrImpl {
   ChangeStatus manifest(Attributor &A) override {
     if (!PrivatizableSize)
       return ChangeStatus::UNCHANGED;
-    assert(!PrivatizableSize->isZero() && "Expected non-zero privatizable size!");
+    assert(!PrivatizableSize->isZero() &&
+           "Expected non-zero privatizable size!");
 
     // Collect all tail calls in the function as we cannot allow new allocas to
     // escape into tail recursion.
@@ -7627,7 +7628,8 @@ struct AAPrivatizablePtrArgument final : public AAPrivatizablePtrImpl {
         A.getAAFor<AAAlign>(*this, IRPosition::value(*Arg), DepClassTy::NONE);
 
     // Callback to repair the associated function. A new alloca is placed at the
-    // beginning and initialized with the replacement value passed as an argument.
+    // beginning and initialized with the replacement value passed as an
+    // argument.
     Type *RepTy = PrivatizableType;
     Attributor::ArgumentReplacementInfo::CalleeRepairCBTy FnRepairCB =
         [=](const Attributor::ArgumentReplacementInfo &ARI,
@@ -7636,10 +7638,10 @@ struct AAPrivatizablePtrArgument final : public AAPrivatizablePtrImpl {
           BasicBlock::iterator IP = EntryBB.getFirstInsertionPt();
           const DataLayout &DL = IP->getDataLayout();
           unsigned AS = DL.getAllocaAddrSpace();
-          Instruction *AI = new AllocaInst(RepTy, AS,
-                                           Arg->getName() + ".priv", IP);
-          createInitialization(RepTy, *AI, ReplacementFn,
-                               ArgIt->getArgNo(), IP);
+          Instruction *AI =
+              new AllocaInst(RepTy, AS, Arg->getName() + ".priv", IP);
+          createInitialization(RepTy, *AI, ReplacementFn, ArgIt->getArgNo(),
+                               IP);
 
           if (AI->getType() != Arg->getType())
             AI = BitCastInst::CreatePointerBitCastOrAddrSpaceCast(
@@ -7650,16 +7652,16 @@ struct AAPrivatizablePtrArgument final : public AAPrivatizablePtrImpl {
             CI->setTailCall(false);
         };
 
-    // Callback to repair a call site of the associated function. The replacement
-    // value is loaded prior to the call and passed to the new function version.
+    // Callback to repair a call site of the associated function. The
+    // replacement value is loaded prior to the call and passed to the new
+    // function version.
     Attributor::ArgumentReplacementInfo::ACSRepairCBTy ACSRepairCB =
         [=](const Attributor::ArgumentReplacementInfo &ARI,
             AbstractCallSite ACS, SmallVectorImpl<Value *> &NewArgOperands) {
           // When no alignment is specified for the load instruction,
           // natural alignment is assumed.
           createReplacementValues(
-              AlignAA ? AlignAA->getAssumedAlign() : Align(0),
-              RepTy, ACS,
+              AlignAA ? AlignAA->getAssumedAlign() : Align(0), RepTy, ACS,
               ACS.getCallArgOperand(ARI.getReplacedArg().getArgNo()),
               NewArgOperands);
         };

``````````

</details>


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


More information about the llvm-commits mailing list