-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][transform] LISH: Add transform op #70630
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
Merged
matthias-springer
merged 1 commit into
llvm:main
from
matthias-springer:lish_transform_op
Nov 5, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
add_subdirectory(IR) | ||
add_subdirectory(LoopExtension) | ||
add_subdirectory(PDLExtension) | ||
add_subdirectory(Transforms) |
6 changes: 6 additions & 0 deletions
6
mlir/include/mlir/Dialect/Transform/LoopExtension/CMakeLists.txt
This file contains hidden or 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,6 @@ | ||
set(LLVM_TARGET_DEFINITIONS LoopExtensionOps.td) | ||
mlir_tablegen(LoopExtensionOps.h.inc -gen-op-decls) | ||
mlir_tablegen(LoopExtensionOps.cpp.inc -gen-op-defs) | ||
add_public_tablegen_target(MLIRTransformDialectLoopExtensionOpsIncGen) | ||
|
||
add_mlir_doc(LoopExtensionOps LoopExtensionOps Dialects/ -gen-op-doc) |
16 changes: 16 additions & 0 deletions
16
mlir/include/mlir/Dialect/Transform/LoopExtension/LoopExtension.h
This file contains hidden or 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,16 @@ | ||
//===- LoopExtension.h - Loop extension for Transform dialect ---*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
namespace mlir { | ||
class DialectRegistry; | ||
|
||
namespace transform { | ||
/// Registers the loop extension of the Transform dialect in the given registry. | ||
void registerLoopExtension(DialectRegistry &dialectRegistry); | ||
} // namespace transform | ||
} // namespace mlir |
23 changes: 23 additions & 0 deletions
23
mlir/include/mlir/Dialect/Transform/LoopExtension/LoopExtensionOps.h
This file contains hidden or 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,23 @@ | ||
//===- LoopExtensionOps.h - Loop ext. for Transform dialect -----*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, 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 MLIR_DIALECT_TRANSFORM_LOOPEXTENSION_LOOPEXTENSIONOPS_H | ||
#define MLIR_DIALECT_TRANSFORM_LOOPEXTENSION_LOOPEXTENSIONOPS_H | ||
|
||
#include "mlir/Bytecode/BytecodeOpInterface.h" | ||
#include "mlir/Dialect/Transform/IR/TransformDialect.h" | ||
#include "mlir/Dialect/Transform/IR/TransformInterfaces.h" | ||
#include "mlir/IR/OpDefinition.h" | ||
#include "mlir/IR/OpImplementation.h" | ||
#include "mlir/Interfaces/LoopLikeInterface.h" | ||
#include "mlir/Interfaces/SideEffectInterfaces.h" | ||
|
||
#define GET_OP_CLASSES | ||
#include "mlir/Dialect/Transform/LoopExtension/LoopExtensionOps.h.inc" | ||
|
||
#endif // MLIR_DIALECT_TRANSFORM_LOOPEXTENSION_LOOPEXTENSIONOPS_H |
76 changes: 76 additions & 0 deletions
76
mlir/include/mlir/Dialect/Transform/LoopExtension/LoopExtensionOps.td
This file contains hidden or 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,76 @@ | ||
//===- LoopExtensionOps.td - Transform dialect operations --*- tablegen -*-===// | ||
// | ||
// Part of the LLVM Project, 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 MLIR_DIALECT_TRANSFORM_LOOPEXTENSION_LOOPEXTENSIONOPS | ||
#define MLIR_DIALECT_TRANSFORM_LOOPEXTENSION_LOOPEXTENSIONOPS | ||
|
||
include "mlir/Dialect/Transform/IR/TransformDialect.td" | ||
include "mlir/Dialect/Transform/IR/TransformInterfaces.td" | ||
include "mlir/Interfaces/SideEffectInterfaces.td" | ||
|
||
def HoistLoopInvariantSubsetsOp | ||
: TransformDialectOp<"loop.hoist_loop_invariant_subsets", | ||
[TransformOpInterface, TransformEachOpTrait, | ||
DeclareOpInterfaceMethods<MemoryEffectsOpInterface>, | ||
ReportTrackingListenerFailuresOpTrait]> { | ||
let summary = "Hoist loop invariant subset ops"; | ||
let description = [{ | ||
This transform hoists loop-invariant subset ops out of the targeted | ||
loop-like op. It looks for matching subset extraction/insertion op pairs and | ||
hoists them. The loop body operates on a newly introduced region iter_arg. | ||
|
||
Subset ops are hoisted only from the targeted op. If subset ops should be | ||
hoisted from an entire loop nest, this transformation must be applied to | ||
each loop-like op of the loop nest, starting with the innermost loop and | ||
ending with the outermost loop. | ||
|
||
Example: | ||
``` | ||
%r = scf.for ... iter_args(%t = %a) -> (tensor<?xf32>) { | ||
%0 = tensor.extract_slice %t[0][5][1] : tensor<?xf32> to tensor<5xf32> | ||
%1 = "test.foo"(%0) : (tensor<5xf32>) -> (tensor<5xf32>) | ||
%2 = tensor.insert_slice %1 into %t[0][5][1] | ||
: tensor<5xf32> into tensor<?xf32> | ||
scf.yield %2 : tensor<?xf32> | ||
} | ||
``` | ||
Is transformed to: | ||
``` | ||
%0 = tensor.extract_slice %a[0][5][1] : tensor<?xf32> to tensor<5xf32> | ||
%new_loop:2 = scf.for ... iter_args(%t = %a, %h = %0) -> (tensor<?xf32>) { | ||
%1 = "test.foo"(%h) : (tensor<5xf32>) -> (tensor<5xf32>) | ||
scf.yield %t, %2 : tensor<?xf32>, tensor<5xf32> | ||
} | ||
%r = tensor.insert_slice %new_loop#1 into %new_loop#0 | ||
: tensor<5xf32> into tensor<?xf32> | ||
``` | ||
|
||
Subset ops are hoisted only if there are no conflicting subset ops. E.g., | ||
if there were a second overlapping extraction in the above example, no ops | ||
could be hoisted safely. | ||
|
||
This transform reads the target handle and modifies the payload. This | ||
transform does not invalidate any handles, but loop-like ops are replaced | ||
with new loop-like ops when a subset op is hoisted. The transform rewriter | ||
updates all handles accordingly. | ||
}]; | ||
|
||
let arguments = (ins TransformHandleTypeInterface:$target); | ||
let results = (outs); | ||
let assemblyFormat = "$target attr-dict `:` type($target)"; | ||
|
||
let extraClassDeclaration = [{ | ||
::mlir::DiagnosedSilenceableFailure applyToOne( | ||
::mlir::transform::TransformRewriter &rewriter, | ||
::mlir::LoopLikeOpInterface loopLikeOp, | ||
::mlir::transform::ApplyToEachResultList &results, | ||
::mlir::transform::TransformState &state); | ||
}]; | ||
} | ||
|
||
#endif // MLIR_DIALECT_TRANSFORM_LOOPEXTENSION_LOOPEXTENSIONOPS |
2 changes: 1 addition & 1 deletion
2
mlir/include/mlir/Dialect/Transform/PDLExtension/PDLExtensionOps.td
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
add_subdirectory(IR) | ||
add_subdirectory(LoopExtension) | ||
add_subdirectory(PDLExtension) | ||
add_subdirectory(Transforms) | ||
add_subdirectory(Utils) |
This file contains hidden or 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,13 @@ | ||
add_mlir_dialect_library(MLIRTransformLoopExtension | ||
LoopExtension.cpp | ||
LoopExtensionOps.cpp | ||
|
||
DEPENDS | ||
MLIRTransformDialectLoopExtensionOpsIncGen | ||
|
||
LINK_LIBS PUBLIC | ||
MLIRIR | ||
MLIRLoopLikeInterface | ||
MLIRTransformDialect | ||
MLIRTransforms | ||
) |
34 changes: 34 additions & 0 deletions
34
mlir/lib/Dialect/Transform/LoopExtension/LoopExtension.cpp
This file contains hidden or 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,34 @@ | ||
//===- LoopExtension.cpp - Loop extension for the Transform dialect -------===// | ||
// | ||
// Part of the LLVM Project, 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 "mlir/Dialect/Transform/LoopExtension/LoopExtension.h" | ||
|
||
#include "mlir/Dialect/Transform/IR/TransformDialect.h" | ||
#include "mlir/Dialect/Transform/LoopExtension/LoopExtensionOps.h" | ||
#include "mlir/IR/DialectRegistry.h" | ||
|
||
using namespace mlir; | ||
|
||
namespace { | ||
/// Loop extension of the Transform dialect. This provides "core" transform | ||
/// operations for loop-like ops. | ||
class LoopExtension | ||
: public transform::TransformDialectExtension<LoopExtension> { | ||
public: | ||
void init() { | ||
registerTransformOps< | ||
#define GET_OP_LIST | ||
#include "mlir/Dialect/Transform/LoopExtension/LoopExtensionOps.cpp.inc" | ||
>(); | ||
} | ||
}; | ||
} // namespace | ||
|
||
void mlir::transform::registerLoopExtension(DialectRegistry &dialectRegistry) { | ||
dialectRegistry.addExtensions<LoopExtension>(); | ||
} |
36 changes: 36 additions & 0 deletions
36
mlir/lib/Dialect/Transform/LoopExtension/LoopExtensionOps.cpp
This file contains hidden or 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,36 @@ | ||
//===- LoopExtensionOps.cpp - Loop extension for the Transform dialect ----===// | ||
// | ||
// Part of the LLVM Project, 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 "mlir/Dialect/Transform/LoopExtension/LoopExtensionOps.h" | ||
|
||
#include "mlir/IR/OpImplementation.h" | ||
#include "mlir/IR/PatternMatch.h" | ||
#include "mlir/Transforms/LoopInvariantCodeMotionUtils.h" | ||
|
||
using namespace mlir; | ||
|
||
#define GET_OP_CLASSES | ||
#include "mlir/Dialect/Transform/LoopExtension/LoopExtensionOps.cpp.inc" | ||
|
||
//===----------------------------------------------------------------------===// | ||
// HoistLoopInvariantSubsetsOp | ||
//===----------------------------------------------------------------------===// | ||
|
||
DiagnosedSilenceableFailure transform::HoistLoopInvariantSubsetsOp::applyToOne( | ||
transform::TransformRewriter &rewriter, LoopLikeOpInterface loopLikeOp, | ||
transform::ApplyToEachResultList &results, | ||
transform::TransformState &state) { | ||
hoistLoopInvariantSubsets(rewriter, loopLikeOp); | ||
return DiagnosedSilenceableFailure::success(); | ||
} | ||
|
||
void transform::HoistLoopInvariantSubsetsOp::getEffects( | ||
SmallVectorImpl<MemoryEffects::EffectInstance> &effects) { | ||
transform::onlyReadsHandle(getTarget(), effects); | ||
transform::modifiesPayload(effects); | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.