Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SV] Added DPI import and call ops #4856

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

[SV] Added DPI import and call ops #4856

wants to merge 1 commit into from

Conversation

nandor
Copy link
Contributor

@nandor nandor commented Mar 20, 2023

This PR introduces DPI import and call operations.

To import a function, the following can be declared at the module level:

sv.dpi.import @test(%arg0: i32) -> (res0: i5, res1: i6)

This is hard-wire to contextual functions.

To call a function, an op can be added to procedural scopes.

%res0, %res1 = sv.dpi.call @test(%arg0) : (i32) -> (i5, i6)

The emission is similar to instances. Temporary registers will be added to capture the results of DPI calls.

In the future, constraints should be relaxed to allow for return types and to place calls in arbitrary contexts.

Copy link
Contributor

@darthscsi darthscsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this is treating calls more like modules than functions. We do need to represent functions, it would be worth doing so now, rather than have to rip this out later.

A couple other things:

  • I think output values from a call should be able to use the same forced-spilling code as modules use. I guess it's not as sometimes you use a reg. I assume that is because the output argument of a call is not a continuous assignment? But maybe not? "For output and inout arguments, the value propagation (i.e., value change events) happens as if an actual argument was assigned a formal argument immediately after control returns from imported functions." I can't tell from that if it's suppose to be blocking or non-blocking. Implicit sensitivity are function aware, fwiw.
  • BPAssign probably shouldn't care what the source of a value is.

include/circt/Dialect/SV/SVDPI.td Show resolved Hide resolved
@@ -3091,6 +3094,9 @@ LogicalResult StmtEmitter::visitSV(AssignOp op) {
}

LogicalResult StmtEmitter::visitSV(BPAssignOp op) {
if (dyn_cast_or_null<DPICallOp>(op.getSrc().getDefiningOp()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you assume that structs won't have accessors prior to assign?

include/circt/Dialect/SV/SVDPI.td Show resolved Hide resolved
include/circt/Dialect/SV/SVDPI.td Show resolved Hide resolved
@nandor
Copy link
Contributor Author

nandor commented Mar 21, 2023

I'll re-work this to separately indicate which arguments are inputs and outputs, requiring inout types for outputs.

@darthscsi
Copy link
Contributor

From talking to @nandor, will handle return types too and make calls expressions. Marking this draft for now.

@darthscsi darthscsi marked this pull request as draft March 24, 2023 16:29
@sequencer
Copy link
Contributor

Is there any update on the DPI import and export functions? This is common used in the DV flow, wondering if there are outstanding work on it.

uenoku added a commit that referenced this pull request Apr 3, 2024
uenoku added a commit that referenced this pull request Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants