[Mlir-commits] [mlir] [mlir][emitc] Add a `declare_func` operation (PR #80297)

Marius Brehler llvmlistbot at llvm.org
Mon Feb 5 02:53:54 PST 2024


================
@@ -393,6 +393,36 @@ FunctionType CallOp::getCalleeType() {
   return FunctionType::get(getContext(), getOperandTypes(), getResultTypes());
 }
 
+//===----------------------------------------------------------------------===//
+// DeclareFuncOp
+//===----------------------------------------------------------------------===//
+
+LogicalResult
+DeclareFuncOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
+  // Check that the sym_name attribute was specified.
+  auto fnAttr = getSymNameAttr();
+  if (!fnAttr)
+    return emitOpError("requires a 'sym_name' symbol reference attribute");
+  FuncOp fn = symbolTable.lookupNearestSymbolFrom<FuncOp>(*this, fnAttr);
+  if (!fn)
+    return emitOpError() << "'" << fnAttr.getValue()
+                         << "' does not reference a valid function";
+
+  return success();
+}
+
+LogicalResult DeclareFuncOp::verify() {
+  auto fnAttr = (*this)->getAttrOfType<FlatSymbolRefAttr>("sym_name");
+  auto funcOp =
+      SymbolTable::lookupNearestSymbolFrom<emitc::FuncOp>((*this), fnAttr);
+
+  if (!isa<ModuleOp>((*this)->getParentOp()) && funcOp.isPrivate())
----------------
marbre wrote:

If it's not, something other is broken but I agree that can be the case. That's another point why a validation pass might be more favorable here. Beside that, going through all specifiers args in the array adds more a much larger overhead to the verifier.

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


More information about the Mlir-commits mailing list