CIRCT  20.0.0git
ModelInfoExport.cpp
Go to the documentation of this file.
1 //===- ModelInfoExport.cpp - Exports model info to JSON format ------------===//
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 // Register the MLIR translation to export model info to JSON format.
10 //
11 //===----------------------------------------------------------------------===//
12 
16 #include "mlir/Dialect/Func/IR/FuncOps.h"
17 #include "mlir/Tools/mlir-translate/Translation.h"
18 
19 using namespace llvm;
20 using namespace mlir;
21 using namespace circt;
22 using namespace arc;
23 
24 LogicalResult circt::arc::collectAndExportModelInfo(ModuleOp module,
25  llvm::raw_ostream &os) {
26  SmallVector<ModelInfo> models;
27  if (failed(collectModels(module, models)))
28  return failure();
29  serializeModelInfoToJson(os, models);
30  return success();
31 }
32 
34  static mlir::TranslateFromMLIRRegistration modelInfoToJson(
35  "export-arc-model-info", "export Arc model info in JSON format",
36  [](ModuleOp module, llvm::raw_ostream &os) {
37  return arc::collectAndExportModelInfo(module, os);
38  },
39  [](mlir::DialectRegistry &registry) {
40  registry.insert<arc::ArcDialect>();
41  registry.insert<func::FuncDialect>();
42  });
43 }
mlir::LogicalResult collectAndExportModelInfo(mlir::ModuleOp module, llvm::raw_ostream &os)
Collects and exports Arc model info to JSON.
void registerArcModelInfoTranslation()
Registers CIRCT translation from Arc to JSON model info.
void serializeModelInfoToJson(llvm::raw_ostream &outputStream, llvm::ArrayRef< ModelInfo > models)
Serializes models to outputStream in JSON format.
mlir::LogicalResult collectModels(mlir::ModuleOp module, llvm::SmallVector< ModelInfo > &models)
Collects information about all Arc models in the provided module, and adds it to models.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21