[PATCH] D84715: [FIX] Add check for empty body function

Wei Wang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 28 09:43:43 PDT 2020


weiwang added a comment.



In D84715#2177627 <https://reviews.llvm.org/D84715#2177627>, @wenlei wrote:

> I'm guessing these are not the only passes that will choke with empty/dead functions. If this is because ORE is being used for a special case, then we might want to fix the special case on the user side.
>
> If we want passes to absorb such empty functions, then there needs to be consistency for all passes. I don't think passes need to absorb such cases though, as this is really a "limbo state" of functions when being removed (a normal empty function should still have entry block and ret instruction).

Agree. The proposed checks are only placed along the particular call path that leads to the failure. If we are going cover all the analyses/passes, the overall effort could be substantial.

If the big assumption is that there shouldn't be an empty body function to deal with, we can probably change how ORE is created at the beginning. Instead of creating a heavy-weight version of ORE (with all dependent analyses invoked), using the light-weight version `OptimizationRemarkEmitter ORE(F, nullptr)` at LTO.cpp:801 <https://github.com/llvm/llvm-project/blob/master/llvm/lib/LTO/LTO.cpp#L801>.



================
Comment at: llvm/lib/Analysis/BranchProbabilityInfo.cpp:1071
                     << " ----\n\n");
+  if (F.empty())
+    return;
----------------
fhahn wrote:
> Are empty functions valid IR? Don't they have to have at least a single BB. And each BB needs at least a terminator?
This is a special case where function is marked dead and its body is completed strip away. AFAIK, it only happens before LTO backend, so analysis/pass in pass pipeline won't see such function.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84715/new/

https://reviews.llvm.org/D84715



More information about the llvm-commits mailing list