LLZK 0.1.0
Veridise's ZK Language IR
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 llvm {
23
24template <class GraphType> struct GraphTraits;
25class raw_ostream;
26
27} // namespace llvm
28
29namespace mlir {
30
31class Operation;
32class ModuleOp;
33
34} // namespace mlir
35
36namespace llzk {
37
44 std::unique_ptr<llzk::CallGraph> cg;
45
46public:
47 CallGraphAnalysis(mlir::Operation *op);
48
49 llzk::CallGraph &getCallGraph() { return *cg.get(); }
50 const llzk::CallGraph &getCallGraph() const { return *cg.get(); }
51};
52
55
56 // Maps function -> callees
57 using CalleeMapTy = mlir::DenseMap<function::FuncDefOp, mlir::DenseSet<function::FuncDefOp>>;
58
59 mutable CalleeMapTy reachabilityMap;
60
61 std::reference_wrapper<llzk::CallGraph> callGraph;
62
63public:
64 CallGraphReachabilityAnalysis(mlir::Operation *, mlir::AnalysisManager &am);
65
66 bool isInvalidated(const mlir::AnalysisManager::PreservedAnalyses &pa) {
67 return !pa.isPreserved<CallGraphReachabilityAnalysis>() || !pa.isPreserved<CallGraphAnalysis>();
68 }
69
72
73 const llzk::CallGraph &getCallGraph() const { return callGraph.get(); }
74
75private:
76 inline bool isReachableCached(function::FuncDefOp &A, function::FuncDefOp &B) const {
77 auto it = reachabilityMap.find(A);
78 return it != reachabilityMap.end() && it->second.find(B) != it->second.end();
79 }
80};
81
82} // namespace llzk
An analysis wrapper to compute the CallGraph for a Module.
llzk::CallGraph & getCallGraph()
const llzk::CallGraph & getCallGraph() const
CallGraphAnalysis(mlir::Operation *op)
bool isInvalidated(const mlir::AnalysisManager::PreservedAnalyses &pa)
const llzk::CallGraph & getCallGraph() const
CallGraphReachabilityAnalysis(mlir::Operation *, mlir::AnalysisManager &am)
NOTE: the need for the mlir::Operation argument is a requirement of the mlir::getAnalysis method,...
bool isReachable(function::FuncDefOp &A, function::FuncDefOp &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:167
iterator end() const
Definition CallGraph.h:221