Skip to content

Commit

Permalink
Merge pull request #27 from spcl/backward-conversion
Browse files Browse the repository at this point in the history
Backward Conversion
  • Loading branch information
Berke-Ates authored Sep 11, 2023
2 parents c947a63 + 7ec5e43 commit 5067939
Show file tree
Hide file tree
Showing 204 changed files with 4,619 additions and 569 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2021-2023, Scalable Parallel Computing Lab, ETH Zurich

cmake_minimum_required(VERSION 3.20.0)
project(sdfg-opt LANGUAGES CXX C)

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2022, SPCL
Copyright (c) 2021-2023, Scalable Parallel Computing Lab, ETH Zurich
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 2 additions & 0 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Copyright (c) 2021-2023, Scalable Parallel Computing Lab, ETH Zurich

add_subdirectory(SDFG)
2 changes: 2 additions & 0 deletions include/SDFG/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2021-2023, Scalable Parallel Computing Lab, ETH Zurich

add_subdirectory(Dialect)
add_subdirectory(Conversion)
add_subdirectory(Translate)
Expand Down
4 changes: 4 additions & 0 deletions include/SDFG/Conversion/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Copyright (c) 2021-2023, Scalable Parallel Computing Lab, ETH Zurich

add_subdirectory(GenericToSDFG)
add_subdirectory(LinalgToSDFG)

add_subdirectory(SDFGToGeneric)
2 changes: 2 additions & 0 deletions include/SDFG/Conversion/GenericToSDFG/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2021-2023, Scalable Parallel Computing Lab, ETH Zurich

set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls -name GenericToSDFG)
add_public_tablegen_target(MLIRGenericToSDFGPassIncGen)
Expand Down
5 changes: 5 additions & 0 deletions include/SDFG/Conversion/GenericToSDFG/PassDetail.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (c) 2021-2023, Scalable Parallel Computing Lab, ETH Zurich

/// Header for Generic to SDFG conversion pass details.

#ifndef SDFG_Conversion_GenericToSDFG_PassDetail_H
#define SDFG_Conversion_GenericToSDFG_PassDetail_H

Expand All @@ -8,6 +12,7 @@ namespace mlir {
namespace sdfg {
namespace conversion {

/// Generate the code for base classes.
#define GEN_PASS_CLASSES
#include "SDFG/Conversion/GenericToSDFG/Passes.h.inc"

Expand Down
4 changes: 4 additions & 0 deletions include/SDFG/Conversion/GenericToSDFG/Passes.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (c) 2021-2023, Scalable Parallel Computing Lab, ETH Zurich

/// Header for Generic to SDFG conversion passes.

#ifndef SDFG_Conversion_GenericToSDFG_H
#define SDFG_Conversion_GenericToSDFG_H

Expand Down
7 changes: 6 additions & 1 deletion include/SDFG/Conversion/GenericToSDFG/Passes.td
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
// Copyright (c) 2021-2023, Scalable Parallel Computing Lab, ETH Zurich

/// Table-driven file for Generic to SDFG conversion passes.

#ifndef SDFG_Conversion_GenericToSDFG
#define SDFG_Conversion_GenericToSDFG

include "mlir/Pass/PassBase.td"
include "SDFG/Dialect/Dialect.td"

/// Define generic to SDFG pass.
def GenericToSDFGPass : Pass<"convert-to-sdfg", "ModuleOp"> {
let summary = "Convert SCF, Arith and Memref dialect to SDFG dialect";
let summary = "Convert SCF, Arith, Math and Memref dialect to SDFG dialect";
let constructor = "mlir::sdfg::conversion::createGenericToSDFGPass()";
let dependentDialects = ["mlir::sdfg::SDFGDialect"];
let options = [
Expand Down
2 changes: 2 additions & 0 deletions include/SDFG/Conversion/LinalgToSDFG/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2021-2023, Scalable Parallel Computing Lab, ETH Zurich

set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls -name LinalgToSDFG)
add_public_tablegen_target(MLIRLinalgToSDFGPassIncGen)
Expand Down
5 changes: 5 additions & 0 deletions include/SDFG/Conversion/LinalgToSDFG/PassDetail.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (c) 2021-2023, Scalable Parallel Computing Lab, ETH Zurich

/// Header for Linalg to SDFG conversion pass details.

#ifndef SDFG_Conversion_LinalgToSDFG_PassDetail_H
#define SDFG_Conversion_LinalgToSDFG_PassDetail_H

Expand All @@ -8,6 +12,7 @@ namespace mlir {
namespace sdfg {
namespace conversion {

/// Generate the code for base classes.
#define GEN_PASS_CLASSES
#include "SDFG/Conversion/LinalgToSDFG/Passes.h.inc"

Expand Down
4 changes: 4 additions & 0 deletions include/SDFG/Conversion/LinalgToSDFG/Passes.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (c) 2021-2023, Scalable Parallel Computing Lab, ETH Zurich

/// Header for Linalg to SDFG conversion passes.

#ifndef SDFG_Conversion_LinalgToSDFG_H
#define SDFG_Conversion_LinalgToSDFG_H

Expand Down
5 changes: 5 additions & 0 deletions include/SDFG/Conversion/LinalgToSDFG/Passes.td
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
// Copyright (c) 2021-2023, Scalable Parallel Computing Lab, ETH Zurich

/// Table-driven file for Linalg to SDFG conversion passes.

#ifndef SDFG_Conversion_LinalgToSDFG
#define SDFG_Conversion_LinalgToSDFG

include "mlir/Pass/PassBase.td"
include "SDFG/Dialect/Dialect.td"

/// Define Linalg to SDFG Pass.
def LinalgToSDFGPass : Pass<"linalg-to-sdfg", "ModuleOp"> {
let summary = "Convert Linalg dialect to SDFG dialect";
let constructor = "mlir::sdfg::conversion::createLinalgToSDFGPass()";
Expand Down
8 changes: 8 additions & 0 deletions include/SDFG/Conversion/SDFGToGeneric/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2021-2023, Scalable Parallel Computing Lab, ETH Zurich

set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls -name SDFGToGeneric)
add_public_tablegen_target(MLIRSDFGToGenericPassIncGen)

target_sources(SOURCE_FILES_H PRIVATE PassDetail.h Passes.h SymbolicParser.h
OpCreators.h)
137 changes: 137 additions & 0 deletions include/SDFG/Conversion/SDFGToGeneric/OpCreators.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// Copyright (c) 2021-2023, Scalable Parallel Computing Lab, ETH Zurich

/// Header for convenience functions, creating various operations.

#ifndef SDFG_Conversion_SDFGToGeneric_Op_Creators_H
#define SDFG_Conversion_SDFGToGeneric_Op_Creators_H

#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/Transforms/DialectConversion.h"

using namespace mlir;

namespace mlir::sdfg::conversion {

/// Builds, creates and inserts a func::FuncOp.
func::FuncOp createFunc(PatternRewriter &rewriter, Location loc, StringRef name,
TypeRange inputTypes, TypeRange resultTypes,
StringRef visibility);

/// Builds, creates and inserts a func::CallOp.
func::CallOp createCall(PatternRewriter &rewriter, Location loc,
TypeRange resultTypes, StringRef callee,
ValueRange operands);

/// Builds, creates and inserts a func::ReturnOp.
func::ReturnOp createReturn(PatternRewriter &rewriter, Location loc,
ValueRange operands);

/// Builds, creates and inserts a cf::BranchOp.
cf::BranchOp createBranch(PatternRewriter &rewriter, Location loc,
ValueRange operands, Block *dest);

/// Builds, creates and inserts a cf::CondBranchOp.
cf::CondBranchOp createCondBranch(PatternRewriter &rewriter, Location loc,
Value condition, Block *trueDest,
Block *falseDest);

/// Builds, creates and inserts a memref::AllocOp.
memref::AllocOp createAlloc(PatternRewriter &rewriter, Location loc,
MemRefType memrefType, ValueRange dynamicSizes);

/// Builds, creates and inserts a memref::LoadOp.
memref::LoadOp createLoad(PatternRewriter &rewriter, Location loc, Value memref,
ValueRange indices);

/// Builds, creates and inserts a memref::StoreOp.
memref::StoreOp createStore(PatternRewriter &rewriter, Location loc,
Value value, Value memref, ValueRange indices);

/// Builds, creates and inserts a memref::CopyOp.
memref::CopyOp createCopy(PatternRewriter &rewriter, Location loc, Value source,
Value target);

/// Allocates a symbol as a memref<i64> if it's not already allocated and
/// populates the symbol map.
void allocSymbol(PatternRewriter &rewriter, Location loc, StringRef symName,
llvm::StringMap<Value> &symbolMap);

/// Builds, creates and inserts an arith::ConstantIntOp.
arith::ConstantIntOp createConstantInt(PatternRewriter &rewriter, Location loc,
int val, int width);

/// Builds, creates and inserts an arith::AddIOp.
arith::AddIOp createAddI(PatternRewriter &rewriter, Location loc, Value a,
Value b);

/// Builds, creates and inserts an arith::SubIOp.
arith::SubIOp createSubI(PatternRewriter &rewriter, Location loc, Value a,
Value b);

/// Builds, creates and inserts an arith::MulIOp.
arith::MulIOp createMulI(PatternRewriter &rewriter, Location loc, Value a,
Value b);

/// Builds, creates and inserts an arith::DivSIOp.
arith::DivSIOp createDivSI(PatternRewriter &rewriter, Location loc, Value a,
Value b);

/// Builds, creates and inserts an arith::FloorDivSIOp.
arith::FloorDivSIOp createFloorDivSI(PatternRewriter &rewriter, Location loc,
Value a, Value b);

/// Builds, creates and inserts an arith::RemSIOp.
arith::RemSIOp createRemSI(PatternRewriter &rewriter, Location loc, Value a,
Value b);

/// Builds, creates and inserts an arith::OrIOp.
arith::OrIOp createOrI(PatternRewriter &rewriter, Location loc, Value a,
Value b);

/// Builds, creates and inserts an arith::AndIOp.
arith::AndIOp createAndI(PatternRewriter &rewriter, Location loc, Value a,
Value b);

/// Builds, creates and inserts an arith::XOrIOp.
arith::XOrIOp createXOrI(PatternRewriter &rewriter, Location loc, Value a,
Value b);

/// Builds, creates and inserts an arith::ShLIOp.
arith::ShLIOp createShLI(PatternRewriter &rewriter, Location loc, Value a,
Value b);

/// Builds, creates and inserts an arith::ShRSIOp.
arith::ShRSIOp createShRSI(PatternRewriter &rewriter, Location loc, Value a,
Value b);

/// Builds, creates and inserts an arith::CmpIOp.
arith::CmpIOp createCmpI(PatternRewriter &rewriter, Location loc,
arith::CmpIPredicate predicate, Value lhs, Value rhs);

/// Builds, creates and inserts an arith::ExtSIOp.
arith::ExtSIOp createExtSI(PatternRewriter &rewriter, Location loc, Type out,
Value in);

/// Builds, creates and inserts an arith::TruncIOp.
arith::TruncIOp createTruncI(PatternRewriter &rewriter, Location loc, Type out,
Value in);

/// Builds, creates and inserts an arith::IndexCastOp.
arith::IndexCastOp createIndexCast(PatternRewriter &rewriter, Location loc,
Type out, Value in);

/// Builds, creates and inserts a scf::ParallelOp.
scf::ParallelOp createParallel(PatternRewriter &rewriter, Location loc,
ValueRange lowerBounds, ValueRange upperBounds,
ValueRange steps);

/// Builds, creates and inserts a scf::YieldOp.
scf::YieldOp createYield(PatternRewriter &rewriter, Location loc);

} // namespace mlir::sdfg::conversion

#endif // SDFG_Conversion_SDFGToGeneric_Op_Creators_H
23 changes: 23 additions & 0 deletions include/SDFG/Conversion/SDFGToGeneric/PassDetail.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2021-2023, Scalable Parallel Computing Lab, ETH Zurich

/// Header for SDFG to Generic conversion pass details.

#ifndef SDFG_Conversion_SDFGToGeneric_PassDetail_H
#define SDFG_Conversion_SDFGToGeneric_PassDetail_H

#include "SDFG/Dialect/Dialect.h"
#include "mlir/Pass/Pass.h"

namespace mlir {
namespace sdfg {
namespace conversion {

/// Generate the code for base classes.
#define GEN_PASS_CLASSES
#include "SDFG/Conversion/SDFGToGeneric/Passes.h.inc"

} // namespace conversion
} // namespace sdfg
} // end namespace mlir

#endif // SDFG_Conversion_SDFGToGeneric_PassDetail_H
25 changes: 25 additions & 0 deletions include/SDFG/Conversion/SDFGToGeneric/Passes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2021-2023, Scalable Parallel Computing Lab, ETH Zurich

/// Header for SDFG to Generic conversion passes.

#ifndef SDFG_Conversion_SDFGToGeneric_H
#define SDFG_Conversion_SDFGToGeneric_H

#include "mlir/Pass/Pass.h"

namespace mlir::sdfg::conversion {

/// Creates a sdfg to generic converting pass
std::unique_ptr<Pass> createSDFGToGenericPass();

//===----------------------------------------------------------------------===//
// Registration
//===----------------------------------------------------------------------===//

/// Generate the code for registering passes.
#define GEN_PASS_REGISTRATION
#include "SDFG/Conversion/SDFGToGeneric/Passes.h.inc"

} // namespace mlir::sdfg::conversion

#endif // SDFG_Conversion_SDFGToGeneric_H
23 changes: 23 additions & 0 deletions include/SDFG/Conversion/SDFGToGeneric/Passes.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2021-2023, Scalable Parallel Computing Lab, ETH Zurich

/// Table-driven file for SDFG to Generic conversion passes.

#ifndef SDFG_Conversion_SDFGToGeneric
#define SDFG_Conversion_SDFGToGeneric

include "mlir/Pass/PassBase.td"
include "SDFG/Dialect/Dialect.td"

/// Define SDFG to generic pass.
def SDFGToGenericPass : Pass<"lower-sdfg", "ModuleOp"> {
let summary = "Convert SDFG dialect to Func, CF, Memref and SCF dialects";
let constructor = "mlir::sdfg::conversion::createSDFGToGenericPass()";
let dependentDialects = [
"mlir::func::FuncDialect",
"mlir::cf::ControlFlowDialect",
"mlir::memref::MemRefDialect",
"mlir::scf::SCFDialect"
];
}

#endif // SDFG_Conversion_SDFGToGeneric
Loading

0 comments on commit 5067939

Please sign in to comment.