Emits a function that returns builtin operator code for each TFLite op. The signature of the function is: llvm::Optional mlir::GetBuiltinOpCode(mlir::Operation* op); TODO(hinsu): Consider converting this to a static constant associative container instead of a series of if conditions, if required.
| 216 | // TODO(hinsu): Consider converting this to a static constant associative |
| 217 | // container instead of a series of if conditions, if required. |
| 218 | static void EmitGetBuiltinOpCode(const std::vector<Record *> &defs, |
| 219 | raw_ostream *ostream) { |
| 220 | raw_ostream &os = *ostream; |
| 221 | |
| 222 | os << "llvm::Optional<tflite::BuiltinOperator> " |
| 223 | "mlir::GetBuiltinOpCode(mlir::Operation* op) {\n"; |
| 224 | |
| 225 | for (const auto *def : defs) { |
| 226 | StringRef op_name = def->getName().drop_front(4); |
| 227 | os << " if (isa<mlir::TFL::" << op_name << ">(op))\n" |
| 228 | << " return tflite::BuiltinOperator_" << GetOperatorName(*def) |
| 229 | << ";\n"; |
| 230 | } |
| 231 | |
| 232 | os << " return llvm::None;\n" |
| 233 | "}\n"; |
| 234 | } |
| 235 | |
| 236 | // Emits a builder function that returns the packed FlatBuffer object given |
| 237 | // a general mlir::Operation. |
no test coverage detected