llvm.org GIT mirror llvm / 6e3abaa
Ok, break down and add some cast<>'ing helper methods to the Type class to reduce the number of cast<>'s we have. This allows someone to use things like Ty->getVectorNumElements() instead of cast<VectorType>(Ty)->getNumElements() when you know that a type is a vector. It would be a great general cleanup to move the codebase to use these, I will do so in the code I'm touching. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148999 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 7 years ago
2 changed file(s) with 65 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
313313 ///
314314 unsigned getNumContainedTypes() const { return NumContainedTys; }
315315
316 //===--------------------------------------------------------------------===//
317 // Helper methods corresponding to subclass methods. This forces a cast to
318 // the specified subclass and calls its accessor. "getVectorNumElements" (for
319 // example) is shorthand for cast(Ty)->getNumElements(). This is
320 // only intended to cover the core methods that are frequently used, helper
321 // methods should not be added here.
322
323 unsigned getIntegerBitWidth() const;
324
325 Type *getFunctionParamType(unsigned i) const;
326 unsigned getFunctionNumParams() const;
327 bool isFunctionVarArg() const;
328
329 // TODO: StructType
330
331 Type *getSequentialElementType() const;
332
333 uint64_t getArrayNumElements() const;
334 Type *getArrayElementType() const { return getSequentialElementType(); }
335
336 unsigned getVectorNumElements() const;
337 Type *getVectorElementType() const { return getSequentialElementType(); }
338
339 unsigned getPointerAddressSpace() const;
340 Type *getPointerElementType() const { return getSequentialElementType(); }
341
316342 //===--------------------------------------------------------------------===//
317343 // Static members exported by the Type class itself. Useful for getting
318344 // instances of Type.
197197 }
198198
199199 //===----------------------------------------------------------------------===//
200 // Subclass Helper Methods
201 //===----------------------------------------------------------------------===//
202
203 unsigned Type::getIntegerBitWidth() const {
204 return cast(this)->getBitWidth();
205 }
206
207 bool Type::isFunctionVarArg() const {
208 return cast(this)->isVarArg();
209 }
210
211 Type *Type::getFunctionParamType(unsigned i) const {
212 return cast(this)->getParamType(i);
213 }
214
215 unsigned Type::getFunctionNumParams() const {
216 return cast(this)->getNumParams();
217 }
218
219 Type *Type::getSequentialElementType() const {
220 return cast(this)->getElementType();
221 }
222
223 uint64_t Type::getArrayNumElements() const {
224 return cast(this)->getNumElements();
225 }
226
227 unsigned Type::getVectorNumElements() const {
228 return cast(this)->getNumElements();
229 }
230
231 unsigned Type::getPointerAddressSpace() const {
232 return cast(this)->getAddressSpace();
233 }
234
235
236
237
238 //===----------------------------------------------------------------------===//
200239 // Primitive 'Type' data
201240 //===----------------------------------------------------------------------===//
202241