[llvm-dev] LLVM Pass for Instructions in Function (error

Gurunath Kadam via llvm-dev llvm-dev at lists.llvm.org
Sun Nov 27 20:47:26 PST 2016


Thanks Sean.

This actually complicates the things for me.

So, I have

%ptrA = getelementptr float, float addrspace(1)* %A, i32 %id

Then I have in same IR these lines after few instructions:

%valA = load float, float addrspace(1)* %ptrA, align 4


So in first iteration over the Function I populate my data structure with
all %ptrA's with respect to %id. Then in second I get the addrspace and
type (LD or ST).

I believe as Sandeep said, I will just store the instruction name and check
against that.

I think I still am missing something. I will implement this first though.

Thank you.

-Gurunath

On Sun, Nov 27, 2016 at 11:36 PM, Sean Silva <chisophugis at gmail.com> wrote:

>
>
> On Sun, Nov 27, 2016 at 8:04 PM, Mehdi Amini via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>
>>
>> On Nov 27, 2016, at 6:40 PM, Gurunath Kadam via llvm-dev <
>> llvm-dev at lists.llvm.org> wrote:
>>
>> Hi Sandeep,
>>
>> Thanks.
>>
>> One question about:
>>
>> Value* AddrPointer = Inst->getIperand(0);
>>
>> So this works for LVALUE(S) i.e. in my case pointer on LHS of '='. I
>> cannot find anything online about getloperand online.
>>
>> For reference this is the instruction:
>>
>> %ptrA = getelementptr float, float addrspace(1)* %A, i32 %id
>>
>>
>> I thought if I just get the return value of the instruction then I can
>> get %ptrA.
>>
>>
>>
>> %ptrA is not the return value of the instruction, it *is* the instruction
>> itself.
>>
>
> http://llvm.org/docs/FAQ.html#what-api-do-i-use-to-store-a-
> value-to-one-of-the-virtual-registers-in-llvm-ir-s-ssa-representation
>
> -- Sean Silva
>
>
>>
>>>> Mehdi
>>
>>
>>
>>
>> Can you please elaborate on that?
>>
>> Thanks again.
>>
>> -Gurunath
>>
>> On Sun, Nov 27, 2016 at 9:21 PM, Dasgupta, Sandeep <sdasgup3 at illinois.edu
>> > wrote:
>>
>>> Hi,
>>>
>>>
>>>
>>>
>>> Sent via the Samsung Galaxy Note® 3, an AT&T 4G LTE smartphone
>>>
>>>
>>> -------- Original message --------
>>> From: Gurunath Kadam via llvm-dev <llvm-dev at lists.llvm.org>
>>> Date: 11/27/2016 7:49 PM (GMT-06:00)
>>> To: llvm-dev at lists.llvm.org
>>> Subject: [llvm-dev] LLVM Pass for Instructions in Function (error
>>>
>>> Hi,
>>>
>>> Please find the embedded code. Also you may follow
>>> http://llvm.org/docs/ProgrammersManual.html#iterating-over-t
>>> he-instruction-in-a-function
>>> -
>>> Sandeep
>>>
>>> I have following lines in my code, where I need to iterate over the
>>> instructions in the function (not BB):
>>>
>>>   for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I){
>>>     Instruction *Inst = I;
>>>
>>> Instruction *Inst = &*I;
>>>   if (Inst -> getOpcode() == Instruction::GetElementPtr){
>>>       Value* AddrPointer = Inst->getIperand(0);
>>>        ....
>>>
>>>     if (cast<Operator>(Inst) -> getOpcode() ==
>>> Instruction::GetElementPtr){
>>>       Value* AddrPointer = cast<Value>(Inst);
>>>       Value* threadId = Inst -> getOperand(1);
>>>       unsigned AddrSpace = Inst -> getAddressSpace()
>>>       DataStructureForTrace.push_back (std:make_tuple(new
>>> Value(threadId), AddrSpace, 0, new Value(AddrPointer)));
>>>     }
>>>   }
>>>
>>> I get following error (there are more, some visible here and some not.
>>> for eg, getAddressSpace not being for Instruction class.):
>>>
>>> error: cannot convert ‘llvm::inst_iterator {aka
>>> llvm::InstIterator<llvm::SymbolTableList<llvm::BasicBlock>,
>>> llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::BasicBlock,
>>> false, false, void>, false, false>, llvm::ilist_iterator<llvm::ili
>>> st_detail::node_options<llvm::Instruction, false, false, void>, false,
>>> false>, llvm::Instruction>}’ to ‘llvm::Instruction*’ in initialization
>>>      Instruction *Inst = I;
>>>
>>> I am not sure about this, as I am following some online code practices.
>>>
>>> Thank you.
>>>
>>> Regards,
>>> Gurunath
>>>
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
>>
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161127/1499dd68/attachment.html>


More information about the llvm-dev mailing list