Intel® Implicit SPMD Program Compiler (Intel® ISPC)  1.13.0
Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
StructType Class Reference

Representation of a structure holding a number of members. More...

#include <type.h>

Inheritance diagram for StructType:
Inheritance graph
[legend]
Collaboration diagram for StructType:
Collaboration graph
[legend]

Public Member Functions

 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)
 
Variability GetVariability () const
 
bool IsBoolType () const
 
bool IsFloatType () const
 
bool IsIntType () const
 
bool IsUnsignedType () const
 
bool IsConstType () const
 
bool IsDefined () const
 
const TypeGetBaseType () const
 
const StructTypeGetAsVaryingType () const
 
const StructTypeGetAsUniformType () const
 
const StructTypeGetAsUnboundVariabilityType () const
 
const StructTypeGetAsSOAType (int width) const
 
const StructTypeResolveUnboundVariability (Variability v) const
 
const StructTypeGetAsConstType () const
 
const StructTypeGetAsNonConstType () const
 
std::string GetString () const
 
std::string Mangle () const
 
std::string GetCDeclaration (const std::string &name) const
 
llvm::Type * LLVMType (llvm::LLVMContext *ctx) const
 
llvm::DIType * GetDIType (llvm::DIScope *scope) const
 
const TypeGetElementType (const std::string &name) const
 
const TypeGetElementType (int i) const
 
int GetElementNumber (const std::string &name) const
 
const std::string & GetElementName (int i) const
 
int GetElementCount () const
 
const SourcePosGetElementPosition (int i) const
 
const std::string & GetStructName () const
 
const std::string GetCStructName () const
 
- Public Member Functions inherited from Type
bool IsPointerType () const
 
bool IsArrayType () const
 
bool IsReferenceType () const
 
bool IsVoidType () const
 
bool IsNumericType () const
 
bool IsUniformType () const
 
bool IsVaryingType () const
 
bool IsSOAType () const
 
int GetSOAWidth () const
 
bool HasUnboundVariability () const
 
virtual const TypeGetAsUnsignedType () const
 
virtual const TypeGetReferenceTarget () const
 
virtual llvm::Type * LLVMStorageType (llvm::LLVMContext *ctx) const
 

Static Private Member Functions

static bool checkIfCanBeSOA (const StructType *st)
 

Private Attributes

std::string name
 
const llvm::SmallVector< const Type *, 8 > elementTypes
 
const llvm::SmallVector< std::string, 8 > elementNames
 
const llvm::SmallVector< SourcePos, 8 > elementPositions
 
const Variability variability
 
const bool isConst
 
const SourcePos pos
 
llvm::SmallVector< const Type *, 8 > finalElementTypes
 
const StructTypeoppositeConstStructType
 

Additional Inherited Members

- Static Public Member Functions inherited from Type
static bool Equal (const Type *a, const Type *b)
 
static bool EqualIgnoringConst (const Type *a, const Type *b)
 
static const TypeMoreGeneralType (const Type *type0, const Type *type1, SourcePos pos, const char *reason, bool forceVarying=false, int vecSize=0)
 
static bool IsBasicType (const Type *type)
 
- Public Attributes inherited from Type
const TypeId typeId
 
- Protected Member Functions inherited from CollectionType
 CollectionType (TypeId id)
 
- Protected Member Functions inherited from Type
 Type (TypeId id)
 

Detailed Description

Representation of a structure holding a number of members.

Definition at line 650 of file type.h.

Constructor & Destructor Documentation

◆ StructType()

StructType::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 
)

Member Function Documentation

◆ checkIfCanBeSOA()

bool StructType::checkIfCanBeSOA ( const StructType st)
staticprivate

◆ GetAsConstType()

const StructType * StructType::GetAsConstType ( ) const
virtual

Get a const version of this type. If it's already const, then the old Type pointer is returned.

Implements Type.

Definition at line 1720 of file type.cpp.

References elementNames, elementPositions, elementTypes, isConst, name, oppositeConstStructType, pos, StructType(), and variability.

◆ GetAsNonConstType()

const StructType * StructType::GetAsNonConstType ( ) const
virtual

Get a non-const version of this type. If it's already not const, then the old Type pointer is returned.

Implements Type.

Definition at line 1733 of file type.cpp.

References elementNames, elementPositions, elementTypes, isConst, name, oppositeConstStructType, pos, StructType(), and variability.

◆ GetAsSOAType()

const StructType * StructType::GetAsSOAType ( int  width) const
virtual

◆ GetAsUnboundVariabilityType()

const StructType * StructType::GetAsUnboundVariabilityType ( ) const
virtual

Get an instance of the type with unbound variability.

Implements Type.

Definition at line 1688 of file type.cpp.

References elementNames, elementPositions, elementTypes, Type::HasUnboundVariability(), isConst, name, pos, StructType(), and Variability::Unbound.

◆ GetAsUniformType()

const StructType * StructType::GetAsUniformType ( ) const
virtual

Return a "uniform" instance of this type. If the type is already uniform, its "this" pointer will be returned.

Implements Type.

Definition at line 1680 of file type.cpp.

References elementNames, elementPositions, elementTypes, isConst, Type::IsUniformType(), name, pos, StructType(), and Variability::Uniform.

◆ GetAsVaryingType()

const StructType * StructType::GetAsVaryingType ( ) const
virtual

Return a "varying" instance of this type. If the type is already varying, its "this" pointer will be returned.

Implements Type.

Definition at line 1672 of file type.cpp.

References elementNames, elementPositions, elementTypes, isConst, Type::IsVaryingType(), name, pos, StructType(), and Variability::Varying.

Referenced by TypeCastExpr::GetValue().

◆ GetBaseType()

const Type * StructType::GetBaseType ( ) const
virtual

Returns the basic root type of the given type. For example, for an array or short-vector, this returns the element type. For a struct or atomic type, it returns itself.

Implements Type.

Definition at line 1670 of file type.cpp.

◆ GetCDeclaration()

std::string StructType::GetCDeclaration ( const std::string &  name) const
virtual

Returns a string that is the declaration of the same type in C syntax.

Implements Type.

Definition at line 1789 of file type.cpp.

References GetCStructName(), isConst, lShouldPrintName(), Variability::soaWidth, and variability.

◆ GetCStructName()

const std::string StructType::GetCStructName ( ) const

Definition at line 1630 of file type.cpp.

References GetStructName(), lMangleStructName(), name, variability, and Variability::Varying.

Referenced by GetCDeclaration(), and lEmitStructDecl().

◆ GetDIType()

llvm::DIType * StructType::GetDIType ( llvm::DIScope *  scope) const
virtual

Returns the DIType (LLVM's debugging information structure), corresponding to this type.

Implements Type.

Definition at line 1820 of file type.cpp.

References Assert, Globals::ctx, Module::diBuilder, elementNames, elementPositions, elementTypes, SourcePos::first_line, g, SourcePos::GetDIFile(), Type::GetDIType(), GetElementType(), Type::LLVMStorageType(), m, Module::module, name, and pos.

◆ GetElementCount()

int StructType::GetElementCount ( ) const
inlinevirtual

◆ GetElementName()

const std::string& StructType::GetElementName ( int  i) const
inline

Returns the name of the i'th element of the structure.

Definition at line 696 of file type.h.

Referenced by MemberExpr::getCandidateNearMatches(), lCheckForConstStructMember(), lEmitStructDecl(), and lVaryingStructHasUniformMember().

◆ GetElementNumber()

int StructType::GetElementNumber ( const std::string &  name) const

Returns which structure element number (starting from zero) that has the given name. If there is no such element, return -1.

Definition at line 1888 of file type.cpp.

References elementNames.

Referenced by StructMemberExpr::getElementNumber().

◆ GetElementPosition()

const SourcePos& StructType::GetElementPosition ( int  i) const
inline

Definition at line 701 of file type.h.

◆ GetElementType() [1/2]

const Type * StructType::GetElementType ( const std::string &  name) const

Returns the type of the structure element with the given name (if any). Returns NULL if there is no such named element.

Definition at line 1881 of file type.cpp.

References elementNames.

Referenced by checkInit(), GetDIType(), StructMemberExpr::getElementType(), StructMemberExpr::GetType(), IsDefined(), lCheckForConstStructMember(), lContainsPtrToVarying(), lEmitStructDecl(), lRecursiveCheckValidParamType(), lUniformValueToVarying(), lVaryingStructHasUniformMember(), and StructType().

◆ GetElementType() [2/2]

const Type * StructType::GetElementType ( int  i) const
virtual

Returns the type of the i'th structure element. The value of i must be between 0 and NumElements()-1.

Implements CollectionType.

Definition at line 1859 of file type.cpp.

References Assert, elementTypes, Module::errorCount, finalElementTypes, Type::GetAsConstType(), isConst, m, Type::ResolveUnboundVariability(), Variability::Unbound, and variability.

◆ GetString()

std::string StructType::GetString ( ) const
virtual

Returns a text representation of the type (for example, for use in warning and error messages).

Implements Type.

Definition at line 1746 of file type.cpp.

References elementNames, elementTypes, Variability::GetString(), isConst, name, and variability.

Referenced by StructMemberExpr::getElementNumber(), StructMemberExpr::GetType(), lCheckForConstStructMember(), lVaryingStructHasUniformMember(), and AssignExpr::TypeCheck().

◆ GetStructName()

const std::string& StructType::GetStructName ( ) const
inline

Returns the name of the structure type. (e.g. struct Foo -> "Foo".)

Definition at line 704 of file type.h.

Referenced by GetCStructName(), and lCheckTypeEquality().

◆ GetVariability()

Variability StructType::GetVariability ( ) const
virtual

Returns the variability of the type.

Implements Type.

Definition at line 1641 of file type.cpp.

References variability.

◆ IsBoolType()

bool StructType::IsBoolType ( ) const
virtual

Returns true if the underlying type is boolean. In other words, this is true for individual bools and for short-vectors with underlying bool type, but not for arrays of bools.

Implements Type.

Definition at line 1643 of file type.cpp.

◆ IsConstType()

bool StructType::IsConstType ( ) const
virtual

Returns true if this type is 'const'-qualified.

Implements Type.

Definition at line 1651 of file type.cpp.

References isConst.

◆ IsDefined()

bool StructType::IsDefined ( ) const

Definition at line 1653 of file type.cpp.

References GetElementCount(), GetElementType(), and IsDefined().

Referenced by MemberExpr::create(), IsDefined(), and NewExpr::TypeCheck().

◆ IsFloatType()

bool StructType::IsFloatType ( ) const
virtual

Returns true if the underlying type is float or double. In other words, this is true for individual floats/doubles and for short-vectors of them, but not for arrays of them.

Implements Type.

Definition at line 1645 of file type.cpp.

◆ IsIntType()

bool StructType::IsIntType ( ) const
virtual

Returns true if the underlying type is an integer type. In other words, this is true for individual integers and for short-vectors of integer types, but not for arrays of integer types.

Implements Type.

Definition at line 1647 of file type.cpp.

◆ IsUnsignedType()

bool StructType::IsUnsignedType ( ) const
virtual

Returns true if the underlying type is unsigned. In other words, this is true for unsigned integers and short vectors of unsigned integer types.

Implements Type.

Definition at line 1649 of file type.cpp.

◆ LLVMType()

llvm::Type * StructType::LLVMType ( llvm::LLVMContext *  ctx) const
virtual

Returns the LLVM type corresponding to this ispc type.

Implements Type.

Definition at line 1809 of file type.cpp.

References Assert, Module::errorCount, lMangleStructName(), lStructTypeMap, m, name, Variability::Unbound, and variability.

Referenced by FunctionEmitContext::AddElementOffset(), and lEmitStructDecl().

◆ Mangle()

std::string StructType::Mangle ( ) const
virtual

Returns a string that represents the mangled type (for use in mangling function symbol names for function overloading). The various Types implementations of this method should collectively ensure that all of them use mangling schemes that are guaranteed not to clash.

Implements Type.

Definition at line 1787 of file type.cpp.

References isConst, lMangleStruct(), name, and variability.

◆ ResolveUnboundVariability()

const StructType * StructType::ResolveUnboundVariability ( Variability  v) const
virtual

Member Data Documentation

◆ elementNames

const llvm::SmallVector<std::string, 8> StructType::elementNames
private

◆ elementPositions

const llvm::SmallVector<SourcePos, 8> StructType::elementPositions
private

Source file position at which each structure element declaration appeared.

Definition at line 725 of file type.h.

Referenced by checkIfCanBeSOA(), GetAsConstType(), GetAsNonConstType(), GetAsSOAType(), GetAsUnboundVariabilityType(), GetAsUniformType(), GetAsVaryingType(), GetDIType(), ResolveUnboundVariability(), and StructType().

◆ elementTypes

const llvm::SmallVector<const Type *, 8> StructType::elementTypes
private

The types of the struct elements. Note that we store these with uniform/varying exactly as they were declared in the source file. (In other words, even if this struct has a varying qualifier and thus all of its members are going to be widened out to be varying, we still store any members that were declared as uniform as uniform types in the elementTypes array, converting them to varying as needed in the implementation.) This is so that if we later need to make a uniform version of the struct, we've maintained the original information about the member types.

Definition at line 721 of file type.h.

Referenced by checkIfCanBeSOA(), GetAsConstType(), GetAsNonConstType(), GetAsSOAType(), GetAsUnboundVariabilityType(), GetAsUniformType(), GetAsVaryingType(), GetDIType(), GetElementType(), GetString(), ResolveUnboundVariability(), and StructType().

◆ finalElementTypes

llvm::SmallVector<const Type *, 8> StructType::finalElementTypes
mutableprivate

Definition at line 730 of file type.h.

Referenced by GetElementType(), and StructType().

◆ isConst

const bool StructType::isConst
private

◆ name

std::string StructType::name
private

◆ oppositeConstStructType

const StructType* StructType::oppositeConstStructType
mutableprivate

Definition at line 732 of file type.h.

Referenced by GetAsConstType(), GetAsNonConstType(), and StructType().

◆ pos

const SourcePos StructType::pos
private

◆ variability

const Variability StructType::variability
private

The documentation for this class was generated from the following files: