Skip to content

emitc: func: Set default dialect to 'emitc' #116297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 11 additions & 1 deletion mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ include "mlir/Interfaces/CastInterfaces.td"
include "mlir/Interfaces/ControlFlowInterfaces.td"
include "mlir/Interfaces/FunctionInterfaces.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/IR/OpAsmInterface.td"
include "mlir/IR/RegionKindInterface.td"

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -632,7 +633,7 @@ def EmitC_DeclareFuncOp : EmitC_Op<"declare_func", [

def EmitC_FuncOp : EmitC_Op<"func", [
AutomaticAllocationScope,
FunctionOpInterface, IsolatedFromAbove
FunctionOpInterface, IsolatedFromAbove, OpAsmOpInterface
]> {
let summary = "An operation with a name containing a single `SSACFG` region";
let description = [{
Expand Down Expand Up @@ -700,6 +701,15 @@ def EmitC_FuncOp : EmitC_Op<"func", [

/// Returns the result types of this function.
ArrayRef<Type> getResultTypes() { return getFunctionType().getResults(); }

//===------------------------------------------------------------------===//
// OpAsmOpInterface Methods
//===------------------------------------------------------------------===//

/// EmitC ops in the body can omit their 'emitc.' prefix in the assembly.
static ::llvm::StringRef getDefaultDialect() {
return "emitc";
}
}];
let hasCustomAssemblyFormat = 1;
let hasVerifier = 1;
Expand Down
18 changes: 9 additions & 9 deletions mlir/test/Conversion/FuncToEmitC/func-to-emitc.mlir
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// RUN: mlir-opt -split-input-file -convert-func-to-emitc %s | FileCheck %s

// CHECK-LABEL: emitc.func @foo()
// CHECK-NEXT: emitc.return
// CHECK-NEXT: return
func.func @foo() {
return
}

// -----

// CHECK-LABEL: emitc.func private @foo() attributes {specifiers = ["static"]}
// CHECK-NEXT: emitc.return
// CHECK-NEXT: return
func.func private @foo() {
return
}
Expand All @@ -25,7 +25,7 @@ func.func @foo(%arg0: i32) {
// -----

// CHECK-LABEL: emitc.func @foo(%arg0: i32) -> i32
// CHECK-NEXT: emitc.return %arg0 : i32
// CHECK-NEXT: return %arg0 : i32
func.func @foo(%arg0: i32) -> i32 {
return %arg0 : i32
}
Expand All @@ -41,14 +41,14 @@ func.func @foo(%arg0: i32, %arg1: i32) -> i32 {
// -----

// CHECK-LABEL: emitc.func private @return_i32(%arg0: i32) -> i32 attributes {specifiers = ["static"]}
// CHECK-NEXT: emitc.return %arg0 : i32
// CHECK-NEXT: return %arg0 : i32
func.func private @return_i32(%arg0: i32) -> i32 {
return %arg0 : i32
}

// CHECK-LABEL: emitc.func @call(%arg0: i32) -> i32
// CHECK-NEXT: %0 = emitc.call @return_i32(%arg0) : (i32) -> i32
// CHECK-NEXT: emitc.return %0 : i32
// CHECK-NEXT: %0 = call @return_i32(%arg0) : (i32) -> i32
// CHECK-NEXT: return %0 : i32
func.func @call(%arg0: i32) -> i32 {
%0 = call @return_i32(%arg0) : (i32) -> (i32)
return %0 : i32
Expand All @@ -62,14 +62,14 @@ func.func private @return_i32(%arg0: i32) -> i32
// -----

// CHECK-LABEL: emitc.func private @return_void() attributes {specifiers = ["static"]}
// CHECK-NEXT: emitc.return
// CHECK-NEXT: return
func.func private @return_void() {
return
}

// CHECK-LABEL: emitc.func @call()
// CHECK-NEXT: emitc.call @return_void() : () -> ()
// CHECK-NEXT: emitc.return
// CHECK-NEXT: call @return_void() : () -> ()
// CHECK-NEXT: return
func.func @call() {
call @return_void() : () -> ()
return
Expand Down
Loading