-
Notifications
You must be signed in to change notification settings - Fork 281
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
[FIRRTL] Add DPI call intrinsic and lowering pass #7139
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5b603f5
[ExportVerilog][HW] Introduce HWEmittableModuleLike and change Prepar…
uenoku 3767a5b
[ExportVerilog] Support sv.func.* emission
uenoku 5e92614
[Sim] Add DPI func/call and lowering
uenoku cbfc483
[FIRRTL] Add DPI call intrinsic and lowering pass
uenoku 2c8b72e
Address comments
uenoku 7f819c6
Merge branch 'main' of github.com:llvm/circt into dev/hidetou/lower-dpi
uenoku 02e489b
fix up
uenoku 484a18d
reserve
uenoku d7675f1
Use matchingconnect
uenoku c6540cb
Add an error test
uenoku 20ff610
format
uenoku File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,11 @@ | |
#define CIRCT_DIALECT_SIM_SIMOPS_TD | ||
|
||
include "mlir/Interfaces/SideEffectInterfaces.td" | ||
include "mlir/Interfaces/FunctionInterfaces.td" | ||
include "circt/Dialect/Sim/SimDialect.td" | ||
include "circt/Dialect/Seq/SeqTypes.td" | ||
include "circt/Dialect/HW/HWOpInterfaces.td" | ||
include "circt/Dialect/HW/HWTypes.td" | ||
|
||
class SimOp<string mnemonic, list<Trait> traits = []> : | ||
Op<SimDialect, mnemonic, traits>; | ||
|
@@ -54,4 +57,93 @@ def FatalOp : SimOp<"fatal"> { | |
let assemblyFormat = "$clk `,` $cond attr-dict"; | ||
} | ||
|
||
def DPIFuncOp : SimOp<"func.dpi", | ||
[IsolatedFromAbove, Symbol, OpAsmOpInterface, | ||
FunctionOpInterface]> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is similar change to 09df7f5. It was necessary to put DPI func op into circuit op to make the lowering composable. |
||
let summary = "A System Verilog function"; | ||
let description = [{ | ||
`sim.func.dpi` models an external function in a core dialect. | ||
}]; | ||
|
||
let arguments = (ins | ||
SymbolNameAttr:$sym_name, | ||
TypeAttrOf<ModuleType>:$module_type, | ||
OptionalAttr<DictArrayAttr>:$per_argument_attrs, | ||
OptionalAttr<LocationArrayAttr>:$argument_locs, | ||
OptionalAttr<StrAttr>:$verilogName | ||
); | ||
let regions = (region AnyRegion:$body); | ||
|
||
let hasCustomAssemblyFormat = 1; | ||
|
||
let extraClassDeclaration = [{ | ||
mlir::FunctionType getFunctionType() { | ||
return getModuleType().getFuncType(); | ||
} | ||
|
||
void setFunctionTypeAttr(mlir::TypeAttr mlirType) { | ||
setModuleType(cast<hw::ModuleType>(mlirType.getValue())); | ||
} | ||
|
||
/// Returns the argument types of this function. | ||
ArrayRef<Type> getArgumentTypes() { return getFunctionType().getInputs(); } | ||
|
||
/// Returns the result types of this function. | ||
ArrayRef<Type> getResultTypes() { return getFunctionType().getResults(); } | ||
|
||
::mlir::Region *getCallableRegion() { return nullptr; } | ||
}]; | ||
} | ||
|
||
def DPICallOp : SimOp<"func.dpi.call", | ||
[CallOpInterface, AttrSizedOperandSegments, | ||
DeclareOpInterfaceMethods<SymbolUserOpInterface>]> { | ||
let summary = "A call option for DPI function with an optional clock and enable"; | ||
let description = [{ | ||
`sim.func.dpi.call` represents SystemVerilog DPI function call. There are two | ||
optional operands `clock` and `enable`. | ||
|
||
If `clock` is not provided, the callee is invoked when input values are changed. | ||
If provided, the dpi function is called at clock's posedge. The result values behave | ||
like registers and the DPI function is used as a state transfer function of them. | ||
|
||
`enable` operand is used to conditionally call the DPI since DPI call could be quite | ||
more expensive than native constructs. When `enable` is low, results of unclocked | ||
calls are undefined and in SV results they are lowered into `X`. Users are expected | ||
to gate result values by another `enable` to model a default value of results. | ||
|
||
For clocked calls, a low enable means that its register state transfer function is | ||
not called. Hence their values will not be modify in that clock. | ||
}]; | ||
|
||
let arguments = (ins FlatSymbolRefAttr:$callee, | ||
Optional<ClockType>:$clock, | ||
Optional<I1>:$enable, | ||
Variadic<AnyType>:$inputs); | ||
let results = (outs Variadic<AnyType>); | ||
|
||
let assemblyFormat = [{ | ||
$callee `(` $inputs `)` (`clock` $clock^)? (`enable` $enable^)? | ||
attr-dict `:` functional-type($inputs, results) | ||
}]; | ||
|
||
let extraClassDeclaration = [{ | ||
operand_range getArgOperands() { | ||
return getInputs(); | ||
} | ||
MutableOperandRange getArgOperandsMutable() { | ||
return getInputsMutable(); | ||
} | ||
mlir::CallInterfaceCallable getCallableForCallee() { | ||
return (*this)->getAttrOfType<mlir::SymbolRefAttr>("callee"); | ||
} | ||
|
||
/// Set the callee for this operation. | ||
void setCalleeFromCallable(mlir::CallInterfaceCallable callee) { | ||
(*this)->setAttr(getCalleeAttrName(), callee.get<mlir::SymbolRefAttr>()); | ||
} | ||
}]; | ||
|
||
} | ||
|
||
#endif // CIRCT_DIALECT_SIM_SIMOPS_TD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enable is not optional at Chisel level to follow the same design as verification intrinsic.