There are two optimization blockers: procedure calls and memory aliasing.
Procedure calls refer to calling to a non-in-lined procedure(function). Because a procedure can change the global state of the program, the procedure is often treated as a black box to the compiler. Therefore, compiler cannot optimize it to have less call to procedure because the procedure may generate side-effects.
There are two possible remedies:
inline
flag to the procedure so that the compiler will consider optimize it. (like opening the black box)When two variable belong to the same space in memory, optimizations can be hindered because behavior of memory manipulation can change based on whether two inputs shares the same region of memory. Because the compiler needs to consider every edge case (where two pointers can point to the same region of memory), it cannot optimize memory access out.
There are two possible remedies:
restrict
to two arguments indicate that these addresses does not share the same region of memory. (will cause undefined behavior if they actually do)There are 3 rules
Since both modules have strong definition of symbol main
, based on rule 1, compilation will result in error.
Based on Piazza Post, void x
is not allowed. The TAs have promised to update it but nothing get resolved as for July.12. So I will assume void x;
be fixed as int x;
in the following answer.
Module 1 has strong symbol x
and weak symbol main
, and module 2 has weak symbols x
and strong symbol main
. So according to rule 2, t x
will be defined by module 1 and main
will be defined by module 2.
Module 1 has 2 strong symbols y
and main
, and module 2 has 3 weak symbols x
, y
, and main
. Therefore, according to rule 2, y
and main
will be defined by module 1. Notice there are two type mismatch which may reduce code readability and they are hard to debug with.
Module 1 has strong symbol z
and 2 weak symbols x
and y
, and module 2 has 3 weak symbols x
, y
, and z
. Therefore, according to rule 2, z
will be defined by module 1. There are multiple weak definition of x
, and y
with different type. According to rule 3, compiler will pick an arbitrary one.
Module 1 has strong symbol y
and 3 weak symbols main
, x
, and p
. Module 2 has strong symbols x
and 2 weak symbols main
and y
. Therefore, according to rule 2, y
will be defined by module 1 and x
will be defined by module 2. Notice there are type mismatch for main
, x
, and y
, which may reduce code readability and they are hard to debug with. Also, there are multiple weak definition of main
, and therefore, according to rule 3, compiler will pick an arbitrary one.
Hypothesis: Since all incorrect values are related to dirty bytes and everything else work correctly, it is very likely that procedures for write to memory is not handled correctly. Specifically, it might be that the dirty bit is not set during write commands.
I propose a possible way to reproduce the error: I try to add assertion to detect if the dirty bit hold true after every write command. If my hypothesis is true, the assertion statement would generate an error.
After fixed it, I would re-run the program to see if my assertion error goes away.
Table of Content