From 289eadfa06745f7f195f357b7d8bba98dcb95ad1 Mon Sep 17 00:00:00 2001 From: Kevin Gleason Date: Thu, 11 Jul 2024 09:49:06 -0500 Subject: [PATCH] Add convenience method to CustomCallOp for checking empty backend config (#2432) This logic is used many times in openxla/xla, so decided to turn it into a method --- stablehlo/dialect/StablehloOps.cpp | 10 ++++++++++ stablehlo/dialect/StablehloOps.td | 1 + 2 files changed, 11 insertions(+) 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(); }]; }