Skip to content

Commit

Permalink
Improve static analysis of cold basic blocks
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D52704

Reviewers: sebpop, tejohnson, brzycki, SirishP
Reviewed By: sebpop

llvm-svn: 343663
  • Loading branch information
hiraditya committed Oct 3, 2018
1 parent 9e20ade commit a27014b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion llvm/lib/Transforms/IPO/HotColdSplitting.cpp
Expand Up @@ -111,6 +111,18 @@ bool blockEndsInUnreachable(const BasicBlock &BB) {
return succ_empty(&BB);
}

static bool exceptionHandlingFunctions(const CallInst *CI) {
auto F = CI->getCalledFunction();
if (!F)
return false;
auto FName = F->getName();
return FName == "__cxa_begin_catch" ||
FName == "__cxa_free_exception" ||
FName == "__cxa_allocate_exception" ||
FName == "__cxa_begin_catch" ||
FName == "__cxa_end_catch";
}

static
bool unlikelyExecuted(const BasicBlock &BB) {
if (blockEndsInUnreachable(BB))
Expand All @@ -122,7 +134,8 @@ bool unlikelyExecuted(const BasicBlock &BB) {
if (const CallInst *CI = dyn_cast<CallInst>(&I)) {
// The block is cold if it calls functions tagged as cold or noreturn.
if (CI->hasFnAttr(Attribute::Cold) ||
CI->hasFnAttr(Attribute::NoReturn))
CI->hasFnAttr(Attribute::NoReturn) ||
exceptionHandlingFunctions(CI))
return true;

// Assume that inline assembly is hot code.
Expand Down

0 comments on commit a27014b

Please sign in to comment.