Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement dead code elimination #145

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
#define MAX_TYPE_LEN 32
#define MAX_PARAMS 8
#define MAX_LOCALS 1500
#define MAX_FIELDS 32
#define MAX_FIELDS 64
#define MAX_FUNCS 512
#define MAX_FUNC_TRIES 2160
#define MAX_BLOCKS 2048
#define MAX_TYPES 64
#define MAX_IR_INSTR 40000
#define MAX_BB_PRED 128
#define MAX_BB_DOM_SUCC 64
#define MAX_BB_RDOM_SUCC 256
#define MAX_GLOBAL_IR 256
#define MAX_LABEL 4096
#define MAX_SOURCE 327680
Expand Down Expand Up @@ -173,6 +174,7 @@ struct var {
int subscripts_idx;
rename_t rename;
ref_block_list_t ref_block_list; /* blocks which kill variable */
struct insn *last_assign;
int consumed;
bool is_ternary_ret;
bool is_log_and_ret;
Expand Down Expand Up @@ -308,6 +310,8 @@ struct insn {
var_t *rs1;
var_t *rs2;
int sz;
bool useful; /* Used in DCE process. Set true if instruction is useful. */
basic_block_t *belong_to;
phi_operand_t *phi_ops;
char str[64];
};
Expand Down Expand Up @@ -352,6 +356,7 @@ struct basic_block {
struct basic_block *then_; /* conditional BB */
struct basic_block *else_;
struct basic_block *idom;
struct basic_block *r_idom;
struct basic_block *rpo_next;
struct basic_block *rpo_r_next;
var_t *live_gen[MAX_ANALYSIS_STACK_SIZE];
Expand All @@ -365,10 +370,15 @@ struct basic_block {
int rpo;
int rpo_r;
struct basic_block *DF[64];
struct basic_block *RDF[64];
int df_idx;
int rdf_idx;
int visited;
bool useful; /* indicate whether this BB contains useful instructions */
struct basic_block *dom_next[64];
struct basic_block *dom_prev;
struct basic_block *rdom_next[256];
struct basic_block *rdom_prev;
fn_t *belong_to;
block_t *scope;
symbol_list_t symbol_list; /* variable declaration */
Expand Down
1 change: 1 addition & 0 deletions src/globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ void add_insn(block_t *block,
n->rs1 = rs1;
n->rs2 = rs2;
n->sz = sz;
n->belong_to = bb;

if (str)
strcpy(n->str, str);
Expand Down
2 changes: 2 additions & 0 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2608,6 +2608,8 @@ basic_block_t *read_body_statement(block_t *parent, basic_block_t *bb)
if (body_) {
bb_connect(body_, inc_, NEXT);
bb_connect(inc_, cond_start, NEXT);
} else if (inc_->insn_list.head) {
bb_connect(inc_, cond_start, NEXT);
} else {
/* TODO: Release dangling inc basic block */
}
Expand Down
Loading