[llvm] Pack out arguments into a struct (PR #119267)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 9 12:45:37 PST 2024
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 ae719f07562a2eb74f620b1f6d798d6507760514 1ab8d0c54403c0fc29013aa02adcc1781fd1d2e4 --extensions cpp -- llvm/lib/Transforms/IPO/Attributor.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 90eecf4589..1757d65080 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -2965,10 +2965,12 @@ bool Attributor::shouldSeedAttribute(AbstractAttribute &AA) {
// For now: argument can be put in the struct if it's write only and
// has no aliases.
-static bool canBeComapctedInAStruct(const Argument &Arg, Attributor &A, const AbstractAttribute &QueryingAA) {
+static bool canBeComapctedInAStruct(const Argument &Arg, Attributor &A,
+ const AbstractAttribute &QueryingAA) {
IRPosition ArgPosition = IRPosition::argument(Arg);
// Check if Arg has no alias.
- auto *AAliasInfo = A.getAAFor<AANoAlias>(QueryingAA, ArgPosition, DepClassTy::NONE);
+ auto *AAliasInfo =
+ A.getAAFor<AANoAlias>(QueryingAA, ArgPosition, DepClassTy::NONE);
if (!AAliasInfo || !AAliasInfo->isKnownNoAlias())
return false;
@@ -2981,8 +2983,10 @@ static bool canBeComapctedInAStruct(const Argument &Arg, Attributor &A, const Ab
return true;
}
-static void replaceArgRetWithStructRetCalls(Function &OldFunction, Function &NewFunction) {
- for (auto UseItr = OldFunction.use_begin(); UseItr != OldFunction.use_end(); ++UseItr) {
+static void replaceArgRetWithStructRetCalls(Function &OldFunction,
+ Function &NewFunction) {
+ for (auto UseItr = OldFunction.use_begin(); UseItr != OldFunction.use_end();
+ ++UseItr) {
CallBase *Call = dyn_cast<CallBase>(UseItr->getUser());
if (!Call)
continue;
@@ -2991,7 +2995,9 @@ static void replaceArgRetWithStructRetCalls(Function &OldFunction, Function &New
SmallVector<Value *, 8> NewArgs;
for (unsigned ArgIdx = 0; ArgIdx < Call->arg_size(); ++ArgIdx)
if (std::find_if(OldFunction.arg_begin(), OldFunction.arg_end(),
- [&](Argument &Arg) { return &Arg == Call->getArgOperand(ArgIdx); }) == OldFunction.arg_end())
+ [&](Argument &Arg) {
+ return &Arg == Call->getArgOperand(ArgIdx);
+ }) == OldFunction.arg_end())
NewArgs.push_back(Call->getArgOperand(ArgIdx));
CallInst *NewCall = Builder.CreateCall(&NewFunction, NewArgs);
@@ -3000,12 +3006,14 @@ static void replaceArgRetWithStructRetCalls(Function &OldFunction, Function &New
}
}
-static bool convertOutArgsToRetStruct(Function &F, Attributor &A, AbstractAttribute &QueryingAA) {
+static bool convertOutArgsToRetStruct(Function &F, Attributor &A,
+ AbstractAttribute &QueryingAA) {
// Get valid ptr args.
- DenseMap<Argument *, Type *> PtrToType;
+ DenseMap<Argument *, Type *> PtrToType;
for (unsigned ArgIdx = 0; ArgIdx < F.arg_size(); ++ArgIdx) {
Argument *Arg = F.getArg(ArgIdx);
- if (Arg->getType()->isPointerTy() && canBeComapctedInAStruct(*Arg, A, QueryingAA)) {
+ if (Arg->getType()->isPointerTy() &&
+ canBeComapctedInAStruct(*Arg, A, QueryingAA)) {
// Get the the type of the pointer through its users
for (auto UseItr = Arg->use_begin(); UseItr != Arg->use_end(); ++UseItr) {
auto *Store = dyn_cast<StoreInst>(UseItr->getUser());
@@ -3027,7 +3035,8 @@ static bool convertOutArgsToRetStruct(Function &F, Attributor &A, AbstractAttrib
for (const auto &[Arg, Type] : PtrToType)
OutStructElements.push_back(Type);
- auto *ReturnStructType = StructType::create(F.getContext(), OutStructElements, (F.getName() + "Out").str());
+ auto *ReturnStructType = StructType::create(F.getContext(), OutStructElements,
+ (F.getName() + "Out").str());
// Get the new Args.
SmallVector<Type *, 4> NewParamTypes;
@@ -3035,8 +3044,10 @@ static bool convertOutArgsToRetStruct(Function &F, Attributor &A, AbstractAttrib
if (!PtrToType.count(F.getArg(ArgIdx)))
NewParamTypes.push_back(F.getArg(ArgIdx)->getType());
- auto *NewFunctionType = FunctionType::get(ReturnStructType, NewParamTypes, F.isVarArg());
- auto *NewFunction = Function::Create(NewFunctionType, F.getLinkage(), F.getAddressSpace(), F.getName());
+ auto *NewFunctionType =
+ FunctionType::get(ReturnStructType, NewParamTypes, F.isVarArg());
+ auto *NewFunction = Function::Create(NewFunctionType, F.getLinkage(),
+ F.getAddressSpace(), F.getName());
// Map old args to new args.
ValueToValueMapTy VMap;
@@ -3047,7 +3058,8 @@ static bool convertOutArgsToRetStruct(Function &F, Attributor &A, AbstractAttrib
// Clone the old function into the new one.
SmallVector<ReturnInst *, 8> Returns;
- CloneFunctionInto(NewFunction, &F, VMap, CloneFunctionChangeType::LocalChangesOnly, Returns);
+ CloneFunctionInto(NewFunction, &F, VMap,
+ CloneFunctionChangeType::LocalChangesOnly, Returns);
// Update the return values (make it struct).
for (ReturnInst *Ret : Returns) {
@@ -3066,7 +3078,8 @@ static bool convertOutArgsToRetStruct(Function &F, Attributor &A, AbstractAttrib
// Build the return struct incrementally.
Value *StructRetVal = UndefValue::get(ReturnStructType);
for (unsigned i = 0; i < StructValues.size(); ++i)
- StructRetVal = Builder.CreateInsertValue(StructRetVal, StructValues[i], i);
+ StructRetVal =
+ Builder.CreateInsertValue(StructRetVal, StructValues[i], i);
Builder.CreateRet(StructRetVal);
Ret->eraseFromParent();
``````````
</details>
https://github.com/llvm/llvm-project/pull/119267
More information about the llvm-commits
mailing list