CIRCT 23.0.0git
Loading...
Searching...
No Matches
CaptureAnalysis.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Pre-pass over the slang AST to determine which non-local, non-global
10// variables each function captures, either directly or transitively through
11// calls to other functions.
12//
13// This information is needed before any MLIR conversion happens so that
14// function declarations can be created with the correct signature (including
15// extra capture parameters) upfront, enabling a clean two-phase
16// declare-then-define approach for functions.
17//
18//===----------------------------------------------------------------------===//
19
20// NOLINTNEXTLINE(llvm-header-guard)
21#ifndef CONVERSION_IMPORTVERILOG_CAPTUREANALYSIS_H
22#define CONVERSION_IMPORTVERILOG_CAPTUREANALYSIS_H
23
24#include "circt/Support/LLVM.h"
25#include "llvm/ADT/SetVector.h"
26
27namespace slang {
28namespace ast {
29class RootSymbol;
30class SubroutineSymbol;
31class ValueSymbol;
32} // namespace ast
33} // namespace slang
34
35namespace circt {
36namespace ImportVerilog {
37
38/// The result of capture analysis: for each function, the set of non-local,
39/// non-global variable symbols that the function captures directly or
40/// transitively through calls.
41using CaptureMap = DenseMap<const slang::ast::SubroutineSymbol *,
43
44/// Analyze the AST rooted at `root` to determine which variables each function
45/// captures. A variable is considered captured by a function if it is
46/// referenced inside the function's body (or transitively through called
47/// functions) and is neither local to the function nor a global variable
48/// (package-scope or compilation-unit-scope variables that are lowered via
49/// `get_global_signal`).
50CaptureMap analyzeFunctionCaptures(const slang::ast::RootSymbol &root);
51
52} // namespace ImportVerilog
53} // namespace circt
54
55#endif // CONVERSION_IMPORTVERILOG_CAPTUREANALYSIS_H
CaptureMap analyzeFunctionCaptures(const slang::ast::RootSymbol &root)
Analyze the AST rooted at root to determine which variables each function captures.
DenseMap< const slang::ast::SubroutineSymbol *, SmallSetVector< const slang::ast::ValueSymbol *, 4 > > CaptureMap
The result of capture analysis: for each function, the set of non-local, non-global variable symbols ...
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.