summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/IPO/HotColdSplitting.cpp
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2018-10-29 19:15:39 +0000
committerVedant Kumar <vsk@apple.com>2018-10-29 19:15:39 +0000
commitdd4be53b20a8e3ad43ed5b4e14f6c93d1a23ae34 (patch)
tree7d1fcada3ca33fe82b465a15287b85afcd9380e2 /llvm/lib/Transforms/IPO/HotColdSplitting.cpp
parent2f628a1030376e751194453d0b0788303d9f6811 (diff)
downloadbcm5719-llvm-dd4be53b20a8e3ad43ed5b4e14f6c93d1a23ae34.tar.gz
bcm5719-llvm-dd4be53b20a8e3ad43ed5b4e14f6c93d1a23ae34.zip
[HotColdSplitting] Allow outlining single-block cold regions
It can be profitable to outline single-block cold regions because they may be large. Allow outlining single-block regions if they have over some threshold of non-debug, non-terminator instructions. I chose 3 as the threshold after experimenting with several internal frameworks. In practice, reducing the threshold further did not give much improvement, whereas increasing it resulted in substantial regressions. Differential Revision: https://reviews.llvm.org/D53824 llvm-svn: 345524
Diffstat (limited to 'llvm/lib/Transforms/IPO/HotColdSplitting.cpp')
-rw-r--r--llvm/lib/Transforms/IPO/HotColdSplitting.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/IPO/HotColdSplitting.cpp b/llvm/lib/Transforms/IPO/HotColdSplitting.cpp
index 4f371a494e9..ce8a5060a3a 100644
--- a/llvm/lib/Transforms/IPO/HotColdSplitting.cpp
+++ b/llvm/lib/Transforms/IPO/HotColdSplitting.cpp
@@ -31,6 +31,7 @@
#include "llvm/IR/Function.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
+#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
@@ -65,6 +66,10 @@ using namespace llvm;
static cl::opt<bool> EnableStaticAnalyis("hot-cold-static-analysis",
cl::init(true), cl::Hidden);
+static cl::opt<unsigned> MinOutliningInstCount(
+ "min-outlining-inst-count", cl::init(3), cl::Hidden,
+ cl::desc("Minimum number of instructions needed for a single-block region "
+ "to be an outlining candidate"));
namespace {
@@ -130,6 +135,19 @@ static bool mayExtractBlock(const BasicBlock &BB) {
return !BB.hasAddressTaken();
}
+/// Check whether \p BB has at least \p Min non-debug, non-terminator
+/// instructions.
+static bool hasMinimumInstCount(const BasicBlock &BB, unsigned Min) {
+ unsigned Count = 0;
+ for (const Instruction &I : BB) {
+ if (isa<DbgInfoIntrinsic>(&I) || &I == BB.getTerminator())
+ continue;
+ if (++Count >= Min)
+ return true;
+ }
+ return false;
+}
+
/// Identify the maximal region of cold blocks which includes \p SinkBB.
///
/// Include all blocks post-dominated by \p SinkBB, \p SinkBB itself, and all
@@ -223,9 +241,8 @@ findMaximalColdRegion(BasicBlock &SinkBB, DominatorTree &DT, PostDomTree &PDT) {
++SuccIt;
}
- // TODO: Consider outlining regions with just 1 block, but more than some
- // threshold of instructions.
- if (ColdRegion.size() == 1)
+ if (ColdRegion.size() == 1 &&
+ !hasMinimumInstCount(*ColdRegion[0], MinOutliningInstCount))
return {};
return ColdRegion;
OpenPOWER on IntegriCloud