[PATCH] D93946: [FuncAttrs] Infer noreturn
Reid Kleckner via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 5 11:36:44 PST 2021
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.
lgtm
================
Comment at: llvm/lib/Transforms/IPO/FunctionAttrs.cpp:1415-1430
+ bool BasicBlockCanReachReturn = true;
+ for (Instruction &I : BB) {
+ if (instructionDoesNotReturn(I)) {
+ BasicBlockCanReachReturn = false;
+ break;
+ }
+ }
----------------
This is code golf, but there is this code style rule here to consider:
https://llvm.org/docs/CodingStandards.html#turn-predicate-loops-into-predicate-functions
This code could be:
// A BB can only return if it ends in ReturnInst and does not contain any calls to noreturn functions.
static bool canBasicBlockReturn(const BasicBlock &BB) {
if (isa<ReturnInst>(BB.getTerminator()))
return llvm::none_of(BB, instructionDoesNotReturn);
return false;
}
...
if (llvm::none_of(F, canBasicBlockReturn)) {
Changed = true;
F->setDoesNotReturn();
}
Feel free to implement or disregard.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D93946/new/
https://reviews.llvm.org/D93946
More information about the llvm-commits
mailing list