[llvm-dev] LLVM IR: 'class llvm::Instruction' has no member named 'getAddressSpace'

Mehdi Amini via llvm-dev llvm-dev at lists.llvm.org
Mon Nov 28 13:45:44 PST 2016


> 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>


More information about the llvm-dev mailing list