From 76aa1c26aa3a1ed0167db9c0f28d6361b6e58bfa Mon Sep 17 00:00:00 2001 From: Alexander Shaposhnikov Date: Mon, 17 Feb 2020 13:35:09 -0800 Subject: [PATCH] [BOLT] Enable reversing the order of basic blocks Summary: Enable reversing the order of basic blocks. (cherry picked from FBD19943692) --- bolt/src/BinaryPassManager.cpp | 4 ++-- bolt/src/MachORewriteInstance.cpp | 15 +++++++++++++++ bolt/src/MachORewriteInstance.h | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/bolt/src/BinaryPassManager.cpp b/bolt/src/BinaryPassManager.cpp index 4cc2449079df..75893afeb405 100644 --- a/bolt/src/BinaryPassManager.cpp +++ b/bolt/src/BinaryPassManager.cpp @@ -104,7 +104,7 @@ PrintFOP("print-fop", cl::Hidden, cl::cat(BoltOptCategory)); -static cl::opt +cl::opt PrintFinalized("print-finalized", cl::desc("print function after CFG is finalized"), cl::Hidden, @@ -166,7 +166,7 @@ PrintPeepholes("print-peepholes", cl::Hidden, cl::cat(BoltOptCategory)); -static cl::opt +cl::opt PrintReordered("print-reordered", cl::desc("print functions after layout optimization"), cl::ZeroOrMore, diff --git a/bolt/src/MachORewriteInstance.cpp b/bolt/src/MachORewriteInstance.cpp index 4cd7f13387f2..58f0ab623980 100644 --- a/bolt/src/MachORewriteInstance.cpp +++ b/bolt/src/MachORewriteInstance.cpp @@ -12,12 +12,16 @@ #include "MachORewriteInstance.h" #include "BinaryContext.h" #include "BinaryFunction.h" +#include "BinaryPassManager.h" #include "Utils.h" #include "llvm/Support/Timer.h" namespace opts { using namespace llvm; +extern cl::opt NeverPrint; +extern cl::opt PrintFinalized; +extern cl::opt PrintReordered; extern cl::opt PrintSections; extern cl::opt PrintDisasm; extern cl::opt PrintCFG; @@ -139,11 +143,22 @@ void MachORewriteInstance::postProcessFunctions() { } } +void MachORewriteInstance::runOptimizationPasses() { + BinaryFunctionPassManager Manager(*BC); + Manager.registerPass( + llvm::make_unique(opts::PrintReordered)); + // This pass should always run last.* + Manager.registerPass( + llvm::make_unique(opts::PrintFinalized)); + Manager.runPasses(); +} + void MachORewriteInstance::run() { readSpecialSections(); discoverFileObjects(); disassembleFunctions(); postProcessFunctions(); + runOptimizationPasses(); } MachORewriteInstance::~MachORewriteInstance() {} diff --git a/bolt/src/MachORewriteInstance.h b/bolt/src/MachORewriteInstance.h index 42fb0bfe29b8..b5f0995a562b 100644 --- a/bolt/src/MachORewriteInstance.h +++ b/bolt/src/MachORewriteInstance.h @@ -31,6 +31,7 @@ class MachORewriteInstance { void discoverFileObjects(); void disassembleFunctions(); void postProcessFunctions(); + void runOptimizationPasses(); public: MachORewriteInstance(object::MachOObjectFile *InputFile, DataReader &DR);