diff --git a/bolt/lib/Passes/Instrumentation.cpp b/bolt/lib/Passes/Instrumentation.cpp --- a/bolt/lib/Passes/Instrumentation.cpp +++ b/bolt/lib/Passes/Instrumentation.cpp @@ -370,6 +370,23 @@ bool HasJumpTable = false; bool IsInvokeBlock = InvokeBlocks.count(&BB) > 0; + auto InstrumentEdge = [&](BinaryFunction &TargetFunction, + BinaryBasicBlock &TargetBB, uint64_t FromOffset, + uint64_t TargetOffset, + BinaryBasicBlock::iterator &I) { + // Do not instrument edges in the spanning tree + if (llvm::is_contained(STOutSet[&BB], &TargetBB)) { + auto L = BC.scopeLock(); + createEdgeDescription(*FuncDesc, Function, FromOffset, BBToID[&BB], + Function, TargetOffset, BBToID[&TargetBB], + /*Instrumented=*/false); + } else { + instrumentOneTarget(SplitWorklist, SplitInstrs, I, Function, BB, + FromOffset, TargetFunction, &TargetBB, TargetOffset, + IsLeafFunction, IsInvokeBlock, FuncDesc, + BBToID[&BB], BBToID[&TargetBB]); + } + }; for (auto I = BB.begin(); I != BB.end(); ++I) { const MCInst &Inst = *I; if (!BC.MIB->getOffset(Inst)) @@ -404,36 +421,13 @@ continue; } if (TargetFunc) { - // Do not instrument edges in the spanning tree - if (llvm::is_contained(STOutSet[&BB], TargetBB)) { - auto L = BC.scopeLock(); - createEdgeDescription(*FuncDesc, Function, FromOffset, BBToID[&BB], - Function, ToOffset, BBToID[TargetBB], - /*Instrumented=*/false); - continue; - } - instrumentOneTarget(SplitWorklist, SplitInstrs, I, Function, BB, - FromOffset, *TargetFunc, TargetBB, ToOffset, - IsLeafFunction, IsInvokeBlock, FuncDesc, - BBToID[&BB], BBToID[TargetBB]); + InstrumentEdge(*TargetFunc, *TargetBB, FromOffset, ToOffset, I); continue; } if (IsJumpTable) { - for (BinaryBasicBlock *&Succ : BB.successors()) { - // Do not instrument edges in the spanning tree - if (llvm::is_contained(STOutSet[&BB], &*Succ)) { - auto L = BC.scopeLock(); - createEdgeDescription(*FuncDesc, Function, FromOffset, BBToID[&BB], - Function, Succ->getInputOffset(), - BBToID[&*Succ], /*Instrumented=*/false); - continue; - } - instrumentOneTarget( - SplitWorklist, SplitInstrs, I, Function, BB, FromOffset, Function, - &*Succ, Succ->getInputOffset(), IsLeafFunction, IsInvokeBlock, - FuncDesc, BBToID[&BB], BBToID[&*Succ]); - } + for (BinaryBasicBlock &Succ : llvm::make_pointee_range(BB.successors())) + InstrumentEdge(Function, Succ, FromOffset, Succ.getInputOffset(), I); continue; } @@ -464,18 +458,7 @@ continue; FromOffset = *BC.MIB->getOffset(*LastInstr); - // Do not instrument edges in the spanning tree - if (llvm::is_contained(STOutSet[&BB], FTBB)) { - auto L = BC.scopeLock(); - createEdgeDescription(*FuncDesc, Function, FromOffset, BBToID[&BB], - Function, FTBB->getInputOffset(), BBToID[FTBB], - /*Instrumented=*/false); - continue; - } - instrumentOneTarget(SplitWorklist, SplitInstrs, I, Function, BB, - FromOffset, Function, FTBB, FTBB->getInputOffset(), - IsLeafFunction, IsInvokeBlock, FuncDesc, BBToID[&BB], - BBToID[FTBB]); + InstrumentEdge(Function, *FTBB, FromOffset, FTBB->getInputOffset(), I); } } // End of BBs loop