-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce FlowPreprocessing and GlobalOptimization layers to Pipeline.
- Loading branch information
Showing
10 changed files
with
207 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# 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:build_defs.oss.bzl", "iree_compiler_cc_library", "iree_gentbl_cc_library") | ||
|
||
package( | ||
default_visibility = ["//visibility:public"], | ||
features = ["layering_check"], | ||
licenses = ["notice"], # Apache 2.0 | ||
) | ||
|
||
iree_compiler_cc_library( | ||
name = "GlobalOptimization", | ||
srcs = [ | ||
"Passes.cpp", | ||
], | ||
hdrs = [ | ||
"Passes.h", | ||
], | ||
deps = [ | ||
"//compiler/src/iree/compiler/Dialect/Flow/Transforms", | ||
"//compiler/src/iree/compiler/Dialect/Util/Transforms", | ||
"//compiler/src/iree/compiler/Utils", | ||
"@llvm-project//llvm:Support", | ||
"@llvm-project//mlir:ArithDialect", | ||
"@llvm-project//mlir:FuncDialect", | ||
"@llvm-project//mlir:IR", | ||
"@llvm-project//mlir:Pass", | ||
], | ||
) |
32 changes: 32 additions & 0 deletions
32
compiler/src/iree/compiler/GlobalOptimization/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
################################################################################ | ||
# Autogenerated by build_tools/bazel_to_cmake/bazel_to_cmake.py from # | ||
# compiler/src/iree/compiler/GlobalOptimization/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_cc_library( | ||
NAME | ||
GlobalOptimization | ||
HDRS | ||
"Passes.h" | ||
SRCS | ||
"Passes.cpp" | ||
DEPS | ||
LLVMSupport | ||
MLIRArithDialect | ||
MLIRFuncDialect | ||
MLIRIR | ||
MLIRPass | ||
iree::compiler::Dialect::Flow::Transforms | ||
iree::compiler::Dialect::Util::Transforms | ||
iree::compiler::Utils | ||
PUBLIC | ||
) | ||
|
||
### BAZEL_TO_CMAKE_PRESERVES_ALL_CONTENT_BELOW_THIS_LINE ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// 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 | ||
|
||
#include "iree/compiler/GlobalOptimization/Passes.h" | ||
#include "iree/compiler/Dialect/Flow/Transforms/Passes.h" | ||
#include "iree/compiler/Dialect/HAL/Transforms/Passes.h" | ||
#include "iree/compiler/Dialect/Util/Transforms/Passes.h" | ||
#include "iree/compiler/Utils/PassUtils.h" | ||
#include "mlir/Transforms/Passes.h" | ||
|
||
namespace mlir { | ||
namespace iree_compiler { | ||
namespace GlobalOptimization { | ||
|
||
using FunctionLikeNest = MultiOpNest<func::FuncOp, IREE::Util::InitializerOp>; | ||
|
||
void buildGlobalOptimizationPassPipeline( | ||
OpPassManager &mainPassManager, const TransformOptions &transformOptions) { | ||
OpPassManager pipeline(ModuleOp::getOperationName()); | ||
|
||
FunctionLikeNest(pipeline) | ||
// Simplify util.global accesses early on; this can help with dispatch | ||
// region formation as redundant store-loads are removed. | ||
.addPass(IREE::Util::createSimplifyGlobalAccessesPass); | ||
|
||
// Module level cleanup and canonicalization of util.global (and other util | ||
// ops). | ||
pipeline.addPass(IREE::Util::createApplyPatternsPass()); | ||
pipeline.addPass(IREE::Util::createFoldGlobalsPass()); | ||
pipeline.addPass(IREE::Util::createIPOPass()); | ||
|
||
if (transformOptions.constExprHoisting) { | ||
pipeline.addPass(IREE::Util::createHoistIntoGlobalsPass()); | ||
} | ||
|
||
if (transformOptions.buildConstEvalPassPipeline) { | ||
transformOptions.buildConstEvalPassPipeline(pipeline); | ||
} | ||
|
||
if (transformOptions.numericPrecisionReduction) { | ||
pipeline.addPass(IREE::Flow::createInferNumericNarrowingPass()); | ||
pipeline.addPass(IREE::Flow::createOptimizeNumericsPass()); | ||
pipeline.addPass(IREE::Flow::createCleanupNumericNarrowingPass()); | ||
} | ||
|
||
FunctionLikeNest(pipeline) | ||
.addPass(mlir::createCanonicalizerPass) | ||
.addPass(mlir::createCSEPass); | ||
|
||
// Add the whole fixed point iterator. | ||
mainPassManager.addPass( | ||
IREE::Util::createFixedPointIteratorPass(std::move(pipeline))); | ||
} | ||
|
||
} // namespace GlobalOptimization | ||
} // namespace iree_compiler | ||
} // namespace mlir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// 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 | ||
|
||
#ifndef IREE_COMPILER_GLOBALOPTIMIZATION_PASSES_H_ | ||
#define IREE_COMPILER_GLOBALOPTIMIZATION_PASSES_H_ | ||
|
||
#include <functional> | ||
|
||
#include "mlir/Pass/Pass.h" | ||
#include "mlir/Pass/PassManager.h" | ||
|
||
namespace mlir { | ||
namespace iree_compiler { | ||
namespace GlobalOptimization { | ||
|
||
struct TransformOptions : public PassPipelineOptions<TransformOptions> { | ||
// Enables the iree-util-hoist-into-globals pass. This should eventually | ||
// become the default. | ||
bool constExprHoisting = false; | ||
|
||
// Enables passes to perform numeric precision reduction. | ||
bool numericPrecisionReduction = false; | ||
|
||
// Hook to populate a constant evaluation pass pipeline. If nullptr, then | ||
// no passes are added for constant evaluation. This must be injected in | ||
// because constant-evaluators can depend on the whole compiler, of which | ||
// this is a part, and we maintain strict optionality for this component. | ||
std::function<void(OpPassManager &passManager)> buildConstEvalPassPipeline; | ||
}; | ||
|
||
// Subset of the overall pass pipeline for optimizing globals and numerics. | ||
// We may ultimately break this out separately so creating a syntactic | ||
// distinction to keep that as an option. | ||
void buildGlobalOptimizationPassPipeline( | ||
OpPassManager &mainPassManager, const TransformOptions &transformOptions); | ||
|
||
} // namespace GlobalOptimization | ||
} // namespace iree_compiler | ||
} // namespace mlir | ||
|
||
#endif // IREE_COMPILER_GLOBALOPTIMIZATION_PASSES_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters