[Mlir-commits] [mlir] [emitC]Pass in `mlir-opt` to wrap a func in class (PR #141158)
Jaden Angella
llvmlistbot at llvm.org
Mon Jun 23 09:49:18 PDT 2025
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,Jaddyen <ajaden at google.com>,Jaddyen
<ajaden at google.com>,Jaddyen <ajaden at google.com>,Jaddyen <ajaden at google.com>,Jaddyen
<ajaden at google.com>,Jaddyen <ajaden at google.com>,Jaddyen <ajaden at google.com>,
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,Jaddyen <ajaden at google.com>,Jaddyen
<ajaden at google.com>,Jaddyen <ajaden at google.com>,Jaddyen <ajaden at google.com>,Jaden
Angella <141196890+Jaddyen at users.noreply.github.com>,Jaden Angella
<141196890+Jaddyen at users.noreply.github.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/141158 at github.com>
================
@@ -1572,4 +1572,105 @@ def EmitC_SwitchOp : EmitC_Op<"switch", [RecursiveMemoryEffects,
let hasVerifier = 1;
}
+def EmitC_ClassOp
+ : EmitC_Op<"class", [AutomaticAllocationScope, IsolatedFromAbove,
+ OpAsmOpInterface, SymbolTable,
+ Symbol]#GraphRegionNoTerminator.traits> {
+ let summary =
+ "Represents a C++ class definition, encapsulating fields and methods.";
+
+ let description = [{
+ The `emitc.class` operation defines a C++ class, acting as a container
+ for its data fields (`emitc.field`) and methods (`emitc.func`).
+ It creates a distinct scope, isolating its contents from the surrounding
+ MLIR region, similar to how C++ classes encapsulate their internals.
+
+ Example:
+ ```mlir
+ emitc.func @model(%input_data : !emitc.array<1xf32> {emitc.opaque = ["input_tensor"]}) attributes { } {
+ %0 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
+ %1 = subscript %input_data[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
+ return
+ }
+ // becomes
+ emitc.class @modelClass {
+ emitc.field @input_tensor : !emitc.array<1xf32> = {emitc.opaque = ["input_tensor"]}
+ emitc.func @execute() {
+ %0 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
+ %1 = get_field @input_tensor : !emitc.array<1xf32>
+ %2 = subscript %1[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
+ return
+ }
+ }
+ ```
+ }];
+
+ let arguments = (ins SymbolNameAttr:$sym_name);
+
+ let regions = (region AnyRegion:$body);
+
+ let builders = [];
----------------
Jaddyen wrote:
addressed.
thanks for the pointer!
https://github.com/llvm/llvm-project/pull/141158
More information about the Mlir-commits
mailing list