[Mlir-commits] [mlir] [mlir][spirv] Switch to `llvm::interleaved`. NFC. (PR #136240)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Apr 17 19:17:58 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Jakub Kuderski (kuhar)
<details>
<summary>Changes</summary>
Clean up printing code by switching to `llvm::interleaved` from https://github.com/llvm/llvm-project/pull/135517.
---
Full diff: https://github.com/llvm/llvm-project/pull/136240.diff
3 Files Affected:
- (modified) mlir/lib/Dialect/SPIRV/IR/ControlFlowOps.cpp (+5-6)
- (modified) mlir/lib/Dialect/SPIRV/IR/SPIRVAttributes.cpp (+8-10)
- (modified) mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp (+7-16)
``````````diff
diff --git a/mlir/lib/Dialect/SPIRV/IR/ControlFlowOps.cpp b/mlir/lib/Dialect/SPIRV/IR/ControlFlowOps.cpp
index ed9a30086deca..577959bbdbeaa 100644
--- a/mlir/lib/Dialect/SPIRV/IR/ControlFlowOps.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/ControlFlowOps.cpp
@@ -15,6 +15,8 @@
#include "mlir/Dialect/SPIRV/IR/SPIRVTypes.h"
#include "mlir/Interfaces/CallInterfaces.h"
+#include "llvm/Support/InterleavedRange.h"
+
#include "SPIRVOpUtils.h"
#include "SPIRVParsingUtils.h"
@@ -119,12 +121,9 @@ ParseResult BranchConditionalOp::parse(OpAsmParser &parser,
void BranchConditionalOp::print(OpAsmPrinter &printer) {
printer << ' ' << getCondition();
- if (auto weights = getBranchWeights()) {
- printer << " [";
- llvm::interleaveComma(weights->getValue(), printer, [&](Attribute a) {
- printer << llvm::cast<IntegerAttr>(a).getInt();
- });
- printer << "]";
+ if (std::optional<ArrayAttr> weights = getBranchWeights()) {
+ printer << ' '
+ << llvm::interleaved_array(weights->getAsValueRange<IntegerAttr>());
}
printer << ", ";
diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVAttributes.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVAttributes.cpp
index b71be23fdf47d..2ba6106896c1f 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVAttributes.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVAttributes.cpp
@@ -12,6 +12,7 @@
#include "mlir/IR/Builders.h"
#include "mlir/IR/DialectImplementation.h"
#include "llvm/ADT/TypeSwitch.h"
+#include "llvm/Support/InterleavedRange.h"
using namespace mlir;
using namespace mlir::spirv;
@@ -621,17 +622,14 @@ Attribute SPIRVDialect::parseAttribute(DialectAsmParser &parser,
//===----------------------------------------------------------------------===//
static void print(spirv::VerCapExtAttr triple, DialectAsmPrinter &printer) {
- auto &os = printer.getStream();
printer << spirv::VerCapExtAttr::getKindName() << "<"
- << spirv::stringifyVersion(triple.getVersion()) << ", [";
- llvm::interleaveComma(
- triple.getCapabilities(), os,
- [&](spirv::Capability cap) { os << spirv::stringifyCapability(cap); });
- printer << "], [";
- llvm::interleaveComma(triple.getExtensionsAttr(), os, [&](Attribute attr) {
- os << llvm::cast<StringAttr>(attr).getValue();
- });
- printer << "]>";
+ << spirv::stringifyVersion(triple.getVersion()) << ", "
+ << llvm::interleaved_array(llvm::map_range(
+ triple.getCapabilities(), spirv::stringifyCapability))
+ << ", "
+ << llvm::interleaved_array(
+ triple.getExtensionsAttr().getAsValueRange<StringAttr>())
+ << ">";
}
static void print(spirv::TargetEnvAttr targetEnv, DialectAsmPrinter &printer) {
diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
index 16e91b0cb2cfc..448b1cf578bd7 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
@@ -35,6 +35,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/TypeSwitch.h"
+#include "llvm/Support/InterleavedRange.h"
#include <cassert>
#include <numeric>
#include <optional>
@@ -808,8 +809,7 @@ void spirv::EntryPointOp::print(OpAsmPrinter &printer) {
printer.printSymbolName(getFn());
auto interfaceVars = getInterface().getValue();
if (!interfaceVars.empty()) {
- printer << ", ";
- llvm::interleaveComma(interfaceVars, printer);
+ printer << ", " << llvm::interleaved(interfaceVars);
}
}
@@ -862,13 +862,9 @@ void spirv::ExecutionModeOp::print(OpAsmPrinter &printer) {
printer << " ";
printer.printSymbolName(getFn());
printer << " \"" << stringifyExecutionMode(getExecutionMode()) << "\"";
- auto values = this->getValues();
- if (values.empty())
- return;
- printer << ", ";
- llvm::interleaveComma(values, printer, [&](Attribute a) {
- printer << llvm::cast<IntegerAttr>(a).getInt();
- });
+ ArrayAttr values = this->getValues();
+ if (!values.empty())
+ printer << ", " << llvm::interleaved(values.getAsValueRange<IntegerAttr>());
}
//===----------------------------------------------------------------------===//
@@ -1824,13 +1820,8 @@ ParseResult spirv::SpecConstantCompositeOp::parse(OpAsmParser &parser,
void spirv::SpecConstantCompositeOp::print(OpAsmPrinter &printer) {
printer << " ";
printer.printSymbolName(getSymName());
- printer << " (";
- auto constituents = this->getConstituents().getValue();
-
- if (!constituents.empty())
- llvm::interleaveComma(constituents, printer);
-
- printer << ") : " << getType();
+ printer << " (" << llvm::interleaved(this->getConstituents().getValue())
+ << ") : " << getType();
}
LogicalResult spirv::SpecConstantCompositeOp::verify() {
``````````
</details>
https://github.com/llvm/llvm-project/pull/136240
More information about the Mlir-commits
mailing list