1 //===- Type.h - Type class --------------------------------------*- C++ -*-===// 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 // Type wrapper to simplify using TableGen Record defining a MLIR Type. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef MLIR_TABLEGEN_TYPE_H_ 14 #define MLIR_TABLEGEN_TYPE_H_ 15 16 #include "mlir/Support/LLVM.h" 17 #include "mlir/TableGen/Constraint.h" 18 #include "mlir/TableGen/Dialect.h" 19 20 namespace llvm { 21 class DefInit; 22 class Record; 23 } // end namespace llvm 24 25 namespace mlir { 26 namespace tblgen { 27 28 // Wrapper class with helper methods for accessing Type constraints defined in 29 // TableGen. 30 class TypeConstraint : public Constraint { 31 public: 32 explicit TypeConstraint(const llvm::Record *record); 33 explicit TypeConstraint(const llvm::DefInit *init); 34 classof(const Constraint * c)35 static bool classof(const Constraint *c) { return c->getKind() == CK_Type; } 36 37 // Returns true if this is an optional type constraint. 38 bool isOptional() const; 39 40 // Returns true if this is a variadic type constraint. 41 bool isVariadic() const; 42 43 // Returns true if this is a variable length type constraint. This is either 44 // variadic or optional. isVariableLength()45 bool isVariableLength() const { return isOptional() || isVariadic(); } 46 47 // Returns the builder call for this constraint if this is a buildable type, 48 // returns None otherwise. 49 Optional<StringRef> getBuilderCall() const; 50 }; 51 52 // Wrapper class with helper methods for accessing Types defined in TableGen. 53 class Type : public TypeConstraint { 54 public: 55 explicit Type(const llvm::Record *record); 56 57 // Returns the description of the type. 58 StringRef getTypeDescription() const; 59 60 // Returns the dialect for the type if defined. 61 Dialect getDialect() const; 62 }; 63 64 } // end namespace tblgen 65 } // end namespace mlir 66 67 #endif // MLIR_TABLEGEN_TYPE_H_ 68