-
Notifications
You must be signed in to change notification settings - Fork 126
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
Conversation
I defer to @vacantron for confirmation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove incorrect description "51,357 lines instructions." You should explicitly mention 51,357 instructions" for certain ISA.
Once the DCE is known to work properly, we can close #88 to declare the capability of performing basic optimizations. |
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.
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.
Thank @nosba0957 for contributing! |
The creation of RDF is based on reverse CFG. The method of building RDF is similar to building DF, but instead of iterating every
prev
nodes, it visitnext
,then_
andelse_
nodes. The code appears to extend the for-loop to handle three cases (compared to the method of building DF).Due to the addition of RDF, several elements were added to the
struct basic_block
. However,MAX_FILED
macro is not large enough, so it has been adjusted to 64.DCE is implemented using mark-sweep algorithm.
dce_insn
marks the useful instruction anddce_sweep
removes the operations that are not marked "useful". Thedce_insn
must execute aftercse
andconst_folding
are done becausedce_insn
may mark some instructions that are not handled bycse
andconst_folding
. These instruction might be mistakenly mark "useful".Related issue: #88