Inline Function Opportunity

Inline Function Opportunity

TITLE: Function Inline Opportunity


DESCRIPTION: PBA looks for opportunities to inline functions since call and ret are fairly expensive instructions for shoft functions.  It does this by simply following the hot path through the function with streams and counting the number of instructions that are executed between the call and the return instructions.  It will ignore zero-length or zero-displacement calls which do not have a corresponding return instructions.

RELEVANCE: Short functions that can be inlined negatively impacts most architectures on all OSs.  


call FUNCA  //Call to FUNCA

FUNCA: mov eax, 1  //Simple one instruction function

ret  //Return after only executing one instruction

SOLUTION:  Inlining is enabled with the /Ob2 flag which is default with /O1, /O2 and /Ox compiler flags with the MSVC compiler.  Inlining is enabled in gcc with the -finline-small-functions flag which is default with the /O2 and /O3 optimization flags.  Typically profile guided optimizations supported by all compilers will allow the compiler to make smarter decisions about which functions to inline.  The Intel compiler will enable aggressive inlining with the interprocedural optimizations.  All compilers also support pragmas that allow the user to explicitly inline known small functions.




1 post / novo 0
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.