Alexandru Ionut Diaconescu
2013-Jan-28 10:31 UTC
[LLVMdev] Value* to Instruction*/LoadInst* casting
Hello everyone, Can you please tell me if it is possible in LLVM to cast a `Value*` to an `Instruction*/LoadInst*` if for example `isa<LoadInst>(MyValue)` is true? In my particular piece of code: Value* V1 = icmpInstrArray[i]->getOperand(0); Value* V2 = icmpInstrArray[i]->getOperand(1); if (isa<LoadInst>(V1) || isa<LoadInst>(V2)){ ... if(isa<LoadInst>(icmpInstrArray[i]->getOperand(0))) LoadInst *LD100 = cast<LoadInst>(icmpInstrArray[i]->getOperand(0)); Value *C100 = LD100->getPointerOperand(); //HERE COMPILATION ERROR Further, I just need to make `C100->getName()` and I will get the loaded variable. I don't think that I can use cast like that. Can you tell me a method to obtain the loaded variable from a Load instruction correspondent to my ICMP instructions? Or better how I can extract the Load instruction from `icmpInstrArray[i]->getOperand(0)`? Thank you a lot ! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130128/b7e75875/attachment.html>
Alexandru Ionut Diaconescu
2013-Jan-28 10:32 UTC
[LLVMdev] Value* to Instruction*/LoadInst* casting
The compilation error is : `error: ‘LD100’ was not declared in this scope.` On Mon, Jan 28, 2013 at 11:31 AM, Alexandru Ionut Diaconescu < alexandruionutdiaconescu at gmail.com> wrote:> Hello everyone, > > Can you please tell me if it is possible in LLVM to cast a `Value*` to an > `Instruction*/LoadInst*` if for example `isa<LoadInst>(MyValue)` is true? > In my particular piece of code: > > Value* V1 = icmpInstrArray[i]->getOperand(0); > Value* V2 = icmpInstrArray[i]->getOperand(1); > if (isa<LoadInst>(V1) || isa<LoadInst>(V2)){ > ... > if(isa<LoadInst>(icmpInstrArray[i]->getOperand(0))) > LoadInst *LD100 = cast<LoadInst>(icmpInstrArray[i]->getOperand(0)); > Value *C100 = LD100->getPointerOperand(); //HERE COMPILATION > ERROR > Further, I just need to make `C100->getName()` and I will get the loaded > variable. > > I don't think that I can use cast like that. Can you tell me a method to > obtain the loaded variable from a Load instruction correspondent to my ICMP > instructions? Or better how I can extract the Load instruction from > `icmpInstrArray[i]->getOperand(0)`? > > Thank you a lot !-- Best regards, Alexandru Ionut Diaconescu -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130128/6dee2e5c/attachment.html>
Hi Alexandru,> The compilation error is : `error: ‘LD100’ was not declared in this scope.` > > On Mon, Jan 28, 2013 at 11:31 AM, Alexandru Ionut Diaconescu < > alexandruionutdiaconescu at gmail.com> wrote: > >> Hello everyone, >> >> Can you please tell me if it is possible in LLVM to cast a `Value*` to an >> `Instruction*/LoadInst*` if for example `isa<LoadInst>(MyValue)` is true? >> In my particular piece of code: >> >> Value* V1 = icmpInstrArray[i]->getOperand(0); >> Value* V2 = icmpInstrArray[i]->getOperand(1); >> if (isa<LoadInst>(V1) || isa<LoadInst>(V2)){ >> ... >> if(isa<LoadInst>(icmpInstrArray[i]->getOperand(0))) >> LoadInst *LD100 = cast<LoadInst>(icmpInstrArray[i]->getOperand(0)); >> Value *C100 = LD100->getPointerOperand(); //HERE COMPILATION >> ERROR >> Further, I just need to make `C100->getName()` and I will get the loaded >> variable.Looks like you meant to write if (isa<LoadInst>(icmpInstrArray[i]->getOperand(0))) { LoadInst *LD100 = cast<LoadInst>(icmpInstrArray[i]->getOperand(0)); Value *C100 = LD100->getPointerOperand(); //HERE COMPILATION ERROR ... } (i.e., you were missing "{...}" after the "if").>> I don't think that I can use cast like that. Can you tell me a method to >> obtain the loaded variable from a Load instruction correspondent to my ICMP >> instructions? Or better how I can extract the Load instruction from >> `icmpInstrArray[i]->getOperand(0)`? >> >> Thank you a lot !Hope this helps, Stephan
Alexandru Ionut Diaconescu
2013-Jan-28 10:53 UTC
[LLVMdev] Value* to Instruction*/LoadInst* casting
Hello, Thank you for answering. I copy paste-it not precisely (I had the bracket), but the array was not ok. Not it is solved. Thank you a lot ! On Mon, Jan 28, 2013 at 11:54 AM, Nick Lewycky <nicholas at mxc.ca> wrote:> Alexandru Ionut Diaconescu wrote: > >> Hello everyone, >> >> Can you please tell me if it is possible in LLVM to cast a `Value*` to >> an `Instruction*/LoadInst*` if for example `isa<LoadInst>(MyValue)` is >> true? >> > > http://llvm.org/docs/**ProgrammersManual.html#the-**isa-cast-and-dyn-cast- > **templates<http://llvm.org/docs/ProgrammersManual.html#the-isa-cast-and-dyn-cast-templates> > > > In my particular piece of code: > >> >> Value* V1 = icmpInstrArray[i]->getOperand(**0); >> Value* V2 = icmpInstrArray[i]->getOperand(**1); >> if (isa<LoadInst>(V1) || isa<LoadInst>(V2)){ >> ... >> if(isa<LoadInst>(**icmpInstrArray[i]->getOperand(**0))) >> LoadInst *LD100 = cast<LoadInst>(icmpInstrArray[** >> i]->getOperand(0)); >> Value *C100 = LD100->getPointerOperand(); //HERE >> COMPILATION ERROR >> > > You're missing braces after the if-statement. > > Nick > > Further, I just need to make `C100->getName()` and I will get the loaded >> variable. >> >> I don't think that I can use cast like that. Can you tell me a method to >> obtain the loaded variable from a Load instruction correspondent to my >> ICMP instructions? Or better how I can extract the Load instruction from >> `icmpInstrArray[i]->**getOperand(0)`? >> >> Thank you a lot ! >> >> >> ______________________________**_________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/**mailman/listinfo/llvmdev<http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev> >> > >-- Best regards, Alexandru Ionut Diaconescu -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130128/b0b0fefb/attachment.html>
Alexandru Ionut Diaconescu wrote:> Hello everyone, > > Can you please tell me if it is possible in LLVM to cast a `Value*` to > an `Instruction*/LoadInst*` if for example `isa<LoadInst>(MyValue)` is > true?http://llvm.org/docs/ProgrammersManual.html#the-isa-cast-and-dyn-cast-templates In my particular piece of code:> > Value* V1 = icmpInstrArray[i]->getOperand(0); > Value* V2 = icmpInstrArray[i]->getOperand(1); > if (isa<LoadInst>(V1) || isa<LoadInst>(V2)){ > ... > if(isa<LoadInst>(icmpInstrArray[i]->getOperand(0))) > LoadInst *LD100 = cast<LoadInst>(icmpInstrArray[i]->getOperand(0)); > Value *C100 = LD100->getPointerOperand(); //HERE > COMPILATION ERRORYou're missing braces after the if-statement. Nick> Further, I just need to make `C100->getName()` and I will get the loaded > variable. > > I don't think that I can use cast like that. Can you tell me a method to > obtain the loaded variable from a Load instruction correspondent to my > ICMP instructions? Or better how I can extract the Load instruction from > `icmpInstrArray[i]->getOperand(0)`? > > Thank you a lot ! > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Hi, if(isa<LoadInst>(icmpInstrArray[i]->getOperand(0)))>> LoadInst *LD100 >> cast<LoadInst>(icmpInstrArray[i]->getOperand(0)); >> Value *C100 = LD100->getPointerOperand(); //HERE COMPILATION >> ERROR >> >Could it be that you simply forgot the braces around the if() body? Best, Jonas -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130128/aaeeee3f/attachment.html>