<div dir="ltr">Sure, you can call store_inst->getOperand(0)->getType(), and call different functions based on the type, e.g., foo_8, foo_16, foo_32, etc...<div><br></div><div>Here's an example of how you could do it: <a href="https://github.com/donhinton/CVRFI/blob/master/lib/pass/Node.cpp#L224">https://github.com/donhinton/CVRFI/blob/master/lib/pass/Node.cpp#L224</a></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jun 11, 2017 at 6:05 PM, Dipanjan Das via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On 11 June 2017 at 14:04, don hinton <span dir="ltr"><<a href="mailto:hintonda@gmail.com" target="_blank">hintonda@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><span style="color:rgb(80,0,80);font-size:12.8px">Assuming you know it's a 64 bit value, and the function you are calling takes a uint64_t, try this:</span></div></div></div></blockquote><div><br></div></span><div>The values from the test program are of type: i32/i32*/i32**. Can't I interpret these as uint64_t some way?</div><div><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><span style="color:rgb(80,0,80);font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Value* args[] = {store_inst->getOperand(0)};</span><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jun 11, 2017 at 1:16 PM, Dipanjan Das via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="m_-2492155031290208452m_-1965551225201116282gmail-">On 11 June 2017 at 12:05, Tim Northover <span dir="ltr"><<a href="mailto:t.p.northover@gmail.com" target="_blank">t.p.northover@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 11 June 2017 at 11:56, Dipanjan Das via llvm-dev<br>
<<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
> I can't pass var_value to a function accepting uint64_t. LLVM complains<br>
> about broken function call.<br>
<br>
Well, yes. var_value has type "ConstantInt *", not uint64_t. Assuming<br>
the value being stored actually is a constant known at compile-time<br>
you should be able to use cast<ConstantInt *>(vo)->getZExtValue() to<br>
retrieve a uint64_t value (careful of i128s!).<br>
<br>
If that cast fails then you're not dealing with a constant store. This<br>
is either a nuisance (if you were expecting the possibility and can<br>
deal with it) or a huge misunderstanding over compile-time vs runtime<br>
values.<br></blockquote><div><br></div></span><div>I think it's a misunderstanding in may part. Let me explain my intention first. I want to retrieve the value (if isPointerTy() returns true) to be stored by a store instruction at run-time and pass on that value as either an unsigned int (64) or a pointer (char*) to an external function. The call to that function is inserted using IRBuilder.CreateCall().</div><div><br></div><div>Consider the code snippet below.</div><div><br></div><div>==============================<wbr>====================</div><div><br></div><div><span class="m_-2492155031290208452m_-1965551225201116282gmail-"><div>if (StoreInst *store_inst = dyn_cast<StoreInst>(&I)) {</div><div> Value* vo = store_inst->getValueOperand();</div></span><div> uint64 var_value = /* cast vo to unsigned int 64 bit */</div><div><br></div><div> // Pass on this value to external function</div><div> IRBuilder<> builder(&I);</div><div><div> builder.SetInsertPoint(&B, ++builder.GetInsertPoint());</div></div><div> Constant *func = F.getParent()->getOrInsertFunc<wbr>tion("instrument_store", </div><div> Type::getVoidTy(Ctx), Type::getInt8PtrTy(Ctx), NULL);</div><div> Value* args[] = {var_value};</div><div> builder.CreateCall(func, args);</div><div> }</div></div><div><br></div><div>==============================<wbr>====================<br></div><div><br></div><div>To reiterate, I want to wrap up the run-time value (var_value) as a Value* and call the method (instrument_store) with that value as an argument.</div><span class="m_-2492155031290208452m_-1965551225201116282gmail-"><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">If it's a nuisance, you can use "dyn_cast" instead of "cast". That'll<br>
return nullptr if the store wasn't a constant instead of crashing; you<br>
can decide what to do at that point.<br>
<br>
Cheers.<br>
<span class="m_-2492155031290208452m_-1965551225201116282gmail-m_-7761647889080654922gmail-HOEnZb"><font color="#888888"><br>
Tim.<br>
</font></span></blockquote></span></div><br><br clear="all"><span class="m_-2492155031290208452HOEnZb"><font color="#888888"><span class="m_-2492155031290208452m_-1965551225201116282gmail-"><div><br></div>-- <br><div class="m_-2492155031290208452m_-1965551225201116282gmail-m_-7761647889080654922gmail_signature"><div dir="ltr"><span><div><div dir="ltr"><p>Thanks & Regards,</p>
<div>Dipanjan</div></div></div></span></div></div>
</span></font></span></div></div><span class="m_-2492155031290208452HOEnZb"><font color="#888888">
<br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></font></span></blockquote></div><br></div></div>
</blockquote></div></div></div><div><div class="h5"><br><br clear="all"><div><br></div>-- <br><div class="m_-2492155031290208452gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><span><div><div dir="ltr"><p>Thanks & Regards,</p>
<div>Dipanjan</div></div></div></span></div></div>
</div></div></div></div>
<br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>