MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / EmitBuildOperator

Function EmitBuildOperator

tensorflow/compiler/mlir/lite/converter_gen.cc:248–272  ·  view source on GitHub ↗

Emits a builder function that returns the packed FlatBuffer object given a general mlir::Operation. The signature of the function is: llvm::Optional > mlir::CreateFlatBufferOperator( mlir::Operation* op, uint32_t opcode_index, const std::vector & operands, const std::vector & results, flatbuffers::FlatBufferBuilder *fbb);

Source from the content-addressed store, hash-verified

246// const std::vector<int32_t>& results,
247// flatbuffers::FlatBufferBuilder *fbb);
248static void EmitBuildOperator(const std::vector<Record *> &defs,
249 raw_ostream *ostream) {
250 raw_ostream &os = *ostream;
251
252 // Signature
253 os << "llvm::Optional<flatbuffers::Offset<tflite::Operator>>\n"
254 "mlir::CreateFlatBufferOperator(mlir::Operation* op, "
255 "uint32_t opcode_index, "
256 "const std::vector<int32_t>& operands,"
257 "const std::vector<int32_t>& results,"
258 "flatbuffers::FlatBufferBuilder *fbb) {\n";
259
260 for (const auto *def : defs) {
261 StringRef op_name = def->getName().drop_front(4);
262
263 // Try to cast to each op case and call the corresponding op builder
264 os << " if (auto tflOp = llvm::dyn_cast<mlir::TFL::" << op_name
265 << ">(op))\n"
266 << " return " << GetOperatorBuilderName(def->getName())
267 << "(tflOp, opcode_index, operands, results, fbb);\n";
268 }
269
270 os << " return llvm::None;\n"
271 "}\n";
272}
273
274// Emit a function that converts a BuiltinOptionsUnion to a vector of attributes
275// Signature:

Callers 1

OperatorWritersMainFunction · 0.70

Calls 2

GetOperatorBuilderNameFunction · 0.70
getNameMethod · 0.45

Tested by

no test coverage detected