CIRCT 23.0.0git
Loading...
Searching...
No Matches
ImportVerilogInternals.h
Go to the documentation of this file.
1//===- ImportVerilogInternals.h - Internal implementation details ---------===//
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// NOLINTNEXTLINE(llvm-header-guard)
10#ifndef CONVERSION_IMPORTVERILOG_IMPORTVERILOGINTERNALS_H
11#define CONVERSION_IMPORTVERILOG_IMPORTVERILOGINTERNALS_H
12
19#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
20#include "mlir/Dialect/Func/IR/FuncOps.h"
21#include "slang/ast/ASTVisitor.h"
22#include "llvm/ADT/ScopedHashTable.h"
23#include "llvm/Support/Debug.h"
24#include <map>
25#include <queue>
26
27#define DEBUG_TYPE "import-verilog"
28
29namespace circt {
30namespace ImportVerilog {
31
32using moore::Domain;
33
34/// Port lowering information.
36 const slang::ast::PortSymbol &ast;
37 Location loc;
38 BlockArgument arg;
39};
40
41/// Lowering information for a single signal flattened from an interface port.
43 StringAttr name;
45 mlir::Type type;
46 Location loc;
47 BlockArgument arg;
48 /// the origin interface port symbol this was flattened from.
49 const slang::ast::InterfacePortSymbol *origin;
50 /// the interface body member (VariableSymbol , NetSymbol)
51 const slang::ast::Symbol *bodySym;
52 /// The connected interface instance backing this port (if any). This enables
53 /// materializing virtual interface handles from interface ports.
54 const slang::ast::InstanceSymbol *ifaceInstance = nullptr;
55};
56
57/// Lowering information for an expanded interface instance. Maps each interface
58/// body member to its expanded SSA value (moore.variable or moore.net).
60 DenseMap<const slang::ast::Symbol *, Value> expandedMembers;
61 DenseMap<StringAttr, Value> expandedMembersByName;
62};
63
64/// Cached lowering information for representing SystemVerilog `virtual
65/// interface` handles as Moore types (a struct of references to interface
66/// members).
68 moore::UnpackedStructType type;
69 SmallVector<StringAttr, 8> fieldNames;
70};
71
72/// A mapping entry for resolving Slang virtual interface member accesses.
73///
74/// Slang may resolve `vif.member` expressions (where `vif` has a
75/// `VirtualInterfaceType`) directly to a `NamedValueExpression` for `member`.
76/// This table records which virtual interface base symbol that member access is
77/// rooted in, so ImportVerilog can materialize the appropriate Moore IR.
79 const slang::ast::ValueSymbol *base = nullptr;
80 /// The name of the field in the lowered virtual interface handle struct that
81 /// should be accessed for this member.
82 StringAttr fieldName;
83};
84
85/// Module lowering information.
87 moore::SVModuleOp op;
88 SmallVector<PortLowering> ports;
89 SmallVector<FlattenedIfacePort> ifacePorts;
90 DenseMap<const slang::syntax::SyntaxNode *, const slang::ast::PortSymbol *>
92};
93
94/// Function lowering information. The `op` field holds either a `func::FuncOp`
95/// (for SystemVerilog functions) or a `moore::CoroutineOp` (for tasks),
96/// accessed through the `FunctionOpInterface`.
98 mlir::FunctionOpInterface op;
99 llvm::SmallVector<Value, 4> captures;
100 llvm::DenseMap<Value, unsigned> captureIndex;
101 bool capturesFinalized = false;
102 bool isConverting = false;
103
104 /// Whether this is a coroutine (task) or a regular function.
105 bool isCoroutine() { return isa<moore::CoroutineOp>(op.getOperation()); }
106};
107
108// Class lowering information.
110 circt::moore::ClassDeclOp op;
111 bool methodsFinalized = false;
112};
113
114/// Information about a loops continuation and exit blocks relevant while
115/// lowering the loop's body statements.
116struct LoopFrame {
117 /// The block to jump to from a `continue` statement.
119 /// The block to jump to from a `break` statement.
121};
122
123/// Hierarchical path information.
124/// The "hierName" means a different hierarchical name at different module
125/// levels.
126/// The "idx" means where the current hierarchical name is on the portlists.
127/// The "direction" means hierarchical names whether downward(In) or
128/// upward(Out).
130 mlir::StringAttr hierName;
131 std::optional<unsigned int> idx;
132 slang::ast::ArgumentDirection direction;
133 const slang::ast::ValueSymbol *valueSym;
134};
135
136/// A helper class to facilitate the conversion from a Slang AST to MLIR
137/// operations. Keeps track of the destination MLIR module, builders, and
138/// various worklists and utilities needed for conversion.
139struct Context {
141 slang::ast::Compilation &compilation, mlir::ModuleOp intoModuleOp,
142 const slang::SourceManager &sourceManager)
145 builder(OpBuilder::atBlockEnd(intoModuleOp.getBody())),
147 Context(const Context &) = delete;
148
149 /// Return the MLIR context.
150 MLIRContext *getContext() { return intoModuleOp.getContext(); }
151
152 /// Convert a slang `SourceLocation` into an MLIR `Location`.
153 Location convertLocation(slang::SourceLocation loc);
154 /// Convert a slang `SourceRange` into an MLIR `Location`.
155 Location convertLocation(slang::SourceRange range);
156
157 /// Convert a slang type into an MLIR type. Returns null on failure. Uses the
158 /// provided location for error reporting, or tries to guess one from the
159 /// given type. Types tend to have unreliable location information, so it's
160 /// generally a good idea to pass in a location.
161 Type convertType(const slang::ast::Type &type, LocationAttr loc = {});
162 Type convertType(const slang::ast::DeclaredType &type);
163
164 /// Convert hierarchy and structure AST nodes to MLIR ops.
165 LogicalResult convertCompilation();
166 ModuleLowering *
167 convertModuleHeader(const slang::ast::InstanceBodySymbol *module);
168 LogicalResult convertModuleBody(const slang::ast::InstanceBodySymbol *module);
169 LogicalResult convertPackage(const slang::ast::PackageSymbol &package);
170 FunctionLowering *
171 declareFunction(const slang::ast::SubroutineSymbol &subroutine);
172 LogicalResult convertFunction(const slang::ast::SubroutineSymbol &subroutine);
173 LogicalResult finalizeFunctionBodyCaptures(FunctionLowering &lowering);
174 ClassLowering *declareClass(const slang::ast::ClassType &cls);
175 LogicalResult buildClassProperties(const slang::ast::ClassType &classdecl);
176 LogicalResult materializeClassMethods(const slang::ast::ClassType &classdecl);
177 LogicalResult convertGlobalVariable(const slang::ast::VariableSymbol &var);
178
179 /// Convert a Slang virtual interface type into the Moore type used to
180 /// represent virtual interface handles. Populates internal caches so that
181 /// interface instance references can be materialized consistently.
182 FailureOr<moore::UnpackedStructType>
183 convertVirtualInterfaceType(const slang::ast::VirtualInterfaceType &type,
184 Location loc);
185
186 /// Materialize a Moore value representing a concrete interface instance as a
187 /// virtual interface handle. This only succeeds for the Slang
188 /// `VirtualInterfaceType` wrappers that refer to a real interface instance
189 /// (`isRealIface`).
190 FailureOr<Value>
191 materializeVirtualInterfaceValue(const slang::ast::VirtualInterfaceType &type,
192 Location loc);
193
194 /// Register the interface members of a virtual interface base symbol for use
195 /// in later expression conversion.
196 LogicalResult
197 registerVirtualInterfaceMembers(const slang::ast::ValueSymbol &base,
198 const slang::ast::VirtualInterfaceType &type,
199 Location loc);
200
201 /// Checks whether one class (actualTy) is derived from another class
202 /// (baseTy). True if it's a subclass, false otherwise.
203 bool isClassDerivedFrom(const moore::ClassHandleType &actualTy,
204 const moore::ClassHandleType &baseTy);
205
206 /// Tries to find the closest base class of actualTy that carries a property
207 /// with name fieldName. The location is used for error reporting.
208 moore::ClassHandleType
209 getAncestorClassWithProperty(const moore::ClassHandleType &actualTy,
210 StringRef fieldName, Location loc);
211
212 Value getImplicitThisRef() const {
213 return currentThisRef; // block arg added in declareFunction
214 }
215
216 Value getIndexedQueue() const { return currentQueue; }
217
218 // Convert a statement AST node to MLIR ops.
219 LogicalResult convertStatement(const slang::ast::Statement &stmt);
220
221 // Convert an expression AST node to MLIR ops.
222 Value convertRvalueExpression(const slang::ast::Expression &expr,
223 Type requiredType = {});
224 Value convertLvalueExpression(const slang::ast::Expression &expr);
225
226 // Convert an assertion expression AST node to MLIR ops.
227 Value convertAssertionExpression(const slang::ast::AssertionExpr &expr,
228 Location loc);
229
230 // Convert an assertion expression AST node to MLIR ops.
232 const slang::ast::CallExpression &expr,
233 const slang::ast::CallExpression::SystemCallInfo &info, Location loc);
234
235 // Traverse the whole AST to collect hierarchical names.
236 LogicalResult
237 collectHierarchicalValues(const slang::ast::Expression &expr,
238 const slang::ast::Symbol &outermostModule);
239 LogicalResult traverseInstanceBody(const slang::ast::Symbol &symbol);
240
241 // Convert timing controls into a corresponding set of ops that delay
242 // execution of the current block. Produces an error if the implicit event
243 // control `@*` or `@(*)` is used.
244 LogicalResult convertTimingControl(const slang::ast::TimingControl &ctrl);
245 // Convert timing controls into a corresponding set of ops that delay
246 // execution of the current block. Then converts the given statement, taking
247 // note of the rvalues it reads and adding them to a wait op in case an
248 // implicit event control `@*` or `@(*)` is used.
249 LogicalResult convertTimingControl(const slang::ast::TimingControl &ctrl,
250 const slang::ast::Statement &stmt);
251
252 /// Helper function to convert a value to a MLIR I1 value.
253 Value convertToI1(Value value);
254
255 // Convert a slang timing control for LTL
256 Value convertLTLTimingControl(const slang::ast::TimingControl &ctrl,
257 const Value &seqOrPro);
258
259 /// Helper function to convert a value to its "truthy" boolean value.
260 Value convertToBool(Value value);
261
262 /// Helper function to convert a value to its "truthy" boolean value and
263 /// convert it to the given domain.
264 Value convertToBool(Value value, Domain domain);
265
266 /// Helper function to convert a value to its simple bit vector
267 /// representation, if it has one. Otherwise returns null. Also returns null
268 /// if the given value is null.
269 Value convertToSimpleBitVector(Value value);
270
271 /// Helper function to insert the necessary operations to cast a value from
272 /// one type to another.
273 Value materializeConversion(Type type, Value value, bool isSigned,
274 Location loc);
275
276 /// Helper function to materialize an `SVInt` as an SSA value.
277 Value materializeSVInt(const slang::SVInt &svint,
278 const slang::ast::Type &type, Location loc);
279
280 /// Helper function to materialize a real value as an SSA value.
281 Value materializeSVReal(const slang::ConstantValue &svreal,
282 const slang::ast::Type &type, Location loc);
283
284 /// Helper function to materialize a string as an SSA value.
285 Value materializeString(const slang::ConstantValue &string,
286 const slang::ast::Type &astType, Location loc);
287
288 /// Helper function to materialize an unpacked array of `SVInt`s as an SSA
289 /// value.
291 const slang::ConstantValue &constant,
292 const slang::ast::FixedSizeUnpackedArrayType &astType, Location loc);
293
294 /// Helper function to materialize a `ConstantValue` as an SSA value. Returns
295 /// null if the constant cannot be materialized.
296 Value materializeConstant(const slang::ConstantValue &constant,
297 const slang::ast::Type &type, Location loc);
298
299 /// Convert a list of string literal arguments with formatting specifiers and
300 /// arguments to be interpolated into a `!moore.format_string` value. Returns
301 /// failure if an error occurs. Returns a null value if the formatted string
302 /// is trivially empty. Otherwise returns the formatted string.
303 FailureOr<Value> convertFormatString(
304 std::span<const slang::ast::Expression *const> arguments, Location loc,
305 moore::IntFormat defaultFormat = moore::IntFormat::Decimal,
306 bool appendNewline = false);
307
308 /// Convert system function calls. Returns a null `Value` on failure after
309 /// emitting an error.
310 Value convertSystemCall(const slang::ast::SystemSubroutine &subroutine,
311 Location loc,
312 std::span<const slang::ast::Expression *const> args);
313
314 /// Convert system function calls within properties and assertion with a
315 /// single argument.
316 FailureOr<Value> convertAssertionSystemCallArity1(
317 const slang::ast::SystemSubroutine &subroutine, Location loc, Value value,
318 Type originalType);
319
320 /// Evaluate the constant value of an expression.
321 slang::ConstantValue evaluateConstant(const slang::ast::Expression &expr);
322
324 slang::ast::Compilation &compilation;
325 mlir::ModuleOp intoModuleOp;
326 const slang::SourceManager &sourceManager;
327
328 /// The builder used to create IR operations.
329 OpBuilder builder;
330 /// A symbol table of the MLIR module we are emitting into.
331 SymbolTable symbolTable;
332
333 /// The top-level operations ordered by their Slang source location. This is
334 /// used to produce IR that follows the source file order.
335 std::map<slang::SourceLocation, Operation *> orderedRootOps;
336
337 /// How we have lowered modules to MLIR.
338 DenseMap<const slang::ast::InstanceBodySymbol *,
339 std::unique_ptr<ModuleLowering>>
341
342 /// Expanded interface instances, keyed by the InstanceSymbol pointer.
343 /// Each entry maps body members to their expanded SSA values. Scoped
344 /// per-module so entries are cleaned up when a module's conversion ends.
346 llvm::ScopedHashTable<const slang::ast::InstanceSymbol *,
348 using InterfaceInstanceScope = InterfaceInstances::ScopeTy;
350 /// Owning storage for InterfaceLowering objects
351 /// because ScopedHashTable stores values by copy.
352 SmallVector<std::unique_ptr<InterfaceLowering>> interfaceInstanceStorage;
353
354 /// Cached virtual interface layouts (type + field order).
355 DenseMap<const slang::ast::InstanceBodySymbol *, VirtualInterfaceLowering>
357 DenseMap<const slang::ast::ModportSymbol *, VirtualInterfaceLowering>
359 /// A list of modules for which the header has been created, but the body has
360 /// not been converted yet.
361 std::queue<const slang::ast::InstanceBodySymbol *> moduleWorklist;
362
363 /// Functions that have already been converted.
364 DenseMap<const slang::ast::SubroutineSymbol *,
365 std::unique_ptr<FunctionLowering>>
367
368 /// Classes that have already been converted.
369 DenseMap<const slang::ast::ClassType *, std::unique_ptr<ClassLowering>>
371
372 /// A table of defined values, such as variables, that may be referred to by
373 /// name in expressions. The expressions use this table to lookup the MLIR
374 /// value that was created for a given declaration in the Slang AST node.
376 llvm::ScopedHashTable<const slang::ast::ValueSymbol *, Value>;
377 using ValueSymbolScope = ValueSymbols::ScopeTy;
379
380 /// A table mapping symbols for interface members accessed through a virtual
381 /// interface to the virtual interface base value symbol.
383 llvm::ScopedHashTable<const slang::ast::ValueSymbol *,
385 using VirtualInterfaceMemberScope = VirtualInterfaceMembers::ScopeTy;
387
388 /// A table of defined global variables that may be referred to by name in
389 /// expressions.
390 DenseMap<const slang::ast::ValueSymbol *, moore::GlobalVariableOp>
392 /// A list of global variables that still need their initializers to be
393 /// converted.
394 SmallVector<const slang::ast::ValueSymbol *> globalVariableWorklist;
395
396 /// Collect all hierarchical names used for the per module/instance.
397 DenseMap<const slang::ast::InstanceBodySymbol *, SmallVector<HierPathInfo>>
399
400 /// It's used to collect the repeat hierarchical names on the same path.
401 /// Such as `Top.sub.a` and `sub.a`, they are equivalent. The variable "a"
402 /// will be added to the port list. But we only record once. If we don't do
403 /// that. We will view the strange IR, such as `module @Sub(out y, out y)`;
404 DenseSet<StringAttr> sameHierPaths;
405
406 /// A stack of assignment left-hand side values. Each assignment will push its
407 /// lowered left-hand side onto this stack before lowering its right-hand
408 /// side. This allows expressions to resolve the opaque
409 /// `LValueReferenceExpression`s in the AST.
410 SmallVector<Value> lvalueStack;
411
412 /// A stack of loop continuation and exit blocks. Each loop will push the
413 /// relevant info onto this stack, lower its loop body statements, and pop the
414 /// info off the stack again. Continue and break statements encountered as
415 /// part of the loop body statements will use this information to branch to
416 /// the correct block.
417 SmallVector<LoopFrame> loopStack;
418
419 /// A listener called for every variable or net being read. This can be used
420 /// to collect all variables read as part of an expression or statement, for
421 /// example to populate the list of observed signals in an implicit event
422 /// control `@*`.
423 std::function<void(moore::ReadOp)> rvalueReadCallback;
424 /// A listener called for every variable or net being assigned. This can be
425 /// used to collect all variables assigned in a task scope.
426 std::function<void(mlir::Operation *)> variableAssignCallback;
427
428 /// Whether we are currently converting expressions inside a timing control,
429 /// such as `@(posedge clk)`. This is used by the implicit event control
430 /// callback to avoid adding reads from explicit event controls to the
431 /// implicit sensitivity list.
433
434 /// The time scale currently in effect.
435 slang::TimeScale timeScale;
436
437 /// Variable to track the value of the current function's implicit `this`
438 /// reference
439 Value currentThisRef = {};
440
441 /// Variable that tracks the queue which we are currently converting the index
442 /// expression for. This is necessary to implement the `$` operator, which
443 /// returns the index of the last element of the queue.
444 Value currentQueue = {};
445
446 /// Ensure that the global variables for `$monitor` state exist. This creates
447 /// the `__monitor_active_id` and `__monitor_enabled` globals on first call.
449
450 /// Process any pending `$monitor` calls and generate the monitoring
451 /// procedures at module level.
452 LogicalResult flushPendingMonitors();
453
454 /// Global variable ops for `$monitor` state management. These are created on
455 /// demand by `ensureMonitorGlobals()`.
456 moore::GlobalVariableOp monitorActiveIdGlobal = nullptr;
457 moore::GlobalVariableOp monitorEnabledGlobal = nullptr;
458
459 /// The next monitor ID to allocate. ID 0 is reserved for "no monitor active".
460 unsigned nextMonitorId = 1;
461
462 /// Information about a pending `$monitor` call that needs to be converted
463 /// after the current module's body has been processed.
465 unsigned id;
466 Location loc;
467 const slang::ast::CallExpression *call;
468 };
469
470 /// Pending `$monitor` calls that need to be converted at module level.
471 SmallVector<PendingMonitor> pendingMonitors;
472
473private:
474 /// Helper function to extract the commonalities in lowering of functions and
475 /// methods
477 declareCallableImpl(const slang::ast::SubroutineSymbol &subroutine,
478 mlir::StringRef qualifiedName,
479 llvm::SmallVectorImpl<Type> &extraParams);
480};
481
482} // namespace ImportVerilog
483} // namespace circt
484#endif // CONVERSION_IMPORTVERILOG_IMPORTVERILOGINTERNALS_H
Domain
The number of values each bit of a type can assume.
Definition MooreTypes.h:50
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Options that control how Verilog input files are parsed and processed.
Information about a pending $monitor call that needs to be converted after the current module's body ...
A helper class to facilitate the conversion from a Slang AST to MLIR operations.
LogicalResult convertFunction(const slang::ast::SubroutineSymbol &subroutine)
Convert a function.
Value convertToI1(Value value)
Helper function to convert a value to a MLIR I1 value.
Value materializeConversion(Type type, Value value, bool isSigned, Location loc)
Helper function to insert the necessary operations to cast a value from one type to another.
llvm::ScopedHashTable< const slang::ast::InstanceSymbol *, InterfaceLowering * > InterfaceInstances
Expanded interface instances, keyed by the InstanceSymbol pointer.
FunctionLowering * declareCallableImpl(const slang::ast::SubroutineSymbol &subroutine, mlir::StringRef qualifiedName, llvm::SmallVectorImpl< Type > &extraParams)
Helper function to extract the commonalities in lowering of functions and methods.
ModuleLowering * convertModuleHeader(const slang::ast::InstanceBodySymbol *module)
Convert a module and its ports to an empty module op in the IR.
Value convertLvalueExpression(const slang::ast::Expression &expr)
LogicalResult registerVirtualInterfaceMembers(const slang::ast::ValueSymbol &base, const slang::ast::VirtualInterfaceType &type, Location loc)
Register the interface members of a virtual interface base symbol for use in later expression convers...
Definition Types.cpp:474
Value materializeConstant(const slang::ConstantValue &constant, const slang::ast::Type &type, Location loc)
Helper function to materialize a ConstantValue as an SSA value.
SmallVector< LoopFrame > loopStack
A stack of loop continuation and exit blocks.
LogicalResult convertModuleBody(const slang::ast::InstanceBodySymbol *module)
Convert a module's body to the corresponding IR ops.
slang::ConstantValue evaluateConstant(const slang::ast::Expression &expr)
Evaluate the constant value of an expression.
SmallVector< PendingMonitor > pendingMonitors
Pending $monitor calls that need to be converted at module level.
Value convertLTLTimingControl(const slang::ast::TimingControl &ctrl, const Value &seqOrPro)
LogicalResult materializeClassMethods(const slang::ast::ClassType &classdecl)
DenseMap< const slang::ast::ValueSymbol *, moore::GlobalVariableOp > globalVariables
A table of defined global variables that may be referred to by name in expressions.
slang::ast::Compilation & compilation
LogicalResult convertTimingControl(const slang::ast::TimingControl &ctrl)
DenseMap< const slang::ast::InstanceBodySymbol *, VirtualInterfaceLowering > virtualIfaceLowerings
Cached virtual interface layouts (type + field order).
LogicalResult flushPendingMonitors()
Process any pending $monitor calls and generate the monitoring procedures at module level.
llvm::ScopedHashTable< const slang::ast::ValueSymbol *, VirtualInterfaceMemberAccess > VirtualInterfaceMembers
A table mapping symbols for interface members accessed through a virtual interface to the virtual int...
Context(const ImportVerilogOptions &options, slang::ast::Compilation &compilation, mlir::ModuleOp intoModuleOp, const slang::SourceManager &sourceManager)
OpBuilder builder
The builder used to create IR operations.
std::queue< const slang::ast::InstanceBodySymbol * > moduleWorklist
A list of modules for which the header has been created, but the body has not been converted yet.
LogicalResult convertGlobalVariable(const slang::ast::VariableSymbol &var)
Convert a variable to a moore.global_variable operation.
Value materializeFixedSizeUnpackedArrayType(const slang::ConstantValue &constant, const slang::ast::FixedSizeUnpackedArrayType &astType, Location loc)
Helper function to materialize an unpacked array of SVInts as an SSA value.
Value convertAssertionCallExpression(const slang::ast::CallExpression &expr, const slang::ast::CallExpression::SystemCallInfo &info, Location loc)
DenseMap< const slang::ast::ClassType *, std::unique_ptr< ClassLowering > > classes
Classes that have already been converted.
std::function< void(moore::ReadOp)> rvalueReadCallback
A listener called for every variable or net being read.
bool isClassDerivedFrom(const moore::ClassHandleType &actualTy, const moore::ClassHandleType &baseTy)
Checks whether one class (actualTy) is derived from another class (baseTy).
Context(const Context &)=delete
std::map< slang::SourceLocation, Operation * > orderedRootOps
The top-level operations ordered by their Slang source location.
Value convertSystemCall(const slang::ast::SystemSubroutine &subroutine, Location loc, std::span< const slang::ast::Expression *const > args)
Convert system function calls.
Type convertType(const slang::ast::Type &type, LocationAttr loc={})
Convert a slang type into an MLIR type.
Definition Types.cpp:224
DenseMap< const slang::ast::SubroutineSymbol *, std::unique_ptr< FunctionLowering > > functions
Functions that have already been converted.
Value materializeSVInt(const slang::SVInt &svint, const slang::ast::Type &type, Location loc)
Helper function to materialize an SVInt as an SSA value.
slang::TimeScale timeScale
The time scale currently in effect.
LogicalResult finalizeFunctionBodyCaptures(FunctionLowering &lowering)
Value materializeSVReal(const slang::ConstantValue &svreal, const slang::ast::Type &type, Location loc)
Helper function to materialize a real value as an SSA value.
ClassLowering * declareClass(const slang::ast::ClassType &cls)
VirtualInterfaceMembers::ScopeTy VirtualInterfaceMemberScope
Value convertToBool(Value value)
Helper function to convert a value to its "truthy" boolean value.
std::function< void(mlir::Operation *)> variableAssignCallback
A listener called for every variable or net being assigned.
moore::ClassHandleType getAncestorClassWithProperty(const moore::ClassHandleType &actualTy, StringRef fieldName, Location loc)
Tries to find the closest base class of actualTy that carries a property with name fieldName.
void ensureMonitorGlobals()
Ensure that the global variables for $monitor state exist.
FailureOr< Value > convertFormatString(std::span< const slang::ast::Expression *const > arguments, Location loc, moore::IntFormat defaultFormat=moore::IntFormat::Decimal, bool appendNewline=false)
Convert a list of string literal arguments with formatting specifiers and arguments to be interpolate...
const ImportVerilogOptions & options
Value convertRvalueExpression(const slang::ast::Expression &expr, Type requiredType={})
SmallVector< std::unique_ptr< InterfaceLowering > > interfaceInstanceStorage
Owning storage for InterfaceLowering objects because ScopedHashTable stores values by copy.
llvm::ScopedHashTable< const slang::ast::ValueSymbol *, Value > ValueSymbols
A table of defined values, such as variables, that may be referred to by name in expressions.
Value convertToSimpleBitVector(Value value)
Helper function to convert a value to its simple bit vector representation, if it has one.
moore::GlobalVariableOp monitorActiveIdGlobal
Global variable ops for $monitor state management.
VirtualInterfaceMembers virtualIfaceMembers
LogicalResult traverseInstanceBody(const slang::ast::Symbol &symbol)
Value materializeString(const slang::ConstantValue &string, const slang::ast::Type &astType, Location loc)
Helper function to materialize a string as an SSA value.
moore::GlobalVariableOp monitorEnabledGlobal
DenseMap< const slang::ast::ModportSymbol *, VirtualInterfaceLowering > virtualIfaceModportLowerings
Value currentThisRef
Variable to track the value of the current function's implicit this reference.
const slang::SourceManager & sourceManager
DenseSet< StringAttr > sameHierPaths
It's used to collect the repeat hierarchical names on the same path.
Value currentQueue
Variable that tracks the queue which we are currently converting the index expression for.
InterfaceInstances::ScopeTy InterfaceInstanceScope
FailureOr< Value > materializeVirtualInterfaceValue(const slang::ast::VirtualInterfaceType &type, Location loc)
Materialize a Moore value representing a concrete interface instance as a virtual interface handle.
Definition Types.cpp:357
SymbolTable symbolTable
A symbol table of the MLIR module we are emitting into.
DenseMap< const slang::ast::InstanceBodySymbol *, SmallVector< HierPathInfo > > hierPaths
Collect all hierarchical names used for the per module/instance.
bool isInsideTimingControl
Whether we are currently converting expressions inside a timing control, such as @(posedge clk).
FunctionLowering * declareFunction(const slang::ast::SubroutineSymbol &subroutine)
Convert a function and its arguments to a function declaration in the IR.
LogicalResult collectHierarchicalValues(const slang::ast::Expression &expr, const slang::ast::Symbol &outermostModule)
Value convertAssertionExpression(const slang::ast::AssertionExpr &expr, Location loc)
LogicalResult buildClassProperties(const slang::ast::ClassType &classdecl)
LogicalResult convertPackage(const slang::ast::PackageSymbol &package)
Convert a package and its contents.
LogicalResult convertCompilation()
Convert hierarchy and structure AST nodes to MLIR ops.
MLIRContext * getContext()
Return the MLIR context.
FailureOr< Value > convertAssertionSystemCallArity1(const slang::ast::SystemSubroutine &subroutine, Location loc, Value value, Type originalType)
Convert system function calls within properties and assertion with a single argument.
unsigned nextMonitorId
The next monitor ID to allocate. ID 0 is reserved for "no monitor active".
LogicalResult convertStatement(const slang::ast::Statement &stmt)
SmallVector< const slang::ast::ValueSymbol * > globalVariableWorklist
A list of global variables that still need their initializers to be converted.
FailureOr< moore::UnpackedStructType > convertVirtualInterfaceType(const slang::ast::VirtualInterfaceType &type, Location loc)
Convert a Slang virtual interface type into the Moore type used to represent virtual interface handle...
Definition Types.cpp:238
SmallVector< Value > lvalueStack
A stack of assignment left-hand side values.
DenseMap< const slang::ast::InstanceBodySymbol *, std::unique_ptr< ModuleLowering > > modules
How we have lowered modules to MLIR.
Location convertLocation(slang::SourceLocation loc)
Convert a slang SourceLocation into an MLIR Location.
Lowering information for a single signal flattened from an interface port.
const slang::ast::InterfacePortSymbol * origin
the origin interface port symbol this was flattened from.
const slang::ast::Symbol * bodySym
the interface body member (VariableSymbol , NetSymbol)
const slang::ast::InstanceSymbol * ifaceInstance
The connected interface instance backing this port (if any).
llvm::DenseMap< Value, unsigned > captureIndex
bool isCoroutine()
Whether this is a coroutine (task) or a regular function.
slang::ast::ArgumentDirection direction
const slang::ast::ValueSymbol * valueSym
Lowering information for an expanded interface instance.
DenseMap< const slang::ast::Symbol *, Value > expandedMembers
DenseMap< StringAttr, Value > expandedMembersByName
Information about a loops continuation and exit blocks relevant while lowering the loop's body statem...
Block * breakBlock
The block to jump to from a break statement.
Block * continueBlock
The block to jump to from a continue statement.
DenseMap< const slang::syntax::SyntaxNode *, const slang::ast::PortSymbol * > portsBySyntaxNode
SmallVector< FlattenedIfacePort > ifacePorts
const slang::ast::PortSymbol & ast
Cached lowering information for representing SystemVerilog virtual interface handles as Moore types (...
A mapping entry for resolving Slang virtual interface member accesses.
StringAttr fieldName
The name of the field in the lowered virtual interface handle struct that should be accessed for this...