[Mlir-commits] [mlir] Fixes in 'tosa.reshape' lowering and folder (PR #85798)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Mar 19 07:43:32 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 276847a65af67bdc4eb79989f196d1968cb50ae6 482e127e33011dd25c6a9468255cafbcd9b28259 -- mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp b/mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp
index 62ed41ebda..2bda5829ca 100644
--- a/mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp
+++ b/mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp
@@ -24,16 +24,18 @@
 using namespace mlir;
 using namespace tosa;
 
-static Value getIndexConstant(OpBuilder& builder, Location loc, int64_t index) {
+static Value getIndexConstant(OpBuilder &builder, Location loc, int64_t index) {
   return builder.create<arith::ConstantIndexOp>(loc, index);
 }
 
 // Return the total size of the given input tensor.
-static Value getTensorSize(OpBuilder& builder, Location loc, TypedValue<TensorType> input) {
+static Value getTensorSize(OpBuilder &builder, Location loc,
+                           TypedValue<TensorType> input) {
   // If the input tensor is statically shaped, return its size as a constant.
   if (input.getType().hasStaticShape()) {
     auto shape = input.getType().getShape();
-    auto size = std::accumulate(shape.begin(), shape.end(), 1, std::multiplies());
+    auto size =
+        std::accumulate(shape.begin(), shape.end(), 1, std::multiplies());
     return getIndexConstant(builder, loc, size);
   }
 
@@ -41,10 +43,10 @@ static Value getTensorSize(OpBuilder& builder, Location loc, TypedValue<TensorTy
   // a 1D tensor and get its size.
   auto rank = input.getType().getRank();
   auto elementType = input.getType().getElementType();
-  auto collapsedType = RankedTensorType::get({ShapedType::kDynamic}, elementType);
+  auto collapsedType =
+      RankedTensorType::get({ShapedType::kDynamic}, elementType);
   auto reassociationIndices = SmallVector<ReassociationIndices>{
-    llvm::to_vector(llvm::seq<int64_t>(rank))
-  };
+      llvm::to_vector(llvm::seq<int64_t>(rank))};
   auto collapsed = builder.create<tensor::CollapseShapeOp>(
       loc, collapsedType, input, reassociationIndices);
   return builder.create<tensor::DimOp>(loc, collapsed, 0);
@@ -101,14 +103,14 @@ public:
     // Create list of values for new shape
     SmallVector<Value> newShapeVector(reshape.getNewShape().size());
     for (auto [index, size] : llvm::enumerate(reshape.getNewShape())) {
-      newShapeVector[index] = size == -1 ?
-          getReshapePlaceholderDimSize(rewriter, reshape, index) :
-          getIndexConstant(rewriter, loc, size);
+      newShapeVector[index] =
+          size == -1 ? getReshapePlaceholderDimSize(rewriter, reshape, index)
+                     : getIndexConstant(rewriter, loc, size);
     }
 
     // Reshape tensor
-    auto newShapeTensor = rewriter.createOrFold<tensor::FromElementsOp>(
-        loc, newShapeVector);
+    auto newShapeTensor =
+        rewriter.createOrFold<tensor::FromElementsOp>(loc, newShapeVector);
     rewriter.replaceOpWithNewOp<tensor::ReshapeOp>(
         reshape, reshape.getResult().getType(), input, newShapeTensor);
     return success();
@@ -297,10 +299,7 @@ struct ConcatConverter : public OpConversionPattern<tosa::ConcatOp> {
 
 void mlir::tosa::populateTosaToTensorConversionPatterns(
     RewritePatternSet *patterns) {
-  patterns->add<
-    ConcatConverter,
-    PadConverter,
-    ReshapeConverter,
-    SliceConverter
-  >(patterns->getContext());
+  patterns
+      ->add<ConcatConverter, PadConverter, ReshapeConverter, SliceConverter>(
+          patterns->getContext());
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/85798


More information about the Mlir-commits mailing list