Commit 689749e4 authored by lxq's avatar lxq

report

parent 11042e7a
This diff is collapsed.
......@@ -127,10 +127,10 @@ main(int argc, char **argv) {
if (loopunroll) {
PM.add_pass<NegCallMerge>(false);
PM.add_pass<LoopUnroll>(false);
PM.add_pass<DeadCode>(false);
PM.add_pass<GVN>(false, dump_json);
PM.add_pass<DeadCode>(false);
PM.add_pass<BrMerge>(false);
/* PM.add_pass<DeadCode>(false);
* PM.add_pass<GVN>(false, dump_json);
* PM.add_pass<DeadCode>(false); */
// PM.add_pass<BrMerge>(false);
}
PM.run();
......
......@@ -4,15 +4,23 @@
#include "Constant.h"
#include "Instruction.h"
#include <iostream>
using std::cout;
using std::endl;
void
BrMerge::run() {
m_->set_print_name();
BranchInst *br;
ReturnInst *ret;
for (auto &func : m_->get_functions()) {
if (func.is_declaration())
continue;
bool cont = true;
while (cont) {
cont = false;
for (auto &bb : func.get_basic_blocks()) {
cout << bb.get_name() << endl;
if (&bb == func.get_entry_block())
continue;
auto &instructions = bb.get_instructions();
......@@ -28,35 +36,45 @@ BrMerge::run() {
} else if (dynamic_cast<Constant *>(
br->get_operand(0))) {
assert(bb.get_succ_basic_blocks().size() == 2);
succ = static_cast<BasicBlock *>(
auto const_bool =
dynamic_cast<ConstantInt *>(br->get_operand(0))
->get_value()
? br->get_operand(1)
: br->get_operand(2));
->get_value();
succ = static_cast<BasicBlock *>(
const_bool ? br->get_operand(1)
: br->get_operand(2));
static_cast<BasicBlock *>(
(const_bool ? br->get_operand(2)
: br->get_operand(1)))
->remove_pre_basic_block(&bb);
} else
continue;
for (auto pre : bb.get_pre_basic_blocks()) {
// change br's op
auto ins = &*pre->get_instructions().rbegin();
bool set = false;
for (int i = 0; i < ins->get_num_operand(); ++i)
if (ins->get_operand(i) == &bb) {
ins->set_operand(i, succ);
set = true;
break;
}
assert(set);
// change pre's succ
pre->remove_succ_basic_block(&bb);
pre->add_succ_basic_block(&bb);
// change succ's pre
succ->add_pre_basic_block(pre);
}
if (bb.get_pre_basic_blocks().size() != 1)
continue;
auto pre = *bb.get_pre_basic_blocks().begin();
// change br's op
auto ins = &*pre->get_instructions().rbegin();
bool set = false;
for (int i = 0; i < ins->get_num_operand(); ++i)
if (ins->get_operand(i) == &bb) {
ins->set_operand(i, succ);
set = true;
bb.remove_use(ins);
break;
}
assert(set);
// change pre's succ
pre->remove_succ_basic_block(&bb);
pre->add_succ_basic_block(&bb);
// change succ's pre
succ->add_pre_basic_block(pre);
// change succ's pre
succ->remove_pre_basic_block(&bb);
// remove useless block
func.get_basic_blocks().remove(&bb);
// replace use
bb.replace_all_use_with(pre);
cont = true;
break;
} else { // ret: do not change
}
} else {
......
......@@ -128,9 +128,6 @@ LoopUnroll::unroll_loop(SimpleLoop &sl) {
// neg block's pre blocks
// replace use
m_->set_print_name();
for (auto [k, v] : old2new)
cout << "[debug]" << k->get_name() << "-" << v->get_name() << endl;
for (auto &bb : func->get_basic_blocks()) {
for (auto &instr : bb.get_instructions()) {
for (int i = 0; i < instr.get_num_operand(); ++i) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment