Alexandru Ionut Diaconescu
2013-Jan-10 13:29 UTC
[LLVMdev] LLVM Instruction to ICmpInst conversion
Hello ! I want some piece of advice regarding a LLVM pass. My particular problem is: There is a method bool patternDC::runOnFunction(Function &F) { ... if ( CC->operEquiv(icmpInstrArray[i], icmpInstrArray[j]) ) {...} ... } having the array elements of type Instruction* : http://llvm.org/doxygen/classllvm_1_1Instruction.html The called method is bool ifChecker::operEquiv(Instruction *I1, Instruction *I2) { ... } BUT I want to use the methods from class ICmpInst : clasa http://llvm.org/doxygen/classllvm_1_1ICmpInst.html inside operEquiv. I cannot do something like ICmpInst** II1 = dyn_cast<ICmpInst*>(I1); (a kind of instanceOf() from Java), having casting compilation problems. The ICmpInst class is defined at line 913 from http://llvm.org/doxygen/Instructions_8h_source.html The inheritance diagram is at http://llvm.org/doxygen/classllvm_1_1ICmpInst.html I want to use the ICmpInst methods for objects of type Instruction. The methods are hard to copy/replicate. What solution I better to use to solve this problem? Should I use visitor pattern (about which I don't know much) ? Thank you for any suggestion ! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130110/faedb643/attachment.html>
Krzysztof Parzyszek
2013-Jan-10 15:02 UTC
[LLVMdev] LLVM Instruction to ICmpInst conversion
On 1/10/2013 7:29 AM, Alexandru Ionut Diaconescu wrote:> > I cannot do something like > > ICmpInst** II1 = dyn_cast<ICmpInst*>(I1); > > (a kind of instanceOf() from Java), having casting compilation problems.You can do ICmpInst *II1 = dyn_cast<ICmpInst>(I1); The "dyn_cast" is a local (to LLVM) template that handles the type casting. It will return 0 if the cast was invalid, so you may need to check the return value. -Krzysztof -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Seemingly Similar Threads
- [LLVMdev] llvm segfault Instruction::getOpcode
- [LLVMdev] LLVM seg fault : dereference an uninitialized pointer Instruction*
- [LLVMdev] Value* to Instruction*/LoadInst* casting
- [LLVMdev] Value* to Instruction*/LoadInst* casting
- [LLVMdev] Value* to Instruction*/LoadInst* casting