| 1 | //===- OpGenHelpers.h - MLIR operation generator helpers --------*- 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 file defines helpers used in the op generators. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef MLIR_TOOLS_MLIRTBLGEN_OPGENHELPERS_H_ |
| 14 | #define MLIR_TOOLS_MLIRTBLGEN_OPGENHELPERS_H_ |
| 15 | |
| 16 | #include "mlir/Support/LLVM.h" |
| 17 | #include "mlir/TableGen/Dialect.h" |
| 18 | #include "llvm/TableGen/Record.h" |
| 19 | #include <string> |
| 20 | #include <vector> |
| 21 | |
| 22 | namespace mlir { |
| 23 | namespace tblgen { |
| 24 | /// Returns all the op definitions filtered by the user. The filtering is via |
| 25 | /// command-line options "op-include-regex", "op-exclude-regex" and |
| 26 | /// "op-partition". If `otherPartitionDefs` is non-null, it is set to the op |
| 27 | /// definitions that are only filtered out by "op-partition". Verifies the op |
| 28 | /// partitions if "op-partition" is set. |
| 29 | std::vector<const llvm::Record *> getRequestedOpDefinitions( |
| 30 | const llvm::RecordKeeper &records, |
| 31 | std::vector<const llvm::Record *> *otherPartitionDefs = nullptr); |
| 32 | |
| 33 | /// Checks whether `str` is a Python keyword or would shadow builtin function. |
| 34 | /// Regenerate using python -c"print(set(sorted(__import__('keyword').kwlist)))" |
| 35 | bool isPythonReserved(llvm::StringRef str); |
| 36 | |
| 37 | /// Shard the op definitions into the number of shards set by "op-shard-count". |
| 38 | void shardOpDefinitions( |
| 39 | ArrayRef<const llvm::Record *> defs, |
| 40 | SmallVectorImpl<ArrayRef<const llvm::Record *>> &shardedDefs); |
| 41 | |
| 42 | /// Returns the op partition set by "op-partition", or an empty string if ops |
| 43 | /// are not generated by partition. |
| 44 | StringRef getSpecifiedOpPartition(); |
| 45 | |
| 46 | /// Returns the name of the partition of op `def`, or an empty string if the op |
| 47 | /// is in no partition. |
| 48 | StringRef getOpPartitionName(const llvm::Record &def); |
| 49 | |
| 50 | /// Returns the name of the function that registers the ops of `dialect` in op |
| 51 | /// partition `partition`, or the ops of all its partitions if `partition` is |
| 52 | /// empty. |
| 53 | std::string getOpRegistrationHookName(const Dialect &dialect, |
| 54 | StringRef partition = "" ); |
| 55 | } // namespace tblgen |
| 56 | } // namespace mlir |
| 57 | |
| 58 | #endif // MLIR_TOOLS_MLIRTBLGEN_OPGENHELPERS_H_ |
| 59 | |