You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It can be observed that the value of 1 + 2 can be determined at the compile time to be equal to 3.
Furthermore, it can be observed that therefore the value of a can be determined at compile time.
Currently the outputed code (with -O 3)
op add _a@main 1 2
print "1 + 2 = "
print _a@main
printflush message1
end
However, we can simplify this to:
print "1 + 2 = 3"
printflush message1
end
I believe one of the ways to do this is, at the abstract syntax tree optimization step, to observe when an operation is done on two (for binary operations or one for unary operations) literals or constants and precompute the calculation.
Note, that variable can be constant at some times, but not constant in others.
#include<mlogevo/io.h>#include<mlogevo/mlog_object.h>externstructMLogObjectmessage1;
voidmain() {
inta=0;
print("a before: ", a, "\n");
a=someFunction();
print("a after: ", a, "\n");
printflush(message1);
}
The first print statement can be optimized to print("a before: 0\n");. The second can not be optimized in this way.
Variable folding & propagation is a bit more difficult than doing the same on constants, but can optimize common patterns, such as assigning a set of bit flags to a variable:
inta=1 | 2 | 3;
At the current state this compiles to two instructions, though it can be compiled to only one.
Edit: typo
The text was updated successfully, but these errors were encountered:
Take the following code as an example:
It can be observed that the value of
1 + 2
can be determined at the compile time to be equal to3
.Furthermore, it can be observed that therefore the value of
a
can be determined at compile time.Currently the outputed code (with
-O 3
)However, we can simplify this to:
I believe one of the ways to do this is, at the abstract syntax tree optimization step, to observe when an operation is done on two (for binary operations or one for unary operations) literals or constants and precompute the calculation.
Note, that variable can be constant at some times, but not constant in others.
The first print statement can be optimized to
print("a before: 0\n");
. The second can not be optimized in this way.Variable folding & propagation is a bit more difficult than doing the same on constants, but can optimize common patterns, such as assigning a set of bit flags to a variable:
At the current state this compiles to two instructions, though it can be compiled to only one.
Edit: typo
The text was updated successfully, but these errors were encountered: