<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=utf-8">
<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;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
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;}
code
        {mso-style-priority:99;
        font-family:"Courier New";}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;}
span.EmailStyle21
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></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="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Please don’t send questions to both cfe-dev and llvm-dev; usually one or the other is more appropriate (in this case, it’s llvm-dev, since there’s no clang code involved).<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I think you meant to call ConstantArray::get, not ConstantDataArray::get.  (We should probably fix ConstantDataArray::get() to use enable_if or something like that, so your example fails to compile instead of generating a weird runtime
 error.)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">-Eli<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b>From:</b> cfe-dev <cfe-dev-bounces@lists.llvm.org> <b>On Behalf Of
</b>Mustakimur Rahman Khandaker (Mustakim) via cfe-dev<br>
<b>Sent:</b> Monday, January 28, 2019 12:12 PM<br>
<b>To:</b> llvm-dev@lists.llvm.org; cfe-dev@lists.llvm.org<br>
<b>Subject:</b> [EXT] [cfe-dev] Create a BlockAddress array from LLVM Pass<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Hi<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Good day. For the following function local static constant array:<o:p></o:p></p>
</div>
<div>
<pre style="background-color:rgba(0,0,0,0.05)"><span style="color:#4B69C6">static</span><span style="color:#333333"> </span><span style="color:#4B69C6">const</span><span style="color:#333333"> </span><span style="color:#7A3E9D">__attribute__</span><span style="color:#777777">((</span><span style="color:#333333">used</span><span style="color:#777777">)</span><span style="color:#333333">)</span><o:p></o:p></pre>
</div>
<div>
<pre><span style="color:#AA3731">__attribute__</span><span style="color:#777777">((</span><span style="color:#AA3731">section</span><span style="color:#777777">("</span><span style="color:#448C27">data</span><span style="color:#777777">")))</span><span style="color:#333333"> </span><span style="color:#7A3E9D">void</span><span style="color:#333333"> </span><span style="color:#777777">*</span><span style="color:#333333">codetable</span><span style="color:#777777">[]</span><span style="color:#333333"> </span><span style="color:#777777">=</span><span style="color:#333333"> </span><span style="color:#777777">{</span><o:p></o:p></pre>
</div>
<div>
<pre><span style="color:#777777">&&</span><span style="color:#333333">RETURN</span><span style="color:#777777">,</span><span style="color:#333333"> </span><span style="color:#777777">&&</span><span style="color:#333333">INCREMENT</span><span style="color:#777777">,</span><span style="color:#333333"> </span><span style="color:#777777">&&</span><span style="color:#333333">DECREMENT</span><span style="color:#777777">,</span><span style="color:#333333"> </span><span style="color:#777777">&&</span><span style="color:#333333">DOUBLE</span><span style="color:#777777">,</span><span style="color:#333333"> </span><span style="color:#777777">&&</span><span style="color:#333333">SWAPWORD</span><span style="color:#777777">};</span><o:p></o:p></pre>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New";color:#333333">I have the following in the LLVM IR.</span><o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New";color:#9C5D27">@sampleCode.codetable</span><span style="font-family:"Courier New";color:#333333"> =
</span><span style="font-family:"Courier New";color:#4B69C6">internal</span><span style="font-family:"Courier New";color:#333333">
</span><span style="font-family:"Courier New";color:#4B69C6">global</span><span style="font-family:"Courier New";color:#333333"> [</span><span style="font-family:"Courier New";color:#9C5D27">5</span><span style="font-family:"Courier New";color:#333333"> x
</span><span style="font-family:"Courier New";color:#7A3E9D">i8*</span><span style="font-family:"Courier New";color:#333333">] [</span><span style="font-family:"Courier New";color:#7A3E9D">i8*</span><span style="font-family:"Courier New";color:#333333">
</span><span style="font-family:"Courier New";color:#4B69C6">blockaddress</span><span style="font-family:"Courier New";color:#333333">(</span><span style="font-family:"Courier New";color:#9C5D27">@sampleCode</span><span style="font-family:"Courier New";color:#333333">,
</span><span style="font-family:"Courier New";color:#9C5D27">%19</span><span style="font-family:"Courier New";color:#333333">),
</span><span style="font-family:"Courier New";color:#7A3E9D">i8*</span><span style="font-family:"Courier New";color:#333333">
</span><span style="font-family:"Courier New";color:#4B69C6">blockaddress</span><span style="font-family:"Courier New";color:#333333">(</span><span style="font-family:"Courier New";color:#9C5D27">@sampleCode</span><span style="font-family:"Courier New";color:#333333">,
</span><span style="font-family:"Courier New";color:#9C5D27">%22</span><span style="font-family:"Courier New";color:#333333">),
</span><span style="font-family:"Courier New";color:#7A3E9D">i8*</span><span style="font-family:"Courier New";color:#333333">
</span><span style="font-family:"Courier New";color:#4B69C6">blockaddress</span><span style="font-family:"Courier New";color:#333333">(</span><span style="font-family:"Courier New";color:#9C5D27">@sampleCode</span><span style="font-family:"Courier New";color:#333333">,
</span><span style="font-family:"Courier New";color:#9C5D27">%25</span><span style="font-family:"Courier New";color:#333333">),
</span><span style="font-family:"Courier New";color:#7A3E9D">i8*</span><span style="font-family:"Courier New";color:#333333">
</span><span style="font-family:"Courier New";color:#4B69C6">blockaddress</span><span style="font-family:"Courier New";color:#333333">(</span><span style="font-family:"Courier New";color:#9C5D27">@sampleCode</span><span style="font-family:"Courier New";color:#333333">,
</span><span style="font-family:"Courier New";color:#9C5D27">%28</span><span style="font-family:"Courier New";color:#333333">),
</span><span style="font-family:"Courier New";color:#7A3E9D">i8*</span><span style="font-family:"Courier New";color:#333333">
</span><span style="font-family:"Courier New";color:#4B69C6">blockaddress</span><span style="font-family:"Courier New";color:#333333">(</span><span style="font-family:"Courier New";color:#9C5D27">@sampleCode</span><span style="font-family:"Courier New";color:#333333">,
</span><span style="font-family:"Courier New";color:#9C5D27">%31</span><span style="font-family:"Courier New";color:#333333">)],
</span><span style="font-family:"Courier New";color:#4B69C6">section</span><span style="font-family:"Courier New";color:#333333">
</span><span style="font-family:"Courier New";color:#448C27">"data"</span><span style="font-family:"Courier New";color:#333333">,
</span><span style="font-family:"Courier New";color:#4B69C6">align</span><span style="font-family:"Courier New";color:#333333">
</span><span style="font-family:"Courier New";color:#9C5D27">16</span><o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Here the array elements are labels in c code. I have done following to create the same array from LLVM pass.<o:p></o:p></p>
</div>
<p class="MsoNormal"><br>
<br>
<code><span style="font-size:10.0pt"><o:p></o:p></span></code></p>
<div>
<pre><span style="color:#333333">std</span><span style="color:#777777">::</span><span style="color:#333333">vector</span><span style="color:#777777"><</span><span style="color:#333333">BlockAddress </span><span style="color:#777777">*></span><span style="color:#333333"> tmp</span><span style="color:#777777">;</span><o:p></o:p></pre>
</div>
<pre><o:p> </o:p></pre>
<div>
<pre>Function *fn = ...<o:p></o:p></pre>
</div>
<div>
<pre>BasicBlock *bb = ...<o:p></o:p></pre>
</div>
<pre><o:p> </o:p></pre>
<div>
<pre><span style="color:#333333">BlockAddress </span><span style="color:#777777">*</span><span style="color:#333333">bba </span><span style="color:#777777">=</span><span style="color:#333333"> </span><span style="color:#AA3731">BlockAddress::get</span><span style="color:#777777">(</span><span style="color:#333333">fn</span><span style="color:#777777">,</span><span style="color:#333333"> bb</span><span style="color:#777777">);</span><o:p></o:p></pre>
</div>
<div>
<pre><span style="color:#333333">tmp</span><span style="color:#777777">.</span><span style="color:#AA3731">push_back</span><span style="color:#777777">(</span><span style="color:#333333">bba</span><span style="color:#777777">);</span><o:p></o:p></pre>
</div>
<pre><o:p> </o:p></pre>
<div>
<pre><code><span style="color:#333333">GlobalVariable </span><span style="color:#777777">*</span><span style="color:#333333">gvar_ptr_abc </span><span style="color:#777777">=</span><span style="color:#333333"> </span><span style="color:#4B69C6">new</span><span style="color:#333333"> </span><span style="color:#AA3731">GlobalVariable</span><span style="color:#777777">(</span></code><o:p></o:p></pre>
</div>
<div>
<pre><code><span style="color:#AAAAAA">/*Module=*/</span><span style="color:#777777">*</span><span style="color:#333333">fn</span><span style="color:#777777">-></span><span style="color:#AA3731">getParent</span><span style="color:#777777">(),</span></code><o:p></o:p></pre>
</div>
<div>
<pre><code><span style="color:#AAAAAA">/*Type=*/</span><span style="color:#333333">PointerTy</span><span style="color:#777777">,</span></code><o:p></o:p></pre>
</div>
<div>
<pre><code><span style="color:#AAAAAA">/*isConstant=*/</span><span style="color:#9C5D27">false</span><span style="color:#777777">,</span></code><o:p></o:p></pre>
</div>
<div>
<pre><code><span style="color:#AAAAAA">/*Linkage=*/</span><span style="color:#333333">GlobalValue</span><span style="color:#777777">::</span><span style="color:#333333">InternalLinkage</span><span style="color:#777777">,</span></code><o:p></o:p></pre>
</div>
<div>
<pre><code><span style="color:#AAAAAA">/*Initializer=*/</span><span style="color:#9C5D27">0</span><span style="color:#777777">,</span><span style="color:#333333"> </span><span style="color:#AAAAAA">// has initializer, specified below</span></code><o:p></o:p></pre>
</div>
<div>
<pre><code><span style="color:#AAAAAA">/*Name=*/</span><span style="color:#777777">"</span><span style="color:#448C27">labelTracker</span><span style="color:#777777">");</span></code><o:p></o:p></pre>
</div>
<div>
<pre><code><span style="color:#333333">gvar_ptr_abc</span><span style="color:#777777">-></span><span style="color:#AA3731">setAlignment</span><span style="color:#777777">(</span><span style="color:#9C5D27">16</span><span style="color:#777777">);</span></code><o:p></o:p></pre>
</div>
<div>
<pre><code><span style="color:#333333">Constant </span><span style="color:#777777">*</span><span style="color:#333333">blockItems </span><span style="color:#777777">=</span><span style="color:#333333"> </span><span style="color:#AA3731">ConstantDataArray::get</span><span style="color:#777777">(</span><span style="color:#333333">fn</span><span style="color:#777777">-></span><span style="color:#AA3731">getContext</span><span style="color:#777777">(),</span><span style="color:#333333"> tmp</span><span style="color:#777777">);</span></code><o:p></o:p></pre>
</div>
<div>
<pre><code><span style="color:#333333">gvar_ptr_abc</span><span style="color:#777777">-></span><span style="color:#AA3731">setInitializer</span><span style="color:#777777">(</span><span style="color:#333333">blockItems</span><span style="color:#777777">);</span></code><o:p></o:p></pre>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10.0pt">I get error with following: Unsupported type in Type::getScalarTy</span></code><o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><code><span style="font-size:10.0pt">Can anyone suggest what I suppose to do? It is definitely related to my type declaration and BlockAddress items, but I don't know what it is exactly.</span></code><o:p></o:p></p>
</div>
</div>
</body>
</html>