-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'vwells/ttir_to_linalg_conversion' into vwells/linalg_to…
…_llvm_conversion
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#ifndef TTMLIR_CONVERSION_TTIRTOLINALG_TTIRTOLINALG_H | ||
#define TTMLIR_CONVERSION_TTIRTOLINALG_TTIRTOLINALG_H | ||
|
||
#include "mlir/Pass/Pass.h" | ||
#include "mlir/Transforms/DialectConversion.h" | ||
|
||
namespace mlir::tt { | ||
|
||
void populateTTIRToLinAlgPatterns(MLIRContext *ctx, RewritePatternSet &patterns, | ||
TypeConverter &typeConverter); | ||
|
||
std::unique_ptr<OperationPass<ModuleOp>> createConvertTTIRToLinAlgPass(); | ||
|
||
} // namespace mlir::tt | ||
|
||
#endif // TTMLIR_CONVERSION_TTIRTOLINALG_TTIRTOLINALG_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "ttmlir/Conversion/TTIRToLinAlg/TTIRToLinAlg.h" | ||
|
||
#include "mlir/Dialect/Func/Transforms/FuncConversions.h" | ||
#include "mlir/IR/BuiltinDialect.h" | ||
#include "mlir/IR/PatternMatch.h" | ||
#include "mlir/Pass/Pass.h" | ||
#include "mlir/Support/LogicalResult.h" | ||
#include "mlir/Transforms/DialectConversion.h" | ||
#include "ttmlir/Conversion/TTIRToTTIRDecomposition/TTIRToTTIRDecomposition.h" | ||
#include "ttmlir/Dialect/TTIR/IR/TTIR.h" | ||
#include <mlir/Dialect/Func/IR/FuncOps.h> | ||
|
||
using namespace mlir; | ||
using namespace mlir::tt; | ||
|
||
namespace mlir::tt::ttir { | ||
|
||
#define GEN_PASS_DEF_CONVERTTTIRTOLINALG | ||
#include "ttmlir/Conversion/Passes.h.inc" | ||
|
||
} // namespace mlir::tt::ttir | ||
|
||
namespace { | ||
|
||
struct ConvertTTIRToLinAlgPass | ||
: public ttir::impl::ConvertTTIRToLinAlgBase<ConvertTTIRToLinAlgPass> { | ||
void runOnOperation() final { | ||
mlir::ConversionTarget target(getContext()); | ||
target.addLegalDialect<BuiltinDialect>(); | ||
target.addLegalDialect<func::FuncDialect>(); | ||
target.addLegalDialect<linalg::LinalgDialect>(); | ||
target.addIllegalDialect<ttir::TTIRDialect>(); | ||
|
||
TypeConverter typeConverter; | ||
// All types map 1:1. | ||
typeConverter.addConversion([](Type type) { return type; }); | ||
|
||
RewritePatternSet patterns(&getContext()); | ||
populateTTIRToLinAlgPatterns(&getContext(), patterns, typeConverter); | ||
|
||
// Apply full conversion | ||
// | ||
if (failed( | ||
applyFullConversion(getOperation(), target, std::move(patterns)))) { | ||
signalPassFailure(); | ||
return; | ||
} | ||
} | ||
}; | ||
|
||
} // namespace | ||
|
||
namespace mlir::tt { | ||
|
||
std::unique_ptr<OperationPass<ModuleOp>> createConvertTTIRToLinAlgPass() { | ||
return std::make_unique<ConvertTTIRToLinAlgPass>(); | ||
} | ||
|
||
} // namespace mlir::tt |