add config option for changing cond splitting behavior (#522)

This commit is contained in:
water111
2021-05-24 19:52:19 -04:00
committed by GitHub
parent d719bf5677
commit 0f0902eabf
15 changed files with 115 additions and 46 deletions
+13 -3
View File
@@ -1124,7 +1124,7 @@ bool is_found_after(CfgVtx* a, CfgVtx* b) {
} // namespace
bool ControlFlowGraph::find_cond_w_else() {
bool ControlFlowGraph::find_cond_w_else(const CondWithElseLengthHack& hack) {
bool found = false;
for_each_top_level_vtx([&](CfgVtx* vtx) {
@@ -1261,6 +1261,13 @@ bool ControlFlowGraph::find_cond_w_else() {
}
}
auto hack_lookup = hack.max_length_by_start_block.find(c0->to_form().print());
if (hack_lookup != hack.max_length_by_start_block.end()) {
if ((int)entries.size() > hack_lookup->second) {
return true;
}
}
// now we need to add it
// printf("got cwe\n");
auto new_cwe = alloc<CondWithElse>();
@@ -1967,7 +1974,10 @@ CfgVtx::DelaySlotKind get_delay_slot(const Instruction& i) {
/*!
* Build and resolve a Control Flow Graph as much as possible.
*/
std::shared_ptr<ControlFlowGraph> build_cfg(const LinkedObjectFile& file, int seg, Function& func) {
std::shared_ptr<ControlFlowGraph> build_cfg(const LinkedObjectFile& file,
int seg,
Function& func,
const CondWithElseLengthHack& cond_with_else_hack) {
// fmt::print("START {}\n", func.guessed_name.to_string());
auto cfg = std::make_shared<ControlFlowGraph>();
@@ -2121,7 +2131,7 @@ std::shared_ptr<ControlFlowGraph> build_cfg(const LinkedObjectFile& file, int se
// todo - should we lower the priority of the conds?
changed = changed || cfg->find_cond_w_else();
changed = changed || cfg->find_cond_w_else(cond_with_else_hack);
changed = changed || cfg->find_while_loop_top_level();
changed = changed || cfg->find_seq_top_level();