Skip to content

Commit

Permalink
Merge branch 'vwells/ttir_to_linalg_conversion' into vwells/linalg_to…
Browse files Browse the repository at this point in the history
…_llvm_conversion
  • Loading branch information
vwellsTT authored Dec 10, 2024
2 parents 49eefb0 + 5272da5 commit c204ee8
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
20 changes: 20 additions & 0 deletions include/ttmlir/Conversion/TTIRToLinAlg/TTIRToLinAlg.h
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
63 changes: 63 additions & 0 deletions lib/Conversion/TTIRToLinAlg/TTIRToLinAlgPass.cpp
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

0 comments on commit c204ee8

Please sign in to comment.