[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:59:47 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>


================
@@ -1400,6 +1400,77 @@ void FileOp::build(OpBuilder &builder, OperationState &state, StringRef id) {
       builder.getNamedAttr("id", builder.getStringAttr(id)));
 }
 
+//===----------------------------------------------------------------------===//
+// FieldOp
+//===----------------------------------------------------------------------===//
+LogicalResult FieldOp::verify() {
+  if (!isSupportedEmitCType(getType())) {
+    return emitOpError("expected valid emitc type");
+  }
+
+  if (!getInitialValue()) {
+    return success();
+  }
+
+  Attribute initValue = *getInitialValue();
+  // Check that the type of the initial value is compatible with the type of
+  // the global variable.
+  if (ElementsAttr elementsAttr = llvm::dyn_cast<ElementsAttr>(initValue)) {
+    Type initialValueType = elementsAttr.getType();
+    if (!initialValueType) {
+      return emitOpError("initial value attribute must have a type");
+    }
+    Type fieldType = getType();
+    if (initialValueType != fieldType) {
+      if (LValueType lvalueType = dyn_cast<LValueType>(fieldType)) {
+        Type innerFieldType = lvalueType.getValueType();
+        if (innerFieldType != initialValueType) {
+          return emitOpError("initial value type ")
+                 << initialValueType << " is not compatible with field type '"
+                 << fieldType << "' its inner type '" << innerFieldType << "'";
+        }
+
+      } else {
+        return emitOpError("initial value type '")
+               << initialValueType << "' is not compatible with field type '"
+               << fieldType << "'";
+      }
+    }
+  }
+
+  return success();
+}
+
+//===----------------------------------------------------------------------===//
+// GetFieldOp
+//===----------------------------------------------------------------------===//
+LogicalResult GetFieldOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
+  mlir::FlatSymbolRefAttr fieldNameAttr = getFieldNameAttr();
+  if (!fieldNameAttr) {
----------------
Jaddyen wrote:

ive been able to use it directly without the pedantic check..

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


More information about the Mlir-commits mailing list