LLZK 3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
CallGraphAnalyses.h
Go to the documentation of this file.
1//===-- CallGraphAnalyses.h -------------------------------------*- 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//===----------------------------------------------------------------------===//
9
10#pragma once
11
14
15#include <mlir/Pass/AnalysisManager.h>
16
17#include <llvm/ADT/DenseMap.h>
18#include <llvm/ADT/DenseSet.h>
19#include <llvm/ADT/SCCIterator.h>
20#include <llvm/ADT/STLExtras.h>
21
22namespace mlir {
23
24class Operation;
25
26} // namespace mlir
27
28namespace llzk {
29
36 std::unique_ptr<llzk::CallGraph> cg;
37
38public:
39 CallGraphAnalysis(mlir::Operation *op);
40
41 llzk::CallGraph &getCallGraph() { return *cg; }
42 const llzk::CallGraph &getCallGraph() const { return *cg; }
43};
44
47
48 // Maps function -> callees
49 using CalleeMapTy =
50 mlir::DenseMap<mlir::CallableOpInterface, mlir::DenseSet<mlir::CallableOpInterface>>;
51
52 mutable CalleeMapTy reachabilityMap;
53
54 std::reference_wrapper<llzk::CallGraph> callGraph;
55
56public:
57 CallGraphReachabilityAnalysis(mlir::Operation *, mlir::AnalysisManager &am);
58
59 static bool isInvalidated(const mlir::AnalysisManager::PreservedAnalyses &pa) {
60 return !pa.isPreserved<CallGraphReachabilityAnalysis>() || !pa.isPreserved<CallGraphAnalysis>();
61 }
62
64 bool isReachable(mlir::CallableOpInterface A, mlir::CallableOpInterface B) const;
65
66 const llzk::CallGraph &getCallGraph() const { return callGraph.get(); }
67
68private:
69 inline bool isReachableCached(mlir::CallableOpInterface A, mlir::CallableOpInterface B) const {
70 auto it = reachabilityMap.find(A);
71 return it != reachabilityMap.end() && it->second.find(B) != it->second.end();
72 }
73};
74
75} // namespace llzk
An analysis wrapper to compute the CallGraph for a Module.
llzk::CallGraph & getCallGraph()
const llzk::CallGraph & getCallGraph() const
CallGraphAnalysis(mlir::Operation *op)
const llzk::CallGraph & getCallGraph() const
static bool isInvalidated(const mlir::AnalysisManager::PreservedAnalyses &pa)
CallGraphReachabilityAnalysis(mlir::Operation *, mlir::AnalysisManager &am)
NOTE: the need for the mlir::Operation argument is a requirement of the mlir::getAnalysis method,...
bool isReachable(mlir::CallableOpInterface A, mlir::CallableOpInterface B) const
Returns whether B is reachable from A.
This is a port of mlir::CallGraph that has been adapted to use the custom symbol lookup helpers (see ...
Definition CallGraph.h:164
iterator end() const
Definition CallGraph.h:218