[fpc-devel] Another benefit of pure functions
J. Gareth Moreton
gareth at moreton-family.com
Wed Jul 10 03:03:19 CEST 2019
This is for my own benefit and note-taking, but I've just found another
use for pure functions.
Though this is not exactly how the compiler source is structured, you
get situations such as this.
RegName := debug_regname(taicpu(p).oper[0]^.reg); { 32-bit register name }
DebugMsg(SPeepholeOptimization + PreMessage + RegName + ',' + RegName +
' (removes REX prefix)', p);
When not in debug mode, DebugMsg is just a null procedure that does
nothing (as is debug_regname, but let's ignore that for the moment).
One of the definitions of pure functions is that it has no side-effects,
so if it can be shown that RegName is not used after its assignment, and
a pure function is being used to assign said value, then the entire call
can be safely removed, since it won't affect any other part of the program.
If anyone is able to notice potential areas where pure functions can
optimise a program, sound off!
Gareth aka. Kit
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
More information about the fpc-devel
mailing list