Hello, I am writing an optimization pass which optimizes code based on an online pointer analysis algorithm and need to detect pointers which are pointing to derived types. I have not had any problem identifying pointers in general using isa<PointerType>(...), but I can't seem to figure out how I can make sure that the pointer is pointing to a scalar value and not a function, array, struct, etc. What am I missing? -- View this message in context: http://www.nabble.com/Using-isa-with-derived-types-tp20472959p20472959.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
On Nov 12, 2008, at 20:42, Zappel-Phillip wrote:> I can't seem to figure out how I can make sure that the pointer is > pointing to a scalar value and not a function, array, struct, etc.http://llvm.org/docs/doxygen/html/classllvm_1_1SequentialType.html#633173cae0cf68e70a7dcc33d3e3ceb8 — Gordon
Zappel-Phillip wrote:> Hello, > > I am writing an optimization pass which optimizes code based on an online > pointer analysis algorithm and need to detect pointers which are pointing to > derived types. I have not had any problem identifying pointers in general > using isa<PointerType>(...), but I can't seem to figure out how I can make > sure that the pointer is pointing to a scalar value and not a function, > array, struct, etc. > > What am I missing?Please see the doxygen: http://llvm.org/doxygen/classllvm_1_1Type.html if (const PointerType *PTy = dyn_cast<PointerType>(...)) { const Type *InnerTy = PTy->getElementType(); switch (InnerTy->getTypeID()) { case Type::ArrayTyID: ... case Type::FunctionTyID: ... case Type::StructTyID: ... case Type::IntegerTyID: ... } } A switch on getTypeID() is equivalent to isa<>, but more efficient than a chain of if's when doing multiple tests. If you only care about whether it's first class or not, you can just call InnerTy->isFirstClass(). Nick Lewycky
I believe I failed to ask the question properly, I am not trying to determine whether the elements of an array are scalar type. Instead, I want to be able to iterate over the function's parameters and determine whether a pointer argument is actually an array being passed which contains scalar values, or simply a pointer with a single scalar value. In other words, I want to ignore functions that accept arrays as arguments. Nick Lewycky wrote:> > Please see the doxygen: http://llvm.org/doxygen/classllvm_1_1Type.html > > if (const PointerType *PTy = dyn_cast<PointerType>(...)) { > const Type *InnerTy = PTy->getElementType(); > switch (InnerTy->getTypeID()) { > case Type::ArrayTyID: > ... > case Type::FunctionTyID: > ... > case Type::StructTyID: > ... > case Type::IntegerTyID: > ... > } > } > >-- View this message in context: http://www.nabble.com/Using-isa-with-derived-types-tp20472959p20903806.html Sent from the LLVM - Dev mailing list archive at Nabble.com.