<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<div dir="ltr">
<div dir="ltr" data-ogsc="" style="">
<div></div>
<div>
<div>
<div dir="ltr"></div>
</div>
<div dir="ltr"><span style="color: rgb(69, 77, 75); font-family: Verdana, Geneva, Helvetica, Arial, sans-serif; font-size: 13.44px; background-color: rgb(250, 249, 245); line-height: 20.159997940063477px; display: inline !important;">Let me clarify my question.</span></div>
<div dir="ltr"><span style="color: rgb(69, 77, 75); font-family: Verdana, Geneva, Helvetica, Arial, sans-serif; font-size: 13.44px; background-color: rgb(250, 249, 245); line-height: 20.159997940063477px; display: inline !important;"><br>
</span></div>
<div dir="ltr"><span style="color: rgb(69, 77, 75); font-family: Verdana, Geneva, Helvetica, Arial, sans-serif; font-size: 13.44px; background-color: rgb(250, 249, 245); line-height: 20.159997940063477px; display: inline !important;">I have a struct array h1
 as follows:</span></div>
<div dir="ltr"><span style="color: rgb(69, 77, 75); font-family: Verdana, Geneva, Helvetica, Arial, sans-serif; font-size: 13.44px; background-color: rgb(250, 249, 245); line-height: 20.159997940063477px; display: inline !important;">dhash h1[10];</span></div>
<div dir="ltr"><span style="color: rgb(69, 77, 75); font-family: Verdana, Geneva, Helvetica, Arial, sans-serif; font-size: 13.44px; background-color: rgb(250, 249, 245); line-height: 20.159997940063477px; display: inline !important;"><br>
</span></div>
<div dir="ltr"><span style="color: rgb(69, 77, 75); font-family: Verdana, Geneva, Helvetica, Arial, sans-serif; font-size: 13.44px; background-color: rgb(250, 249, 245); line-height: 20.159997940063477px; display: inline !important;">I want to get a <i>Constant*
</i>to variable h1. </span><span style="color: rgb(69, 77, 75); font-family: Verdana, Geneva, Helvetica, Arial, sans-serif; font-size: 13.44px; background-color: rgb(250, 249, 245); line-height: 20.159997940063477px;">It looks like I can use </span><i style="color: rgb(69, 77, 75); font-family: Verdana, Geneva, Helvetica, Arial, sans-serif; font-size: 13.44px; background-color: rgb(250, 249, 245); line-height: 20.159997940063477px;">ConstantStruct::get(StructType*,
 ArrayRef<Constant *>) </i><span style="color: rgb(69, 77, 75); font-family: Verdana, Geneva, Helvetica, Arial, sans-serif; font-size: 13.44px; background-color: rgb(250, 249, 245); line-height: 20.159997940063477px;">to do this.</span></div>
<div dir="ltr"><span style="color: rgb(69, 77, 75); font-family: Verdana, Geneva, Helvetica, Arial, sans-serif; font-size: 13.44px; background-color: rgb(250, 249, 245); line-height: 20.159997940063477px;"><br>
</span></div>
<div dir="ltr"><span style="color: rgb(69, 77, 75); font-family: Verdana, Geneva, Helvetica, Arial, sans-serif; font-size: 13.44px; background-color: rgb(250, 249, 245); line-height: 20.159997940063477px;">My question is how to get the second argument of type </span><i style="color: rgb(69, 77, 75); font-family: Verdana, Geneva, Helvetica, Arial, sans-serif; font-size: 13.44px; background-color: rgb(250, 249, 245); line-height: 20.159997940063477px;">ArrayRef<Constant
 *></i><span style="color: rgb(69, 77, 75); font-family: Verdana, Geneva, Helvetica, Arial, sans-serif; font-size: 13.44px; background-color: rgb(250, 249, 245); line-height: 20.159997940063477px;"> from the above variable h1.</span></div>
<div dir="ltr"><br>
</div>
<div class="ms-outlook-ios-signature">
<div style="direction: ltr;">Thanks,</div>
<div style="direction: ltr;">Chaitra</div>
</div>
</div>
<div id="id-deb75e75-ddb1-489e-9be6-8c6f1da6dd96" class="ms-outlook-mobile-reference-message">
<hr style="display: inline-block; width: 98%; font-family: -webkit-standard; font-size: 12pt; color: rgb(0, 0, 0);" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif"><b>From:</b> Tim Northover <t.p.northover@gmail.com><br>
<b>Sent:</b> Wednesday, September 23, 2020 03:04<br>
<b>To:</b> Niddodi, Chaitra<br>
<b>Cc:</b> llvm-dev@lists.llvm.org<br>
<b>Subject:</b> Re: [llvm-dev] Creating a global variable for a struct array
<div> </div>
</font></div>
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style><font size="2"><span style="font-size:11pt;">
<div class="PlainText">On Tue, 22 Sep 2020 at 23:52, Niddodi, Chaitra via llvm-dev<br>
<llvm-dev@lists.llvm.org> wrote:<br>
> dhash* h1 = new dhash[10];<br>
<br>
Note that this "new" expression needs a runtime call to actually<br>
allocate the memory on the heap. In LLVM terms this is A<br>
GlobalVariable with type PointerType::get(StructTy, ...), initialized<br>
to null, together with a global init function (runs when the program<br>
starts) that makes the call to new and stores it to that global. My<br>
guess is that's not what you intended<br>
<br>
> I also need to allocate space for:<br>
> 1) the field llist in struct dhash which is a pointer to another struct dlist and<br>
> 2) the field dptr in struct dlist<br>
><br>
> Is there an example that I can refer to for doing this ?<br>
<br>
I think you should start by writing exactly what you want in C++, and<br>
then (when you're happy with the assembly output) using Clang's "-S<br>
-emit-llvm" options to see what LLVM IR that produces.<br>
<br>
That will clear up the question of how things should be allocated,<br>
which isn't quite obvious from the questions you're asking, and make<br>
translating the IR into LLVM API calls more straightforward.<br>
<br>
> I tried to create a GlobalVariable using ConstantStruct::get(StructType*, ArrayRef<Constant *>). I'm not sure how to get the second argument of type ArrayRef<Constant *> from the above variable h1.<br>
<br>
Hopefully it'll be clearer when you have the real IR you want (in<br>
textual form) in front of you.<br>
<br>
Cheers.<br>
<br>
Tim.<br>
</div>
</span></font></div>
<!--{"start":[1,3,6,0,28],"end":[1,3,6,0,28]}--></div>
<!--{"start":[0,1,3,6,0,28],"end":[0,1,3,6,0,28]}--></div>
</body>
</html>