Gurunath Kadam via llvm-dev
2016-Nov-28 21:31 UTC
[llvm-dev] LLVM IR: 'class llvm::Instruction' has no member named 'getAddressSpace'
I have following LLVM IR instruction: %ptrA = getelementptr float, float addrspace(1)* %A, i32 %id To get the addrspace value, do I use function call getAddressSpace() or getPointerAddressSpace() ? Using getAddressSpace() results in following error: 'class llvm::Instruction' has no member named 'getAddressSpace' But I see these methods in Instruction.h implemented for getelementptr inst class. Thank you. Regards, Gurunath P.S.: is this the right forum to ask such questions? I see very high-level discussions going on here. If this is not the right forum then please guide me to the appropriate one. Otherwise thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161128/96d21188/attachment.html>
Mehdi Amini via llvm-dev
2016-Nov-28 21:45 UTC
[llvm-dev] LLVM IR: 'class llvm::Instruction' has no member named 'getAddressSpace'
> On Nov 28, 2016, at 1:31 PM, Gurunath Kadam via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > I have following LLVM IR instruction: > > %ptrA = getelementptr float, float addrspace(1)* %A, i32 %id > > To get the addrspace value, do I use function call getAddressSpace() or getPointerAddressSpace() ? > > Using getAddressSpace() results in following error: > > 'class llvm::Instruction' has no member named 'getAddressSpace' > > But I see these methods in Instruction.h implemented for getelementptr inst class. > >You need to cast the instruction to the right subclass before being able to call the method that are implemented for the particular subclass. If you have an “Instruction *” you can only call on it methods that defined in the class Instruction. (Note that this is not LLVM specific, this is generic C++). LLVM has its own RTTI implementation, when you have an instruction and you don’t know if it is a particular subclass, you can “try” to cast it to the type you want: if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(I)) { … // use GEP } — Mehdi -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161128/b6567f2d/attachment.html>
Vedant Kumar via llvm-dev
2016-Nov-28 21:46 UTC
[llvm-dev] LLVM IR: 'class llvm::Instruction' has no member named 'getAddressSpace'
> On Nov 28, 2016, at 1:31 PM, Gurunath Kadam via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > I have following LLVM IR instruction: > > %ptrA = getelementptr float, float addrspace(1)* %A, i32 %id > > To get the addrspace value, do I use function call getAddressSpace() or getPointerAddressSpace() ? > > Using getAddressSpace() results in following error: > > 'class llvm::Instruction' has no member named 'getAddressSpace' > > But I see these methods in Instruction.h implemented for getelementptr inst class.GetElementPtrInst subclasses Instruction, so you need a cast. E.g: if (auto *GEP = dyn_cast<llvm::GetElementPtrInst>(I)) return GEP->getAddressSpace();> P.S.: is this the right forum to ask such questions? I see very high-level discussions going on here. If this is not the right forum then please guide me to the appropriate one. Otherwise thanks.llvm-dev is fine. best, vedant