Hi All, I am trying to check if a Value type is a int32 pointer by using if(T == Type::getInt1PtrTy(Context, AS)) ... I am trying to understand the AS (address space). How do I get it? Thanks. George * * -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110606/775e4f09/attachment.html>
On 6 June 2011 17:08, George Baah <georgebaah at gmail.com> wrote:> if(T == Type::getInt1PtrTy(Context, AS)) ...Hi, You don't need to care about address spaces to check for an int32*: if (T->isPointerTy()) { const Type* intT = cast<PointerType>(T)->getElementType(); if (intT->isIntegerTy() && intT->getPrimitiveSizeInBits() == 32) cout << "Yeah!" << endl; } Also, to create a pointer type, if you don't care about address space at all, use the unqualified version: const Type* ptrT = PointerType::getUnqual(intT); cheers, --renato
On Jun 6, 2011, at 10:05 AM, Renato Golin wrote:> On 6 June 2011 17:08, George Baah <georgebaah at gmail.com> wrote: >> if(T == Type::getInt1PtrTy(Context, AS)) ... > > You don't need to care about address spaces to check for an int32*: > > if (T->isPointerTy()) { > const Type* intT = cast<PointerType>(T)->getElementType(); > if (intT->isIntegerTy() && intT->getPrimitiveSizeInBits() == 32) > cout << "Yeah!" << endl; > }The more idiomatic way would be: if (const PointerType *Ptr = dyn_cast<PointerType>(T)) if (Ptr->getElementType()->isIntegerTy(32)) cout << "Yeah!" << endl; John.