MLIR 23.0.0git
SPIRVTosaOps.cpp
Go to the documentation of this file.
1//===- SPIRVTosaOps.cpp - MLIR SPIR-V Tosa operations ---------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the Tosa operations in the SPIR-V dialect.
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/Support/InterleavedRange.h"
15
16namespace mlir::spirv {
17
18//===----------------------------------------------------------------------===//
19// SPIRV Tosa Custom formatters
20//===----------------------------------------------------------------------===//
21
25 auto f = [&]() {
26 int32_t value;
27 ParseResult r = parser.parseInteger(value);
28 elements.push_back(value);
29 return r;
30 };
31 if (parser.parseCommaSeparatedList(
33 "parsing values in integer list attribute")) {
34 return failure();
35 }
36
37 auto i32Type = IntegerType::get(parser.getContext(), 32);
38 auto type = TensorArmType::get(
39 ArrayRef{static_cast<int64_t>(elements.size())}, i32Type);
40 attr = DenseIntElementsAttr::get(type, elements);
41 return success();
42}
43
46 printer << llvm::interleaved_array(
47 llvm::map_range(attr.getValues<APInt>(),
48 [](const APInt &a) { return a.getSExtValue(); }));
49}
50
51} // namespace mlir::spirv
return success()
@ Square
Square brackets surrounding zero or more operands.
virtual ParseResult parseCommaSeparatedList(Delimiter delimiter, function_ref< ParseResult()> parseElementFn, StringRef contextMessage=StringRef())=0
Parse a list of comma-separated items with an optional delimiter.
MLIRContext * getContext() const
ParseResult parseInteger(IntT &result)
Parse an integer value from the stream.
An attribute that represents a reference to a dense integer vector or tensor object.
static DenseIntElementsAttr get(const ShapedType &type, Arg &&arg)
Get an instance of a DenseIntElementsAttr with the given arguments.
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
static TensorArmType get(ArrayRef< int64_t > shape, Type elementType)
void printSPIRV_I32_1DArmTensor(OpAsmPrinter &printer, Operation *, DenseIntElementsAttr attr)
ParseResult parseSPIRV_I32_1DArmTensor(OpAsmParser &parser, DenseIntElementsAttr &attr)