Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move more pass from Flow stage to GlobalOptimization stage. #14707

Merged
merged 14 commits into from
Aug 28, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,6 @@ void buildFlowTransformPassPipeline(OpPassManager &passManager,

FunctionLikeNest(passManager)
// Preprocess the input to a form more amenable for fusion
// - Convert all elementwise ops to Linalg
// - Remove unit-extent dimensions.
.addPass(mlir::createConvertElementwiseToLinalgPass)
.addPass(createGeneralizeLinalgNamedOpsPass)
.addPass(createFuseDequantizationMatmulPass)
.addPass(createFoldUnitExtentDimsPass)
.addPass(createRaiseSpecialOps)
.addPass(createInterchangeGenericOpsPass)
.addPass(createCollapseDimsPass)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ iree_lit_test_suite(
"tensor_pad_to_tensor_insert_slice.mlir",
"top_level_scf_to_cfg.mlir",
"transform_dispatch_region_formation.mlir",
"transformation_pipeline.mlir",
"verify_input_ir.mlir",
],
include = ["*.mlir"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ iree_lit_test_suite(
"tensor_pad_to_tensor_insert_slice.mlir"
"top_level_scf_to_cfg.mlir"
"transform_dispatch_region_formation.mlir"
"transformation_pipeline.mlir"
"verify_input_ir.mlir"
TOOLS
FileCheck
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: iree-opt --iree-flow-transformation-pipeline --split-input-file %s | FileCheck %s
// TODO(hanchung): Split the transformation pipeline tests into two mlir files.
// RUN: iree-opt --iree-global-optimization-transformation-pipeline --iree-flow-transformation-pipeline --split-input-file %s | FileCheck %s

#map = affine_map<(d0, d1) -> (d0)>
#map1 = affine_map<(d0, d1) -> (d1)>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ iree_compiler_cc_library(
"@llvm-project//mlir:FuncDialect",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:LinalgTransforms",
"@llvm-project//mlir:MemRefTransforms",
"@llvm-project//mlir:Pass",
"@llvm-project//mlir:Transforms",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ iree_cc_library(
MLIRFuncDialect
MLIRIR
MLIRLinalgTransforms
MLIRMemRefTransforms
MLIRPass
MLIRTransforms
iree::compiler::Dialect::Flow::Transforms
Expand Down
16 changes: 14 additions & 2 deletions compiler/src/iree/compiler/GlobalOptimization/Passes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "iree/compiler/Utils/PassUtils.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/Linalg/Passes.h"
#include "mlir/Dialect/MemRef/Transforms/Passes.h"
#include "mlir/Transforms/Passes.h"

namespace mlir {
Expand Down Expand Up @@ -51,12 +52,23 @@ void buildGlobalOptimizationPassPipeline(
mainPassManager.addPass(IREE::Flow::createEraseUnusedLinalgOperands());

// Expand tensor shapes into SSA values and optimize the whole program.
// The more we are able to equate shape dimensions at this level the better
// our fusions will be.
// The more we are able to equate shape dimensions at this level the
// better our fusions will be.
FunctionLikeNest(mainPassManager)
.addPass(IREE::Flow::createTopLevelSCFToCFGPass);
mainPassManager.addPass(IREE::Flow::createExpandTensorShapesPass());

FunctionLikeNest(mainPassManager)
// Preprocess the input to a form more amenable for fusion
// - Convert all elementwise ops to Linalg
// - Remove unit-extent dimensions.
.addPass(mlir::createConvertElementwiseToLinalgPass)
.addPass(IREE::Flow::createGeneralizeLinalgNamedOpsPass)
.addPass(IREE::Flow::createFuseDequantizationMatmulPass)
.addPass(IREE::Flow::createFoldUnitExtentDimsPass)
.addPass(mlir::createCanonicalizerPass)
.addPass(mlir::createCSEPass);

OpPassManager pipeline(ModuleOp::getOperationName());
FunctionLikeNest(pipeline)
// Simplify util.global accesses early on; this can help with dispatch
Expand Down
28 changes: 28 additions & 0 deletions compiler/src/iree/compiler/GlobalOptimization/test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2023 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")

package(
features = ["layering_check"],
licenses = ["notice"], # Apache 2.0
)

iree_lit_test_suite(
name = "lit",
srcs = enforce_glob(
[
"transformation_pipeline.mlir",
],
include = ["*.mlir"],
),
cfg = "//compiler:lit.cfg.py",
tools = [
"//tools:iree-opt",
"@llvm-project//llvm:FileCheck",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
################################################################################
# Autogenerated by build_tools/bazel_to_cmake/bazel_to_cmake.py from #
# compiler/src/iree/compiler/GlobalOptimization/test/BUILD.bazel #
# #
# Use iree_cmake_extra_content from iree/build_defs.oss.bzl to add arbitrary #
# CMake-only content. #
# #
# To disable autogeneration for this file entirely, delete this header. #
################################################################################

iree_add_all_subdirs()

iree_lit_test_suite(
NAME
lit
SRCS
"transformation_pipeline.mlir"
TOOLS
FileCheck
iree-opt
)

### BAZEL_TO_CMAKE_PRESERVES_ALL_CONTENT_BELOW_THIS_LINE ###
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: iree-opt --split-input-file --iree-flow-transformation-pipeline %s | FileCheck %s
// RUN: iree-opt --split-input-file --iree-global-optimization-transformation-pipeline %s | FileCheck %s

// CHECK-LABEL: @empty
func.func @empty() {
Expand Down
Loading