Cilk-Plus-Transformation.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2017 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>GNU Compiler Collection (GCC) Internals: Cilk Plus Transformation</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Cilk Plus Transformation">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Cilk Plus Transformation">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Passes.html#Passes" rel="up" title="Passes">
  30. <link href="Gimplification-pass.html#Gimplification-pass" rel="next" title="Gimplification pass">
  31. <link href="Parsing-pass.html#Parsing-pass" rel="prev" title="Parsing pass">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style:oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="Cilk-Plus-Transformation"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Gimplification-pass.html#Gimplification-pass" accesskey="n" rel="next">Gimplification pass</a>, Previous: <a href="Parsing-pass.html#Parsing-pass" accesskey="p" rel="prev">Parsing pass</a>, Up: <a href="Passes.html#Passes" accesskey="u" rel="up">Passes</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  66. </div>
  67. <hr>
  68. <a name="Cilk-Plus-Transformation-1"></a>
  69. <h3 class="section">9.2 Cilk Plus Transformation</h3>
  70. <a name="index-CILK_005fPLUS"></a>
  71. <p>If Cilk Plus generation (flag <samp>-fcilkplus</samp>) is enabled, all the Cilk
  72. Plus code is transformed into equivalent C and C++ functions. Majority of this
  73. transformation occurs toward the end of the parsing and right before the
  74. gimplification pass.
  75. </p>
  76. <p>These are the major components to the Cilk Plus language extension:
  77. </p><ul>
  78. <li> Array Notations:
  79. During parsing phase, all the array notation specific information is stored in
  80. <code>ARRAY_NOTATION_REF</code> tree using the function
  81. <code>c_parser_array_notation</code>. During the end of parsing, we check the entire
  82. function to see if there are any array notation specific code (using the
  83. function <code>contains_array_notation_expr</code>). If this function returns
  84. true, then we expand them using either <code>expand_array_notation_exprs</code> or
  85. <code>build_array_notation_expr</code>. For the cases where array notations are
  86. inside conditions, they are transformed using the function
  87. <code>fix_conditional_array_notations</code>. The C language-specific routines are
  88. located in <samp>c/c-array-notation.c</samp> and the equivalent C++ routines are in
  89. the file <samp>cp/cp-array-notation.c</samp>. Common routines such as functions to
  90. initialize built-in functions are stored in <samp>array-notation-common.c</samp>.
  91. </li><li> Cilk keywords:
  92. <ul>
  93. <li> <code>_Cilk_spawn</code>:
  94. The <code>_Cilk_spawn</code> keyword is parsed and the function it contains is marked
  95. as a spawning function. The spawning function is called the spawner. At
  96. the end of the parsing phase, appropriate built-in functions are
  97. added to the spawner that are defined in the Cilk runtime. The appropriate
  98. locations of these functions, and the internal structures are detailed in
  99. <code>cilk_init_builtins</code> in the file <samp>cilk-common.c</samp>. The pointers to
  100. Cilk functions and fields of internal structures are described
  101. in <samp>cilk.h</samp>. The built-in functions are described in
  102. <samp>cilk-builtins.def</samp>.
  103. <p>During gimplification, a new &quot;spawn-helper&quot; function is created.
  104. The spawned function is replaced with a spawn helper function in the spawner.
  105. The spawned function-call is moved into the spawn helper. The main function
  106. that does these transformations is <code>gimplify_cilk_spawn</code> in
  107. <samp>c-family/cilk.c</samp>. In the spawn-helper, the gimplification function
  108. <code>gimplify_call_expr</code>, inserts a function call <code>__cilkrts_detach</code>.
  109. This function is expanded by <code>builtin_expand_cilk_detach</code> located in
  110. <samp>c-family/cilk.c</samp>.
  111. </p>
  112. </li><li> <code>_Cilk_sync</code>:
  113. <code>_Cilk_sync</code> is parsed like a keyword. During gimplification,
  114. the function <code>gimplify_cilk_sync</code> in <samp>c-family/cilk.c</samp>, will replace
  115. this keyword with a set of functions that are stored in the Cilk runtime.
  116. One of the internal functions inserted during gimplification,
  117. <code>__cilkrts_pop_frame</code> must be expanded by the compiler and is
  118. done by <code>builtin_expand_cilk_pop_frame</code> in <samp>cilk-common.c</samp>.
  119. </li></ul>
  120. </li></ul>
  121. <p>Documentation about Cilk Plus and language specification is provided under the
  122. &quot;Learn&quot; section in <a href="https://www.cilkplus.org">https://www.cilkplus.org</a><!-- /@w -->. It is worth mentioning
  123. that the current implementation follows ABI 1.1.
  124. </p>
  125. <hr>
  126. <div class="header">
  127. <p>
  128. Next: <a href="Gimplification-pass.html#Gimplification-pass" accesskey="n" rel="next">Gimplification pass</a>, Previous: <a href="Parsing-pass.html#Parsing-pass" accesskey="p" rel="prev">Parsing pass</a>, Up: <a href="Passes.html#Passes" accesskey="u" rel="up">Passes</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  129. </div>
  130. </body>
  131. </html>