Skip to content

Commit 29a4c14

Browse files
[WPD][ThinLTO]Add cutoff option for WPD
1 parent 4a9da96 commit 29a4c14

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@ static cl::list<std::string>
168168
cl::desc("Prevent function(s) from being devirtualized"),
169169
cl::Hidden, cl::CommaSeparated);
170170

171+
/// If this value is other than 0, the devirt module pass will stop
172+
/// transformation once the total number of devirtualizations reach the cutoff
173+
/// value.
174+
static cl::opt<unsigned> WholeProgramDevirtCutoff(
175+
"wholeprogramdevirt-cutoff",
176+
cl::desc("Max number of devirtualization for devirt module pass"),
177+
cl::init(0));
178+
171179
/// Mechanism to add runtime checking of devirtualization decisions, optionally
172180
/// trapping or falling back to indirect call on any that are not correct.
173181
/// Trapping mode is useful for debugging undefined behavior leading to failures
@@ -1169,6 +1177,10 @@ void DevirtModule::applySingleImplDevirt(VTableSlotInfo &SlotInfo,
11691177
if (!OptimizedCalls.insert(&VCallSite.CB).second)
11701178
continue;
11711179

1180+
if (WholeProgramDevirtCutoff.getNumOccurrences() > 0 &&
1181+
NumSingleImpl >= WholeProgramDevirtCutoff)
1182+
return;
1183+
11721184
if (RemarksEnabled)
11731185
VCallSite.emitRemark("single-impl",
11741186
TheFn->stripPointerCasts()->getName(), OREGetter);

llvm/test/Transforms/WholeProgramDevirt/import.ll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
; RUN: opt -S -passes=wholeprogramdevirt -wholeprogramdevirt-summary-action=import -wholeprogramdevirt-read-summary=%S/Inputs/import-vcp-branch-funnel.yaml < %s | FileCheck --check-prefixes=CHECK,VCP,VCP-X86,VCP64,BRANCH-FUNNEL %s
99
; RUN: opt -S -passes=wholeprogramdevirt -wholeprogramdevirt-summary-action=import -wholeprogramdevirt-read-summary=%S/Inputs/import-branch-funnel.yaml < %s | FileCheck --check-prefixes=CHECK,BRANCH-FUNNEL,BRANCH-FUNNEL-NOVCP %s
1010

11+
; Cutoff value is not explicitly set. Expect 3 remark messages.
12+
; RUN: opt -S -passes=wholeprogramdevirt -wholeprogramdevirt-summary-action=import -pass-remarks=wholeprogramdevirt -wholeprogramdevirt-read-summary=%S/Inputs/import-single-impl.yaml < %s 2>&1 | grep "single-impl" | count 3
13+
; Cutoff value is set to 1. Expect one remark messages.
14+
; RUN: opt -S -passes=wholeprogramdevirt -wholeprogramdevirt-summary-action=import -pass-remarks=wholeprogramdevirt -wholeprogramdevirt-cutoff=1 -wholeprogramdevirt-read-summary=%S/Inputs/import-single-impl.yaml < %s 2>&1 | grep "single-impl" | count 1
15+
; Cutoff value is explicitly set to zero. Expect no remark message.
16+
; RUN: opt -S -passes=wholeprogramdevirt -wholeprogramdevirt-summary-action=import -pass-remarks=wholeprogramdevirt -wholeprogramdevirt-cutoff=0 -wholeprogramdevirt-read-summary=%S/Inputs/import-single-impl.yaml < %s 2>&1 | FileCheck -implicit-check-not="remark" %s
1117
target datalayout = "e-p:64:64"
1218
target triple = "x86_64-unknown-linux-gnu"
1319

0 commit comments

Comments
 (0)