Skip to content

Commit

Permalink
[BOLT] Add first bits to build CFG
Browse files Browse the repository at this point in the history
Summary: Add first bits to build CFG.

(cherry picked from FBD19943472)
  • Loading branch information
Alexander Shaposhnikov authored and maksfb committed Feb 17, 2020
1 parent 5b64bf2 commit 4ad5048
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
18 changes: 17 additions & 1 deletion bolt/src/MachORewriteInstance.cpp
Expand Up @@ -20,7 +20,7 @@ namespace opts {
using namespace llvm;
extern cl::opt<bool> PrintSections;
extern cl::opt<bool> PrintDisasm;

extern cl::opt<bool> PrintCFG;
} // namespace opts

namespace llvm {
Expand Down Expand Up @@ -121,13 +121,29 @@ void MachORewriteInstance::disassembleFunctions() {
Function.disassemble();
if (opts::PrintDisasm)
Function.print(outs(), "after disassembly", true);
if (!Function.buildCFG(/*AllocId*/0)) {
errs() << "BOLT-WARNING: failed to build CFG for the function "
<< Function << "\n";
}
}
}

void MachORewriteInstance::postProcessFunctions() {
for (auto &BFI : BC->getBinaryFunctions()) {
BinaryFunction &Function = BFI.second;
if (Function.empty())
continue;
Function.postProcessCFG();
if (opts::PrintCFG)
Function.print(outs(), "after building cfg", true);
}
}

void MachORewriteInstance::run() {
readSpecialSections();
discoverFileObjects();
disassembleFunctions();
postProcessFunctions();
}

MachORewriteInstance::~MachORewriteInstance() {}
Expand Down
1 change: 1 addition & 0 deletions bolt/src/MachORewriteInstance.h
Expand Up @@ -30,6 +30,7 @@ class MachORewriteInstance {
void readSpecialSections();
void discoverFileObjects();
void disassembleFunctions();
void postProcessFunctions();

public:
MachORewriteInstance(object::MachOObjectFile *InputFile, DataReader &DR);
Expand Down
2 changes: 1 addition & 1 deletion bolt/src/RewriteInstance.cpp
Expand Up @@ -273,7 +273,7 @@ PrintAll("print-all",
cl::Hidden,
cl::cat(BoltCategory));

static cl::opt<bool>
cl::opt<bool>
PrintCFG("print-cfg",
cl::desc("print functions after CFG construction"),
cl::ZeroOrMore,
Expand Down

0 comments on commit 4ad5048

Please sign in to comment.