<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
{mso-style-priority:99;
mso-style-link:"Plain Text Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.PlainTextChar
{mso-style-name:"Plain Text Char";
mso-style-priority:99;
mso-style-link:"Plain Text";
font-family:"Calibri",sans-serif;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:2.0cm 42.5pt 2.0cm 3.0cm;}
div.WordSection1
{page:WordSection1;}
/* List Definitions */
@list l0
{mso-list-id:1452742412;
mso-list-type:hybrid;
mso-list-template-ids:-273930950 68747279 68747289 68747291 68747279 68747289 68747291 68747279 68747289 68747291;}
@list l0:level1
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level2
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level3
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l0:level4
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level5
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level6
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l0:level7
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level8
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level9
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="RU" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoPlainText"><span lang="EN-US">Hello,<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">I'm working on the following patch: </span>
<a href="https://reviews.llvm.org/D26794"><span lang="EN-US" style="color:windowtext;text-decoration:none">https://reviews.llvm.org/D26794</span></a><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">In the beginning of the work it was a bug in spec:
</span><a href="https://cvs.khronos.org/bugzilla/show_bug.cgi?id=15659"><span lang="EN-US" style="color:windowtext;text-decoration:none">https://cvs.khronos.org/bugzilla/show_bug.cgi?id=15659</span></a><span lang="EN-US"> and it was fixed in rev. 39 (example
5, chapter 6.12.5): </span><a href="https://cvs.khronos.org/svn/repos/OpenCL/trunk/Khronos/specs/opencl20-openclc-rev39.pdf"><span lang="EN-US" style="color:windowtext;text-decoration:none">https://cvs.khronos.org/svn/repos/OpenCL/trunk/Khronos/specs/opencl20-openclc-rev39.pdf</span></a><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">After these changes in specification, block capture semantics follows regular C argument passing convention, i.e. arrays are captured by reference (decayed to pointers) and structs are captured by value. But in current
implementation array will be captured by value in both cases.<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">I added new check in function <b><i>EmitBlockLiteral</i></b> in file
<b><i>CGBlocks.cpp</i></b> where I check if type is array, I do some operations for keeping reference to initial array. I think that the code in this check should work correctly (I saw how it works for cpp lambdas). But I cannot check it because type of captured
variable in block is <b><i>[4 x i32]</i></b>. For keeping reference I expect that it should be
<b><i>[4 x i32]*</i></b> or <b><i>i8*</i></b>. <o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">I tried to get the pointer on array by two different ways:<o:p></o:p></span></p>
<p class="MsoPlainText" style="margin-left:36.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo1">
<![if !supportLists]><span lang="EN-US"><span style="mso-list:Ignore">1.<span style="font:7.0pt "Times New Roman"">
</span></span></span><![endif]><span lang="EN-US">I extended an if statement in file
<b><i>SemaExpr.cpp</i></b> in function: <b><i>captureInBlock</i></b>. In the following statement I added OpenCL check:<o:p></o:p></span></p>
<p class="MsoPlainText" style="margin-left:36.0pt"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><i><span lang="EN-US" style="color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%">if (HasBlocksAttr || CaptureType->isReferenceType() ||<o:p></o:p></span></i></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><i><span lang="EN-US" style="color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%"> (S.getLangOpts().OpenMP && S.IsOpenMPCapturedDecl(Var))
<b>||<o:p></o:p></b></span></i></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><b><i><span lang="EN-US" style="color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%"> (S.getLangOpts().OpenCL && CaptureType->isArrayType()))</span></i></b><i><span lang="EN-US" style="color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%">
{ <o:p></o:p></span></i></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><b><i><span lang="EN-US" style="color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%"> </span></i></b><i><span lang="EN-US" style="color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%">//
Block capture by reference does not change the capture or // declaration reference types.<o:p></o:p></span></i></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><i><span lang="EN-US" style="color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%">ByRef = true;
<o:p></o:p></span></i></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><i><span lang="EN-US"><o:p> </o:p></span></i></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><span lang="EN-US">And also, in the same file in function
<b><i>ActOnBlockStmtExpr</i></b>. I added check if captured value is reference capture:<o:p></o:p></span></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><i><span lang="EN-US" style="color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%">BlockDecl::Capture NewCap(Cap.getVariable(), Cap.isBlockCapture()<b> || Cap.isReferenceCapture()</b>,<o:p></o:p></span></i></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><i><span lang="EN-US" style="color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%"> Cap.isNested(), Cap.getInitExpr());
</span></i><i><span lang="EN-US"><o:p></o:p></span></i></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><span lang="EN-US">I thought that it will get me a reference to the array. But it doesn't work and fails when I try to get llvm ir with the following assert: "<b><i>clang: ./llvm/include/llvm/IR/Instructions.h:832:
llvm::Type* llvm::checkGEPType(llvm::Type*): Assertion `Ty && "Invalid GetElementPtrInst indices for type!"' failed.</i></b>"<o:p></o:p></span></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><span lang="EN-US">And in the AST I have capturing variable in block by reference:<o:p></o:p></span></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><i><span lang="EN-US" style="color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%">`-BlockDecl 0xa14cd00 <col:17, col:35> col:17<o:p></o:p></span></i></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><i><span lang="EN-US" style="color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%"> |-capture
<b>byref</b> Var 0xa14cab0 'arr' 'int [4]'<o:p></o:p></span></i></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><i><span lang="EN-US" style="color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%"> `-CompoundStmt 0xa171b58 <col:20, col:35><o:p></o:p></span></i></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><i><span lang="EN-US" style="color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%"> `-ReturnStmt 0xa171b40 <col:21, col:33><o:p></o:p></span></i></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><i><span lang="EN-US" style="color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%"> `-ImplicitCastExpr 0xa171b28 <col:28, col:33> 'int' <LValueToRValue><o:p></o:p></span></i></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><i><span lang="EN-US" style="color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%"> `-ArraySubscriptExpr 0xa171b00 <col:28, col:33> 'int' lvalue<o:p></o:p></span></i></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><i><span lang="EN-US" style="color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%"> |-ImplicitCastExpr 0xa171ae8 <col:28> 'int *' <ArrayToPointerDecay><o:p></o:p></span></i></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><i><span lang="EN-US" style="color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%"> | `-DeclRefExpr 0xa171a70 <col:28> 'int [4]' lvalue Var 0xa14cab0 'arr' 'int
[4]'<o:p></o:p></span></i></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><i><span lang="EN-US" style="color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%"> `-IntegerLiteral 0xa171a98 <col:32> 'int' 1<o:p></o:p></span></i></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText" style="margin-left:36.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo1">
<![if !supportLists]><span lang="EN-US"><span style="mso-list:Ignore">2.<span style="font:7.0pt "Times New Roman"">
</span></span></span><![endif]><span lang="EN-US">Also, I tried to set capture type to a reference on the array. In file
<b><i>SemaExpr.cpp</i></b> in function <b><i>tryCaptureVariable</i></b> after a loop: "<b><i>} while (!VarDC->Equals(DC));</i></b>", I added the following lines:\<o:p></o:p></span></p>
<p class="MsoPlainText" style="margin-left:36.0pt"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><i><span lang="EN-US" style="color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%">if (getLangOpts().OpenCL && CaptureType.getTypePtr()->isArrayType()) {<o:p></o:p></span></i></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><i><span lang="EN-US" style="color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%"> CaptureType = Context.getLValueReferenceType(CaptureType);<o:p></o:p></span></i></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><i><span lang="EN-US" style="color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%">}<o:p></o:p></span></i></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><i><span lang="EN-US"><o:p> </o:p></span></i></p>
<p class="MsoPlainText" style="margin-left:35.4pt"><span lang="EN-US">But nothing interesting has happen. No changes in AST or llvm ir.<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">Could you please help me? What is the better way to get the pointer on array?<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">Best regards,<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">Egor<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p><br>--------------------------------------------------------------------<br>Joint Stock Company Intel A/O<br>Registered legal address: Krylatsky Hills Business Park, <br>17 Krylatskaya Str., Bldg 4, Moscow 121614, <br>Russian Federation</p><p>This e-mail and any attachments may contain confidential material for<br>the sole use of the intended recipient(s). Any review or distribution<br>by others is strictly prohibited. If you are not the intended<br>recipient, please contact the sender and delete all copies.</p>
</body>
</html>