Index: mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h =================================================================== --- mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h +++ mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h @@ -88,10 +88,10 @@ Type elementType, unsigned numElements); /// Returns the element type of the array. - Type getElementType(); + Type getElementType() const; /// Returns the number of elements in the array type. - unsigned getNumElements(); + unsigned getNumElements() const; /// Verifies that the type about to be constructed is well-formed. static LogicalResult verify(function_ref emitError, @@ -120,7 +120,7 @@ static bool isValidResultType(Type type); /// Returns whether the function is variadic. - bool isVarArg(); + bool isVarArg() const; /// Gets or creates an instance of LLVM dialect function in the same context /// as the `result` type. @@ -131,17 +131,17 @@ ArrayRef arguments, bool isVarArg = false); /// Returns the result type of the function. - Type getReturnType(); + Type getReturnType() const; /// Returns the number of arguments to the function. - unsigned getNumParams(); + unsigned getNumParams() const; /// Returns `i`-th argument of the function. Asserts on out-of-bounds. - Type getParamType(unsigned i); + Type getParamType(unsigned i) const; /// Returns a list of argument types of the function. - ArrayRef getParams(); - ArrayRef params() { return getParams(); } + ArrayRef getParams() const; + ArrayRef params() const { return getParams(); } /// Verifies that the type about to be constructed is well-formed. static LogicalResult verify(function_ref emitError, @@ -282,22 +282,22 @@ LogicalResult setBody(ArrayRef types, bool isPacked); /// Checks if a struct is packed. - bool isPacked(); + bool isPacked() const; /// Checks if a struct is identified. - bool isIdentified(); + bool isIdentified() const; /// Checks if a struct is opaque. - bool isOpaque(); + bool isOpaque() const; /// Checks if a struct is initialized. - bool isInitialized(); + bool isInitialized() const; /// Returns the name of an identified struct. - StringRef getName(); + StringRef getName() const; /// Returns the list of element types contained in a non-opaque struct. - ArrayRef getBody(); + ArrayRef getBody() const; /// Verifies that the type about to be constructed is well-formed. static LogicalResult verify(function_ref emitError, @@ -325,10 +325,10 @@ static bool isValidElementType(Type type); /// Returns the element type of the vector. - Type getElementType(); + Type getElementType() const; /// Returns the number of elements in the vector. - llvm::ElementCount getElementCount(); + llvm::ElementCount getElementCount() const; /// Verifies that the type about to be constructed is well-formed. static LogicalResult verify(function_ref emitError, @@ -362,10 +362,10 @@ static bool isValidElementType(Type type); /// Returns the element type of the vector. - Type getElementType(); + Type getElementType() const; /// Returns the number of elements in the fixed vector. - unsigned getNumElements(); + unsigned getNumElements() const; /// Verifies that the type about to be constructed is well-formed. static LogicalResult verify(function_ref emitError, @@ -398,12 +398,12 @@ static bool isValidElementType(Type type); /// Returns the element type of the vector. - Type getElementType(); + Type getElementType() const; /// Returns the scaling factor of the number of elements in the vector. The /// vector contains at least the resulting number of elements, or any non-zero /// multiple of this number. - unsigned getMinNumElements(); + unsigned getMinNumElements() const; /// Verifies that the type about to be constructed is well-formed. static LogicalResult verify(function_ref emitError, Index: mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp =================================================================== --- mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp +++ mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp @@ -47,9 +47,11 @@ numElements); } -Type LLVMArrayType::getElementType() { return getImpl()->elementType; } +Type LLVMArrayType::getElementType() const { return getImpl()->elementType; } -unsigned LLVMArrayType::getNumElements() { return getImpl()->numElements; } +unsigned LLVMArrayType::getNumElements() const { + return getImpl()->numElements; +} LogicalResult LLVMArrayType::verify(function_ref emitError, @@ -86,19 +88,21 @@ isVarArg); } -Type LLVMFunctionType::getReturnType() { return getImpl()->getReturnType(); } +Type LLVMFunctionType::getReturnType() const { + return getImpl()->getReturnType(); +} -unsigned LLVMFunctionType::getNumParams() { +unsigned LLVMFunctionType::getNumParams() const { return getImpl()->getArgumentTypes().size(); } -Type LLVMFunctionType::getParamType(unsigned i) { +Type LLVMFunctionType::getParamType(unsigned i) const { return getImpl()->getArgumentTypes()[i]; } -bool LLVMFunctionType::isVarArg() { return getImpl()->isVariadic(); } +bool LLVMFunctionType::isVarArg() const { return getImpl()->isVariadic(); } -ArrayRef LLVMFunctionType::getParams() { +ArrayRef LLVMFunctionType::getParams() const { return getImpl()->getArgumentTypes(); } @@ -361,15 +365,17 @@ return Base::mutate(types, isPacked); } -bool LLVMStructType::isPacked() { return getImpl()->isPacked(); } -bool LLVMStructType::isIdentified() { return getImpl()->isIdentified(); } -bool LLVMStructType::isOpaque() { +bool LLVMStructType::isPacked() const { return getImpl()->isPacked(); } +bool LLVMStructType::isIdentified() const { return getImpl()->isIdentified(); } +bool LLVMStructType::isOpaque() const { return getImpl()->isIdentified() && (getImpl()->isOpaque() || !getImpl()->isInitialized()); } -bool LLVMStructType::isInitialized() { return getImpl()->isInitialized(); } -StringRef LLVMStructType::getName() { return getImpl()->getIdentifier(); } -ArrayRef LLVMStructType::getBody() { +bool LLVMStructType::isInitialized() const { + return getImpl()->isInitialized(); +} +StringRef LLVMStructType::getName() const { return getImpl()->getIdentifier(); } +ArrayRef LLVMStructType::getBody() const { return isIdentified() ? getImpl()->getIdentifiedStructBody() : getImpl()->getTypeList(); } @@ -421,11 +427,11 @@ numElements); } -Type LLVMFixedVectorType::getElementType() { +Type LLVMFixedVectorType::getElementType() const { return static_cast(impl)->elementType; } -unsigned LLVMFixedVectorType::getNumElements() { +unsigned LLVMFixedVectorType::getNumElements() const { return getImpl()->numElements; } @@ -458,11 +464,11 @@ minNumElements); } -Type LLVMScalableVectorType::getElementType() { +Type LLVMScalableVectorType::getElementType() const { return static_cast(impl)->elementType; } -unsigned LLVMScalableVectorType::getMinNumElements() { +unsigned LLVMScalableVectorType::getMinNumElements() const { return getImpl()->numElements; }