Skip to content

Commit

Permalink
Suppress compiler warnings
Browse files Browse the repository at this point in the history
The cfront does not accept casting. Don't apply it at shecc run-time.

Resolve sysprog21#89
  • Loading branch information
vacantron committed Dec 19, 2023
1 parent 702044a commit 6815c9f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 18 deletions.
10 changes: 10 additions & 0 deletions src/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@
/* Number of the available registers. Either 7 or 8 is accepted now. */
#define REG_CNT 8

/* This macro will be automatically defined at shecc run-time. */
#ifdef __SHECC__
#define UNUSED(x) (x)
#define SHECC_CAST(x) (x)
#else
/* suppress GCC/Clang warnings */
#define UNUSED(x) (void) (x)
#define SHECC_CAST(x) (void *) (x)
#endif

/* builtin types */
typedef enum { TYPE_void = 0, TYPE_int, TYPE_char, TYPE_struct } base_type_t;

Expand Down
3 changes: 3 additions & 0 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2516,6 +2516,9 @@ void parse_internal()
/* architecture defines */
add_alias(ARCH_PREDEFINED, "1");

/* shecc run-time defines */
add_alias("__SHECC__", "1");

/* Linux syscall */
func = add_func("__syscall");
func->num_params = 0;
Expand Down
49 changes: 31 additions & 18 deletions src/ssa.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ void build_dom()

void bb_build_df(fn_t *fn, basic_block_t *bb)
{
UNUSED(fn);

int i, cnt = 0;
for (i = 0; i < MAX_BB_PRED; i++)
if (bb->prev[i].bb)
Expand Down Expand Up @@ -338,6 +340,8 @@ void fn_add_global(fn_t *fn, var_t *var)

void bb_solve_globals(fn_t *fn, basic_block_t *bb)
{
UNUSED(fn);

insn_t *insn;
for (insn = bb->insn_list.head; insn; insn = insn->next) {
if (insn->rs1)
Expand Down Expand Up @@ -518,7 +522,7 @@ var_t *get_stack_top_subscript_var(var_t *var)
abort();
}

void rename_var(block_t *block, var_t **var)
void rename_var(var_t **var)
{
if (!(*var)->base)
(*var)->base = *var;
Expand Down Expand Up @@ -558,10 +562,10 @@ void bb_solve_phi_params(basic_block_t *bb)
new_name(bb->scope, &insn->rd);
else {
if (insn->rs1)
rename_var(bb->scope, &insn->rs1);
rename_var(&insn->rs1);
if (insn->rs2)
if (!insn->rs2->is_func)
rename_var(bb->scope, &insn->rs2);
rename_var(&insn->rs2);
if (insn->rd)
new_name(bb->scope, &insn->rd);
}
Expand Down Expand Up @@ -649,6 +653,8 @@ void append_unwound_phi_insn(basic_block_t *bb, var_t *dest, var_t *rs)

void bb_unwind_phi(fn_t *fn, basic_block_t *bb)
{
UNUSED(fn);

insn_t *insn;
for (insn = bb->insn_list.head; insn; insn = insn->next) {
if (insn->opcode != OP_phi)
Expand Down Expand Up @@ -788,18 +794,18 @@ void bb_dump(FILE *fd, fn_t *fn, basic_block_t *bb)
if (next_ && (then_ || else_))
printf("Warning: normal BB with condition\n");

fprintf(fd, "subgraph cluster_%p {\n", bb);
fprintf(fd, "label=\"BasicBlock %p\"\n", bb);
fprintf(fd, "subgraph cluster_%p {\n", SHECC_CAST(bb));
fprintf(fd, "label=\"BasicBlock %p\"\n", SHECC_CAST(bb));

insn_t *insn = bb->insn_list.head;
if (!insn)
fprintf(fd, "pseudo_%p [label=\"pseudo\"]\n", bb);
fprintf(fd, "pseudo_%p [label=\"pseudo\"]\n", SHECC_CAST(bb));
if (!insn && (then_ || else_))
printf("Warning: pseudo node should only have NEXT\n");

for (; insn; insn = insn->next) {
if (insn->opcode == OP_phi) {
fprintf(fd, "insn_%p [label=", insn);
fprintf(fd, "insn_%p [label=", SHECC_CAST(insn));
fprintf(fd, "<%s<SUB>%d</SUB> := PHI(%s<SUB>%d</SUB>",
insn->rd->var_name, insn->rd->subscript,
insn->phi_ops->var->var_name,
Expand Down Expand Up @@ -923,11 +929,12 @@ void bb_dump(FILE *fd, fn_t *fn, basic_block_t *bb)
printf("Unknown opcode\n");
abort();
}
fprintf(fd, "insn_%p [label=%s]\n", insn, str);
fprintf(fd, "insn_%p [label=%s]\n", SHECC_CAST(insn), str);
}

if (insn->next)
fprintf(fd, "insn_%p->insn_%p [weight=100]\n", insn, insn->next);
fprintf(fd, "insn_%p->insn_%p [weight=100]\n", SHECC_CAST(insn),
SHECC_CAST(insn->next));
}
fprintf(fd, "}\n");

Expand Down Expand Up @@ -959,8 +966,8 @@ void dump_cfg(char name[])
fprintf(fd, "node [shape=box]\n");
for (fn = FUNC_LIST.head; fn; fn = fn->next) {
fn->visited++;
fprintf(fd, "subgraph cluster_%p {\n", fn);
fprintf(fd, "label=\"%p\"\n", fn);
fprintf(fd, "subgraph cluster_%p {\n", SHECC_CAST(fn));
fprintf(fd, "label=\"%p\"\n", SHECC_CAST(fn));
bb_dump(fd, fn, fn->bbs);
fprintf(fd, "}\n");
}
Expand All @@ -970,13 +977,14 @@ void dump_cfg(char name[])

void dom_dump(FILE *fd, basic_block_t *bb)
{
fprintf(fd, "\"%p\"\n", bb);
fprintf(fd, "\"%p\"\n", SHECC_CAST(bb));
int i;
for (i = 0; i < MAX_BB_DOM_SUCC; i++) {
if (!bb->dom_next[i])
break;
dom_dump(fd, bb->dom_next[i]);
fprintf(fd, "\"%p\":s->\"%p\":n\n", bb, bb->dom_next[i]);
fprintf(fd, "\"%p\":s->\"%p\":n\n", SHECC_CAST(bb),
SHECC_CAST(bb->dom_next[i]));
}
}

Expand All @@ -989,8 +997,8 @@ void dump_dom(char name[])
fprintf(fd, "node [shape=box]\n");
fprintf(fd, "splines=polyline\n");
for (fn = FUNC_LIST.head; fn; fn = fn->next) {
fprintf(fd, "subgraph cluster_%p {\n", fn);
fprintf(fd, "label=\"%p\"\n", fn);
fprintf(fd, "subgraph cluster_%p {\n", SHECC_CAST(fn));
fprintf(fd, "label=\"%p\"\n", SHECC_CAST(fn));
dom_dump(fd, fn->bbs);
fprintf(fd, "}\n");
}
Expand Down Expand Up @@ -1075,6 +1083,7 @@ void build_reversed_rpo()

void bb_reset_live_kill_idx(fn_t *fn, basic_block_t *bb)
{
UNUSED(fn);
bb->live_kill_idx = 0;
}

Expand All @@ -1098,6 +1107,8 @@ void update_consumed(insn_t *insn, var_t *var)

void bb_solve_locals(fn_t *fn, basic_block_t *bb)
{
UNUSED(fn);

int i = 0;
insn_t *insn;
for (insn = bb->insn_list.head; insn; insn = insn->next) {
Expand Down Expand Up @@ -1157,7 +1168,7 @@ void merge_live_in(var_t *live_out[], int *live_out_idx, basic_block_t *bb)
}
}

int recompute_live_out(fn_t *fn, basic_block_t *bb)
int recompute_live_out(basic_block_t *bb)
{
var_t *live_out[MAX_ANALYSIS_STACK_SIZE];
int live_out_idx = 0;
Expand Down Expand Up @@ -1217,7 +1228,7 @@ void liveness_analysis()
bb_add_killed_var(fn->bbs, fn->func->param_defs[i].subscripts[0]);

fn->visited++;
args->preorder_cb = bb_solve_locals;
args->preorder_cb = &bb_solve_locals;
bb_forward_traversal(args);
}
free(args);
Expand All @@ -1228,13 +1239,15 @@ void liveness_analysis()
do {
changed = 0;
for (bb = fn->exit; bb; bb = bb->rpo_r_next)
changed |= recompute_live_out(fn, bb);
changed |= recompute_live_out(bb);
} while (changed);
}
}

void bb_release(fn_t *fn, basic_block_t *bb)
{
UNUSED(fn);

insn_t *insn = bb->insn_list.head;
insn_t *next_insn;
while (insn) {
Expand Down

0 comments on commit 6815c9f

Please sign in to comment.