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 mia.setPropagateInputConstraints(propagateInputConstraints);
53 auto am = getAnalysisManager();
54 mia.runAnalysis(am);
55
56 for (auto &[s, si] : mia) {
57 auto &structDef = const_cast<StructDefOp &>(s);
58 // Don't print the analysis for built-ins.
59 if (isSignalType(structDef.getType())) {
60 continue;
61 }
62 auto fullName = getPathFromTopRoot(structDef);
63 ensure(
64 mlir::succeeded(fullName),
65 "could not resolve fully qualified name of struct " + mlir::Twine(structDef.getName())
66 );
67 os << fullName.value() << ' ';
69 }
70 }
71};
72
73std::unique_ptr<mlir::Pass>
74createIntervalAnalysisPrinterPass(llvm::raw_ostream &os = llvm::errs()) {
75 return std::make_unique<IntervalAnalysisPrinterPass>(os);
76}
77
78} // namespace llzk
static const Field & getField(const char *fieldName)
Get a Field from a given field name string.
Definition Field.cpp:26
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:35
bool isSignalType(Type type)
FailureOr< SymbolRefAttr > getPathFromTopRoot(SymbolOpInterface to, ModuleOp *foundRoot)