@@ -168,6 +168,14 @@ static cl::list<std::string>
168
168
cl::desc (" Prevent function(s) from being devirtualized" ),
169
169
cl::Hidden, cl::CommaSeparated);
170
170
171
+ // / If explicitly specified, the devirt module pass will stop transformation
172
+ // / once the total number of devirtualizations reach the cutoff value. Setting
173
+ // / this option to 0 explicitly will do 0 devirtualization.
174
+ static cl::opt<unsigned > WholeProgramDevirtCutoff (
175
+ " wholeprogramdevirt-cutoff" ,
176
+ cl::desc (" Max number of devirtualizations for devirt module pass" ),
177
+ cl::init(0 ));
178
+
171
179
// / Mechanism to add runtime checking of devirtualization decisions, optionally
172
180
// / trapping or falling back to indirect call on any that are not correct.
173
181
// / Trapping mode is useful for debugging undefined behavior leading to failures
@@ -316,6 +324,9 @@ VirtualCallTarget::VirtualCallTarget(GlobalValue *Fn, const TypeMemberInfo *TM)
316
324
317
325
namespace {
318
326
327
+ // Tracks the number of devirted calls in the IR transformation.
328
+ static unsigned NumDevirtCalls = 0 ;
329
+
319
330
// A slot in a set of virtual tables. The TypeID identifies the set of virtual
320
331
// tables, and the ByteOffset is the offset in bytes from the address point to
321
332
// the virtual function pointer.
@@ -1169,10 +1180,16 @@ void DevirtModule::applySingleImplDevirt(VTableSlotInfo &SlotInfo,
1169
1180
if (!OptimizedCalls.insert (&VCallSite.CB ).second )
1170
1181
continue ;
1171
1182
1183
+ // Stop when the number of devirted calls reaches the cutoff.
1184
+ if (WholeProgramDevirtCutoff.getNumOccurrences () > 0 &&
1185
+ NumDevirtCalls >= WholeProgramDevirtCutoff)
1186
+ return ;
1187
+
1172
1188
if (RemarksEnabled)
1173
1189
VCallSite.emitRemark (" single-impl" ,
1174
1190
TheFn->stripPointerCasts ()->getName (), OREGetter);
1175
1191
NumSingleImpl++;
1192
+ NumDevirtCalls++;
1176
1193
auto &CB = VCallSite.CB ;
1177
1194
assert (!CB.getCalledFunction () && " devirtualizing direct call?" );
1178
1195
IRBuilder<> Builder (&CB);
0 commit comments