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