[llvm] d3e8495 - [FunctionAttrs] Slightly clean up returned attr inference (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 22 00:33:01 PST 2023
Author: Nikita Popov
Date: 2023-02-22T09:32:53+01:00
New Revision: d3e84953ddbbfc2b6298ae108f5852ba7786e9c8
URL: https://github.com/llvm/llvm-project/commit/d3e84953ddbbfc2b6298ae108f5852ba7786e9c8
DIFF: https://github.com/llvm/llvm-project/commit/d3e84953ddbbfc2b6298ae108f5852ba7786e9c8.diff
LOG: [FunctionAttrs] Slightly clean up returned attr inference (NFC)
Use hasAttrSomewhere() and directly return Argument from the
helper.
Added:
Modified:
llvm/lib/Transforms/IPO/FunctionAttrs.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index 95dc7ba97aea..6e4876a0cc7b 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -723,18 +723,18 @@ static void addArgumentReturnedAttrs(const SCCNodeSet &SCCNodes,
continue;
// There is nothing to do if an argument is already marked as 'returned'.
- if (llvm::any_of(F->args(),
- [](const Argument &Arg) { return Arg.hasReturnedAttr(); }))
+ if (F->getAttributes().hasAttrSomewhere(Attribute::Returned))
continue;
- auto FindRetArg = [&]() -> Value * {
- Value *RetArg = nullptr;
+ auto FindRetArg = [&]() -> Argument * {
+ Argument *RetArg = nullptr;
for (BasicBlock &BB : *F)
if (auto *Ret = dyn_cast<ReturnInst>(BB.getTerminator())) {
// Note that stripPointerCasts should look through functions with
// returned arguments.
- Value *RetVal = Ret->getReturnValue()->stripPointerCasts();
- if (!isa<Argument>(RetVal) || RetVal->getType() != F->getReturnType())
+ auto *RetVal =
+ dyn_cast<Argument>(Ret->getReturnValue()->stripPointerCasts());
+ if (!RetVal || RetVal->getType() != F->getReturnType())
return nullptr;
if (!RetArg)
@@ -746,9 +746,8 @@ static void addArgumentReturnedAttrs(const SCCNodeSet &SCCNodes,
return RetArg;
};
- if (Value *RetArg = FindRetArg()) {
- auto *A = cast<Argument>(RetArg);
- A->addAttr(Attribute::Returned);
+ if (Argument *RetArg = FindRetArg()) {
+ RetArg->addAttr(Attribute::Returned);
++NumReturned;
Changed.insert(F);
}
More information about the llvm-commits
mailing list