LLZK 2.1.1
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
ConstraintDependencyGraphPass.cpp
Go to the documentation of this file.
1//===-- ConstraintDependencyGraphPass.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
18
19#include <llvm/ADT/SmallVector.h>
20#include <llvm/Support/ErrorHandling.h>
21
22namespace llzk {
23#define GEN_PASS_DEF_CONSTRAINTDEPENDENCYGRAPHPRINTERPASS
25} // namespace llzk
26
27using namespace mlir;
28
29namespace {
30
31class PassImpl : public llzk::impl::ConstraintDependencyGraphPrinterPassBase<PassImpl> {
32 using Base = ConstraintDependencyGraphPrinterPassBase<PassImpl>;
33 using Base::Base;
34
35 void runOnOperation() override {
36 markAllAnalysesPreserved();
37
38 if (!llvm::isa<ModuleOp>(getOperation())) {
39 const char *msg = "ConstraintDependencyGraphPrinterPass error: should be run on ModuleOp!";
40 getOperation()->emitError(msg).report();
41 llvm::report_fatal_error(msg);
42 }
43
44 auto &cs = getAnalysis<llzk::ConstraintDependencyGraphModuleAnalysis>();
45 cs.setIntraprocedural(runIntraprocedural);
46 auto am = getAnalysisManager();
47 cs.ensureAnalysisRun(am);
48
49 auto &os = llzk::toStream(outputStream);
50 for (const auto &[s, cdg] : cs.getCurrentResults()) {
51 auto &structDef = const_cast<llzk::component::StructDefOp &>(s);
52 FailureOr<SymbolRefAttr> fullName = llzk::getPathFromTopRoot(structDef);
54 succeeded(fullName),
55 "could not resolve fully qualified name of struct " + Twine(structDef.getName())
56 );
57 os << fullName.value() << ' ';
58 cdg.get().print(os);
59 }
60 }
61};
62
63} // namespace
llvm::raw_ostream & toStream(OutputStream val)
void ensure(bool condition, const llvm::Twine &errMsg)
FailureOr< SymbolRefAttr > getPathFromTopRoot(SymbolOpInterface to, ModuleOp *foundRoot)