| 460 | } |
| 461 | |
| 462 | StatusOr<Operation*> BuildConstOp(const tflite::TensorT& tensor, |
| 463 | const std::vector<uint8_t>& buffer, |
| 464 | OpBuilder builder, Location loc) { |
| 465 | TF_ASSIGN_OR_RETURN(auto type, GetTensorType(tensor, builder, |
| 466 | /*shapeless_are_scalars=*/true, |
| 467 | /*is_constant=*/true)); |
| 468 | auto shaped_type = type.dyn_cast<mlir::RankedTensorType>(); |
| 469 | if (!shaped_type) { |
| 470 | return errors::Internal("Constant doesn't have a shape"); |
| 471 | } |
| 472 | |
| 473 | auto elem_type = shaped_type.getElementType(); |
| 474 | |
| 475 | mlir::ElementsAttr value; |
| 476 | if (auto float_type = elem_type.dyn_cast<mlir::FloatType>()) { |
| 477 | TF_ASSIGN_OR_RETURN(value, |
| 478 | ConvertFloatBuffer(shaped_type, float_type, buffer)); |
| 479 | } else if (elem_type.isa<mlir::IntegerType>() || |
| 480 | elem_type.isa<QuantizedType>()) { |
| 481 | TF_ASSIGN_OR_RETURN(value, |
| 482 | ConvertIntBuffer(shaped_type, elem_type, buffer)); |
| 483 | } else if (elem_type.isa<mlir::ComplexType>() || |
| 484 | elem_type.isa<mlir::TF::TensorFlowType>()) { |
| 485 | auto dialect = elem_type.getContext()->getRegisteredDialect("tf"); |
| 486 | tensorflow::TensorProto repr = ConvertTfliteConstTensor(tensor, buffer); |
| 487 | std::string mangled = tensorflow::mangling_util::MangleTensor(repr); |
| 488 | |
| 489 | value = mlir::OpaqueElementsAttr::get(dialect, shaped_type, mangled); |
| 490 | } else { |
| 491 | return errors::Unimplemented("Constant of unsupported type"); |
| 492 | } |
| 493 | |
| 494 | if (IsQuantized(tensor)) { |
| 495 | auto op = builder.create<tfl::QConstOp>( |
| 496 | loc, mlir::TypeAttr::get(shaped_type), value); |
| 497 | return op.getOperation(); |
| 498 | } |
| 499 | auto op = builder.create<tfl::ConstOp>(loc, value); |
| 500 | return op.getOperation(); |
| 501 | } |
| 502 | |
| 503 | llvm::SmallVector<mlir::NamedAttribute, 4> ConvertSubgraphIdxsToFunctionAttrs( |
| 504 | tflite::BuiltinOptionsUnion options, |
no test coverage detected