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

Implement dead code elimination #145

merged 2 commits into from
Aug 14, 2024

Commits on Aug 12, 2024

  1. Fix error with return statement in for-loop body

    This error occurred when a return statement was in for-loop body. After
    parsing loop body, "body_" was assigned NULL as the return value,
    causing the compiler to failed in correctly connect "inc_" and
    "cond_start" basic blocks.
    
    This error can be analyzed by examining the CFG.dot file.
    nosba0957 committed Aug 12, 2024
    Configuration menu
    Copy the full SHA
    562ec5f View commit details
    Browse the repository at this point in the history
  2. Implement dead code elimination

    Introduces the creaetion of reverse dominance frontier (RDF) to support
    dead code elimination (DCE). Method for implementing RDF is similar to
    that of dominance frontier (DF). The key difference is that RDF is
    computed on the reverse CFG. In other words, operations were performed
    on "prev[]" which in the basic block structure, now switched to operate
    on "next", "then_" and "else_".
    
    In the "dce_insn" function, mark useful instructions during the initial
    analysis of the current basic block. Continue identifying useful
    instructions by tracing back from the last assigned instruction of the
    both operands of the current "insn". In the "dce_sweep" function remove
    the useless instruction from the current "insn_list". If a branch
    instruction is encountered, remove it and reconnect the current basic
    block to its reverse immediate dominator.
    
    Before implementing DCE, compiling "src/main.c" resulted in an
    executable with 51,357 instructions for ARMv7-A. After DCE, the
    executable was 51,330 instructions, reducing the total by 27
    instructions.
    nosba0957 committed Aug 12, 2024
    Configuration menu
    Copy the full SHA
    8729626 View commit details
    Browse the repository at this point in the history