How to identify and remove redundant code?
Practical Information for the IBM Rational Apex® developer.This paper is a brief overview of the identification and removal of redundant code that can be done at different level with Apex. At a source code level and/or at a binary code level, using primarily two Apex layered products called Little Tree Consulting® Ada Analyzer™ and Rational®Testmate™, and then performing a code optimization using Rational Apex switches created for this purpose.
IBM no longer owns this product but is providing its technical support documents "AS-IS" for Atego customer benefit until 1 May 2013. For information about technical assistance, visit http://www.atego.com/support/
Resolving the problem
There are primarily two aspects to this question: identifying redundant code and removing redundant code. Apex provides means of achieving both, however there is no direct connection between them.
Unused source code can be identified by using Ada Analyzer and TestMate for Ada code.
Ada Analyzer has the following options:
Locate Unused Declarations
Locate Unused With Clauses
The resulting report will provide a static analysis of the source code to identify these features. It cannot identify branches of code which cannot be executed following tests of variables, for example.
TestMate can be used for Ada and/or C/C++ to create tests to exercise the different branches of the source code. The results show which source code is used and unused for each test. However, the results will be totally dependent on the test design. With very simple modules TestMate can identify source code that is not used in a given set of circumstances. With large and complex programs it will require extremely rigorous test design to have a chance of detecting uncovered and redundant source code. Note that TestMate is not available for Windows™.
The Apex compiler removes unused assembly code depending on the optimization level selected. The level is selected by setting the OPTIMIZATION_LEVEL in the switches file.
Full details on Code Optimization is given in the Ada Compiler Reference, Optimizing Code.
There are 3 levels of Optimization in the Ada Compiler:
Level 0 results in no optimization at all
Level 1 maximizes performance without loss of debuggability
Level 2 code is removed, re-ordered and inlined.
However, with Level 2 the code removed by optimization is not identified. For example, the original line of source code may still be displayed in the debugger even though it may no longer have a direct relationship with the actual object code.
Information on C++ Optimization can be found in the C/C++ Compiler Reference Manual, Invocation Options, -O[0-9]
There is no way of actually seeing how the code has been changed without looking at
the disassembled code. Some redundant code, such as NOP instructions, may be located with ease, however it will need an assembler expert to really understand how the code has been altered.
There is no link between the code optimized away by the compiler and the source code identified by Ada Analyzer and TestMate above.
With both Ada Analyzer and TestMate the source code thus identified will need to be removed by hand, following inspection to check that it is truly inaccessible (in the case of TestMate).
In general, even with the best optimization, this is a challenging task for any compiler/linker and therefore it is difficult to guarantee the removal af all redundant code.
Safety critical applications will need additional measures beyond the scope of this paper.
Microsoft, Windows, Windows NT, Windows 2000, Windows XP, and the Windows logo are trademarks of Microsoft Corporation in the United States, other countries, or both.
Ada Analyzer and Ada Repair are registered trademarks of Little Tree consulting Ltd.
in the United States, other countries, or both.
UNIX is a registered trademark of The Open Group in the United States
and other countries.
|Software Development||Rational Ada Developer||--|
More support for:
Software version: 2.2.4, 2.4.1, 2.4.2, 2.4.4, 2.4.6, 2.5.0, 3.0.0b, 3.0.0, 3.0.1, 3.0.2b, 3.0.2, 3.2.0b, 3.2
Operating system(s): Platform Independent
Reference #: 1124868
Modified date: 2007-01-22