From 23d9a2b49d12ced9d8291f1097af92ae067bd4a6 Mon Sep 17 00:00:00 2001 From: Jacques Pienaar Date: Fri, 29 Jan 2021 16:51:37 -0800 Subject: [PATCH] Remove unneeded copies now that int64 and int64_t are the same Just removed a couple of obvious ones. Larger/more uniform update coming later. PiperOrigin-RevId: 354637425 Change-Id: If7ae27acf47c81f1a39eb9120ddbfd0bae828a15 --- .../mlir/lite/transforms/lower_static_tensor_list.cc | 8 +------- .../mlir/tensorflow/utils/shape_inference_utils.cc | 8 +------- .../compiler/mlir/utils/array_container_utils.h | 5 ----- tensorflow/compiler/mlir/xla/ir/mlir_hlo_builder.cc | 12 ++++-------- 4 files changed, 6 insertions(+), 27 deletions(-) diff --git a/tensorflow/compiler/mlir/lite/transforms/lower_static_tensor_list.cc b/tensorflow/compiler/mlir/lite/transforms/lower_static_tensor_list.cc index 7194e73ca28..554c7e0bfa3 100644 --- a/tensorflow/compiler/mlir/lite/transforms/lower_static_tensor_list.cc +++ b/tensorflow/compiler/mlir/lite/transforms/lower_static_tensor_list.cc @@ -216,14 +216,8 @@ struct ConvertConst : public OpConversionPattern { // If the list is empty, directly create the final result instead of // creating the tf.Pack op. tf.Pack op requires at least one operand. if (tensors.empty()) { - absl::InlinedVector tf_shape; - tf_shape.reserve(result_shape.size()); - for (int64_t dim : result_shape) { - tf_shape.push_back(dim); - } - tensorflow::Tensor tensor(list->element_dtype, - tensorflow::TensorShape(tf_shape)); + tensorflow::TensorShape(result_shape)); auto attr_or = tensorflow::ConvertTensor(tensor, &rewriter); if (!attr_or.ok()) return failure(); rewriter.replaceOpWithNewOp(op, attr_or.ValueOrDie()); diff --git a/tensorflow/compiler/mlir/tensorflow/utils/shape_inference_utils.cc b/tensorflow/compiler/mlir/tensorflow/utils/shape_inference_utils.cc index 6b97aba1016..2aebfd2c443 100644 --- a/tensorflow/compiler/mlir/tensorflow/utils/shape_inference_utils.cc +++ b/tensorflow/compiler/mlir/tensorflow/utils/shape_inference_utils.cc @@ -56,7 +56,6 @@ limitations under the License. #define DEBUG_TYPE "tf-shape-inference-utils" -using ::tensorflow::int64; using tensorflow::shape_inference::DimensionHandle; using tensorflow::shape_inference::InferenceContext; using tensorflow::shape_inference::ShapeHandle; @@ -83,12 +82,7 @@ NamedAttrList GetAllAttributesFromOperation(Operation* op) { // Extracts a PartialTensorShape from the MLIR type. Optional GetShapeFromMlirType(Type t) { if (auto ranked_type = t.dyn_cast()) { - // Convert the MLIR shape indices (int64_t) to TensorFlow indices - // (int64). - ArrayRef shape = ranked_type.getShape(); - SmallVector tf_shape(shape.begin(), shape.end()); - return tensorflow::PartialTensorShape( - MutableArrayRefToSpan(tf_shape)); + return tensorflow::PartialTensorShape(ranked_type.getShape()); } return None; } diff --git a/tensorflow/compiler/mlir/utils/array_container_utils.h b/tensorflow/compiler/mlir/utils/array_container_utils.h index c1a898185d9..80fa14e294c 100644 --- a/tensorflow/compiler/mlir/utils/array_container_utils.h +++ b/tensorflow/compiler/mlir/utils/array_container_utils.h @@ -41,11 +41,6 @@ inline absl::Span ArrayRefToSpan(llvm::ArrayRef ref) { return absl::Span(ref.data(), ref.size()); } -template -inline absl::Span MutableArrayRefToSpan(llvm::MutableArrayRef ref) { - return absl::Span(ref.data(), ref.size()); -} - } // namespace mlir #endif // TENSORFLOW_COMPILER_MLIR_UTILS_ARRAY_CONTAINER_UTILS_H_ diff --git a/tensorflow/compiler/mlir/xla/ir/mlir_hlo_builder.cc b/tensorflow/compiler/mlir/xla/ir/mlir_hlo_builder.cc index 2f1320a548f..6cc053914e0 100644 --- a/tensorflow/compiler/mlir/xla/ir/mlir_hlo_builder.cc +++ b/tensorflow/compiler/mlir/xla/ir/mlir_hlo_builder.cc @@ -49,16 +49,12 @@ static mlir::DenseIntElementsAttr GetI64ElementsAttr( absl::Span values, mlir::Builder* builder) { auto ty = mlir::RankedTensorType::get({static_cast(values.size())}, builder->getIntegerType(64)); - llvm::SmallVector mlir_values; - mlir_values.reserve(values.size()); - for (const auto& value : values) { - mlir_values.push_back(value); - } - return mlir::DenseIntElementsAttr::get(ty, mlir_values); + return mlir::DenseIntElementsAttr::get( + ty, llvm::makeArrayRef(values.data(), values.size())); } static mlir::DenseIntElementsAttr ConvertPadding( - absl::Span> padding, + absl::Span> padding, mlir::Builder* builder) { llvm::SmallVector elements; elements.reserve(padding.size() * 2); @@ -80,7 +76,7 @@ StatusOr MlirHloBuilder::MakeXlaOp(mlir::Value val) { return InvalidArgument("unsupported type: %s", ToString(ty).c_str()); } - int64 handle = reinterpret_cast(val.getAsOpaquePointer()); + int64_t handle = reinterpret_cast(val.getAsOpaquePointer()); handle_to_shape_[handle] = std::move(shape); return XlaOp(handle, this); }