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;
32class InstanceSymbol;
33class HierarchicalReference;
34enum class SymbolKind : int;
35} // namespace ast
36} // namespace slang
37
38namespace circt {
39namespace ImportVerilog {
40
41/// Return true if symbols of this kind are elaboration-time constants. They
42/// are materialized inline instead of being captured or ported.
43bool isCompileTimeConstant(slang::ast::SymbolKind kind);
44
45/// Return the first instance on a hierarchical reference path, i.e. the
46/// instance the reference enters the hierarchy through.
47const slang::ast::InstanceSymbol *
48getRootInstance(const slang::ast::HierarchicalReference &ref);
49
50/// The result of capture analysis: for each function, the set of non-local,
51/// non-global variable symbols that the function captures directly or
52/// transitively through calls.
53using CaptureMap = DenseMap<const slang::ast::SubroutineSymbol *,
55
56/// A function whose hierarchical reference resolves to one symbol reachable
57/// through more than one instance. Lowering cannot pick an instance safely.
59 const slang::ast::SubroutineSymbol *function;
60 const slang::ast::ValueSymbol *symbol;
61};
62
63/// Analyze the AST rooted at `root` to determine which variables each
64/// function captures: symbols referenced inside the function's body (directly
65/// or through called functions) that are neither local nor global, including
66/// hierarchical references to other instances. Captures that cannot be
67/// resolved to a single instance are reported in `ambiguous`.
69analyzeFunctionCaptures(const slang::ast::RootSymbol &root,
70 SmallVectorImpl<AmbiguousHierCapture> &ambiguous);
71
72} // namespace ImportVerilog
73} // namespace circt
74
75#endif // CONVERSION_IMPORTVERILOG_CAPTUREANALYSIS_H
const slang::ast::InstanceSymbol * getRootInstance(const slang::ast::HierarchicalReference &ref)
Return the first instance on a hierarchical reference path, i.e.
CaptureMap analyzeFunctionCaptures(const slang::ast::RootSymbol &root, SmallVectorImpl< AmbiguousHierCapture > &ambiguous)
Analyze the AST rooted at root to determine which variables each function captures: symbols reference...
bool isCompileTimeConstant(slang::ast::SymbolKind kind)
Return true if symbols of this kind are elaboration-time constants.
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.
A function whose hierarchical reference resolves to one symbol reachable through more than one instan...
const slang::ast::ValueSymbol * symbol
const slang::ast::SubroutineSymbol * function