[clang] [llvm] [Clang] CGCoroutine: Skip moving parameters if the allocation decision is false (PR #81195)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 6 16:06:06 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 dcd08daed5fb9928fedb09c2a84d1e9d2ab59630 1e03c2ec24c7bc6a303266a7023a56d6449a46e5 -- clang/lib/CodeGen/CGCoroutine.cpp clang/test/CodeGenCoroutines/coro-gro.cpp clang/test/CodeGenCoroutines/coro-params.cpp llvm/lib/Transforms/Coroutines/CoroElide.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/Transforms/Coroutines/CoroElide.cpp b/llvm/lib/Transforms/Coroutines/CoroElide.cpp
index 51c155767c..3b0766031a 100644
--- a/llvm/lib/Transforms/Coroutines/CoroElide.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroElide.cpp
@@ -52,10 +52,9 @@ struct Lowerer : coro::LowererBase {
AAResults &AA);
bool shouldElide(Function *F, DominatorTree &DT) const;
void collectPostSplitCoroIds(Function *F);
- bool processCoroId(Function &F, CoroIdInst *, AAResults &AA, DominatorTree &DT,
- OptimizationRemarkEmitter &ORE);
- bool hasEscapePath(Function &F,
- const CoroBeginInst *,
+ bool processCoroId(Function &F, CoroIdInst *, AAResults &AA,
+ DominatorTree &DT, OptimizationRemarkEmitter &ORE);
+ bool hasEscapePath(Function &F, const CoroBeginInst *,
const SmallPtrSetImpl<BasicBlock *> &) const;
};
@@ -79,7 +78,8 @@ struct StackAliases {
return It != Stores.end() && It->second.size() == 1;
}
- const SmallPtrSetImpl<LoadInst *>& getLoadsByStore(const StoreInst *Store) const {
+ const SmallPtrSetImpl<LoadInst *> &
+ getLoadsByStore(const StoreInst *Store) const {
const static SmallPtrSet<LoadInst *, 4> EmptyStores;
auto Ptr = Store->getPointerOperand();
if (Loads.contains(Ptr)) {
@@ -89,7 +89,8 @@ struct StackAliases {
return EmptyStores;
}
- const SmallPtrSetImpl<StoreInst *>& getStoresByLoad(const LoadInst *Load) const {
+ const SmallPtrSetImpl<StoreInst *> &
+ getStoresByLoad(const LoadInst *Load) const {
const static SmallPtrSet<StoreInst *, 4> EmptyLoads;
auto Ptr = Load->getPointerOperand();
if (Stores.contains(Ptr)) {
@@ -108,8 +109,7 @@ private:
// Go through the list of coro.subfn.addr intrinsics and replace them with the
// provided constant.
template <typename Range>
-static void replaceWithConstant(Constant *Value,
- Range &Users) {
+static void replaceWithConstant(Constant *Value, Range &Users) {
if (Users.empty())
return;
@@ -233,10 +233,8 @@ void Lowerer::elideHeapAllocations(Function *F, uint64_t FrameSize,
removeTailCallAttribute(Frame, AA);
}
-bool Lowerer::hasEscapePath(
- Function &F,
- const CoroBeginInst *CB,
- const SmallPtrSetImpl<BasicBlock *> &TIs) const {
+bool Lowerer::hasEscapePath(Function &F, const CoroBeginInst *CB,
+ const SmallPtrSetImpl<BasicBlock *> &TIs) const {
const auto &It = DestroyAddr.find(CB);
assert(It != DestroyAddr.end());
@@ -261,8 +259,7 @@ bool Lowerer::hasEscapePath(
if (isa<CoroFreeInst, CoroSubFnInst, CoroSaveInst>(U))
continue;
- if (auto *SI = dyn_cast<StoreInst>(U);
- SI && SI->getPointerOperand() == U) {
+ if (auto *SI = dyn_cast<StoreInst>(U); SI && SI->getPointerOperand() == U) {
for (const auto *Load : SA.getLoadsByStore(SI)) {
AliasUsers.insert(Load);
}
@@ -364,7 +361,7 @@ bool Lowerer::shouldElide(Function *F, DominatorTree &DT) const {
}
SmallPtrSet<CoroBeginInst *, 8> CoroBeginsToTest;
- for (const auto& Class : CoroBeginClasses) {
+ for (const auto &Class : CoroBeginClasses) {
if (Class.isLeader()) {
CoroBeginsToTest.insert(Class.getData());
}
@@ -394,8 +391,7 @@ bool Lowerer::shouldElide(Function *F, DominatorTree &DT) const {
return DT.dominates(DA, TI->getTerminator());
});
}) ||
- !hasEscapePath(*F, CB, Terminators))
- {
+ !hasEscapePath(*F, CB, Terminators)) {
ReferencedCoroBegins.insert(CB);
} else {
llvm::dbgs() << "not referenced\n";
@@ -407,8 +403,7 @@ bool Lowerer::shouldElide(Function *F, DominatorTree &DT) const {
// perform heap elision.
llvm::dbgs() << "DestroyAddr: " << DestroyAddr.size()
<< " ReferencedCoroBegins: " << ReferencedCoroBegins.size()
- << " CoroBeginsToTest: " << CoroBeginsToTest.size()
- << "\n";
+ << " CoroBeginsToTest: " << CoroBeginsToTest.size() << "\n";
return ReferencedCoroBegins.size() == CoroBeginsToTest.size();
}
@@ -437,10 +432,9 @@ void Lowerer::collectPostSplitCoroIds(Function *F) {
}
}
-static void findReachableCoroSubFnForValue(
- llvm::Value *V,
- const StackAliases &SA,
- SmallSet<CoroSubFnInst *, 4> &Res) {
+static void findReachableCoroSubFnForValue(llvm::Value *V,
+ const StackAliases &SA,
+ SmallSet<CoroSubFnInst *, 4> &Res) {
if (auto *CSFI = dyn_cast<CoroSubFnInst>(V)) {
Res.insert(CSFI);
@@ -472,7 +466,8 @@ bool Lowerer::processCoroId(Function &F, CoroIdInst *CoroId, AAResults &AA,
CoroAllocs.clear();
ResumeAddr.clear();
DestroyAddr.clear();
- CoroBeginClasses = EquivalenceClasses<CoroBeginInst *>{}; // No clear function.
+ CoroBeginClasses =
+ EquivalenceClasses<CoroBeginInst *>{}; // No clear function.
// Collect all coro.begin and coro.allocs associated with this coro.id.
for (User *U : CoroId->users()) {
@@ -483,7 +478,8 @@ bool Lowerer::processCoroId(Function &F, CoroIdInst *CoroId, AAResults &AA,
CoroAllocs.push_back(CA);
}
- // Create Equivalent Classes for CoroBegins, so that multiple begins going to the same Phi Node can be count as one.
+ // Create Equivalent Classes for CoroBegins, so that multiple begins going to
+ // the same Phi Node can be count as one.
for (CoroBeginInst *CB : CoroBegins) {
CoroBeginClasses.insert(CB);
for (User *U : CB->users()) {
@@ -501,7 +497,7 @@ bool Lowerer::processCoroId(Function &F, CoroIdInst *CoroId, AAResults &AA,
StackAliases SA{F};
// Collect all coro.subfn.addrs associated with coro.begin.
- for (const auto& Class : CoroBeginClasses) {
+ for (const auto &Class : CoroBeginClasses) {
if (!Class.isLeader()) {
continue;
}
@@ -510,14 +506,14 @@ bool Lowerer::processCoroId(Function &F, CoroIdInst *CoroId, AAResults &AA,
findReachableCoroSubFnForValue(Leader, SA, Res);
for (auto *CSFI : Res) {
switch (CSFI->getIndex()) {
- case llvm::CoroSubFnInst::ResumeIndex:
- ResumeAddr.insert(CSFI);
- break;
- case llvm::CoroSubFnInst::DestroyIndex:
- DestroyAddr[Leader].insert(CSFI);
- break;
- default:
- llvm_unreachable("unexpected coro.subfn.addr constant");
+ case llvm::CoroSubFnInst::ResumeIndex:
+ ResumeAddr.insert(CSFI);
+ break;
+ case llvm::CoroSubFnInst::DestroyIndex:
+ DestroyAddr[Leader].insert(CSFI);
+ break;
+ default:
+ llvm_unreachable("unexpected coro.subfn.addr constant");
}
}
}
@@ -533,7 +529,8 @@ bool Lowerer::processCoroId(Function &F, CoroIdInst *CoroId, AAResults &AA,
replaceWithConstant(ResumeAddrConstant, ResumeAddr);
bool ShouldElide = shouldElide(CoroId->getFunction(), DT);
- llvm::dbgs() << "ShouldElide " << CoroId->getCoroutine()->getName() << ": " << ShouldElide << "\n";
+ llvm::dbgs() << "ShouldElide " << CoroId->getCoroutine()->getName() << ": "
+ << ShouldElide << "\n";
if (!ShouldElide)
ORE.emit([&]() {
if (auto FrameSizeAndAlign =
``````````
</details>
https://github.com/llvm/llvm-project/pull/81195
More information about the cfe-commits
mailing list