1 //===- Types.cpp - MLIR Type Classes --------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "mlir/IR/Types.h" 10 #include "TypeDetail.h" 11 #include "mlir/IR/Diagnostics.h" 12 #include "mlir/IR/Dialect.h" 13 #include "llvm/ADT/Twine.h" 14 15 using namespace mlir; 16 using namespace mlir::detail; 17 18 //===----------------------------------------------------------------------===// 19 // Type 20 //===----------------------------------------------------------------------===// 21 22 Dialect &Type::getDialect() const { 23 return impl->getAbstractType().getDialect(); 24 } 25 26 MLIRContext *Type::getContext() const { return getDialect().getContext(); } 27 28 //===----------------------------------------------------------------------===// 29 // FunctionType 30 //===----------------------------------------------------------------------===// 31 32 FunctionType FunctionType::get(TypeRange inputs, TypeRange results, 33 MLIRContext *context) { 34 return Base::get(context, inputs, results); 35 } 36 37 unsigned FunctionType::getNumInputs() const { return getImpl()->numInputs; } 38 39 ArrayRef<Type> FunctionType::getInputs() const { 40 return getImpl()->getInputs(); 41 } 42 43 unsigned FunctionType::getNumResults() const { return getImpl()->numResults; } 44 45 ArrayRef<Type> FunctionType::getResults() const { 46 return getImpl()->getResults(); 47 } 48 49 //===----------------------------------------------------------------------===// 50 // OpaqueType 51 //===----------------------------------------------------------------------===// 52 53 OpaqueType OpaqueType::get(Identifier dialect, StringRef typeData, 54 MLIRContext *context) { 55 return Base::get(context, dialect, typeData); 56 } 57 58 OpaqueType OpaqueType::getChecked(Identifier dialect, StringRef typeData, 59 MLIRContext *context, Location location) { 60 return Base::getChecked(location, dialect, typeData); 61 } 62 63 /// Returns the dialect namespace of the opaque type. 64 Identifier OpaqueType::getDialectNamespace() const { 65 return getImpl()->dialectNamespace; 66 } 67 68 /// Returns the raw type data of the opaque type. 69 StringRef OpaqueType::getTypeData() const { return getImpl()->typeData; } 70 71 /// Verify the construction of an opaque type. 72 LogicalResult OpaqueType::verifyConstructionInvariants(Location loc, 73 Identifier dialect, 74 StringRef typeData) { 75 if (!Dialect::isValidNamespace(dialect.strref())) 76 return emitError(loc, "invalid dialect namespace '") << dialect << "'"; 77 return success(); 78 } 79