Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions mlir/include/mlir-c/Dialect/EmitC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===-- mlir-c/Dialect/EmitC.h - C API for EmitC 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_C_DIALECT_EmitC_H
#define MLIR_C_DIALECT_EmitC_H

#include "mlir-c/IR.h"
#include "mlir-c/Support.h"

#ifdef __cplusplus
extern "C" {
#endif

MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(EmitC, emitc);

#ifdef __cplusplus
}
#endif

#endif // MLIR_C_DIALECT_EmitC_H
9 changes: 9 additions & 0 deletions mlir/lib/CAPI/Dialect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ add_mlir_upstream_c_api_library(MLIRCAPIControlFlow
MLIRControlFlowDialect
)

add_mlir_upstream_c_api_library(MLIRCAPIEmitC
EmitC.cpp

PARTIAL_SOURCES_INTENDED
LINK_LIBS PUBLIC
MLIRCAPIIR
MLIREmitCDialect
)

add_mlir_upstream_c_api_library(MLIRCAPIMath
Math.cpp

Expand Down
13 changes: 13 additions & 0 deletions mlir/lib/CAPI/Dialect/EmitC.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===- EmitC.cpp - C Interface for EmitC 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-c/Dialect/EmitC.h"
#include "mlir/CAPI/Registration.h"
#include "mlir/Dialect/EmitC/IR/EmitC.h"

MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(EmitC, emitc, mlir::emitc::EmitCDialect)
7 changes: 7 additions & 0 deletions mlir/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,13 @@ declare_mlir_python_sources(
dialects/quant.py
_mlir_libs/_mlir/dialects/quant.pyi)

declare_mlir_dialect_python_bindings(
ADD_TO_PARENT MLIRPythonSources.Dialects
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
TD_FILE dialects/EmitC.td
SOURCES dialects/emitc.py
DIALECT_NAME emitc)

declare_mlir_dialect_python_bindings(
ADD_TO_PARENT MLIRPythonSources.Dialects
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
Expand Down
14 changes: 14 additions & 0 deletions mlir/python/mlir/dialects/EmitC.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//===-- EmitC.td - Entry point for EmitC bind --------*- 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 PYTHON_BINDINGS_EMITC
#define PYTHON_BINDINGS_EMITC

include "mlir/Dialect/EmitC/IR/EmitC.td"

#endif
5 changes: 5 additions & 0 deletions mlir/python/mlir/dialects/emitc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 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

from ._emitc_ops_gen import *
31 changes: 31 additions & 0 deletions mlir/test/python/dialects/emitc_dialect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# RUN: %PYTHON %s | FileCheck %s

from mlir.ir import *
import mlir.dialects.emitc as emitc


def run(f):
print("\nTEST:", f.__name__)
with Context() as ctx, Location.unknown():
module = Module.create()
with InsertionPoint(module.body):
f(ctx)
print(module)


# CHECK-LABEL: TEST: testConstantOp
@run
def testConstantOp(ctx):
i32 = IntegerType.get_signless(32)
a = emitc.ConstantOp(result=i32, value=IntegerAttr.get(i32, 42))
# CHECK: %{{.*}} = "emitc.constant"() <{value = 42 : i32}> : () -> i32


# CHECK-LABEL: TEST: testAddOp
@run
def testAddOp(ctx):
i32 = IntegerType.get_signless(32)
lhs = emitc.ConstantOp(result=i32, value=IntegerAttr.get(i32, 0))
rhs = emitc.ConstantOp(result=i32, value=IntegerAttr.get(i32, 0))
a = emitc.AddOp(i32, lhs, rhs)
# CHECK: %{{.*}} = emitc.add %{{.*}}, %{{.*}} : (i32, i32) -> i32
31 changes: 31 additions & 0 deletions utils/bazel/llvm-project-overlay/mlir/python/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,37 @@ filegroup(
],
)

##---------------------------------------------------------------------------##
# EmitC dialect.
##---------------------------------------------------------------------------##

gentbl_filegroup(
name = "EmitCPyGen",
tbl_outs = [
(
[
"-gen-python-op-bindings",
"-bind-dialect=emitc",
],
"mlir/dialects/_emitc_ops_gen.py",
),
],
tblgen = "//mlir:mlir-tblgen",
td_file = "mlir/dialects/EmitC.td",
deps = [
"//mlir:OpBaseTdFiles",
"//mlir:EmitCTdFiles",
],
)

filegroup(
name = "EmitCPyFiles",
srcs = [
"mlir/dialects/emitc.py",
":EmitCPyGen",
],
)

##---------------------------------------------------------------------------##
# Linalg dialect.
##---------------------------------------------------------------------------##
Expand Down
Loading