PSL Optimizer Tool
The PATROL PSL Optimizer tool is a three-level, multi-pass, intermediate code (quad) optimizer
- PATROL 3.2 only
The PSL Optimizer requires no additional resources beyond those specified for running the PATROL product.
When to Use the PSL Optimizer
Use this tool to optimize your KM code.
How to Install the PSL Optimizer
This tool is part of the PATROL Agent. No further setup is required once PATROL has been installed.
How to Deactivate the PSL Optimizer
Since this tool is part of the PATROL product, there is no requirement to deactivate the tool.
About the PSL Optimizer
When a PSL script is compiled, it is compiled down to an intermediate code. The PATROL Optimizer transforms the intermediate code generated by the PSL Compiler so that the code executes more efficiently in the PSL interpreter.
You can specify the level of optimization by using the
-O flag with the PSL stand-alone compiler or with the PATROL Agent function. You can also use the
pragma keyword in PSL to set the optimization level for a particular PSL script.
The supported levels of optimization are:
peephole optimization (default)
Level 1: Peephole optimizations
Level 1 optimizations are ignorant of a program's control flow and are limited to the analysis of a program on an instruction by instruction basis.
Level 1 optimizations include the following:
- jump chain reduction
- useless jump removal
- redundant instruction removal
- parameter packing
Jump chain reduction
This optimization looks for unconditional jumps to one or more Control Transfer Statement (CTS) instructions. The terminal CTS instruction is then replicated onto all of the non-terminal CTS instructions.
Useless jump removal
This optimization looks for unconditional and conditional jumps to the next instruction. The jump is then removed.
Redundant instruction removal
This optimization looks for redundant statements without side effects. One of the redundant statements is then removed.
This optimization looks for adjacent parameter instructions and packs them into a more efficient parameter instruction.
Level 2: Local optimizations
Level 2 optimizations use a flowgraph to optimize the program one basic block at a time. Code motion, addition, and removal are limited to a basic block unit.
Level 2 optimizations include the following:
- constant folding
- constant propagation
- global constant propagation
- definition removal
- string concatenation conversion
- parameter ordering
Expressions are evaluated when their arguments are known at optimization time. The result of the folded expression replaces the original expression with an assignment operation.
The results of constant folding are tracked and propagated into other expressions using the value. These values can then be folded into other expressions.
Global constant propagation
The values of symbols used in subsequent basic blocks are seeded for future Level 2 fold-and-propagate optimizations.
Expressions defining symbols that are later defined, without first being referenced, are removed. Expressions with side effects remove only the assignment to the symbol.
String concatenation conversion
Chains of string concatenations are converted into a single and more efficient call to the PSL
Parameter statements with nested expressions are re-ordered so all expression evaluation occurs before the first parameter statement and all parameter statements immediately precede the call statement. This exposes Level 1 parameter packing opportunities.
Level 3: Global optimizations
Level 3 optimizations alter the flowgraph by adding, removing, and re-locating basic blocks.
Level 3 optimizations include the following:
Block chain reduction
One or more basic blocks that are entered from an unconditional jump are copied to the jump point. The resultant basic block is then extended to include the copied block.
Unreachable code removal
Code that can never be executed is removed.
Loop tail logic injection
Loops with conditional heads and unconditional tails are converted so that the condition evaluation takes place in the loop's tail(s). This decreases loop overhead by removing an unnecessary jump to the condition block.
Orphan block inlining
Blocks that are entered exclusively via jumps are inlined (moved) into the innermost loop that references this block.
The PSL Optimizer decides at what level to optimize a program based on the following criteria:
Requested level of optimization
The requested level is implicitly defined based on the context of the call to the PSL Compiler. For example, a PSL parameter script will request Level 3 global optimization when it is compiled. A script submitted via the
%PSL command will request the default level (Level 1 peephole) of optimization when it is compiled.
Currently, Level 3 global optimization is requested for all pre-discovery, discovery, and parameter PSL scripts. The default Level 1 is used for all other commands.
Demanded level of optimization
The demanded level is explicitly defined and takes precedence over the requested level. The demanded level can be specified on the command line or directly in the PSL program via the pragma statement.
For example, a parameter can demand Level 2 optimization (and thus override the Level 3 request) by inserting the following
pragma statement in the program:
Note that the O in the O2 in the line above is an uppercase alphabetic character and not a number zero.
Likewise, the optimization level can be specified system-wide via the command line as follows:
Note that the
0 in the
02 in the line above is a numeric and not an alpha capital letter O.
This will cause all PSL scripts to be optimized at Level 2 except for any scripts containing a
pragma statement requesting another level of optimization.
Maximum level of optimization
The maximum level is explicitly defined and takes precedence over the demanded level and the requested level. The maximum level restricts the Optimizer tool from invoking higher levels. For example, if a parameter specifies a maximum optimization level of 1, it will never get optimized at Levels 2 or 3. A program specifying a maximum level can use a
pragma statement like this:
# This program will be optimized at level 1 and # print the levels 1 and 2 results for the # program and its processes.
Likewise, the maximum level can be specified system-wide via the command line as follows:
Specifying a maximum level of zero (0) turns off the PSL Optimizer tool.
Command-Line Specified Options
The PSL Optimizer tool can be controlled using the following methods:
- Via a command-line switch for the
PatrolAgentcommands. This affects scripts system wide.
- Via the
pragmaPSL statement. This affects only the script using the pragma statement.
The format is as follows:
-O # M# P#
specify the demanded optimization level If no level is specified, the requested optimization level, defined implicitly based on the context of the PSL script, will be used. Valid values are 0, 1, 2 and 3.
specify the maximum optimization level. Valid values are 0, 1, 2 and 3. The default level is 3.
Specify the level at which to print optimization results (to stdout). Valid values are:
Log in or register to comment.