-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db3507c
commit ca82cbe
Showing
6 changed files
with
80 additions
and
17 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
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,53 @@ | ||
// SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "ttmlir/Dialect/TT/IR/TT.h" | ||
#include "ttmlir/Dialect/TTIR/Transforms/Passes.h" | ||
|
||
#include "mlir/Transforms/GreedyPatternRewriteDriver.h" | ||
#include <mlir/Transforms/GreedyPatternRewriteDriver.h> | ||
|
||
namespace mlir::tt::ttir { | ||
#define GEN_PASS_DEF_TTIRRESHAPEFOLD | ||
#include "ttmlir/Dialect/TTIR/Transforms/Passes.h.inc" | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Constant as fill pass | ||
//===----------------------------------------------------------------------===// | ||
|
||
class TTIRReshapeFoldingRewriter : public OpRewritePattern<ReshapeOp> { | ||
public: | ||
using OpRewritePattern<ReshapeOp>::OpRewritePattern; | ||
|
||
LogicalResult matchAndRewrite(ReshapeOp op, | ||
PatternRewriter &rewriter) const final { | ||
if (op.getType() == op->getOperand(0).getType()) { | ||
rewriter.replaceOp(op, op->getOperand(0)); | ||
return success(); | ||
} | ||
return failure(); | ||
} | ||
}; | ||
|
||
class TTIRReshapeFold : public impl::TTIRReshapeFoldBase<TTIRReshapeFold> { | ||
public: | ||
using impl::TTIRReshapeFoldBase<TTIRReshapeFold>::TTIRReshapeFoldBase; | ||
|
||
void runOnOperation() final { | ||
RewritePatternSet patterns(&getContext()); | ||
patterns.add<TTIRReshapeFoldingRewriter>(&getContext()); | ||
FrozenRewritePatternSet patternSet(std::move(patterns)); | ||
if (failed(applyPatternsAndFoldGreedily(getOperation(), patternSet))) { | ||
signalPassFailure(); | ||
return; | ||
} | ||
} | ||
|
||
void getDependentDialects(mlir::DialectRegistry ®istry) const override { | ||
registry.insert<mlir::tt::ttir::TTIRDialect>(); | ||
registry.insert<mlir::tt::TTDialect>(); | ||
} | ||
}; | ||
|
||
} // namespace mlir::tt::ttir |
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