LLZK 0.1.0
Veridise's ZK Language IR
Loading...
Searching...
No Matches
IntervalAnalysisPass.cpp
Go to the documentation of this file.
1//===-- IntervalAnalysisPass.cpp --------------------------------*- C++ -*-===//
2//
3// Part of the LLZK Project, under the Apache License v2.0.
4// See LICENSE.txt for license information.
5// Copyright 2025 Veridise Inc.
6// SPDX-License-Identifier: Apache-2.0
7//
8//===----------------------------------------------------------------------===//
13//===----------------------------------------------------------------------===//
14
19
20#include <llvm/ADT/SmallVector.h>
21#include <llvm/Support/Debug.h>
22#include <llvm/Support/ErrorHandling.h>
23
24namespace llzk {
25
26#define GEN_PASS_DECL_INTERVALANALYSISPRINTERPASS
27#define GEN_PASS_DEF_INTERVALANALYSISPRINTERPASS
29
30using namespace component;
31
33 : public impl::IntervalAnalysisPrinterPassBase<IntervalAnalysisPrinterPass> {
34 llvm::raw_ostream &os;
35
36public:
37 explicit IntervalAnalysisPrinterPass(llvm::raw_ostream &ostream)
39
40protected:
41 void runOnOperation() override {
42 markAllAnalysesPreserved();
43
44 if (!mlir::isa<mlir::ModuleOp>(getOperation())) {
45 auto msg = "IntervalAnalysisPrinterPass error: should be run on ModuleOp!";
46 getOperation()->emitError(msg);
47 llvm::report_fatal_error(msg);
48 }
49
50 auto &mia = getAnalysis<ModuleIntervalAnalysis>();
51 mia.setField(Field::getField(fieldName.c_str()));
52 auto am = getAnalysisManager();
53 mia.runAnalysis(am);
54
55 for (auto &[s, si] : mia) {
56 auto &structDef = const_cast<StructDefOp &>(s);
57 // Don't print the analysis for built-ins.
58 if (isSignalType(structDef.getType())) {
59 continue;
60 }
61 auto fullName = getPathFromTopRoot(structDef);
62 ensure(
63 mlir::succeeded(fullName),
64 "could not resolve fully qualified name of struct " + mlir::Twine(structDef.getName())
65 );
66 os << fullName.value() << ' ';
67 si.get().print(os, printSolverConstraints);
68 }
69 }
70};
71
72std::unique_ptr<mlir::Pass>
73createIntervalAnalysisPrinterPass(llvm::raw_ostream &os = llvm::errs()) {
74 return std::make_unique<IntervalAnalysisPrinterPass>(os);
75}
76
77} // namespace llzk
static const Field & getField(const char *fieldName)
Get a Field from a given field name string.
IntervalAnalysisPrinterPass(llvm::raw_ostream &ostream)
std::unique_ptr< mlir::Pass > createIntervalAnalysisPrinterPass(llvm::raw_ostream &os=llvm::errs())
void ensure(bool condition, llvm::Twine errMsg)
Definition ErrorHelper.h:32
FailureOr< SymbolRefAttr > getPathFromTopRoot(StructDefOp &to)
bool isSignalType(Type type)