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

Enhance code reusability for the compiler backends #167

Merged
merged 1 commit into from
Nov 24, 2024

Conversation

DrXiao
Copy link
Collaborator

@DrXiao DrXiao commented Nov 23, 2024

After observing ARM and RISC-V backends, I noticed that the instruction sequences of load and global load operations are very similar:

/* ARM backend */
if (ph2_ir->src0 > 4095) {
    emit(__movw(__AL, __r8, ph2_ir->src0));
    emit(__movt(__AL, __r8, ph2_ir->src0));
-   emit(__add_r(__AL, __r8, __sp, __r8));      /* OP_load */
+   emit(__add_r(__AL, __r8, __r12, __r8));     /* OP_global_load */
    emit(__lw(__AL, rd, __r8, 0));
} else
-   emit(__lw(__AL, rd, __sp, ph2_ir->src0));   /* OP_load */
+   emit(__lw(__AL, rd, __r12, ph2_ir->src0));  /* OP_global_load */

A similar case occurs for store and global store operations.

Thus, this pull request improves code reusability for the compiler backends.

@jserv jserv requested a review from vacantron November 23, 2024 16:52
*/
rv_reg soft_div_rd = __t0, divisor_mask = __t1;
rv_reg helper_reg, divisor_mask = __t1;
Copy link
Collaborator

@jserv jserv Nov 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of naming it helper_reg, how about interm, which is the abbreviated form of "intermediate"? i.e., place an intermediate register for the division/modulo and load-store instructions.

Copy link
Collaborator

@vacantron vacantron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except the naming mentioned above, the changes look good to me.

@DrXiao
Copy link
Collaborator Author

DrXiao commented Nov 24, 2024

Because of pushing a redundant commit, I will squash the commits later.

After observing ARM and RISC-V backends, the instruction
sequences of load and global load operations are very similar,
and both of them just use a different register for two
instructions. A similar situation occurs for store and global
store operations.

Therefore, this commit improves the compiler backends to reuse
the same code more efficiently.
@jserv jserv merged commit a8bc7cf into sysprog21:master Nov 24, 2024
4 checks passed
@jserv
Copy link
Collaborator

jserv commented Nov 24, 2024

Thank @DrXiao for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants