snowman
snowman copied to clipboard
Add partial constant folding
` uint32_t _Z5isqrtj(uint32_t edi) { uint32_t v2; uint32_t v3; uint32_t v4;
v2 = edi;
v3 = 0;
v4 = 0x40000000;
do {
if (v3 + v4 <= v2) {
v2 = v2 - (v3 + v4);
v3 = v3 + v4 + v4;
}
v3 = v3 >> 1;
v4 = v4 >> 2;
} while (v4);
if (v2 > v3) {
++v3;
}
return v3;
} int64_t main(int32_t edi, int64_t rsi) { int64_t rsi3; uint32_t eax4; uint32_t eax5; int64_t rax6;
rsi3 = rsi;
eax4 = *reinterpret_cast<uint32_t*>(&rsi3);
*reinterpret_cast<unsigned char*>(&eax4) = static_cast<unsigned char>(static_cast<uint1_t>(eax4 >> 5));
eax5 = _Z5isqrtj(0x2137);
*reinterpret_cast<uint32_t*>(&rax6) = eax4 + eax5;
*reinterpret_cast<int32_t*>(reinterpret_cast<int64_t>(&rax6) + 4) = 0;
return rax6;
} `
In this code the value being passed to isqrt is known and isqrt does not reference global memory at all. Evaluating completely pure functions and embedding their results into the generated code could improve the output considerably in certain situations. The generated code would include a comment telling the user that the function was evaluated and the values that were passed to it. This could be toggled on and off by the user if they would prefer pure functions not be evaluated.
Would anyone object to this being added?
No one would object. Actually, there was some code for inlining some time ago, see, e.g., 37391125ed8b90a2f411f4868f2f45f8164f16d6. The code was not used and was removed. One could bring it back and provide an interface to the user, so that she could say which functions to inline and/or which calls to inline.
Why was it removed?
Because it was not used. There was no access to inlining from the GUI.
Seems like it could be useful if applied automatically to trivial functions, like one-line return functions or provably 100% pure functions
Well, you definition of trivial may be different from the one of other users. :) So, Snowman prefers to be on the safe side: it produces what it sees (modulo bugs). At least, it cannot confuse anybody this way.
Fair 'nuff, how about a toggle?
I would prefer to give the user an ability to inline a particular function or a particular call through the GUI. But a switch is a good first step. At least, better than nothing.
where exactly is the last compiled result for the entire compilation unit cached?
On Mar 25, 2017 7:43 PM, "yegord" [email protected] wrote:
I would prefer to give the user an ability to inline a particular function or a particular call through the GUI. But a switch is a good first step. At least, better than nothing.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/yegord/snowman/issues/115#issuecomment-289247438, or mute the thread https://github.com/notifications/unsubscribe-auth/AFDrY5GE9WtR4m0skWNXJEugp_pKfjkTks5rpaaSgaJpZM4MpH6G .
nc::gui::Project::context()
nc::gui::MainWindow
stores a pointer to a Project
.