Skip to content

[CodeGen] Add an option to skip extTSP BB placement for huge functions. #99310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion llvm/lib/CodeGen/MachineBlockPlacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ static cl::opt<bool> RenumberBlocksBeforeView(
"into a dot graph. Only used when a function is being printed."),
cl::init(false), cl::Hidden);

static cl::opt<unsigned> ExtTspBlockPlacementMaxBlocks(
"ext-tsp-block-placement-max-blocks",
cl::desc("Maximum number of basic blocks in a function to run ext-TSP "
"block placement."),
cl::init(UINT_MAX), cl::Hidden);

namespace llvm {
extern cl::opt<bool> EnableExtTspBlockPlacement;
extern cl::opt<bool> ApplyExtTspWithoutProfile;
Expand Down Expand Up @@ -3511,7 +3517,8 @@ bool MachineBlockPlacement::runOnMachineFunction(MachineFunction &MF) {

// Apply a post-processing optimizing block placement.
if (MF.size() >= 3 && EnableExtTspBlockPlacement &&
(ApplyExtTspWithoutProfile || MF.getFunction().hasProfileData())) {
(ApplyExtTspWithoutProfile || MF.getFunction().hasProfileData()) &&
MF.size() <= ExtTspBlockPlacementMaxBlocks) {
// Find a new placement and modify the layout of the blocks in the function.
applyExtTsp();

Expand Down
15 changes: 15 additions & 0 deletions llvm/test/CodeGen/X86/code_placement_ext_tsp_large.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
; RUN: llc -mcpu=corei7 -mtriple=x86_64-linux -enable-ext-tsp-block-placement=1 -ext-tsp-chain-split-threshold=128 -debug-only=block-placement < %s 2>&1 | FileCheck %s
; RUN: llc -mcpu=corei7 -mtriple=x86_64-linux -enable-ext-tsp-block-placement=1 -ext-tsp-chain-split-threshold=1 -debug-only=block-placement < %s 2>&1 | FileCheck %s -check-prefix=CHECK2
; RUN: llc -mcpu=corei7 -mtriple=x86_64-linux -enable-ext-tsp-block-placement=0 -debug-only=block-placement < %s 2>&1 | FileCheck %s -check-prefix=CHECK3
; RUN: llc -mcpu=corei7 -mtriple=x86_64-linux -enable-ext-tsp-block-placement=1 -ext-tsp-block-placement-max-blocks=8 -debug-only=block-placement < %s 2>&1 | FileCheck %s -check-prefix=CHECK4

@yydebug = dso_local global i32 0, align 4

Expand Down Expand Up @@ -110,6 +111,20 @@ define void @func_large() !prof !0 {
; CHECK3: b7
; CHECK3: b8
; CHECK3: b9
;
; An expected output with function size larger than the threshold -- the layout is not modified:
;
; CHECK4-LABEL: func_large:
; CHECK4: b0
; CHECK4: b1
; CHECK4: b2
; CHECK4: b3
; CHECK4: b4
; CHECK4: b5
; CHECK4: b6
; CHECK4: b7
; CHECK4: b8
; CHECK4: b9

b0:
%0 = load i32, ptr @yydebug, align 4
Expand Down
Loading