Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions mlir/lib/Dialect/SPIRV/IR/ControlFlowOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 << ", ";
Expand Down
18 changes: 8 additions & 10 deletions mlir/lib/Dialect/SPIRV/IR/SPIRVAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
26 changes: 8 additions & 18 deletions mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -807,10 +808,8 @@ void spirv::EntryPointOp::print(OpAsmPrinter &printer) {
printer << " \"" << stringifyExecutionModel(getExecutionModel()) << "\" ";
printer.printSymbolName(getFn());
auto interfaceVars = getInterface().getValue();
if (!interfaceVars.empty()) {
printer << ", ";
llvm::interleaveComma(interfaceVars, printer);
}
if (!interfaceVars.empty())
printer << ", " << llvm::interleaved(interfaceVars);
}

LogicalResult spirv::EntryPointOp::verify() {
Expand Down Expand Up @@ -862,13 +861,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>());
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -1824,13 +1819,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() {
Expand Down
Loading