@@ -317,38 +317,46 @@ void NormalizeCFG::runOnFunctions(BinaryContext &BC) {
317
317
}
318
318
319
319
void EliminateUnreachableBlocks::runOnFunction (BinaryFunction &Function) {
320
- if (!Function.getLayout ().block_empty ()) {
321
- unsigned Count;
322
- uint64_t Bytes;
323
- Function.markUnreachableBlocks ();
324
- LLVM_DEBUG ({
325
- for (BinaryBasicBlock &BB : Function) {
326
- if (!BB.isValid ()) {
327
- dbgs () << " BOLT-INFO: UCE found unreachable block " << BB.getName ()
328
- << " in function " << Function << " \n " ;
329
- Function.dump ();
330
- }
320
+ BinaryContext &BC = Function.getBinaryContext ();
321
+ unsigned Count;
322
+ uint64_t Bytes;
323
+ Function.markUnreachableBlocks ();
324
+ LLVM_DEBUG ({
325
+ for (BinaryBasicBlock &BB : Function) {
326
+ if (!BB.isValid ()) {
327
+ dbgs () << " BOLT-INFO: UCE found unreachable block " << BB.getName ()
328
+ << " in function " << Function << " \n " ;
329
+ Function.dump ();
331
330
}
332
- });
333
- std::tie (Count, Bytes) = Function.eraseInvalidBBs ();
334
- DeletedBlocks += Count;
335
- DeletedBytes += Bytes;
336
- if (Count) {
337
- Modified.insert (&Function);
338
- if (opts::Verbosity > 0 )
339
- outs () << " BOLT-INFO: removed " << Count
340
- << " dead basic block(s) accounting for " << Bytes
341
- << " bytes in function " << Function << ' \n ' ;
342
331
}
332
+ });
333
+ BinaryContext::IndependentCodeEmitter Emitter =
334
+ BC.createIndependentMCCodeEmitter ();
335
+ std::tie (Count, Bytes) = Function.eraseInvalidBBs (Emitter.MCE .get ());
336
+ DeletedBlocks += Count;
337
+ DeletedBytes += Bytes;
338
+ if (Count) {
339
+ auto L = BC.scopeLock ();
340
+ Modified.insert (&Function);
341
+ if (opts::Verbosity > 0 )
342
+ outs () << " BOLT-INFO: removed " << Count
343
+ << " dead basic block(s) accounting for " << Bytes
344
+ << " bytes in function " << Function << ' \n ' ;
343
345
}
344
346
}
345
347
346
348
void EliminateUnreachableBlocks::runOnFunctions (BinaryContext &BC) {
347
- for (auto &It : BC.getBinaryFunctions ()) {
348
- BinaryFunction &Function = It.second ;
349
- if (shouldOptimize (Function))
350
- runOnFunction (Function);
351
- }
349
+ ParallelUtilities::WorkFuncTy WorkFun = [&](BinaryFunction &BF) {
350
+ runOnFunction (BF);
351
+ };
352
+
353
+ ParallelUtilities::PredicateTy SkipPredicate = [&](const BinaryFunction &BF) {
354
+ return !shouldOptimize (BF) || BF.getLayout ().block_empty ();
355
+ };
356
+
357
+ ParallelUtilities::runOnEachFunction (
358
+ BC, ParallelUtilities::SchedulingPolicy::SP_CONSTANT, WorkFun,
359
+ SkipPredicate, " elimininate-unreachable" );
352
360
353
361
if (DeletedBlocks)
354
362
outs () << " BOLT-INFO: UCE removed " << DeletedBlocks << " blocks and "
0 commit comments