[Mlir-commits] [mlir] [mlir][EmitC]Add a Reflection Map to a Class (PR #150572)

Andrzej WarzyƄski llvmlistbot at llvm.org
Mon Mar 2 10:03:02 PST 2026


================
@@ -60,4 +60,42 @@ def WrapFuncInClassPass : Pass<"wrap-emitc-func-in-class"> {
   ];
 }
 
+def MLGOAddReflectionMapPass : Pass<"MLGO-add-reflection-map", "ModuleOp"> {
+  let summary =
+      "Add a reflection map function to EmitC classes for runtime field lookup. This is MLGO Specific.";
+  let description = [{
+        This pass adds a `getBufferForName` function to EmitC classes that enables 
+        runtime lookup of field buffers by their string names. 
+        This requires that the class has fields with attributes and a function named `execute`.
+        The `fieldop` attribute is expected to be a dictionary where:
+        - The keys are `namedAttribute`.
+        - The values are arrays containing a single string attribute.
+
+
+        Example:
+
+        ```mlir
+        emitc.class @MyClass {
+          emitc.field @fieldName0 : !emitc.array<1xf32> {emitc.field_ref = ["another_feature"]}
+          emitc.field @fieldName1 : !emitc.array<1xf32> {emitc.field_ref = ["some_feature"]}
+          emitc.func @execute() { ... }
+        }
+
+        // becomes:
+        
+        emitc.class @MyClass {
+          emitc.field @fieldName0 : !emitc.array<1xf32> {emitc.field_ref = ["another_feature"]}
+          emitc.field @fieldName1 : !emitc.array<1xf32> {emitc.field_ref = ["some_feature"]}
+          emitc.field @reflectionMap : !emitc.opaque<"const std::map<std::string, char*>"> = #emitc.opaque<"{ { \22another_feature\22, reinterpret_cast<char*>(&fieldName0) }, { \22some_feature\22, reinterpret_cast<char*>(&fieldName1) } }">
----------------
banach-space wrote:

[nit] Could you wrap this line?

https://github.com/llvm/llvm-project/pull/150572


More information about the Mlir-commits mailing list