-
Notifications
You must be signed in to change notification settings - Fork 11.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Coroutines] Better optimization remarks for CoroAnnotationElide pass #109352
[Coroutines] Better optimization remarks for CoroAnnotationElide pass #109352
Conversation
614a6f7
to
f25a43f
Compare
@llvm/pr-subscribers-llvm-transforms Author: Yuxuan Chen (yuxuanchen1997) ChangesShow why the elision did not happen for a certain coroutine call. Currently there might be two reasons.
Full diff: https://github.com/llvm/llvm-project/pull/109352.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Coroutines/CoroAnnotationElide.cpp b/llvm/lib/Transforms/Coroutines/CoroAnnotationElide.cpp
index ed036f254a1cfb..5f19d600a983aa 100644
--- a/llvm/lib/Transforms/Coroutines/CoroAnnotationElide.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroAnnotationElide.cpp
@@ -101,42 +101,54 @@ PreservedAnalyses CoroAnnotationElidePass::run(Function &F,
Function *NewCallee =
F.getParent()->getFunction((F.getName() + ".noalloc").str());
- if (!NewCallee) {
- return PreservedAnalyses::all();
- }
-
- auto FramePtrArgPosition = NewCallee->arg_size() - 1;
- auto FrameSize =
- NewCallee->getParamDereferenceableBytes(FramePtrArgPosition);
- auto FrameAlign =
- NewCallee->getParamAlign(FramePtrArgPosition).valueOrOne();
-
- SmallVector<CallBase *, 4> Users;
- for (auto *U : F.users()) {
- if (auto *CB = dyn_cast<CallBase>(U)) {
- if (CB->getCalledFunction() == &F)
- Users.push_back(CB);
- }
- }
- auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(F);
+ if (!NewCallee)
+ return PreservedAnalyses::all();
- for (auto *CB : Users) {
- auto *Caller = CB->getFunction();
- if (Caller && Caller->isPresplitCoroutine() &&
- CB->hasFnAttr(llvm::Attribute::CoroElideSafe)) {
+ auto FramePtrArgPosition = NewCallee->arg_size() - 1;
+ auto FrameSize = NewCallee->getParamDereferenceableBytes(FramePtrArgPosition);
+ auto FrameAlign = NewCallee->getParamAlign(FramePtrArgPosition).valueOrOne();
- processCall(CB, Caller, NewCallee, FrameSize, FrameAlign);
+ SmallVector<CallBase *, 4> Users;
+ for (auto *U : F.users()) {
+ if (auto *CB = dyn_cast<CallBase>(U)) {
+ if (CB->getCalledFunction() == &F)
+ Users.push_back(CB);
+ }
+ }
- ORE.emit([&]() {
- return OptimizationRemark(DEBUG_TYPE, "CoroAnnotationElide", Caller)
- << "'" << ore::NV("callee", F.getName()) << "' elided in '"
- << ore::NV("caller", Caller->getName());
- });
- FAM.invalidate(*Caller, PreservedAnalyses::none());
- Changed = true;
- }
+ auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(F);
+
+ for (auto *CB : Users) {
+ auto *Caller = CB->getFunction();
+ if (!Caller)
+ continue;
+
+ bool IsCallerPresplitCoroutine = Caller->isPresplitCoroutine();
+ bool HasAttr = CB->hasFnAttr(llvm::Attribute::CoroElideSafe);
+ if (IsCallerPresplitCoroutine && HasAttr) {
+ processCall(CB, Caller, NewCallee, FrameSize, FrameAlign);
+
+ ORE.emit([&]() {
+ return OptimizationRemark(DEBUG_TYPE, "CoroAnnotationElide", Caller)
+ << "'" << ore::NV("callee", F.getName()) << "' elided in '"
+ << ore::NV("caller", Caller->getName()) << "'";
+ });
+
+ FAM.invalidate(*Caller, PreservedAnalyses::none());
+ Changed = true;
+ } else {
+ ORE.emit([&]() {
+ return OptimizationRemarkMissed(DEBUG_TYPE, "CoroAnnotationElide",
+ Caller)
+ << "'" << ore::NV("callee", F.getName()) << "' not elided in '"
+ << ore::NV("caller", Caller->getName()) << "' (caller_presplit="
+ << ore::NV("caller_presplit", IsCallerPresplitCoroutine)
+ << ", elide_safe_attr=" << ore::NV("elide_safe_attr", HasAttr)
+ << ")";
+ });
}
+ }
return Changed ? PreservedAnalyses::none() : PreservedAnalyses::all();
}
|
@llvm/pr-subscribers-coroutines Author: Yuxuan Chen (yuxuanchen1997) ChangesShow why the elision did not happen for a certain coroutine call. Currently there might be two reasons.
Full diff: https://github.com/llvm/llvm-project/pull/109352.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Coroutines/CoroAnnotationElide.cpp b/llvm/lib/Transforms/Coroutines/CoroAnnotationElide.cpp
index ed036f254a1cfb..5f19d600a983aa 100644
--- a/llvm/lib/Transforms/Coroutines/CoroAnnotationElide.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroAnnotationElide.cpp
@@ -101,42 +101,54 @@ PreservedAnalyses CoroAnnotationElidePass::run(Function &F,
Function *NewCallee =
F.getParent()->getFunction((F.getName() + ".noalloc").str());
- if (!NewCallee) {
- return PreservedAnalyses::all();
- }
-
- auto FramePtrArgPosition = NewCallee->arg_size() - 1;
- auto FrameSize =
- NewCallee->getParamDereferenceableBytes(FramePtrArgPosition);
- auto FrameAlign =
- NewCallee->getParamAlign(FramePtrArgPosition).valueOrOne();
-
- SmallVector<CallBase *, 4> Users;
- for (auto *U : F.users()) {
- if (auto *CB = dyn_cast<CallBase>(U)) {
- if (CB->getCalledFunction() == &F)
- Users.push_back(CB);
- }
- }
- auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(F);
+ if (!NewCallee)
+ return PreservedAnalyses::all();
- for (auto *CB : Users) {
- auto *Caller = CB->getFunction();
- if (Caller && Caller->isPresplitCoroutine() &&
- CB->hasFnAttr(llvm::Attribute::CoroElideSafe)) {
+ auto FramePtrArgPosition = NewCallee->arg_size() - 1;
+ auto FrameSize = NewCallee->getParamDereferenceableBytes(FramePtrArgPosition);
+ auto FrameAlign = NewCallee->getParamAlign(FramePtrArgPosition).valueOrOne();
- processCall(CB, Caller, NewCallee, FrameSize, FrameAlign);
+ SmallVector<CallBase *, 4> Users;
+ for (auto *U : F.users()) {
+ if (auto *CB = dyn_cast<CallBase>(U)) {
+ if (CB->getCalledFunction() == &F)
+ Users.push_back(CB);
+ }
+ }
- ORE.emit([&]() {
- return OptimizationRemark(DEBUG_TYPE, "CoroAnnotationElide", Caller)
- << "'" << ore::NV("callee", F.getName()) << "' elided in '"
- << ore::NV("caller", Caller->getName());
- });
- FAM.invalidate(*Caller, PreservedAnalyses::none());
- Changed = true;
- }
+ auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(F);
+
+ for (auto *CB : Users) {
+ auto *Caller = CB->getFunction();
+ if (!Caller)
+ continue;
+
+ bool IsCallerPresplitCoroutine = Caller->isPresplitCoroutine();
+ bool HasAttr = CB->hasFnAttr(llvm::Attribute::CoroElideSafe);
+ if (IsCallerPresplitCoroutine && HasAttr) {
+ processCall(CB, Caller, NewCallee, FrameSize, FrameAlign);
+
+ ORE.emit([&]() {
+ return OptimizationRemark(DEBUG_TYPE, "CoroAnnotationElide", Caller)
+ << "'" << ore::NV("callee", F.getName()) << "' elided in '"
+ << ore::NV("caller", Caller->getName()) << "'";
+ });
+
+ FAM.invalidate(*Caller, PreservedAnalyses::none());
+ Changed = true;
+ } else {
+ ORE.emit([&]() {
+ return OptimizationRemarkMissed(DEBUG_TYPE, "CoroAnnotationElide",
+ Caller)
+ << "'" << ore::NV("callee", F.getName()) << "' not elided in '"
+ << ore::NV("caller", Caller->getName()) << "' (caller_presplit="
+ << ore::NV("caller_presplit", IsCallerPresplitCoroutine)
+ << ", elide_safe_attr=" << ore::NV("elide_safe_attr", HasAttr)
+ << ")";
+ });
}
+ }
return Changed ? PreservedAnalyses::none() : PreservedAnalyses::all();
}
|
Show why the elision did not happen for a certain coroutine call. Currently there might be two reasons.