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

[Do-Not-Merge][FIRRTL][Sim][SV] Rework printf lowering pipeline #7973

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/circt/Conversion/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@
#include "circt/Conversion/LoopScheduleToCalyx.h"
#include "circt/Conversion/MooreToCore.h"
#include "circt/Conversion/PipelineToHW.h"
#include "circt/Conversion/PrintsToSV.h"
#include "circt/Conversion/SCFToCalyx.h"
#include "circt/Conversion/SCFToSV.h"
#include "circt/Conversion/SMTToZ3LLVM.h"
#include "circt/Conversion/SeqToSV.h"
#include "circt/Conversion/SimToSV.h"
#include "circt/Conversion/TriggersToSV.h"
#include "circt/Conversion/VerifToSMT.h"
#include "circt/Conversion/VerifToSV.h"
#include "mlir/IR/DialectRegistry.h"
Expand Down
45 changes: 45 additions & 0 deletions include/circt/Conversion/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,51 @@ def LowerSimToSV: Pass<"lower-sim-to-sv", "mlir::ModuleOp"> {
];
}

//===----------------------------------------------------------------------===//
// LowerPrintsToSV
//===----------------------------------------------------------------------===//

def LowerPrintsToSV: Pass<"lower-prints-to-sv", "hw::HWModuleOp"> {
let summary = "Lower `sim` print operations to SV.";
let dependentDialects = [
"circt::sv::SVDialect"
];
let options = [
Option<"printToStdErr", "stderr-output", "bool", "false",
"Print to STDERR instead of STDOUT">
];
}

//===----------------------------------------------------------------------===//
// LowerTriggersToSV
//===----------------------------------------------------------------------===//

def LowerTriggersToSV: Pass<"lower-triggers-to-sv", "mlir::ModuleOp"> {
let summary = "Lower `sim` trigger trees to SV.";
let dependentDialects = [
"circt::sv::SVDialect",
"circt::hw::HWDialect",
"circt::comb::CombDialect"
];
let options = [
Option<"disallowForkJoin", "no-fork-join", "bool", "false",
"Do not produce concurrent triggered operations with fork/join. "
"An arbitrary non-concurrent sequence will be selected.">
];
}

//===----------------------------------------------------------------------===//
// SCFToSV
//===----------------------------------------------------------------------===//

def SCFToSV : Pass<"lower-scf-to-sv", "hw::HWModuleOp"> {
let summary = "Lower SCF to SV";
let dependentDialects = [
"sv::SVDialect"
];
}


//===----------------------------------------------------------------------===//
// ConvertCombToAIG
//===----------------------------------------------------------------------===//
Expand Down
26 changes: 26 additions & 0 deletions include/circt/Conversion/PrintsToSV.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===- PrintsToSV.h - SV conversion for sim ops -------------===-*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// TODO
//
//===----------------------------------------------------------------------===//

#ifndef CIRCT_CONVERSION_PRINTSTOSV_H
#define CIRCT_CONVERSION_PRINTSTOSV_H

#include "circt/Support/LLVM.h"
#include <memory>

namespace circt {

#define GEN_PASS_DECL_LOWERPRINTSTOSV
#include "circt/Conversion/Passes.h.inc"

} // namespace circt

#endif // CIRCT_CONVERSION_PRINTSTOSV_H
26 changes: 26 additions & 0 deletions include/circt/Conversion/SCFToSV.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===- SCFToSV.h - SV conversion for scf ops ----------------===-*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// TODO
//
//===----------------------------------------------------------------------===//

#ifndef CIRCT_CONVERSION_SCFTOSV_H
#define CIRCT_CONVERSION_SCFTOSV_H

#include "circt/Support/LLVM.h"
#include <memory>

namespace circt {

#define GEN_PASS_DECL_SCFTOSV
#include "circt/Conversion/Passes.h.inc"

} // namespace circt

#endif // CIRCT_CONVERSION_SCFTOSV_H
26 changes: 26 additions & 0 deletions include/circt/Conversion/TriggersToSV.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===- TriggersToSV.h - SV conversion for sim ops -----------===-*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// TODO
//
//===----------------------------------------------------------------------===//

#ifndef CIRCT_CONVERSION_TRIGGERSTOSV_H
#define CIRCT_CONVERSION_TRIGGERSTOSV_H

#include "circt/Support/LLVM.h"
#include <memory>

namespace circt {

#define GEN_PASS_DECL_LOWERTRIGGERSTOSV
#include "circt/Conversion/Passes.h.inc"

} // namespace circt

#endif // CIRCT_CONVERSION_TRIGGERSTOSV_H
38 changes: 36 additions & 2 deletions include/circt/Dialect/SV/SVInOutOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def XMROp : SVOp<"xmr", []> {
path has public visibility so paths are not invalidated.
}];
let arguments = (ins UnitAttr:$isRooted, StrArrayAttr:$path, StrAttr:$terminal);
let results = (outs InOutType:$result);
let results = (outs AnyType:$result);
let assemblyFormat = "(`isRooted` $isRooted^)? custom<XMRPath>($path, $terminal) attr-dict `:` qualified(type($result))";
}

Expand All @@ -132,7 +132,7 @@ def XMRRefOp : SVOp<"xmr.ref", [
ins FlatSymbolRefAttr:$ref,
DefaultValuedAttr<StrAttr, "{}">:$verbatimSuffix
);
let results = (outs InOutType:$result);
let results = (outs AnyType:$result);
let assemblyFormat = [{
$ref ( $verbatimSuffix^ )? attr-dict `:` qualified(type($result))
}];
Expand Down Expand Up @@ -268,3 +268,37 @@ def LogicOp : SVOp<"logic", [
}
}];
}

def BitOp : SVOp<"bit", [
DeclareOpInterfaceMethods<OpAsmOpInterface, ["getAsmResultNames"]>,
DeclareOpInterfaceMethods<InnerSymbol, ["getTargetResultIndex"]>]> {
let summary = "Define a bit";
let description = [{
Declare a SystemVerilog Variable Declaration of 'bit' type.
}];

let arguments = (ins StrAttr:$name, OptionalAttr<InnerSymAttr>:$inner_sym);
let results = (outs InOutType:$result);

let skipDefaultBuilders = 1;
let builders = [
OpBuilder<(ins "::mlir::Type":$elementType,
CArg<"StringAttr", "StringAttr()">:$name,
CArg<"hw::InnerSymAttr", "hw::InnerSymAttr()">:$innerSym)>,
OpBuilder<(ins "::mlir::Type":$elementType, CArg<"StringRef">:$name), [{
return build($_builder, $_state, elementType,
$_builder.getStringAttr(name));
}]>
];

let assemblyFormat = [{
(`sym` $inner_sym^)? `` custom<ImplicitSSAName>($name) attr-dict
`:` qualified(type($result))
}];

let extraClassDeclaration = [{
Type getElementType() {
return llvm::cast<InOutType>(getResult().getType()).getElementType();
}
}];
}
37 changes: 35 additions & 2 deletions include/circt/Dialect/SV/SVStatements.td
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,15 @@ def InitialOp : SVOp<"initial", [SingleBlock, NoTerminator, NoRegionArguments,
}];
}

def ForkJoinOp : SVOp<"fork_join", [NoTerminator, NoRegionArguments,
RecursiveMemoryEffects,
RecursivelySpeculatable,
ProceduralRegion, ProceduralOp]> {

let regions = (region VariadicRegion<SizedRegion<1>>:$regions);
let assemblyFormat = "attr-dict-with-keyword $regions";
}

def CaseStmt: I32EnumAttrCase<"CaseStmt", 0, "case">;
def CaseXStmt: I32EnumAttrCase<"CaseXStmt", 1, "casex">;
def CaseZStmt: I32EnumAttrCase<"CaseZStmt", 2, "casez">;
Expand Down Expand Up @@ -448,8 +457,6 @@ def PAssignOp : SVOp<"passign", [InOutTypeConstraint<"src", "dest">,
let hasVerifier = 1;
}



//===----------------------------------------------------------------------===//
// Other Statements
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -519,6 +526,20 @@ def FWriteOp : SVOp<"fwrite", [ProceduralOp]> {
}];
}

def DisplayOp : SVOp<"display", [ProceduralOp]> {
let summary = "'$display'/'$write' statement";

let arguments = (ins StrAttr:$format_string,
Variadic<AnyType>:$substitutions,
UnitAttr:$noNewLine);
let results = (outs);

let assemblyFormat = [{
(`nolf` $noNewLine^)? $format_string attr-dict (`(` $substitutions^ `)` `:`
qualified(type($substitutions)))?
}];
}

def VerbatimOp : SVOp<"verbatim"> {
let summary = "Verbatim opaque text emitted inline.";
let description = [{
Expand Down Expand Up @@ -568,6 +589,18 @@ def MacroRefOp : SVOp<"macro.ref", [
}];
}

def WaitOp : SVOp<"wait", [ProceduralOp]> {
let arguments = (ins I1:$cond);
let results = (outs);
let assemblyFormat = "$cond attr-dict";
}

def DelayOp : SVOp<"delay", [ProceduralOp]> {
let arguments = (ins UI32Attr:$delayValue);
let results = (outs);
let assemblyFormat = "$delayValue attr-dict";
}

//===----------------------------------------------------------------------===//
// Bind Statements
//===----------------------------------------------------------------------===//
Expand Down
11 changes: 8 additions & 3 deletions include/circt/Dialect/SV/SVVisitors.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ class Visitor {
ConstantXOp, ConstantZOp, ConstantStrOp, MacroRefExprOp,
MacroRefExprSEOp, UnpackedArrayCreateOp, UnpackedOpenArrayCastOp,
// Declarations.
RegOp, WireOp, LogicOp, LocalParamOp, XMROp, XMRRefOp,
RegOp, WireOp, LogicOp, BitOp, LocalParamOp, XMROp, XMRRefOp,
// Control flow.
OrderedOutputOp, IfDefOp, IfDefProceduralOp, IfOp, AlwaysOp,
AlwaysCombOp, AlwaysFFOp, InitialOp, CaseOp,
AlwaysCombOp, AlwaysFFOp, InitialOp, CaseOp, ForkJoinOp,
// Other Statements.
AssignOp, BPAssignOp, PAssignOp, ForceOp, ReleaseOp, AliasOp,
FWriteOp, SystemFunctionOp, VerbatimOp, MacroRefOp, FuncCallOp,
FuncCallProceduralOp, ReturnOp,
FuncCallProceduralOp, ReturnOp, WaitOp, DelayOp, DisplayOp,
// Type declarations.
InterfaceOp, InterfaceSignalOp, InterfaceModportOp,
InterfaceInstanceOp, GetModportOp, AssignInterfaceSignalOp,
Expand Down Expand Up @@ -92,6 +92,7 @@ class Visitor {
HANDLE(RegOp, Unhandled);
HANDLE(WireOp, Unhandled);
HANDLE(LogicOp, Unhandled);
HANDLE(BitOp, Unhandled);
HANDLE(LocalParamOp, Unhandled);
HANDLE(XMROp, Unhandled);
HANDLE(XMRRefOp, Unhandled);
Expand Down Expand Up @@ -121,6 +122,7 @@ class Visitor {
HANDLE(AlwaysCombOp, Unhandled);
HANDLE(AlwaysFFOp, Unhandled);
HANDLE(InitialOp, Unhandled);
HANDLE(ForkJoinOp, Unhandled);
HANDLE(CaseOp, Unhandled);

// Other Statements.
Expand All @@ -137,6 +139,9 @@ class Visitor {
HANDLE(ReturnOp, Unhandled);
HANDLE(VerbatimOp, Unhandled);
HANDLE(MacroRefOp, Unhandled);
HANDLE(WaitOp, Unhandled);
HANDLE(DelayOp, Unhandled);
HANDLE(DisplayOp, Unhandled);

// Type declarations.
HANDLE(InterfaceOp, Unhandled);
Expand Down
7 changes: 7 additions & 0 deletions include/circt/Dialect/Sim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ add_circt_dialect(Sim sim)
add_circt_doc(SimOps Dialects/SimOps -gen-op-doc)
add_circt_doc(SimTypes Dialects/SimTypes -gen-typedef-doc -dialect sim)

set(LLVM_TARGET_DEFINITIONS Sim.td)

mlir_tablegen(SimAttributes.h.inc -gen-attrdef-decls -attrdefs-dialect=sim)
mlir_tablegen(SimAttributes.cpp.inc -gen-attrdef-defs -attrdefs-dialect=sim)
add_public_tablegen_target(MLIRSimAttributesIncGen)
add_dependencies(circt-headers MLIRSimAttributesIncGen)

set(LLVM_TARGET_DEFINITIONS SimPasses.td)
mlir_tablegen(SimPasses.h.inc -gen-pass-decls)
add_public_tablegen_target(CIRCTSimTransformsIncGen)
Expand Down
3 changes: 2 additions & 1 deletion include/circt/Dialect/Sim/Sim.td
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ include "mlir/IR/OpAsmInterface.td"
include "mlir/IR/SymbolInterfaces.td"

include "circt/Dialect/Sim/SimDialect.td"
include "circt/Dialect/Sim/SimOps.td"
include "circt/Dialect/Sim/SimTypes.td"
include "circt/Dialect/Sim/SimAttributes.td"
include "circt/Dialect/Sim/SimOps.td"

#endif // CIRCT_DIALECT_SIM_SIM_TD
19 changes: 19 additions & 0 deletions include/circt/Dialect/Sim/SimAttributes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===- SimAttributes.h - Declare Sim dialect attributes ----------*- C++-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef CIRCT_DIALECT_SIM_SIMATTRIBUTES_H
#define CIRCT_DIALECT_SIM_SIMATTRIBUTES_H

#include "mlir/IR/Attributes.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/BuiltinTypes.h"

#define GET_ATTRDEF_CLASSES
#include "circt/Dialect/Sim/SimAttributes.h.inc"

#endif // CIRCT_DIALECT_SIM_SEQATTRIBUTES_H
23 changes: 23 additions & 0 deletions include/circt/Dialect/Sim/SimAttributes.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===- SimAttributes.td - Attributes for Sim dialect -------*- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef CIRCT_DIALECT_SIM_SIMATTRIBUTES_TD
#define CIRCT_DIALECT_SIM_SIMATTRIBUTES_TD

include "circt/Dialect/Sim/SimDialect.td"
include "mlir/IR/BuiltinAttributeInterfaces.td"

def NeverTriggerAttr : AttrDef<SimDialect, "NeverTrigger",
[TypedAttrInterface]> {
let mnemonic = "never";
let parameters = (ins AttributeSelfTypeParameter<"">:$type);
let assemblyFormat = "";
let genVerifyDecl = true;
}

#endif // CIRCT_DIALECT_SIM_SIMATTRIBUTES_TD
4 changes: 3 additions & 1 deletion include/circt/Dialect/Sim/SimDialect.td
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ def SimDialect : Dialect {

let dependentDialects = ["circt::hw::HWDialect"];

let useDefaultAttributePrinterParser = 0;
let useDefaultAttributePrinterParser = 1;
let useDefaultTypePrinterParser = 1;
let hasConstantMaterializer = 1;

let extraClassDeclaration = [{
/// Register all Sim types.
void registerTypes();
/// Register all attributes.
void registerAttributes();
}];

}
Expand Down
Loading
Loading