diff --git a/bolt/include/bolt/Passes/ZeroIdiom.h b/bolt/include/bolt/Passes/ZeroIdiom.h --- a/bolt/include/bolt/Passes/ZeroIdiom.h +++ b/bolt/include/bolt/Passes/ZeroIdiom.h @@ -24,6 +24,11 @@ class ZeroIdiomPass : public BinaryFunctionPass { void runOnFunction(BinaryFunction &Function, DataflowInfoManager &Info); + static std::atomic ReplacedInsts; + static std::atomic ModifiedFunctions; + static std::atomic ReplacedDynamicCount; + static std::atomic SavedBytes; + public: explicit ZeroIdiomPass(const cl::opt &PrintPass) : BinaryFunctionPass(PrintPass) {} diff --git a/bolt/lib/Passes/ZeroIdiom.cpp b/bolt/lib/Passes/ZeroIdiom.cpp --- a/bolt/lib/Passes/ZeroIdiom.cpp +++ b/bolt/lib/Passes/ZeroIdiom.cpp @@ -20,18 +20,31 @@ namespace llvm { namespace bolt { +std::atomic ZeroIdiomPass::ReplacedInsts{0}; +std::atomic ZeroIdiomPass::ModifiedFunctions{0}; +std::atomic ZeroIdiomPass::ReplacedDynamicCount{0}; +std::atomic ZeroIdiomPass::SavedBytes{0}; + void ZeroIdiomPass::runOnFunction(BinaryFunction &BF, DataflowInfoManager &Info) { BinaryContext &BC = BF.getBinaryContext(); LivenessAnalysis &LA = Info.getLivenessAnalysis(); + bool Modified = false; for (BinaryBasicBlock &BB : BF) { for (MCInst &Inst : BB) { if (LA.isAlive(ProgramPoint(&Inst), BC.MIB->getFlagsReg())) continue; - BC.MIB->replaceZeroIdiom(Inst); + if (BC.MIB->replaceZeroIdiom(Inst)) { + Modified = true; + ++ReplacedInsts; + ReplacedDynamicCount += BB.getExecutionCount(); + SavedBytes += 3; // FIXME + } } } + if (Modified) + ++ModifiedFunctions; } void ZeroIdiomPass::runOnFunctions(BinaryContext &BC) { @@ -52,6 +65,14 @@ ParallelUtilities::runOnEachFunctionWithUniqueAllocId( BC, ParallelUtilities::SchedulingPolicy::SP_INST_LINEAR, WorkFun, nullptr, "ZeroIdiom"); + + if (!ReplacedInsts) + return; + + outs() << "BOLT-INFO: zero-idiom replaced " << ReplacedInsts + << " instructions (exec count " << ReplacedDynamicCount << ") in " + << ModifiedFunctions << " functions saving " << SavedBytes + << " bytes\n"; } } // end namespace bolt