Compiler-Guided Identification of Critical Sections in Parallel Code

  • Stefan Kempf
  • Ronald Veldema
  • Michael Philippsen
Part of the Lecture Notes in Computer Science book series (LNCS, volume 7791)


There is a huge body of sequential legacy code that needs to be refactored for multicore processors. Especially for control code for embedded systems it is often easy to split the program into multiple threads. But it is difficult to identify critical sections to avoid data races as the legacy code hides its synchronization in a static schedule, priorities and interrupts.

To ease refactoring, this paper presents a new static data-dependence analysis that identifies necessary critical sections in thread-parallel code that does not yet contain any synchronization between threads. A novel optimization pass then breaks up and shrinks the identified critical sections to maximize parallelism while preserving correctness. Our technique proved to be successful in refactoring sequential assembly-like legacy codes in an industry-sponsored project.

But as refactoring projects are hard to evaluate quantitatively and as the domain specific low-level language is of limited interest, we use a standard benchmark suite for which the optimum, i.e., the minimal set of the necessary atomic block annotations is known. We removed the annotations and let the compiler attempt to rediscover them. For 5 out of 7 benchmarks, our compiler identified the same critical sections as the original programmers did by hand. For the other two benchmarks, the compiler found slightly larger (but also correct) critical sections. In all cases, the versions of the benchmarks that the compiler annotated achieved the original run-time performance.


Shared Variable Data Dependence Critical Section Transactional Memory Multiple Thread 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


  1. 1.
    Banerjee, U.: Dependence Analysis. Kluwer Academic Publishers, Norwell (1997)zbMATHGoogle Scholar
  2. 2.
    Bogda, J., Hölzle, U.: Removing unnecessary synchronization in java. In: OOPSLA 1999: Proc. ACM SIGPLAN Conf. on Object-Priented Programming, Systems, Languages, and Applications. Denver, Co., ACM (November 1999)Google Scholar
  3. 3.
    Cao Minh, C., Chung, J., Kozyrakis, C., Olukotun, K.: STAMP: Stanford transactional applications for multi-processing. In: IISWC 2008: Proc. IEEE Intl. Symp. Workload Characterization, Seattle, WA, pp. 35–46 (September 2008)Google Scholar
  4. 4.
    Ceze, L., Montesinos, P., von Praun, C., Torrellas, J.: Colorama: Architectural support for data-centric synchronization. In: HPCA 2007: Proc. IEEE Intl. Symp. High Performance Computer Architecture, Phoenix, AZ, pp. 133–144 (February 2007)Google Scholar
  5. 5.
    Dragojević, A., Guerraoui, R., Kapalka, M.: Stretching transactional memory. In: PLDI 2009: Proc. ACM SIGPLAN Conf. Programming Lang. Design and Impl., Dublin, Ireland, pp. 155–165 (June 2009)Google Scholar
  6. 6.
    Flanagan, C., Freund, S.N.: Fasttrack: efficient and precise dynamic race detection. In: PLDI 2009: Proc. ACM SIGPLAN Conf. on Programming Language Design and Implementation, Dublin, Ireland, pp. 121–133 (June 2009)Google Scholar
  7. 7.
    Gudka, K., Harris, T., Eisenbach, S.: Lock Inference in the Presence of Large Libraries. In: Noble, J. (ed.) ECOOP 2012. LNCS, vol. 7313, pp. 308–332. Springer, Heidelberg (2012)CrossRefGoogle Scholar
  8. 8.
    Halpert, R.L., Pickett Christopher, J.F., Clark, V.: Component-based lock allocation. In: PACT 2007: Proc. 16th Intl. Conf. on Parallel Architecture and Compilation Techniques, Brasov, Romania, pp. 353–364 (September 2007)Google Scholar
  9. 9.
    Heintze, N., Tardieu, O.: Ultra-fast aliasing analysis using CLA: a million lines of C code in a second. In: PLDI 2001: Proc. ACM SIGPLAN Conf. on Programming Language Design and Implementation, Snowbird, UT, pp. 254–263 (June 2001)Google Scholar
  10. 10.
    Herlihy, M., Moss, J.E.B.: Transactional memory: architectural support for lock-free data structures. ACM SIGARCH Comput. Archit. News 21(2), 289–300 (1993)CrossRefGoogle Scholar
  11. 11.
    Jeremiassen, T., Eggers, S.J.: Static analysis of barrier synchronization in explicitly parallel programs. In: PACT 1994: Proc. IFIP WG 10.3 Working Conf. on Parallel Architectures and Compilation Techniques, pp. 171–180 (August 1994)Google Scholar
  12. 12.
    Johnson, R., Pearson, D., Pingali, K.: The program structure tree: Computing control regions in linear time. In: PLDI 1994: Proc. ACM SIGPLAN Conf. on Programming Language Design and Implementation, Orlando, FL, pp. 171–185 (June 1994)Google Scholar
  13. 13.
    Lu, S., Park, S., Hu, C., Ma, X., Jiang, W., Li, Z., Popa, R.A., Zhou, Y.: MUVI: automatically inferring multi-variable access correlations and detecting related semantic and concurrency bugs. In: SOSP 2007: Proc. ACM SIGOPS Symp. Operating Systems Principles, Stevenson, WA, pp. 103–116 (October 2007)Google Scholar
  14. 14.
    Muchnick, S.: Advanced Compiler Design And Implementation. Morgan Kaufmann Publishers Inc., San Francisco (1997)Google Scholar
  15. 15.
    Muzahid, A., Otsuki, N., Torrellas, J.: AtomTracker: A comprehensive approach to atomic region inference and violation detection. In: MICRO 43: Proc. 43rd Annual IEEE/ACM Intl. Symp. Microarchitecture, Atlanta, GA, pp. 287–297 (December 2010)Google Scholar
  16. 16.
    Naik, M., Aiken, A., Whaley, J.: Effective static race detection for java. In: PLDI 2006: Proc. ACM SIGPLAN Conf. on Programming Language Design and Implementation, Ottawa, ON, Canada, pp. 308–319 (June 2006)Google Scholar
  17. 17.
    Salcianu, A., Rinard, M.: Pointer and escape analysis for multithreaded programs. In: PPoPP 2001: Proc. ACM SIGPLAN Symp. Principles and Practices of Parallel Programming, Snowbird, UT, pp. 12–23 (June 2001)Google Scholar
  18. 18.
    Vaziri, M., Tip, F., Dolby, J.: Associating synchronization constraints with data in an object-oriented language. In: POPL 2006: Proc. ACM SIGPLAN-SIGACT Symp. Principles of Programming Languages, Charleston, SC, pp. 334–345 (January 2006)Google Scholar
  19. 19.
    Vechev, M., Yahav, E., Yorsh, G.: Abstraction-guided synthesis of synchronization. In: POPL 2010: Proc. ACM SIGPLAN-SIGACT Symp. Principles of Programming Languages, Madrid, Spain, pp. 327–338 (January 2010)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2013

Authors and Affiliations

  • Stefan Kempf
    • 1
  • Ronald Veldema
    • 1
  • Michael Philippsen
    • 1
  1. 1.Computer Science Dept., Programming Systems GroupUniversity of Erlangen-NurembergErlangenGermany

Personalised recommendations