1 //===- Argument.h - Argument definitions ------------------------*- 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 // This header file contains definitions for TableGen operation's arguments. 10 // Operation arguments fall into two categories: 11 // 12 // 1. Operands: SSA values operated on by the operation 13 // 2. Attributes: compile-time known properties that have influence over 14 // the operation's behavior 15 // 16 // These two categories are modelled with the unified argument concept in 17 // TableGen because we need similar pattern matching mechanisms for them. 18 // 19 //===----------------------------------------------------------------------===// 20 21 #ifndef MLIR_TABLEGEN_ARGUMENT_H_ 22 #define MLIR_TABLEGEN_ARGUMENT_H_ 23 24 #include "mlir/TableGen/Attribute.h" 25 #include "mlir/TableGen/Type.h" 26 #include "llvm/ADT/PointerUnion.h" 27 #include <string> 28 29 namespace llvm { 30 class StringRef; 31 } // end namespace llvm 32 33 namespace mlir { 34 namespace tblgen { 35 36 // A struct wrapping an op attribute and its name together 37 struct NamedAttribute { 38 llvm::StringRef name; 39 Attribute attr; 40 }; 41 42 // A struct wrapping an op operand/result's constraint and its name together 43 struct NamedTypeConstraint { 44 // Returns true if this operand/result has constraint to be satisfied. 45 bool hasPredicate() const; 46 // Returns true if this is an optional type constraint. This is a special case 47 // of variadic for 0 or 1 type. 48 bool isOptional() const; 49 // Returns true if this operand/result is variadic. 50 bool isVariadic() const; 51 // Returns true if this is a variable length type constraint. This is either 52 // variadic or optional. isVariableLengthNamedTypeConstraint53 bool isVariableLength() const { return isOptional() || isVariadic(); } 54 55 llvm::StringRef name; 56 TypeConstraint constraint; 57 }; 58 59 // Operation argument: either attribute or operand 60 using Argument = llvm::PointerUnion<NamedAttribute *, NamedTypeConstraint *>; 61 62 } // end namespace tblgen 63 } // end namespace mlir 64 65 #endif // MLIR_TABLEGEN_ARGUMENT_H_ 66