1//===- TestAvailability.cpp - Pass to test Tosa op availability ---------===//
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#include "mlir/Dialect/Func/IR/FuncOps.h"
10#include "mlir/Dialect/Tosa/IR/TosaOps.h"
11#include "mlir/Pass/Pass.h"
12
13using namespace mlir;
14
15//===----------------------------------------------------------------------===//
16// Printing op availability pass
17//===----------------------------------------------------------------------===//
18
19namespace {
20/// A pass for testing Tosa op availability.
21struct PrintOpAvailability
22 : public PassWrapper<PrintOpAvailability, OperationPass<func::FuncOp>> {
23 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(PrintOpAvailability)
24
25 void runOnOperation() override;
26 StringRef getArgument() const final { return "test-tosa-op-availability"; }
27 StringRef getDescription() const final { return "Test Tosa op availability"; }
28};
29} // namespace
30
31void PrintOpAvailability::runOnOperation() {
32 auto f = getOperation();
33 llvm::outs() << f.getName() << "\n";
34
35 Dialect *tosaDialect = getContext().getLoadedDialect("tosa");
36
37 f->walk([&](Operation *op) {
38 if (op->getDialect() != tosaDialect)
39 return WalkResult::advance();
40
41 auto opName = op->getName();
42 auto &os = llvm::outs();
43
44 if (auto profile = dyn_cast<tosa::QueryProfileInterface>(op)) {
45 os << opName << " profiles: [";
46 for (const auto &profs : profile.getProfiles()) {
47 os << " [";
48 llvm::interleaveComma(profs, os, [&](tosa::Profile prof) {
49 os << tosa::stringifyProfile(prof);
50 });
51 os << "]";
52 }
53 os << " ]\n";
54 }
55
56 if (auto extension = dyn_cast<tosa::QueryExtensionInterface>(op)) {
57 os << opName << " extensions: [";
58 for (const auto &exts : extension.getExtensions()) {
59 os << " [";
60 llvm::interleaveComma(exts, os, [&](tosa::Extension ext) {
61 os << tosa::stringifyExtension(ext);
62 });
63 os << "]";
64 }
65 os << " ]\n";
66 }
67
68 os.flush();
69
70 return WalkResult::advance();
71 });
72}
73
74namespace mlir {
75void registerPrintTosaAvailabilityPass() {
76 PassRegistration<PrintOpAvailability>();
77}
78} // namespace mlir
79

Provided by KDAB

Privacy Policy
Improve your Profiling and Debugging skills
Find out more

source code of mlir/test/lib/Dialect/Tosa/TestAvailability.cpp