This Article 
   
 Share 
   
 Bibliographic References 
   
 Add to: 
 
Digg
Furl
Spurl
Blink
Simpy
Google
Del.icio.us
Y!MyWeb
 
 Search 
   
Using Hammock Graphs to Structure Programs
April 2004 (vol. 30 no. 4)
pp. 231-245
Advanced computer architectures rely mainly on compiler optimizations for parallelization, vectorization, and pipelining. Efficient code generation is based on a control dependence analysis to find the basic blocks and to determine the regions of control. However, unstructured branch statements, such as jumps and goto's, render the control flow analysis difficult, time-consuming, and result in poor code generation. Branches are part of many programming languages and occur in legacy and maintenance code as well as in assembler, intermediate languages, and byte code. A simple and effective technique is presented to convert unstructured branches into hammock graph control structures. Using three basic transformations, an equivalent program is obtained in which all control statements have a well-defined scope. In the interest of predication and branch prediction, the number of control variables has been minimized, thereby allowing a limited code replication. The correctness of the transformations has been proven using an axiomatic proof rule system. With respect to previous work, the algorithm is simpler and the branch conditions are less complex, making the program more readable and the code generation more efficient. Additionally, hammock graphs define single entry single exit regions and therefore allow localized optimizations. The restructuring method has been implemented into the parallelizing compiler FPT and allows to extract parallelism in unstructured programs. The use of hammock graph transformations in other application areas such as vectorization, decompilation, and assembly program restructuring is also demonstrated.

[1] S. Alagic and M.A. Arbib, The Design of Well-Structured and Correct Programs. Springer, 1978.
[2] J.-R. Allen, K. Kennedy, C. Porterfield, and J. Warren, Conversion of Control Dependence to Data Dependence Proc. 10th Ann. ACM Symp. Principles of Programming Languages, pp. 177-189, Jan. 1983.
[3] Z. Ammarguellat, A Control-Flow Normalization Algorithm and Its Complexity IEEE Trans. Software Eng., vol. 18, no. 3, pp. 237-251, 1992.
[4] M.A. Arbib and S. Alagic, Proof Rules for Gotos Acta Informatica, vol. 11, pp. 139-148, 1979.
[5] E. Ashcroft and Z. Manna, The Translation of Goto Programs into While Programs Proc. IFIP Congress 71, C. Freiman, J. Griffith, and J. Rosenfeld, eds., vol. 1, pp. 250-255, 1972.
[6] B. Dutertre, Elements of Mathematical Analysis in PVS Proc. Ninth Int'l Conf. Theorem Proving in Higher Order Logics TPHOL, J. Von Wright, J. Grundy, and J. Harrison, eds., Aug. 1996.
[7] C. Boehm and G. Jacopini, Flow Diagrams, Turing Machines and Languages with Only Two Formation Rules Comm. ACM, vol. 9, no. 5, pp. 366-371, May 1966.
[8] L. Carter, B. Simon, B. Calder, L. Carter, and J. Ferrante, Path Analysis and Renaming for Predicated Instruction Scheduling Int'l J. Parallel Programming, vol. 28, no. 6, pp. 563-588, 2000.
[9] C. Cifuentes, Structuring Decompiled Graphs Lecture Notes in Computer Science, vol. 1060, pp. 91-104, 1996.
[10] B. De Bus, D. Kästner, D. Chanet, L. Van Put, and B. De Sutter, Post-Pass Compaction Techniques Comm. ACM, vol. 46, no. 8, pp. 41-46, 2003.
[11] E.H. D'Hollander and F. Zhang, Restructuring Program Transformations with Proof Verification Using PVS Technical Report RUG/ELIS01, p. 47, 2001.
[12] E.H. D'Hollander, F. Zhang, and Q. Wang, The Fortran Parallel Transformer and Its Programming Environment Information Sciences, vol. 106, nos. 3-4, pp. 293-317, 1998.
[13] A.M. Erosa and L.J. Hendren, Taming Control Flow: A Structured Approach to Eliminating Goto Statements Proc. Fifth Int'l Conf. Computer Languages, pp. 229-240, 1994.
[14] J. Ferrante, K.J. Ottenstein, and J.D. Warren, The Program Dependence Graph and Its Use in Optimization ACM Trans. Programming Languages and Systems, vol. 9, no. 3, pp. 319-349, 1987.
[15] P. Havlak, Nesting of Reducible and Irreducible Loops ACM Trans. Programming Languages and Systems (TOPLAS), vol. 19, no. 4, pp. 557-567, 1997.
[16] M.S. Hecht and J.D. Ullman, Characterizations of Reducible Flow Graphs J. ACM, vol. 21, no. 3, pp. 367-375, 1974.
[17] C.A.R. Hoare, An Axiomatic Basis of Computer Programming Comm. ACM, vol. 12, pp. 576-580, 1969.
[18] C.A.R. Hoare, An Axiomatic Definition of the Programming Language Pascal Acta Informatca, vol. 2, pp. 335-355, 1973.
[19] J. Janssen and H. Corporaal, Making Graphs Reducible with Controlled Node Splitting ACM Trans. Programming Languages and Systems, vol. 19, no. 6, pp. 1031-1052, 1997.
[20] V.N. Kas'janov, Distinguishing Hammocks in a Directed Graph Soviet Math. Doklady, vol. 16, no. 5, pp. 448-450, 1975.
[21] A. Klauser, T. Austin, D. Grunwald, and B. Calder, Dynamic Hammock Predication for Non-Predicated Instruction Set Architectures Proc. 1998 Int'l Conf. Parallel Architectures and Compilation Techniques (PACT '98), pp. 278-285, Oct. 1998.
[22] L. Lamport, How to Make a Multiprocessor Computer that Correctly Executes Multiprocess Programs IEEE Trans. Computers, vol. 28, no. 9, pp. 690-691, 1979.
[23] P. Morris, R.A. Gray, and R.E. Filman, GOTO Removal Based on Regular Expressions J. Software Maintenance Research and Practice, vol. 9, no. 1, pp. 47-66, Jan./Feb. 1997.
[24] H.R. Nielson and F. Nielson, Semantics with Applications. John Wiley and Sons, 1993.
[25] G. Oulsnam, Unravelling Unstructured Programs The Computer J., vol. 25, no. 3, pp. 379-387, Aug. 1982.
[26] G. Oulsnam, The Algorithmic Transformation of Schemas to Structured Form The Computer J., vol. 30, no. 1, pp. 43-51, Feb. 1987.
[27] S. Owre, J. Rushby, N. Shankar, and F. von Henke, "Formal Verification for Fault-Tolerant Architectures: Prolegomena to the Design of PVS," IEEE Trans. Software Eng., vol. 21, pp. 107-125, Feb. 1995.
[28] S. Owre, J.M. Rushby, and N. Shankar, PVS: A Prototype Verification System Proc. 11th Int'l Conf. Automated Deduction (CADE-11), D. Kapur, ed., June 1992.
[29] W.W. Peterson, T. Kasami, and N. Tokura, On the Capabilities of While, Repeat, and Exit Statements Comm. ACM, vol. 16, no. 8, pp. 503-512, Aug. 1973.
[30] L. Ramshaw, Eliminating Goto's While Preserving Program Structure J. ACM, vol. 35, no. 4, pp. 893-920, Oct. 1988.
[31] N. Shankar, Steps Towards Mechanizing Program Transformations Using PVS Science of Computer Programming, vol. 26, nos. 1-3, pp. 33-57, May 1996.
[32] S. Unger and F. Mueller, Handling Irreducible Loops: Optimized Node Splitting Versus DJ-Graphs ACM Trans. Programming Languages and Systems (TOPLAS), vol. 24, no. 4, pp. 299-333, 2002.
[33] M. Weiser, Program Slicing IEEE Trans. Software Eng., vol. 10, no. 4, pp. 352-357, July 1984.
[34] M.H. Williams, Generating Structured Flow Diagrams: The Nature of Unstructuredness The Computer J., vol. 20, no. 1, pp. 45-50, Feb. 1977.
[35] M.H. Williams and G. Chen, Restructuring Pascal Programs Containing Goto Statements The Computer J., vol. 28, no. 2, pp. 134-137, 1985.
[36] M.H. Williams and H.L. Ossher, Conversion of Unstructured Flow Diagrams to Structured Form The Computer J., vol. 21, no. 2, pp. 161-167, 1978.
[37] F. Zhang, FPT: A Parallel Programming Environment PhD thesis, Dept. of Electrical Eng., Univ. of Ghent, 1996.
[38] F. Zhang and E.H. D'Hollander, Extracting the Parallelism in Programs with Unstructured Control Statements Proc. Int'l Conf. Parallel and Distributed Systems, (ICPADS '94), pp. 264-270, Dec. 1994.

Index Terms:
Program transformation, structured programming, compilers, optimization, parallel processing, software/program verification, correctness proofs.
Citation:
Fubo Zhang, Erik H. D'Hollander, "Using Hammock Graphs to Structure Programs," IEEE Transactions on Software Engineering, vol. 30, no. 4, pp. 231-245, April 2004, doi:10.1109/TSE.2004.1274043
Usage of this product signifies your acceptance of the Terms of Use.