diff --git a/stablehlo/dialect/StablehloOps.cpp b/stablehlo/dialect/StablehloOps.cpp index 20fcfdaa91a..57b3475b12e 100644 --- a/stablehlo/dialect/StablehloOps.cpp +++ b/stablehlo/dialect/StablehloOps.cpp @@ -518,6 +518,16 @@ mlir::Attribute CustomCallOp::getBackendConfigOrDefault() { return StringAttr::get(getContext(), ""); } +// Returns if the backend config is unset, or if empty dict / string attribute. +bool CustomCallOp::hasEmptyBackendConfig() { + if (!getBackendConfig().has_value()) return true; + Attribute backendConfig = getBackendConfigOrDefault(); + if (auto strAttr = dyn_cast(backendConfig)) { + return strAttr.empty(); + } + return cast(backendConfig).empty(); +} + //===----------------------------------------------------------------------===// // CholeskyOp //===----------------------------------------------------------------------===// diff --git a/stablehlo/dialect/StablehloOps.td b/stablehlo/dialect/StablehloOps.td index 3608c97d816..6f9f02debb3 100644 --- a/stablehlo/dialect/StablehloOps.td +++ b/stablehlo/dialect/StablehloOps.td @@ -2389,6 +2389,7 @@ def StableHLO_CustomCallOp: StableHLO_Op<"custom_call", let extraClassDeclaration = commonClassDeclaration # [{ mlir::Attribute getBackendConfigOrDefault(); + bool hasEmptyBackendConfig(); }]; }