[BOLT] Enable reversing the order of basic blocks

Summary: Enable reversing the order of basic blocks.

(cherry picked from FBD19943692)
This commit is contained in:
Alexander Shaposhnikov 2020-02-17 13:35:09 -08:00 committed by Maksim Panchenko
parent 4ad5048393
commit 76aa1c26aa
3 changed files with 18 additions and 2 deletions

View File

@ -104,7 +104,7 @@ PrintFOP("print-fop",
cl::Hidden,
cl::cat(BoltOptCategory));
static cl::opt<bool>
cl::opt<bool>
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<bool>
cl::opt<bool>
PrintReordered("print-reordered",
cl::desc("print functions after layout optimization"),
cl::ZeroOrMore,

View File

@ -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<bool> NeverPrint;
extern cl::opt<bool> PrintFinalized;
extern cl::opt<bool> PrintReordered;
extern cl::opt<bool> PrintSections;
extern cl::opt<bool> PrintDisasm;
extern cl::opt<bool> PrintCFG;
@ -139,11 +143,22 @@ void MachORewriteInstance::postProcessFunctions() {
}
}
void MachORewriteInstance::runOptimizationPasses() {
BinaryFunctionPassManager Manager(*BC);
Manager.registerPass(
llvm::make_unique<ReorderBasicBlocks>(opts::PrintReordered));
// This pass should always run last.*
Manager.registerPass(
llvm::make_unique<FinalizeFunctions>(opts::PrintFinalized));
Manager.runPasses();
}
void MachORewriteInstance::run() {
readSpecialSections();
discoverFileObjects();
disassembleFunctions();
postProcessFunctions();
runOptimizationPasses();
}
MachORewriteInstance::~MachORewriteInstance() {}

View File

@ -31,6 +31,7 @@ class MachORewriteInstance {
void discoverFileObjects();
void disassembleFunctions();
void postProcessFunctions();
void runOptimizationPasses();
public:
MachORewriteInstance(object::MachOObjectFile *InputFile, DataReader &DR);