Intel SPMD Program Compiler  1.9.1
type.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010-2013, Intel Corporation
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are
7  met:
8 
9  * Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11 
12  * Redistributions in binary form must reproduce the above copyright
13  notice, this list of conditions and the following disclaimer in the
14  documentation and/or other materials provided with the distribution.
15 
16  * Neither the name of Intel Corporation nor the names of its
17  contributors may be used to endorse or promote products derived from
18  this software without specific prior written permission.
19 
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
25  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 
34 /** @file type.h
35  @brief File with declarations for classes related to type representation
36 */
37 
38 #ifndef ISPC_TYPE_H
39 #define ISPC_TYPE_H 1
40 
41 #include "ispc.h"
42 #include "util.h"
43 #if ISPC_LLVM_VERSION == ISPC_LLVM_3_2
44  #include <llvm/Type.h>
45  #include <llvm/DerivedTypes.h>
46 #else // >= 3.3
47  #include <llvm/IR/Type.h>
48  #include <llvm/IR/DerivedTypes.h>
49 #endif
50 #include <llvm/ADT/SmallVector.h>
51 
52 class ConstExpr;
53 class StructType;
54 
55 /** Types may have uniform, varying, SOA, or unbound variability; this
56  struct is used by Type implementations to record their variability.
57 */
58 struct Variability {
60 
61  Variability(VarType t = Unbound, int w = 0) : type(t), soaWidth(w) { }
62 
63  bool operator==(const Variability &v) const {
64  return v.type == type && v.soaWidth == soaWidth;
65  }
66  bool operator!=(const Variability &v) const {
67  return v.type != type || v.soaWidth != soaWidth;
68  }
69 
70  bool operator==(const VarType &t) const { return type == t; }
71  bool operator!=(const VarType &t) const { return type != t; }
72 
73  std::string GetString() const;
74  std::string MangleString() const;
75 
77  int soaWidth;
78 };
79 
80 
81 /** Enumerant that records each of the types that inherit from the Type
82  baseclass. */
83 enum TypeId {
85  ENUM_TYPE, // 1
87  ARRAY_TYPE, // 3
93 };
94 
95 
96 /** @brief Interface class that defines the type abstraction.
97 
98  Abstract base class that defines the interface that must be implemented
99  for all types in the language.
100  */
101 class Type {
102 public:
103  /** Returns true if the underlying type is boolean. In other words,
104  this is true for individual bools and for short-vectors with
105  underlying bool type, but not for arrays of bools. */
106  virtual bool IsBoolType() const = 0;
107 
108  /** Returns true if the underlying type is float or double. In other
109  words, this is true for individual floats/doubles and for
110  short-vectors of them, but not for arrays of them. */
111  virtual bool IsFloatType() const = 0;
112 
113  /** Returns true if the underlying type is an integer type. In other
114  words, this is true for individual integers and for short-vectors
115  of integer types, but not for arrays of integer types. */
116  virtual bool IsIntType() const = 0;
117 
118  /** Returns true if the underlying type is unsigned. In other words,
119  this is true for unsigned integers and short vectors of unsigned
120  integer types. */
121  virtual bool IsUnsignedType() const = 0;
122 
123  /** Returns true if the underlying type is either a pointer type */
124  bool IsPointerType() const;
125 
126  /** Returns true if the underlying type is a array type */
127  bool IsArrayType() const;
128 
129  /** Returns true if the underlying type is a array type */
130  bool IsReferenceType() const;
131 
132  /** Returns true if the underlying type is either a pointer or an array */
133  bool IsVoidType() const;
134 
135  /** Returns true if this type is 'const'-qualified. */
136  virtual bool IsConstType() const = 0;
137 
138  /** Returns true if the underlying type is a float or integer type. */
139  bool IsNumericType() const { return IsFloatType() || IsIntType(); }
140 
141  /** Returns the variability of the type. */
142  virtual Variability GetVariability() const = 0;
143 
144  /** Returns true if the underlying type is uniform */
145  bool IsUniformType() const {
147  }
148 
149  /** Returns true if the underlying type is varying */
150  bool IsVaryingType() const {
152  }
153 
154  /** Returns true if the type is laid out in "structure of arrays"
155  layout. */
156  bool IsSOAType() const { return GetVariability() == Variability::SOA; }
157 
158  /** Returns the structure of arrays width for SOA types. This method
159  returns zero for types with non-SOA variability. */
160  int GetSOAWidth() const { return GetVariability().soaWidth; }
161 
162  /** Returns true if the underlying type's uniform/varying-ness is
163  unbound. */
164  bool HasUnboundVariability() const {
166  }
167 
168  /* Returns a type wherein any elements of the original type and
169  contained types that have unbound variability have their variability
170  set to the given variability. */
171  virtual const Type *ResolveUnboundVariability(Variability v) const = 0;
172 
173  /** Return a "uniform" instance of this type. If the type is already
174  uniform, its "this" pointer will be returned. */
175  virtual const Type *GetAsUniformType() const = 0;
176 
177  /** Return a "varying" instance of this type. If the type is already
178  varying, its "this" pointer will be returned. */
179  virtual const Type *GetAsVaryingType() const = 0;
180 
181  /** Get an instance of the type with unbound variability. */
182  virtual const Type *GetAsUnboundVariabilityType() const = 0;
183 
184  virtual const Type *GetAsSOAType(int width) const = 0;
185 
186  /** If this is a signed integer type, return the unsigned version of
187  the type. Otherwise, return the original type. */
188  virtual const Type *GetAsUnsignedType() const;
189 
190  /** Returns the basic root type of the given type. For example, for an
191  array or short-vector, this returns the element type. For a struct
192  or atomic type, it returns itself. */
193  virtual const Type *GetBaseType() const = 0;
194 
195  /** If this is a reference type, returns the type it is referring to.
196  For all other types, just returns its own type. */
197  virtual const Type *GetReferenceTarget() const;
198 
199  /** Get a const version of this type. If it's already const, then the old
200  Type pointer is returned. */
201  virtual const Type *GetAsConstType() const = 0;
202 
203  /** Get a non-const version of this type. If it's already not const,
204  then the old Type pointer is returned. */
205  virtual const Type *GetAsNonConstType() const = 0;
206 
207  /** Returns a text representation of the type (for example, for use in
208  warning and error messages). */
209  virtual std::string GetString() const = 0;
210 
211  /** Returns a string that represents the mangled type (for use in
212  mangling function symbol names for function overloading). The
213  various Types implementations of this method should collectively
214  ensure that all of them use mangling schemes that are guaranteed
215  not to clash. */
216  virtual std::string Mangle() const = 0;
217 
218  /** Returns a string that is the declaration of the same type in C
219  syntax. */
220  virtual std::string GetCDeclaration(const std::string &name) const = 0;
221 
222  /** Returns the LLVM type corresponding to this ispc type */
223  virtual llvm::Type *LLVMType(llvm::LLVMContext *ctx) const = 0;
224 
225 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_6
226  /** Returns the DIType (LLVM's debugging information structure),
227  corresponding to this type. */
228  virtual llvm::DIType GetDIType(llvm::DIDescriptor scope) const = 0;
229 #else
230  /** Returns the DIType (LLVM's debugging information structure),
231  corresponding to this type. */
232  virtual llvm::DIType *GetDIType(llvm::DIScope *scope) const = 0;
233 #endif
234 
235  /** Checks two types for equality. Returns true if they are exactly
236  the same, false otherwise. */
237  static bool Equal(const Type *a, const Type *b);
238 
239  /** Checks two types for equality. Returns true if they are exactly
240  the same (ignoring const-ness of the type), false otherwise. */
241  static bool EqualIgnoringConst(const Type *a, const Type *b);
242 
243  /** Given two types, returns the least general Type that is more general
244  than both of them. (i.e. that can represent their values without
245  any loss of data.) If there is no such Type, return NULL.
246 
247  @param type0 First of the two types
248  @param type1 Second of the two types
249  @param pos Source file position where the general type is
250  needed.
251  @param reason String describing the context of why the general
252  type is needed (e.g. "+ operator").
253  @param forceVarying If \c true, then make sure that the returned
254  type is "varying".
255  @param vecSize The vector size of the returned type. If non-zero,
256  the returned type will be a VectorType of the
257  more general type with given length. If zero,
258  this parameter has no effect.
259  @return The more general type, based on the provided parameters.
260 
261  @todo the vecSize and forceVarying parts of this should probably be
262  factored out and done separately in the cases when needed.
263 
264  */
265  static const Type *MoreGeneralType(const Type *type0, const Type *type1,
266  SourcePos pos, const char *reason,
267  bool forceVarying = false, int vecSize = 0);
268 
269  /** Returns true if the given type is an atomic, enum, or pointer type
270  (i.e. not an aggregation of multiple instances of a type or
271  types.) */
272  static bool IsBasicType(const Type *type);
273 
274  /** Indicates which Type implementation this type is. This value can
275  be used to determine the actual type much more efficiently than
276  using dynamic_cast. */
277  const TypeId typeId;
278 
279 protected:
280  Type(TypeId id) : typeId(id) { }
281 };
282 
283 
284 /** @brief AtomicType represents basic types like floats, ints, etc.
285 
286  AtomicTypes can be either uniform or varying. Unique instances of all
287  of the possible <tt>AtomicType</tt>s are available in the static members
288  like AtomicType::UniformInt32. It is thus possible to compare
289  AtomicTypes for equality with simple pointer equality tests; this is
290  not true for the other Type implementations.
291  */
292 class AtomicType : public Type {
293 public:
294  Variability GetVariability() const;
295 
296  bool IsBoolType() const;
297  bool IsFloatType() const;
298  bool IsIntType() const;
299  bool IsUnsignedType() const;
300  bool IsConstType() const;
301 
302  /** For AtomicTypes, the base type is just the same as the AtomicType
303  itself. */
304  const AtomicType *GetBaseType() const;
305  const AtomicType *GetAsUniformType() const;
306  const AtomicType *GetAsVaryingType() const;
308  const AtomicType *GetAsSOAType(int width) const;
309 
311  const AtomicType *GetAsUnsignedType() const;
312  const AtomicType *GetAsConstType() const;
313  const AtomicType *GetAsNonConstType() const;
314 
315  std::string GetString() const;
316  std::string Mangle() const;
317  std::string GetCDeclaration(const std::string &name) const;
318 
319  llvm::Type *LLVMType(llvm::LLVMContext *ctx) const;
320 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_6
321  llvm::DIType GetDIType(llvm::DIDescriptor scope) const;
322 #else // LLVM 3.7++
323  llvm::DIType *GetDIType(llvm::DIScope *scope) const;
324 #endif
325 
326  /** This enumerator records the basic types that AtomicTypes can be
327  built from. */
328  enum BasicType {
342  };
343 
345 
357  static const AtomicType *Void;
358 
359 private:
361  const bool isConst;
362  AtomicType(BasicType basicType, Variability v, bool isConst);
363 
365 };
366 
367 
368 /** @brief Type implementation for enumerated types
369  */
370 class EnumType : public Type {
371 public:
372  /** Constructor for anonymous enumerated types */
374  /** Constructor for named enumerated types */
375  EnumType(const char *name, SourcePos pos);
376 
377  Variability GetVariability() const;
378 
379  bool IsBoolType() const;
380  bool IsFloatType() const;
381  bool IsIntType() const;
382  bool IsUnsignedType() const;
383  bool IsConstType() const;
384 
385  const EnumType *GetBaseType() const;
386  const EnumType *GetAsVaryingType() const;
387  const EnumType *GetAsUniformType() const;
388  const EnumType *GetAsUnboundVariabilityType() const;
389  const EnumType *GetAsSOAType(int width) const;
390 
392  const EnumType *GetAsConstType() const;
393  const EnumType *GetAsNonConstType() const;
394 
395  std::string GetString() const;
396  std::string Mangle() const;
397  std::string GetCDeclaration(const std::string &name) const;
398 
399  /** Returns the name of the enum type. (e.g. struct Foo -> "Foo".) */
400  const std::string &GetEnumName() const { return name; }
401 
402  llvm::Type *LLVMType(llvm::LLVMContext *ctx) const;
403 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_6
404  llvm::DIType GetDIType(llvm::DIDescriptor scope) const;
405 #else // LLVM 3.7++
406  llvm::DIType *GetDIType(llvm::DIScope *scope) const;
407 #endif
408 
409  /** Provides the enumerators defined in the enum definition. */
410  void SetEnumerators(const std::vector<Symbol *> &enumerators);
411  /** Returns the total number of enuemrators in this enum type. */
412  int GetEnumeratorCount() const;
413  /** Returns the symbol for the given enumerator number. */
414  const Symbol *GetEnumerator(int i) const;
415 
416  const SourcePos pos;
417 
418 private:
419  const std::string name;
421  bool isConst;
422  std::vector<Symbol *> enumerators;
423 };
424 
425 
426 /** @brief Type implementation for pointers to other types
427 
428  Pointers can have two additional properties beyond their variability
429  and the type of object that they are pointing to. Both of these
430  properties are used for internal bookkeeping and aren't directly
431  accessible from the language.
432 
433  - Slice: pointers that point to data with SOA layout have this
434  property--it indicates that the pointer has two components, where the
435  first (major) component is a regular pointer that points to an
436  instance of the soa<> type being indexed, and where the second
437  (minor) component is an integer that indicates which of the soa
438  slices in that instance the pointer points to.
439 
440  - Frozen: only slice pointers may have this property--it indicates that
441  any further indexing calculations should only be applied to the major
442  pointer, and the value of the minor offset should be left unchanged.
443  Pointers to lvalues from structure member access have the frozen
444  property; see discussion in comments in the StructMemberExpr class.
445  */
446 class PointerType : public Type {
447 public:
448  PointerType(const Type *t, Variability v, bool isConst,
449  bool isSlice = false, bool frozen = false);
450 
451  /** Helper method to return a uniform pointer to the given type. */
452  static PointerType *GetUniform(const Type *t, bool isSlice = false);
453  /** Helper method to return a varying pointer to the given type. */
454  static PointerType *GetVarying(const Type *t);
455 
456  /** Returns true if the given type is a void * type. */
457  static bool IsVoidPointer(const Type *t);
458 
459  Variability GetVariability() const;
460 
461  bool IsBoolType() const;
462  bool IsFloatType() const;
463  bool IsIntType() const;
464  bool IsUnsignedType() const;
465  bool IsConstType() const;
466 
467  bool IsSlice() const { return isSlice; }
468  bool IsFrozenSlice() const { return isFrozen; }
469  const PointerType *GetAsSlice() const;
470  const PointerType *GetAsNonSlice() const;
471  const PointerType *GetAsFrozenSlice() const;
472 
473  const Type *GetBaseType() const;
474  const PointerType *GetAsVaryingType() const;
475  const PointerType *GetAsUniformType() const;
477  const PointerType *GetAsSOAType(int width) const;
478 
480  const PointerType *GetAsConstType() const;
481  const PointerType *GetAsNonConstType() const;
482 
483  std::string GetString() const;
484  std::string Mangle() const;
485  std::string GetCDeclaration(const std::string &name) const;
486 
487  llvm::Type *LLVMType(llvm::LLVMContext *ctx) const;
488 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_6
489  llvm::DIType GetDIType(llvm::DIDescriptor scope) const;
490 #else // LLVM 3.7++
491  llvm::DIType *GetDIType(llvm::DIScope *scope) const;
492 #endif
493 
494  static PointerType *Void;
495 
496 private:
498  const bool isConst;
499  const bool isSlice, isFrozen;
500  const Type *baseType;
501 };
502 
503 
504 /** @brief Abstract base class for types that represent collections of
505  other types.
506 
507  This is a common base class that StructTypes, ArrayTypes, and
508  VectorTypes all inherit from.
509 */
510 class CollectionType : public Type {
511 public:
512  /** Returns the total number of elements in the collection. */
513  virtual int GetElementCount() const = 0;
514 
515  /** Returns the type of the element given by index. (The value of
516  index must be between 0 and GetElementCount()-1.
517  */
518  virtual const Type *GetElementType(int index) const = 0;
519 
520 protected:
521  CollectionType(TypeId id) : Type(id) { }
522 };
523 
524 
525 /** @brief Abstract base class for types that represent sequences
526 
527  SequentialType is an abstract base class that adds interface routines
528  for types that represent linear sequences of other types (i.e., arrays
529  and vectors).
530  */
532 public:
533  /** Returns the Type of the elements that the sequence stores; for
534  SequentialTypes, all elements have the same type . */
535  virtual const Type *GetElementType() const = 0;
536 
537  /** SequentialType provides an implementation of this CollectionType
538  method, just passing the query on to the GetElementType(void)
539  implementation, since all of the elements of a SequentialType have
540  the same type.
541  */
542  const Type *GetElementType(int index) const;
543 
544 protected:
546 };
547 
548 
549 /** @brief One-dimensional array type.
550 
551  ArrayType represents a one-dimensional array of instances of some other
552  type. (Multi-dimensional arrays are represented by ArrayTypes that in
553  turn hold ArrayTypes as their child types.)
554 */
555 class ArrayType : public SequentialType {
556 public:
557  /** An ArrayType is created by providing the type of the elements that
558  it stores, and the SOA width to use in laying out the array in
559  memory.
560 
561  @param elementType Type of the array elements
562  @param numElements Total number of elements in the array. This
563  parameter may be zero, in which case this is an
564  "unsized" array type. (Arrays of specific size
565  can be converted to unsized arrays to be passed
566  to functions that take array parameters, for
567  example).
568  */
569  ArrayType(const Type *elementType, int numElements);
570 
571  Variability GetVariability() const;
572 
573  bool IsBoolType() const;
574  bool IsFloatType() const;
575  bool IsIntType() const;
576  bool IsUnsignedType() const;
577  bool IsConstType() const;
578 
579  const Type *GetBaseType() const;
580  const ArrayType *GetAsVaryingType() const;
581  const ArrayType *GetAsUniformType() const;
582  const ArrayType *GetAsUnboundVariabilityType() const;
583  const ArrayType *GetAsSOAType(int width) const;
585 
586  const ArrayType *GetAsUnsignedType() const;
587  const ArrayType *GetAsConstType() const;
588  const ArrayType *GetAsNonConstType() const;
589 
590  std::string GetString() const;
591  std::string Mangle() const;
592  std::string GetCDeclaration(const std::string &name) const;
593 
594 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_6
595  llvm::DIType GetDIType(llvm::DIDescriptor scope) const;
596 #else // LLVM 3.7++
597  llvm::DIType *GetDIType(llvm::DIScope *scope) const;
598 #endif
599  llvm::ArrayType *LLVMType(llvm::LLVMContext *ctx) const;
600 
601  /** This method returns the total number of elements in the array,
602  including all dimensions if this is a multidimensional array. */
603  int TotalElementCount() const;
604 
605  int GetElementCount() const;
606  const Type *GetElementType() const;
607 
608  /** Returns a new array of the same child type, but with the given
609  length. */
610  virtual ArrayType *GetSizedArray(int length) const;
611 
612  /** If the given type is a (possibly multi-dimensional) array type and
613  the initializer expression is an expression list, set the size of
614  any array dimensions that are unsized according to the number of
615  elements in the corresponding sectoin of the initializer
616  expression.
617  */
618  static const Type *SizeUnsizedArrays(const Type *type, Expr *initExpr);
619 
620 private:
621  /** Type of the elements of the array. */
622  const Type * const child;
623  /** Number of elements in the array. */
624  const int numElements;
625 };
626 
627 
628 /** @brief A (short) vector of atomic types.
629 
630  VectorType is used to represent a fixed-size array of elements of an
631  AtomicType. Vectors are similar to arrays in that they support
632  indexing of the elements, but have two key differences. First, all
633  arithmetic and logical operations that are value for the element type
634  can be performed on corresponding VectorTypes (as long as the two
635  VectorTypes have the same size). Second, VectorTypes of uniform
636  elements are laid out in memory aligned to the target's vector size;
637  this allows them to be packed 'horizontally' into vector registers.
638  */
639 class VectorType : public SequentialType {
640 public:
641  VectorType(const AtomicType *base, int size);
642 
643  Variability GetVariability() const;
644 
645  bool IsBoolType() const;
646  bool IsFloatType() const;
647  bool IsIntType() const;
648  bool IsUnsignedType() const;
649  bool IsConstType() const;
650 
651  const Type *GetBaseType() const;
652  const VectorType *GetAsVaryingType() const;
653  const VectorType *GetAsUniformType() const;
655  const VectorType *GetAsSOAType(int width) const;
657 
658  const VectorType *GetAsConstType() const;
659  const VectorType *GetAsNonConstType() const;
660 
661  std::string GetString() const;
662  std::string Mangle() const;
663  std::string GetCDeclaration(const std::string &name) const;
664 
665  llvm::Type *LLVMType(llvm::LLVMContext *ctx) const;
666 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_6
667  llvm::DIType GetDIType(llvm::DIDescriptor scope) const;
668 #else // LLVM 3.7++
669  llvm::DIType *GetDIType(llvm::DIScope *scope) const;
670 #endif
671 
672  int GetElementCount() const;
673  const AtomicType *GetElementType() const;
674 
675 private:
676  /** Base type that the vector holds elements of */
677  const AtomicType * const base;
678  /** Number of elements in the vector */
679  const int numElements;
680 
681  /** Returns the number of elements stored in memory for the vector.
682  For uniform vectors, this is rounded up so that the number of
683  elements evenly divides the target's native vector width. */
684  int getVectorMemoryCount() const;
685 };
686 
687 
688 /** @brief Representation of a structure holding a number of members.
689  */
690 class StructType : public CollectionType {
691 public:
692  StructType(const std::string &name, const llvm::SmallVector<const Type *, 8> &elts,
693  const llvm::SmallVector<std::string, 8> &eltNames,
694  const llvm::SmallVector<SourcePos, 8> &eltPositions, bool isConst,
696 
697  Variability GetVariability() const;
698 
699  bool IsBoolType() const;
700  bool IsFloatType() const;
701  bool IsIntType() const;
702  bool IsUnsignedType() const;
703  bool IsConstType() const;
704  bool IsDefined() const;
705 
706  const Type *GetBaseType() const;
707  const StructType *GetAsVaryingType() const;
708  const StructType *GetAsUniformType() const;
710  const StructType *GetAsSOAType(int width) const;
712 
713  const StructType *GetAsConstType() const;
714  const StructType *GetAsNonConstType() const;
715 
716  std::string GetString() const;
717  std::string Mangle() const;
718  std::string GetCDeclaration(const std::string &name) const;
719 
720  llvm::Type *LLVMType(llvm::LLVMContext *ctx) const;
721 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_6
722  llvm::DIType GetDIType(llvm::DIDescriptor scope) const;
723 #else // LLVM 3.7++
724  llvm::DIType *GetDIType(llvm::DIScope *scope) const;
725 #endif
726 
727  /** Returns the type of the structure element with the given name (if any).
728  Returns NULL if there is no such named element. */
729  const Type *GetElementType(const std::string &name) const;
730 
731  /** Returns the type of the i'th structure element. The value of \c i must
732  be between 0 and NumElements()-1. */
733  const Type *GetElementType(int i) const;
734 
735  /** Returns which structure element number (starting from zero) that
736  has the given name. If there is no such element, return -1. */
737  int GetElementNumber(const std::string &name) const;
738 
739  /** Returns the name of the i'th element of the structure. */
740  const std::string &GetElementName(int i) const { return elementNames[i]; }
741 
742  /** Returns the total number of elements in the structure. */
743  int GetElementCount() const { return int(elementTypes.size()); }
744 
745  const SourcePos &GetElementPosition(int i) const { return elementPositions[i]; }
746 
747  /** Returns the name of the structure type. (e.g. struct Foo -> "Foo".) */
748  const std::string &GetStructName() const { return name; }
749  const std::string GetCStructName() const;
750 
751 private:
752  static bool checkIfCanBeSOA(const StructType *st);
753 
754  /*const*/ std::string name;
755  /** The types of the struct elements. Note that we store these with
756  uniform/varying exactly as they were declared in the source file.
757  (In other words, even if this struct has a varying qualifier and
758  thus all of its members are going to be widened out to be varying,
759  we still store any members that were declared as uniform as uniform
760  types in the elementTypes array, converting them to varying as
761  needed in the implementation.) This is so that if we later need to
762  make a uniform version of the struct, we've maintained the original
763  information about the member types.
764  */
765  const llvm::SmallVector<const Type *, 8> elementTypes;
766  const llvm::SmallVector<std::string, 8> elementNames;
767  /** Source file position at which each structure element declaration
768  appeared. */
769  const llvm::SmallVector<SourcePos, 8> elementPositions;
771  const bool isConst;
772  const SourcePos pos;
773 
774  mutable llvm::SmallVector<const Type *, 8> finalElementTypes;
775 
777 };
778 
779 
780 /** Type implementation representing a struct name that has been declared
781  but where the struct members haven't been defined (i.e. "struct Foo;").
782  This class doesn't do much besides serve as a placeholder that other
783  code can use to detect the presence of such as truct.
784  */
785 class UndefinedStructType : public Type {
786 public:
787  UndefinedStructType(const std::string &name, const Variability variability,
788  bool isConst, SourcePos pos);
789 
790  Variability GetVariability() const;
791 
792  bool IsBoolType() const;
793  bool IsFloatType() const;
794  bool IsIntType() const;
795  bool IsUnsignedType() const;
796  bool IsConstType() const;
797 
798  const Type *GetBaseType() const;
799  const UndefinedStructType *GetAsVaryingType() const;
800  const UndefinedStructType *GetAsUniformType() const;
802  const UndefinedStructType *GetAsSOAType(int width) const;
804 
805  const UndefinedStructType *GetAsConstType() const;
806  const UndefinedStructType *GetAsNonConstType() const;
807 
808  std::string GetString() const;
809  std::string Mangle() const;
810  std::string GetCDeclaration(const std::string &name) const;
811 
812  llvm::Type *LLVMType(llvm::LLVMContext *ctx) const;
813 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_6
814  llvm::DIType GetDIType(llvm::DIDescriptor scope) const;
815 #else // LLVM 3.7++
816  llvm::DIType *GetDIType(llvm::DIScope *scope) const;
817 #endif
818 
819  /** Returns the name of the structure type. (e.g. struct Foo -> "Foo".) */
820  const std::string &GetStructName() const { return name; }
821 
822 private:
823  const std::string name;
825  const bool isConst;
826  const SourcePos pos;
827 };
828 
829 
830 /** @brief Type representing a reference to another (non-reference) type.
831  */
832 class ReferenceType : public Type {
833 public:
834  ReferenceType(const Type *targetType);
835 
836  Variability GetVariability() const;
837 
838  bool IsBoolType() const;
839  bool IsFloatType() const;
840  bool IsIntType() const;
841  bool IsUnsignedType() const;
842  bool IsConstType() const;
843 
844  const Type *GetBaseType() const;
845  const Type *GetReferenceTarget() const;
846  const ReferenceType *GetAsVaryingType() const;
847  const ReferenceType *GetAsUniformType() const;
849  const Type *GetAsSOAType(int width) const;
851 
852  const ReferenceType *GetAsConstType() const;
853  const ReferenceType *GetAsNonConstType() const;
854 
855  std::string GetString() const;
856  std::string Mangle() const;
857  std::string GetCDeclaration(const std::string &name) const;
858 
859  llvm::Type *LLVMType(llvm::LLVMContext *ctx) const;
860 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_6
861  llvm::DIType GetDIType(llvm::DIDescriptor scope) const;
862 #else // LLVM 3.7++
863  llvm::DIType *GetDIType(llvm::DIScope *scope) const;
864 #endif
865 
866 private:
867  const Type * const targetType;
869 };
870 
871 
872 /** @brief Type representing a function (return type + argument types)
873 
874  FunctionType encapsulates the information related to a function's type,
875  including the return type and the types of the arguments.
876 
877  @todo This class has a fair number of methods inherited from Type that
878  don't make sense here (e.g. IsUniformType(), GetBaseType(), LLVMType(), etc.
879  Would be nice to refactor the inheritance hierarchy to move most of
880  those interface methods to a sub-class of Type, which in turn all of
881  the other Type implementations inherit from.
882  */
883 class FunctionType : public Type {
884 public:
886  const llvm::SmallVector<const Type *, 8> &argTypes, SourcePos pos);
887  FunctionType(const Type *returnType,
888  const llvm::SmallVector<const Type *, 8> &argTypes,
889  const llvm::SmallVector<std::string, 8> &argNames,
890  const llvm::SmallVector<Expr *, 8> &argDefaults,
891  const llvm::SmallVector<SourcePos, 8> &argPos,
892  bool isTask, bool isExported, bool isExternC, bool isUnmasked);
893 
894  Variability GetVariability() const;
895 
896  bool IsBoolType() const;
897  bool IsFloatType() const;
898  bool IsIntType() const;
899  bool IsUnsignedType() const;
900  bool IsConstType() const;
901 
902  const Type *GetBaseType() const;
903  const Type *GetAsVaryingType() const;
904  const Type *GetAsUniformType() const;
905  const Type *GetAsUnboundVariabilityType() const;
906  const Type *GetAsSOAType(int width) const;
908 
909  const Type *GetAsConstType() const;
910  const Type *GetAsNonConstType() const;
911 
912  std::string GetString() const;
913  std::string Mangle() const;
914  std::string GetCDeclaration(const std::string &fname) const;
915  std::string GetCDeclarationForDispatch(const std::string &fname) const;
916 
917  llvm::Type *LLVMType(llvm::LLVMContext *ctx) const;
918 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_6
919  llvm::DIType GetDIType(llvm::DIDescriptor scope) const;
920 #else // LLVM 3.7++
921  llvm::DIType *GetDIType(llvm::DIScope *scope) const;
922 #endif
923 
924  const Type *GetReturnType() const { return returnType; }
925 
926  const std::string GetReturnTypeString() const;
927 
928  /** This method returns the LLVM FunctionType that corresponds to this
929  function type. The \c disableMask parameter indicates whether the
930  llvm::FunctionType should have the trailing mask parameter, if
931  present, removed from the return function signature. */
932  llvm::FunctionType *LLVMFunctionType(llvm::LLVMContext *ctx,
933  bool disableMask = false) const;
934 
935  int GetNumParameters() const { return (int)paramTypes.size(); }
936  const Type *GetParameterType(int i) const;
937  Expr * GetParameterDefault(int i) const;
938  const SourcePos &GetParameterSourcePos(int i) const;
939  const std::string &GetParameterName(int i) const;
940 
941  /** This value is true if the function had a 'task' qualifier in the
942  source program. */
943  const bool isTask;
944 
945  /** This value is true if the function had a 'export' qualifier in the
946  source program. */
947  const bool isExported;
948 
949  /** This value is true if the function was declared as an 'extern "C"'
950  function in the source program. */
951  const bool isExternC;
952 
953  /** Indicates whether the function doesn't take an implicit mask
954  parameter (and thus should start execution with an "all on"
955  mask). */
956  const bool isUnmasked;
957 
958  /** Indicates whether this function has been declared to be safe to run
959  with an all-off mask. */
960  bool isSafe;
961 
962  /** If non-negative, this provides a user-supplied override to the cost
963  function estimate for the function. */
965 
966 private:
967  const Type * const returnType;
968 
969  // The following four vectors should all have the same length (which is
970  // in turn the length returned by GetNumParameters()).
971  const llvm::SmallVector<const Type *, 8> paramTypes;
972  const llvm::SmallVector<std::string, 8> paramNames;
973  /** Default values of the function's arguments. For arguments without
974  default values provided, NULL is stored. */
975  mutable llvm::SmallVector<Expr *, 8> paramDefaults;
976  /** The names provided (if any) with the function arguments in the
977  function's signature. These should only be used for error messages
978  and the like and so not affect testing function types for equality,
979  etc. */
980  const llvm::SmallVector<SourcePos, 8> paramPositions;
981 };
982 
983 
984 /* Efficient dynamic casting of Types. First, we specify a default
985  template function that returns NULL, indicating a failed cast, for
986  arbitrary types. */
987 template <typename T> inline const T *
988 CastType(const Type *type) {
989  return NULL;
990 }
991 
992 
993 /* Now we have template specializaitons for the Types implemented in this
994  file. Each one checks the Type::typeId member and then performs the
995  corresponding static cast if it's safe as per the typeId.
996  */
997 template <> inline const AtomicType *
998 CastType(const Type *type) {
999  if (type != NULL && type->typeId == ATOMIC_TYPE)
1000  return (const AtomicType *)type;
1001  else
1002  return NULL;
1003 }
1004 
1005 template <> inline const EnumType *
1006 CastType(const Type *type) {
1007  if (type != NULL && type->typeId == ENUM_TYPE)
1008  return (const EnumType *)type;
1009  else
1010  return NULL;
1011 }
1012 
1013 template <> inline const PointerType *
1014 CastType(const Type *type) {
1015  if (type != NULL && type->typeId == POINTER_TYPE)
1016  return (const PointerType *)type;
1017  else
1018  return NULL;
1019 }
1020 
1021 template <> inline const ArrayType *
1022 CastType(const Type *type) {
1023  if (type != NULL && type->typeId == ARRAY_TYPE)
1024  return (const ArrayType *)type;
1025  else
1026  return NULL;
1027 }
1028 
1029 template <> inline const VectorType *
1030 CastType(const Type *type) {
1031  if (type != NULL && type->typeId == VECTOR_TYPE)
1032  return (const VectorType *)type;
1033  else
1034  return NULL;
1035 }
1036 
1037 template <> inline const SequentialType *
1038 CastType(const Type *type) {
1039  // Note that this function must be updated if other sequential type
1040  // implementations are added.
1041  if (type != NULL &&
1042  (type->typeId == ARRAY_TYPE || type->typeId == VECTOR_TYPE))
1043  return (const SequentialType *)type;
1044  else
1045  return NULL;
1046 }
1047 
1048 template <> inline const CollectionType *
1049 CastType(const Type *type) {
1050  // Similarly a new collection type implementation requires updating
1051  // this function.
1052  if (type != NULL &&
1053  (type->typeId == ARRAY_TYPE || type->typeId == VECTOR_TYPE ||
1054  type->typeId == STRUCT_TYPE))
1055  return (const CollectionType *)type;
1056  else
1057  return NULL;
1058 }
1059 
1060 template <> inline const StructType *
1061 CastType(const Type *type) {
1062  if (type != NULL && type->typeId == STRUCT_TYPE)
1063  return (const StructType *)type;
1064  else
1065  return NULL;
1066 }
1067 
1068 template <> inline const UndefinedStructType *
1069 CastType(const Type *type) {
1070  if (type != NULL && type->typeId == UNDEFINED_STRUCT_TYPE)
1071  return (const UndefinedStructType *)type;
1072  else
1073  return NULL;
1074 }
1075 
1076 template <> inline const ReferenceType *
1077 CastType(const Type *type) {
1078  if (type != NULL && type->typeId == REFERENCE_TYPE)
1079  return (const ReferenceType *)type;
1080  else
1081  return NULL;
1082 }
1083 
1084 template <> inline const FunctionType *
1085 CastType(const Type *type) {
1086  if (type != NULL && type->typeId == FUNCTION_TYPE)
1087  return (const FunctionType *)type;
1088  else
1089  return NULL;
1090 }
1091 
1092 
1093 inline bool IsReferenceType(const Type *t) {
1094  return CastType<ReferenceType>(t) != NULL;
1095 }
1096 
1097 
1098 #endif // ISPC_TYPE_H
bool IsVoidType() const
Definition: type.cpp:246
bool operator==(const Variability &v) const
Definition: type.h:63
static const AtomicType * VaryingInt32
Definition: type.h:349
llvm::SmallVector< Expr *, 8 > paramDefaults
Definition: type.h:975
const AtomicType * GetAsUnsignedType() const
Definition: type.cpp:284
bool IsVaryingType() const
Definition: type.h:150
Expr * GetParameterDefault(int i) const
Definition: type.cpp:3277
bool IsUnsignedType() const
Definition: type.cpp:1687
std::string GetString() const
Definition: type.cpp:2182
bool IsUnsignedType() const
Definition: type.cpp:671
const StructType * oppositeConstStructType
Definition: type.h:776
virtual ArrayType * GetSizedArray(int length) const
Definition: type.cpp:1594
const std::string GetReturnTypeString() const
Definition: type.cpp:3177
static const AtomicType * VaryingInt16
Definition: type.h:348
llvm::Type * LLVMType(llvm::LLVMContext *ctx) const
Definition: type.cpp:2829
EnumType(SourcePos pos)
Definition: type.cpp:631
bool IsFloatType() const
Definition: type.cpp:2907
Variability GetVariability() const
Definition: type.cpp:224
const VectorType * GetAsNonConstType() const
Definition: type.cpp:1747
Variability GetVariability() const
Definition: type.cpp:647
const UndefinedStructType * GetAsSOAType(int width) const
Definition: type.cpp:2501
int GetElementCount() const
Definition: type.cpp:1470
llvm::DIType GetDIType(llvm::DIDescriptor scope) const
Definition: type.cpp:1824
const ReferenceType * GetAsVaryingType() const
Definition: type.cpp:2683
virtual Variability GetVariability() const =0
std::string GetString() const
Definition: type.cpp:3011
const Type * GetAsVaryingType() const
Definition: type.cpp:2944
const EnumType * GetAsUniformType() const
Definition: type.cpp:689
llvm::DIType GetDIType(llvm::DIDescriptor scope) const
Definition: type.cpp:1575
bool IsConstType() const
Definition: type.cpp:1699
std::string GetCDeclaration(const std::string &name) const
Definition: type.cpp:1771
const std::string & GetStructName() const
Definition: type.h:820
const bool isConst
Definition: type.h:825
const ArrayType * GetAsUnsignedType() const
Definition: type.cpp:1440
int GetEnumeratorCount() const
Definition: type.cpp:937
llvm::DIType GetDIType(llvm::DIDescriptor scope) const
Definition: type.cpp:2267
const PointerType * GetAsConstType() const
Definition: type.cpp:1105
llvm::Type * LLVMType(llvm::LLVMContext *ctx) const
Definition: type.cpp:490
const AtomicType * GetAsConstType() const
Definition: type.cpp:308
const std::string GetCStructName() const
Definition: type.cpp:2017
const Type * GetAsUniformType() const
Definition: type.cpp:2951
static const AtomicType * VaryingUInt64
Definition: type.h:355
const UndefinedStructType * GetAsConstType() const
Definition: type.cpp:2516
std::string GetCDeclaration(const std::string &name) const
Definition: type.cpp:1159
bool IsIntType() const
Definition: type.cpp:1000
int TotalElementCount() const
Definition: type.cpp:1565
const bool isConst
Definition: type.h:361
static PointerType * Void
Definition: type.h:494
const ArrayType * GetAsUnboundVariabilityType() const
Definition: type.cpp:1410
bool IsIntType() const
Definition: type.cpp:2913
bool IsFrozenSlice() const
Definition: type.h:468
bool IsArrayType() const
Definition: type.cpp:236
bool IsIntType() const
Definition: type.cpp:2453
llvm::DIType GetDIType(llvm::DIDescriptor scope) const
Definition: type.cpp:3125
virtual bool IsUnsignedType() const =0
virtual const Type * GetAsUnboundVariabilityType() const =0
Type(TypeId id)
Definition: type.h:280
const VectorType * GetAsSOAType(int width) const
Definition: type.cpp:1729
llvm::DIType GetDIType(llvm::DIDescriptor scope) const
Definition: type.cpp:2846
bool HasUnboundVariability() const
Definition: type.h:164
bool IsUnsignedType() const
Definition: type.cpp:2925
const EnumType * GetAsSOAType(int width) const
Definition: type.cpp:737
static const AtomicType * VaryingDouble
Definition: type.h:356
virtual const Type * GetElementType(int index) const =0
Expression representing a compile-time constant value.
Definition: expr.h:390
Abstract base class for types that represent sequences.
Definition: type.h:531
TypeId
Definition: type.h:83
bool IsBoolType() const
Definition: type.cpp:2617
const PointerType * GetAsNonSlice() const
Definition: type.cpp:1072
bool IsConstType() const
Definition: type.cpp:2060
bool IsUnsignedType() const
Definition: type.cpp:265
int GetElementNumber(const std::string &name) const
Definition: type.cpp:2381
const EnumType * GetAsNonConstType() const
Definition: type.cpp:761
std::string GetString() const
Definition: type.cpp:397
Variability variability
Definition: type.h:420
PointerType(const Type *t, Variability v, bool isConst, bool isSlice=false, bool frozen=false)
Definition: type.cpp:955
bool IsDefined() const
Definition: type.cpp:2066
const Type * GetBaseType() const
Definition: type.cpp:1377
std::string Mangle() const
Definition: type.cpp:1507
const std::string name
Definition: type.h:419
bool IsBoolType() const
Definition: type.cpp:2441
llvm::FunctionType * LLVMFunctionType(llvm::LLVMContext *ctx, bool disableMask=false) const
Definition: type.cpp:3203
bool IsPointerType() const
Definition: type.cpp:230
bool IsConstType() const
Definition: type.cpp:2465
static const AtomicType * UniformUInt32
Definition: type.h:352
std::string GetCDeclaration(const std::string &name) const
Definition: type.cpp:450
int soaWidth
Definition: type.h:77
const Type * GetElementType(const std::string &name) const
Definition: type.cpp:2372
Variability GetVariability() const
Definition: type.cpp:1341
static PointerType * GetVarying(const Type *t)
Definition: type.cpp:969
const PointerType * GetAsVaryingType() const
Definition: type.cpp:1024
std::string Mangle() const
Definition: type.cpp:2228
const EnumType * GetAsConstType() const
Definition: type.cpp:749
virtual const Type * GetAsUniformType() const =0
std::string GetCDeclaration(const std::string &name) const
Definition: type.cpp:2796
const Variability variability
Definition: type.h:770
const StructType * GetAsUnboundVariabilityType() const
Definition: type.cpp:2111
virtual const Type * GetElementType() const =0
Type implementation for pointers to other types.
Definition: type.h:446
Variability GetVariability() const
Definition: type.cpp:2435
bool IsFloatType() const
Definition: type.cpp:1347
const int numElements
Definition: type.h:624
bool IsUnsignedType() const
Definition: type.cpp:2054
UndefinedStructType(const std::string &name, const Variability variability, bool isConst, SourcePos pos)
Definition: type.cpp:2420
bool IsUnsignedType() const
Definition: type.cpp:1006
Variability GetVariability() const
Definition: type.cpp:1669
const Type * GetBaseType() const
Definition: type.cpp:2471
bool IsFloatType() const
Definition: type.cpp:251
virtual std::string GetString() const =0
bool IsUnsignedType() const
Definition: type.cpp:1359
virtual std::string Mangle() const =0
const Variability variability
Definition: type.h:824
const ReferenceType * GetAsNonConstType() const
Definition: type.cpp:2753
Variability GetVariability() const
Definition: type.cpp:2901
const llvm::SmallVector< std::string, 8 > paramNames
Definition: type.h:972
const VectorType * ResolveUnboundVariability(Variability v) const
Definition: type.cpp:1735
static const AtomicType * UniformUInt16
Definition: type.h:351
const Type * GetReferenceTarget() const
Definition: type.cpp:2667
const UndefinedStructType * GetAsUnboundVariabilityType() const
Definition: type.cpp:2493
int GetSOAWidth() const
Definition: type.h:160
static PointerType * GetUniform(const Type *t, bool isSlice=false)
Definition: type.cpp:963
const PointerType * GetAsSOAType(int width) const
Definition: type.cpp:1054
const StructType * ResolveUnboundVariability(Variability v) const
Definition: type.cpp:2134
const ArrayType * GetAsNonConstType() const
Definition: type.cpp:1460
bool IsIntType() const
Definition: type.cpp:1353
const StructType * GetAsNonConstType() const
Definition: type.cpp:2166
static const AtomicType * UniformBool
Definition: type.h:346
const ArrayType * GetAsVaryingType() const
Definition: type.cpp:1390
bool IsBoolType() const
Definition: type.cpp:1365
int costOverride
Definition: type.h:964
Type representing a reference to another (non-reference) type.
Definition: type.h:832
std::string GetString() const
Definition: type.cpp:1482
bool IsNumericType() const
Definition: type.h:139
const UndefinedStructType * ResolveUnboundVariability(Variability v) const
Definition: type.cpp:2508
const Type * baseType
Definition: type.h:500
bool IsBoolType() const
Definition: type.cpp:2919
const AtomicType * GetAsUniformType() const
Definition: type.cpp:355
VectorType(const AtomicType *base, int size)
Definition: type.cpp:1661
static bool IsVoidPointer(const Type *t)
Definition: type.cpp:975
const llvm::SmallVector< std::string, 8 > elementNames
Definition: type.h:766
int getVectorMemoryCount() const
Definition: type.cpp:1872
const ArrayType * GetAsUniformType() const
Definition: type.cpp:1400
std::vector< Symbol * > enumerators
Definition: type.h:422
bool IsReferenceType(const Type *t)
Definition: type.h:1093
bool operator!=(const Variability &v) const
Definition: type.h:66
const EnumType * GetBaseType() const
Definition: type.cpp:683
bool IsFloatType() const
Definition: type.cpp:2627
static const AtomicType * UniformUInt64
Definition: type.h:355
bool IsUniformType() const
Definition: type.h:145
bool IsBoolType() const
Definition: type.cpp:2036
llvm::DIType GetDIType(llvm::DIDescriptor scope) const
Definition: type.cpp:851
const Type * GetAsNonConstType() const
Definition: type.cpp:3005
bool IsIntType() const
Definition: type.cpp:256
std::string GetCDeclaration(const std::string &name) const
Definition: type.cpp:799
const std::string & GetParameterName(int i) const
Definition: type.cpp:3291
AtomicType(BasicType basicType, Variability v, bool isConst)
Definition: type.cpp:216
const bool isExternC
Definition: type.h:951
const UndefinedStructType * GetAsVaryingType() const
Definition: type.cpp:2477
bool IsConstType() const
Definition: type.cpp:278
const llvm::SmallVector< SourcePos, 8 > elementPositions
Definition: type.h:769
virtual bool IsConstType() const =0
const Type * GetAsSOAType(int width) const
Definition: type.cpp:2719
llvm::SmallVector< const Type *, 8 > finalElementTypes
Definition: type.h:774
Definition: type.h:85
std::string GetCDeclaration(const std::string &name) const
Definition: type.cpp:2549
const EnumType * ResolveUnboundVariability(Variability v) const
Definition: type.cpp:701
static bool checkIfCanBeSOA(const StructType *st)
Definition: type.cpp:2390
llvm::Type * LLVMType(llvm::LLVMContext *ctx) const
Definition: type.cpp:1792
bool IsSlice() const
Definition: type.h:467
const VectorType * GetAsVaryingType() const
Definition: type.cpp:1711
virtual bool IsBoolType() const =0
const AtomicType * GetBaseType() const
Definition: type.cpp:334
virtual std::string GetCDeclaration(const std::string &name) const =0
std::string GetString() const
Definition: type.cpp:773
const SourcePos pos
Definition: type.h:416
static const Type * MoreGeneralType(const Type *type0, const Type *type1, SourcePos pos, const char *reason, bool forceVarying=false, int vecSize=0)
Definition: type.cpp:3343
const StructType * GetAsUniformType() const
Definition: type.cpp:2101
Representation of a structure holding a number of members.
Definition: type.h:690
virtual llvm::DIType GetDIType(llvm::DIDescriptor scope) const =0
const AtomicType * ResolveUnboundVariability(Variability v) const
Definition: type.cpp:388
const StructType * GetAsConstType() const
Definition: type.cpp:2150
std::string Mangle() const
Definition: type.cpp:3029
bool IsFloatType() const
Definition: type.cpp:994
llvm::ArrayType * LLVMType(llvm::LLVMContext *ctx) const
Definition: type.cpp:1325
const PointerType * GetAsNonConstType() const
Definition: type.cpp:1114
virtual bool IsIntType() const =0
const EnumType * GetAsVaryingType() const
Definition: type.cpp:713
std::string GetCDeclaration(const std::string &name) const
Definition: type.cpp:2234
const AtomicType *const base
Definition: type.h:677
const Type * GetParameterType(int i) const
Definition: type.cpp:3270
const AtomicType * asVaryingType
Definition: type.h:364
virtual const Type * GetAsConstType() const =0
static bool IsBasicType(const Type *type)
Definition: type.cpp:3509
CollectionType(TypeId id)
Definition: type.h:521
const VectorType * GetAsUniformType() const
Definition: type.cpp:1717
bool IsBoolType() const
Definition: type.cpp:988
const StructType * GetAsVaryingType() const
Definition: type.cpp:2091
std::string name
Definition: type.h:754
AtomicType represents basic types like floats, ints, etc.
Definition: type.h:292
const Type *const returnType
Definition: type.h:967
const std::string & GetElementName(int i) const
Definition: type.h:740
const bool isConst
Definition: type.h:498
Representation of a range of positions in a source file.
Definition: ispc.h:134
SequentialType(TypeId id)
Definition: type.h:545
const ArrayType * GetAsSOAType(int width) const
Definition: type.cpp:1420
int GetElementCount() const
Definition: type.cpp:1780
Type implementation for enumerated types.
Definition: type.h:370
static const AtomicType * VaryingBool
Definition: type.h:346
Abstract base class for types that represent collections of other types.
Definition: type.h:510
std::string GetCDeclarationForDispatch(const std::string &fname) const
Definition: type.cpp:3076
const Type * GetAsSOAType(int width) const
Definition: type.cpp:2965
bool operator==(const VarType &t) const
Definition: type.h:70
ArrayType(const Type *elementType, int numElements)
Definition: type.cpp:1316
const AtomicType * asOtherConstType
Definition: type.h:364
llvm::Type * LLVMType(llvm::LLVMContext *ctx) const
Definition: type.cpp:3118
std::string GetString() const
Definition: type.cpp:128
bool isConst
Definition: type.h:421
const BasicType basicType
Definition: type.h:344
std::string Mangle() const
Definition: type.cpp:1762
bool IsFloatType() const
Definition: type.cpp:2447
const PointerType * GetAsSlice() const
Definition: type.cpp:1064
const Type *const targetType
Definition: type.h:867
static const AtomicType * VaryingInt64
Definition: type.h:354
bool IsConstType() const
Definition: type.cpp:2931
bool IsIntType() const
Definition: type.cpp:665
const Type * GetBaseType() const
Definition: type.cpp:1018
std::string MangleString() const
Definition: type.cpp:146
virtual bool IsFloatType() const =0
const SourcePos pos
Definition: type.h:772
llvm::DIType GetDIType(llvm::DIDescriptor scope) const
Definition: type.cpp:530
ReferenceType(const Type *targetType)
Definition: type.cpp:2600
const Type * GetReturnType() const
Definition: type.h:924
bool IsBoolType() const
Definition: type.cpp:1693
std::string Mangle() const
Definition: type.cpp:2543
const int numElements
Definition: type.h:679
const llvm::SmallVector< const Type *, 8 > elementTypes
Definition: type.h:765
const Variability variability
Definition: type.h:360
virtual llvm::Type * LLVMType(llvm::LLVMContext *ctx) const =0
A (short) vector of atomic types.
Definition: type.h:639
const FunctionType * ResolveUnboundVariability(Variability v) const
Definition: type.cpp:2972
const Type * GetBaseType() const
Definition: type.cpp:1705
bool IsConstType() const
Definition: type.cpp:677
const AtomicType * GetElementType() const
Definition: type.cpp:1786
bool IsUnsignedType() const
Definition: type.cpp:2647
static const AtomicType * UniformUInt8
Definition: type.h:350
const UndefinedStructType * GetAsUniformType() const
Definition: type.cpp:2485
Variability GetVariability() const
Definition: type.cpp:982
const VectorType * GetAsUnboundVariabilityType() const
Definition: type.cpp:1723
const bool isSlice
Definition: type.h:499
const Symbol * GetEnumerator(int i) const
Definition: type.cpp:943
const llvm::SmallVector< SourcePos, 8 > paramPositions
Definition: type.h:980
void SetEnumerators(const std::vector< Symbol * > &enumerators)
Definition: type.cpp:931
bool IsConstType() const
Definition: type.cpp:2657
const T * CastType(const Type *type)
Definition: type.h:988
const std::string & GetStructName() const
Definition: type.h:748
static bool Equal(const Type *a, const Type *b)
Definition: type.cpp:3619
static const AtomicType * VaryingUInt16
Definition: type.h:351
const SourcePos & GetElementPosition(int i) const
Definition: type.h:745
const bool isTask
Definition: type.h:943
virtual const Type * GetAsVaryingType() const =0
const PointerType * GetAsUnboundVariabilityType() const
Definition: type.cpp:1044
const ArrayType * ResolveUnboundVariability(Variability v) const
Definition: type.cpp:1430
const Type *const child
Definition: type.h:622
const AtomicType * GetAsUnboundVariabilityType() const
Definition: type.cpp:370
std::string Mangle() const
Definition: type.cpp:786
const StructType * GetAsSOAType(int width) const
Definition: type.cpp:2121
const Type * GetBaseType() const
Definition: type.cpp:2085
static const AtomicType * UniformFloat
Definition: type.h:353
static const AtomicType * VaryingInt8
Definition: type.h:347
BasicType
Definition: type.h:328
const UndefinedStructType * GetAsNonConstType() const
Definition: type.cpp:2524
llvm::Type * LLVMType(llvm::LLVMContext *ctx) const
Definition: type.cpp:831
const AtomicType * GetAsVaryingType() const
Definition: type.cpp:340
bool IsIntType() const
Definition: type.cpp:2048
static const AtomicType * UniformInt32
Definition: type.h:349
std::string GetString() const
Definition: type.cpp:1123
const PointerType * GetAsUniformType() const
Definition: type.cpp:1034
Type representing a function (return type + argument types)
Definition: type.h:883
bool IsFloatType() const
Definition: type.cpp:1675
Representation of a program symbol.
Definition: sym.h:63
std::string GetString() const
Definition: type.cpp:1753
const llvm::SmallVector< const Type *, 8 > paramTypes
Definition: type.h:971
Variability(VarType t=Unbound, int w=0)
Definition: type.h:61
llvm::Type * LLVMType(llvm::LLVMContext *ctx) const
Definition: type.cpp:2560
Interface class that defines the type abstraction.
Definition: type.h:101
static const AtomicType * UniformDouble
Definition: type.h:356
const bool isFrozen
Definition: type.h:499
llvm::Type * LLVMType(llvm::LLVMContext *ctx) const
Definition: type.cpp:1199
static const AtomicType * Void
Definition: type.h:357
const bool isUnmasked
Definition: type.h:956
const SourcePos pos
Definition: type.h:826
virtual const Type * GetBaseType() const =0
const Type * GetAsUnboundVariabilityType() const
Definition: type.cpp:2958
const Type * GetBaseType() const
Definition: type.cpp:2937
std::string GetCDeclaration(const std::string &fname) const
Definition: type.cpp:3045
const AtomicType * asUniformType
Definition: type.h:364
StructType(const std::string &name, const llvm::SmallVector< const Type *, 8 > &elts, const llvm::SmallVector< std::string, 8 > &eltNames, const llvm::SmallVector< SourcePos, 8 > &eltPositions, bool isConst, Variability variability, SourcePos pos)
Definition: type.cpp:1947
bool IsReferenceType() const
Definition: type.cpp:241
const std::string & GetEnumName() const
Definition: type.h:400
Expr is the abstract base class that defines the interface that all expression types must implement...
Definition: expr.h:48
bool IsUnsignedType() const
Definition: type.cpp:2459
const AtomicType * GetAsSOAType(int width) const
Definition: type.cpp:379
virtual const Type * GetAsNonConstType() const =0
bool IsIntType() const
Definition: type.cpp:2637
llvm::Type * LLVMType(llvm::LLVMContext *ctx) const
Definition: type.cpp:2255
std::string GetString() const
Definition: type.cpp:2770
virtual const Type * GetAsSOAType(int width) const =0
virtual int GetElementCount() const =0
static const Type * SizeUnsizedArrays(const Type *type, Expr *initExpr)
Definition: type.cpp:1601
VarType type
Definition: type.h:76
const SourcePos & GetParameterSourcePos(int i) const
Definition: type.cpp:3284
const AtomicType * GetAsNonConstType() const
Definition: type.cpp:321
bool IsConstType() const
Definition: type.cpp:1371
const std::string name
Definition: type.h:823
bool isSafe
Definition: type.h:960
std::string GetString() const
Definition: type.cpp:2532
bool operator!=(const VarType &t) const
Definition: type.h:71
const bool isExported
Definition: type.h:947
static const AtomicType * VaryingUInt8
Definition: type.h:350
const Type * GetElementType() const
Definition: type.cpp:1476
bool IsConstType() const
Definition: type.cpp:1012
FunctionType(const Type *returnType, const llvm::SmallVector< const Type *, 8 > &argTypes, SourcePos pos)
Definition: type.cpp:2868
bool IsFloatType() const
Definition: type.cpp:2042
bool IsBoolType() const
Definition: type.cpp:272
virtual const Type * GetAsUnsignedType() const
Definition: type.cpp:3308
static const AtomicType * UniformInt64
Definition: type.h:354
const VectorType * GetAsConstType() const
Definition: type.cpp:1741
const TypeId typeId
Definition: type.h:277
static const AtomicType * UniformInt16
Definition: type.h:348
const ReferenceType * ResolveUnboundVariability(Variability v) const
Definition: type.cpp:2726
bool IsBoolType() const
Definition: type.cpp:653
Variability GetVariability() const
Definition: type.cpp:2607
Main ispc.header file. Defines Target, Globals and Opt classes.
bool IsFloatType() const
Definition: type.cpp:659
const ReferenceType * GetAsUniformType() const
Definition: type.cpp:2695
const Type * GetBaseType() const
Definition: type.cpp:2673
static bool EqualIgnoringConst(const Type *a, const Type *b)
Definition: type.cpp:3625
virtual const Type * GetReferenceTarget() const
Definition: type.cpp:3301
bool IsSOAType() const
Definition: type.h:156
const ReferenceType * asOtherConstType
Definition: type.h:868
llvm::DIType GetDIType(llvm::DIDescriptor scope) const
Definition: type.cpp:1260
const Type * GetAsConstType() const
Definition: type.cpp:2999
const PointerType * GetAsFrozenSlice() const
Definition: type.cpp:1080
const ArrayType * GetAsConstType() const
Definition: type.cpp:1450
Variability GetVariability() const
Definition: type.cpp:2030
llvm::DIType GetDIType(llvm::DIDescriptor scope) const
Definition: type.cpp:2572
std::string Mangle() const
Definition: type.cpp:425
static const AtomicType * VaryingUInt32
Definition: type.h:352
std::string Mangle() const
Definition: type.cpp:1142
int GetNumParameters() const
Definition: type.h:935
bool IsIntType() const
Definition: type.cpp:1681
static const AtomicType * VaryingFloat
Definition: type.h:353
std::string GetCDeclaration(const std::string &name) const
Definition: type.cpp:1524
virtual const Type * ResolveUnboundVariability(Variability v) const =0
static const AtomicType * UniformInt8
Definition: type.h:347
int GetElementCount() const
Definition: type.h:743
const PointerType * ResolveUnboundVariability(Variability v) const
Definition: type.cpp:1088
std::string Mangle() const
Definition: type.cpp:2784
const bool isConst
Definition: type.h:771
const ReferenceType * GetAsConstType() const
Definition: type.cpp:2736
const ReferenceType * GetAsUnboundVariabilityType() const
Definition: type.cpp:2707
const EnumType * GetAsUnboundVariabilityType() const
Definition: type.cpp:725
One-dimensional array type.
Definition: type.h:555
const Variability variability
Definition: type.h:497