LLZK 0.1.0
Veridise's ZK Language IR
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
24using namespace component;
25
26#define GEN_PASS_DEF_CONSTRAINTDEPENDENCYGRAPHPRINTERPASS
28
30 : public impl::ConstraintDependencyGraphPrinterPassBase<ConstraintDependencyGraphPrinterPass> {
31 llvm::raw_ostream &os;
32
33public:
37
38protected:
39 void runOnOperation() override {
40 markAllAnalysesPreserved();
41
42 if (!mlir::isa<mlir::ModuleOp>(getOperation())) {
43 auto msg = "ConstraintDependencyGraphPrinterPass error: should be run on ModuleOp!";
44 getOperation()->emitError(msg);
45 llvm::report_fatal_error(msg);
46 }
47
48 auto &cs = getAnalysis<ConstraintDependencyGraphModuleAnalysis>();
49 auto am = getAnalysisManager();
50 cs.runAnalysis(am);
51 for (auto &[s, cdg] : cs) {
52 auto &structDef = const_cast<StructDefOp &>(s);
53 auto fullName = getPathFromTopRoot(structDef);
54 ensure(
55 mlir::succeeded(fullName),
56 "could not resolve fully qualified name of struct " + mlir::Twine(structDef.getName())
57 );
58 os << fullName.value() << ' ';
59 cdg.get().print(os);
60 }
61 }
62};
63
64std::unique_ptr<mlir::Pass>
65createConstraintDependencyGraphPrinterPass(llvm::raw_ostream &os = llvm::errs()) {
66 return std::make_unique<ConstraintDependencyGraphPrinterPass>(os);
67}
68
69} // namespace llzk
std::unique_ptr< mlir::Pass > createConstraintDependencyGraphPrinterPass(llvm::raw_ostream &os=llvm::errs())
void ensure(bool condition, llvm::Twine errMsg)
Definition ErrorHelper.h:32
FailureOr< SymbolRefAttr > getPathFromTopRoot(StructDefOp &to)