OPTIMIZATION - IBM Mainframe

This section discusses the benefits of the OPTIMIZE compiler option as well as other compiler features affecting optimization.

The OPTIMIZE Compiler Option

The VS COBOL II optimizer is activated by specifying the OPTIMIZE compiler option. The purpose of the OPTIMIZE compiler option is to:

  • Eliminate unnecessary transfers of control or simplify inefficient branches (including those generated by the compiler) that are not evident from looking at the source program.
  • Simplify the compiled code for both a PERFORM statement and a CALL statement to a contained (nested) program. Where possible, the optimizer places the statements in-line, eliminating the need for linkage code. This optimization is known as procedure integration. If procedure integration cannot be done, the optimizer uses the simplest linkage possible (perhaps as few as two instructions) to get to and from the called program.
  • Eliminate duplicate computations (such as subscript computations) by saving the results for later reuse.
  • Eliminate constant computations by performing them when the program is compiled.
  • Aggregate moves of contiguous items (such as those that often occur with the use of MOVE CORRESPONDING) into a single move. Both the source and target must be contiguous for the moves to be aggregated.
  • Delete from the program, and identify with a warning message, code that can never be executed (unreachable code elimination). To see how the optimizer works on your program, compile it with and without the OPTIMIZE option and then compare the generated code. (You can request the assembler language listing of the generated code by specifying the LIST compiler option.)

For unit testing your programs, you may find it easier to debug code that has not been optimized. But when the program is ready for final test, specify OPTIMIZE, so that the tested code and the production code are identical. You may also want to use the option during development, if a program is used frequently without recompilation. However, the overhead for OPTIMIZE may outweigh its benefits if you recompile frequently, unless you are using the assembler language expansion (LIST option) to fine tune your program.

PERFORM Procedure Integration

PERFORM procedure integration is the process whereby a PERFORM statement is replaced by its performed procedures. The advantage here is that the resulting program runs faster without the overhead of PERFORM linkage and with more linear control flow.

  • Program size - If the performed procedures are invoked by several PERFORM statements and replace each such PERFORM statement, then the program may become larger. The optimizer limits this increase to no more than 50 percent, after which it no longer uses procedure integration. However, if you are concerned about program size, you may want to prevent procedure integration in specific instances. You can do this by using a priority number on section names. If you do not want a PERFORM statement to be replaced by its performed procedures, put the PERFORM statement in one section and put the performed procedures in another section with a different priority number. The optimizer then chooses the next best optimization for the PERFORM statement; the linkage overhead can be as few as two instructions.
  • Unreachable code elimination - Because of procedure integration, one PERFORM procedure may be repeated several times. As further optimization proceeds on each copy of the procedure, portions may be found to be unreachable, depending on the context into which the code was copied. A warning message is generated for each such occurrence.

Contained Program Procedure Integration

Contained program procedure integration is the process where a CALL to a contained program is replaced by the program code. The advantage here is that the resulting program runs faster without the overhead of CALL linkage and with more linear control flow.

  • Program size - If the contained programs are invoked by several CALL statements and replace each such CALL statement, then the program may become larger. The optimizer limits this increase to no more than 50 percent, after which it no longer uses procedure integration. The optimizer then chooses the next best optimization for the CALL statement; the linkage overhead can be as few as two instructions.
  • Unreachable code elimination - As a result of procedure integration, one contained program may be repeated several times. As further optimization proceeds on each copy of the program. portions may be found to be unreachable, depending on the context into which the code was copied. When this happens, a warning message is generated.

Other Compiler Features That Affect Optimization

There are two compiler features that can have a significant influence on the effects of the optimizer, the FDUMP compiler option and the USE FOR DEBUGGING ON ALL PROCEDURES statement.

  • The FOUMP Compiler Option - FDUMP generates extra code. Generally, the extra code does not significantly interfere with optimization. In most cases, you do not need to worry about size constraints on your source program.
  • USE FOR DEBUOOINC ON ALL PROCEDURES - The ON ALL PROCEDURES option of the USE FOR DEBUGGING sentence generates extra code at each transfer to every procedure name. It can be very useful for debugging, but can make the program significantly larger as well as substantially inhibit optimization.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

IBM Mainframe Topics