| 933 | } |
| 934 | |
| 935 | Optional<BufferOffset<tflite::Operator>> Translator::BuildOperator( |
| 936 | Operation* inst, const std::vector<int32_t>& operands, |
| 937 | const std::vector<int32_t>& results) { |
| 938 | const auto* dialect = inst->getDialect(); |
| 939 | if (!dialect) { |
| 940 | inst->emitOpError("dialect is not registered"); |
| 941 | return llvm::None; |
| 942 | } |
| 943 | |
| 944 | // If TFLite built in op, create operator as a builtin op. |
| 945 | if (dialect == tfl_dialect_) { |
| 946 | // Only if built-in TFLite op emission is enabled, would legalization have |
| 947 | // converted any TF->TFL. |
| 948 | if (!enabled_op_types_.contains(OpType::kTfliteBuiltin)) { |
| 949 | return inst->emitOpError( |
| 950 | "is a TFLite builtin op but builtin emission is not enabled"), |
| 951 | llvm::None; |
| 952 | } |
| 953 | |
| 954 | auto builtin_code = GetBuiltinOpCode(inst); |
| 955 | if (!builtin_code) { |
| 956 | if (auto verify_op = dyn_cast<mlir::TFL::NumericVerifyOp>(inst)) { |
| 957 | return BuildNumericVerifyOperator(verify_op, operands, results); |
| 958 | } |
| 959 | if (auto conv_transpose_bias_op = |
| 960 | dyn_cast<mlir::TFL::Convolution2DTransposeBiasOp>(inst)) { |
| 961 | return BuildConvolution2DTransposeBiasOperator( |
| 962 | inst, conv_transpose_bias_op, operands, results); |
| 963 | } |
| 964 | if (auto max_pooling_with_arg_max_op = |
| 965 | dyn_cast<mlir::TFL::MaxPoolingWithArgMax2DOp>(inst)) { |
| 966 | return BuildMaxPoolingWithArgMax2DOperator( |
| 967 | inst, max_pooling_with_arg_max_op, operands, results); |
| 968 | } |
| 969 | if (auto max_unpooling_op = dyn_cast<mlir::TFL::MaxUnpooling2DOp>(inst)) { |
| 970 | return BuildMaxUnpooling2DOperator(inst, max_unpooling_op, operands, |
| 971 | results); |
| 972 | } |
| 973 | if (auto whileOp = dyn_cast<mlir::TFL::WhileOp>(inst)) { |
| 974 | if (inst->getNumOperands() != inst->getNumResults()) { |
| 975 | inst->emitOpError( |
| 976 | "number of operands and results don't match, only canonical " |
| 977 | "TFL While supported"); |
| 978 | return llvm::None; |
| 979 | } |
| 980 | return BuildWhileOperator(whileOp, operands, results); |
| 981 | } |
| 982 | |
| 983 | inst->emitOpError("is not a supported TFLite op"); |
| 984 | return llvm::None; |
| 985 | } |
| 986 | |
| 987 | std::string op_name = inst->getName().getStringRef().str(); |
| 988 | uint32_t opcode_index = GetOpcodeIndex(op_name, *builtin_code); |
| 989 | auto offset = CreateFlatBufferOperator(inst, opcode_index, operands, |
| 990 | results, &builder_); |
| 991 | if (!offset) { |
| 992 | inst->emitOpError("is not a supported TFLite op"); |
nothing calls this directly
no test coverage detected