aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/BranchFolding.cpp
diff options
context:
space:
mode:
authorPengcheng Wang <wangpengcheng.pp@bytedance.com>2024-07-22 14:41:07 +0800
committerGitHub <noreply@github.com>2024-07-22 14:41:07 +0800
commit6b9ac2a4951453fa61fbda285a23be1b32bbff49 (patch)
tree82e78b1027dd5d17f6044f000fc1be3ab9b2d955 /llvm/lib/CodeGen/BranchFolding.cpp
parent8dafbb5fdd4099df72d24af2ceb7ecade8216820 (diff)
downloadllvm-6b9ac2a4951453fa61fbda285a23be1b32bbff49.zip
llvm-6b9ac2a4951453fa61fbda285a23be1b32bbff49.tar.gz
llvm-6b9ac2a4951453fa61fbda285a23be1b32bbff49.tar.bz2
[BranchFolding] Add a hook to override tail merge size (#99025)
A new hook `TargetInstrInfo::getTailMergeSize()` is added so that targets can override it. This removes an existing TODO.
Diffstat (limited to 'llvm/lib/CodeGen/BranchFolding.cpp')
-rw-r--r--llvm/lib/CodeGen/BranchFolding.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp
index c0fc7a2..92a03eb5 100644
--- a/llvm/lib/CodeGen/BranchFolding.cpp
+++ b/llvm/lib/CodeGen/BranchFolding.cpp
@@ -80,7 +80,6 @@ TailMergeThreshold("tail-merge-threshold",
cl::init(150), cl::Hidden);
// Heuristic for tail merging (and, inversely, tail duplication).
-// TODO: This should be replaced with a target query.
static cl::opt<unsigned>
TailMergeSize("tail-merge-size",
cl::desc("Min number of instructions to consider tail merging"),
@@ -145,8 +144,6 @@ BranchFolder::BranchFolder(bool DefaultEnableTailMerge, bool CommonHoist,
ProfileSummaryInfo *PSI, unsigned MinTailLength)
: EnableHoistCommonCode(CommonHoist), MinCommonTailLength(MinTailLength),
MBBFreqInfo(FreqInfo), MBPI(ProbInfo), PSI(PSI) {
- if (MinCommonTailLength == 0)
- MinCommonTailLength = TailMergeSize;
switch (FlagEnableTailMerge) {
case cl::BOU_UNSET:
EnableTailMerge = DefaultEnableTailMerge;
@@ -195,6 +192,12 @@ bool BranchFolder::OptimizeFunction(MachineFunction &MF,
MLI = mli;
this->MRI = &MRI;
+ if (MinCommonTailLength == 0) {
+ MinCommonTailLength = TailMergeSize.getNumOccurrences() > 0
+ ? TailMergeSize
+ : TII->getTailMergeSize(MF);
+ }
+
UpdateLiveIns = MRI.tracksLiveness() && TRI->trackLivenessAfterRegAlloc(MF);
if (!UpdateLiveIns)
MRI.invalidateLiveness();