Commit 689749e4 authored by lxq's avatar lxq

report

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