-
Notifications
You must be signed in to change notification settings - Fork 309
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
Add the BLIF dialect. #8019
Open
darthscsi
wants to merge
14
commits into
main
Choose a base branch
from
dev/darthscsi/blif
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add the BLIF dialect. #8019
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c509a64
Add the BLIF dialect.
aa64772
lib
b0cd895
parser checkpoint
bed4465
formatting
55542d9
fix build
dd2888a
add a test (not working)
5a60636
a wild modelop appears
58f041c
partially parse a .names
3d6fc1c
fewer vestages
604b9bc
handle truth tables
2e7d28e
parse latches
6255036
warnings
f618e0a
missing dependency
90088c2
blif emission
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//===- BLIF.td - BLIF dialect definition -------------------*- 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This is the top level file for the BLIF dialect. This dialect represents | ||
// the (extended) Berkely Logic Interchange Format | ||
// [http://bear.ces.cwru.edu/eecs_cad/sis_blif.pdf]. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef CIRCT_DIALECT_BLIF_BLIF_TD | ||
#define CIRCT_DIALECT_BLIF_BLIF_TD | ||
|
||
include "circt/Dialect/BLIF/BLIFDialect.td" | ||
include "circt/Dialect/BLIF/BLIFOps.td" | ||
|
||
#endif // CIRCT_DIALECT_BLIF_BLIF_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//===- BLIFDialect.h - BLIF dialect declaration -----------------*- 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file defines an BLIF MLIR dialect. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef CIRCT_DIALECT_BLIF_BLIFDIALECT_H | ||
#define CIRCT_DIALECT_BLIF_BLIFDIALECT_H | ||
|
||
#include "circt/Support/LLVM.h" | ||
#include "mlir/IR/BuiltinAttributes.h" | ||
#include "mlir/IR/Dialect.h" | ||
|
||
// Pull in the dialect definition. | ||
#include "circt/Dialect/BLIF/BLIFDialect.h.inc" | ||
#include "circt/Dialect/BLIF/BLIFEnums.h.inc" | ||
|
||
#endif // CIRCT_DIALECT_BLIF_BLIFDIALECT_H |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//===- BLIFDialect.td - BLIF dialect definition ------------*- 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This contains the BLIFDialect definition to be included in other files. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef CIRCT_DIALECT_BLIF_BLIFDIALECT | ||
#define CIRCT_DIALECT_BLIF_BLIFDIALECT | ||
|
||
include "mlir/IR/OpBase.td" | ||
|
||
def BLIFDialect : Dialect { | ||
let name = "blif"; | ||
let cppNamespace = "::circt::blif"; | ||
|
||
let summary = "Types and operations for the BLIF format dialect"; | ||
let description = [{ | ||
This dialect defines the `BLIF` dialect, which is a representation of | ||
the Berkely Logic Interchange Format. | ||
}]; | ||
} | ||
|
||
// Base class for the operation in this dialect. | ||
class BLIFOp<string mnemonic, list<Trait> traits = []> : | ||
Op<BLIFDialect, mnemonic, traits>; | ||
|
||
#endif // CIRCT_DIALECT_BLIF_BLIFDIALECT |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//===- BLIFEmitter.h - BLIF dialect to .blif emitter ------------*- 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Defines the interface to the .blif file emitter. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef CIRCT_DIALECT_BLIF_BLIFEMITTER_H | ||
#define CIRCT_DIALECT_BLIF_BLIFEMITTER_H | ||
|
||
#include "circt/Support/LLVM.h" | ||
|
||
namespace circt { | ||
namespace blif { | ||
|
||
mlir::LogicalResult exportBLIFFile(mlir::ModuleOp module, | ||
llvm::raw_ostream &os); | ||
|
||
void registerToBLIFFileTranslation(); | ||
|
||
} // namespace blif | ||
} // namespace circt | ||
|
||
#endif // CIRCT_DIALECT_BLIF_BLIFEMITTER_H |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//===- BLIFOps.h - Declare BLIF dialect operations --------------*- 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file declares the operation classes for the BLIF dialect. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef CIRCT_DIALECT_BLIF_BLIFOPS_H | ||
#define CIRCT_DIALECT_BLIF_BLIFOPS_H | ||
|
||
#include "circt/Dialect/BLIF/BLIFDialect.h" | ||
#include "circt/Dialect/HW/HWOpInterfaces.h" | ||
#include "mlir/Bytecode/BytecodeOpInterface.h" | ||
#include "mlir/IR/OpImplementation.h" | ||
|
||
#define GET_OP_CLASSES | ||
#include "circt/Dialect/BLIF/BLIF.h.inc" | ||
|
||
#endif // CIRCT_DIALECT_BLIF_BLIFOPS_H | ||
|
||
using namespace circt; | ||
using namespace blif; |
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
//===- BLIFOps.td - BLIF ops ============-------------------*- 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This defines the BLIF ops. This defines module-like operations, connections, | ||
// and logic. | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef CIRCT_DIALECT_BLIF_BLIFOPS_TD | ||
#define CIRCT_DIALECT_BLIF_BLIFOPS_TD | ||
|
||
include "circt/Dialect/BLIF/BLIFDialect.td" | ||
include "circt/Dialect/HW/HWTypes.td" | ||
include "mlir/IR/EnumAttr.td" | ||
include "mlir/IR/RegionKindInterface.td" | ||
|
||
def ModelOp : BLIFOp<"model", [IsolatedFromAbove, RegionKindInterface, SingleBlockImplicitTerminator<"OutputOp">]> { | ||
let summary = "A model, which is a module"; | ||
let description = [{ | ||
The basic container. Is like a module. | ||
}]; | ||
|
||
let arguments = (ins SymbolNameAttr:$sym_name, | ||
TypeAttrOf<ModuleType>:$module_type, | ||
APIntAttr:$clocks); | ||
let results = (outs); | ||
let regions = (region SizedRegion<1>:$body); | ||
|
||
let builders = [ | ||
OpBuilder<(ins "StringRef":$name, | ||
"ArrayRef<StringRef>":$inputs, | ||
"ArrayRef<StringRef>":$outputs, | ||
"ArrayRef<StringRef>":$clocks)> | ||
Comment on lines
+34
to
+37
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. Omega-nit: |
||
]; | ||
|
||
|
||
let extraClassDeclaration = [{ | ||
static mlir::RegionKind getRegionKind(unsigned index) { | ||
return mlir::RegionKind::Graph; | ||
} | ||
}]; | ||
} | ||
|
||
def OutputOp : BLIFOp<"output", [Terminator]> { | ||
let arguments = (ins Variadic<I1>:$inputs); | ||
} | ||
|
||
def I8Property : IntProperty<"int8_t">; | ||
|
||
def LogicGateOp: BLIFOp<"logic_gate", []> { | ||
let summary = "Combinatorial logic"; | ||
let description = [{ | ||
A logic gate represents a logic function in sum-of-products | ||
form. Each entry in $func is a vector applied to the inputs | ||
where 0 means invert the input, 1 means use the input, and 2 | ||
means don't use the input. | ||
}]; | ||
|
||
let arguments = (ins ArrayProperty<IntArrayProperty<I8Property>>:$func, | ||
Variadic<I1>:$inputs); | ||
let results = (outs I1:$result); | ||
} | ||
|
||
def LatchMode : I32EnumAttr< | ||
"LatchModeEnum", "Latch Mode", [ | ||
I32EnumAttrCase<"Unspecified", 0, "un">, | ||
I32EnumAttrCase<"FallingEdge", 1, "fe">, | ||
I32EnumAttrCase<"RisingEdge", 2, "re">, | ||
I32EnumAttrCase<"ActiveHigh", 3, "ah">, | ||
I32EnumAttrCase<"ActiveLow", 4, "al">, | ||
I32EnumAttrCase<"Asynchronous", 5, "as"> | ||
]> { | ||
let cppNamespace = "circt::blif"; | ||
} | ||
|
||
def LatchGateOp: BLIFOp<"latch_gate", []> { | ||
|
||
let arguments = (ins I1:$input, LatchMode:$mode, Optional<I1>:$clock, I32Property:$initVal); | ||
let results = (outs I1:$output); | ||
} | ||
|
||
#endif // CIRCT_DIALECT_BLIF_BLIFOPS_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//===- BLIFParser.h - .blif to BLIF dialect parser --------------*- 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Defines the interface to the .blif file parser. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef CIRCT_DIALECT_BLIF_BLIFPARSER_H | ||
#define CIRCT_DIALECT_BLIF_BLIFPARSER_H | ||
|
||
#include "circt/Support/LLVM.h" | ||
#include <optional> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace llvm { | ||
class SourceMgr; | ||
} // namespace llvm | ||
|
||
namespace mlir { | ||
class LocationAttr; | ||
class TimingScope; | ||
} // namespace mlir | ||
|
||
namespace circt { | ||
namespace blif { | ||
|
||
struct BLIFParserOptions { | ||
/// Specify how @info locators should be handled. | ||
enum class InfoLocHandling { | ||
/// If this is set to true, the @info locators are ignored, and the | ||
/// locations are set to the location in the .BLIF file. | ||
IgnoreInfo, | ||
/// Prefer @info locators, fallback to .BLIF locations. | ||
PreferInfo, | ||
/// Attach both @info locators (when present) and .BLIF locations. | ||
FusedInfo | ||
}; | ||
|
||
InfoLocHandling infoLocatorHandling = InfoLocHandling::PreferInfo; | ||
|
||
/// parse strict blif instead of extended blif | ||
bool strictBLIF = false; | ||
}; | ||
|
||
mlir::OwningOpRef<mlir::ModuleOp> | ||
importBLIFFile(llvm::SourceMgr &sourceMgr, mlir::MLIRContext *context, | ||
mlir::TimingScope &ts, BLIFParserOptions options = {}); | ||
|
||
void registerFromBLIFFileTranslation(); | ||
|
||
} // namespace blif | ||
} // namespace circt | ||
|
||
#endif // CIRCT_DIALECT_BLIF_BLIFPARSER_H |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
add_circt_dialect(BLIF blif) | ||
|
||
set(LLVM_TARGET_DEFINITIONS BLIF.td) | ||
mlir_tablegen(BLIFEnums.h.inc -gen-enum-decls) | ||
mlir_tablegen(BLIFEnums.cpp.inc -gen-enum-defs) | ||
add_public_tablegen_target(CIRCTBLIFEnumsIncGen) | ||
add_dependencies(circt-headers CIRCTBLIFEnumsIncGen) |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//===- BLIFDialect.cpp - Implement the BLIF dialect -----------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file implements the BLIF dialect. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "circt/Dialect/BLIF/BLIFDialect.h" | ||
#include "circt/Dialect/BLIF/BLIFOps.h" | ||
#include "mlir/IR/BuiltinTypes.h" | ||
#include "mlir/IR/DialectImplementation.h" | ||
|
||
using namespace circt; | ||
using namespace blif; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Dialect specification. | ||
//===----------------------------------------------------------------------===// | ||
|
||
void BLIFDialect::initialize() { | ||
// Register operations. | ||
addOperations< | ||
#define GET_OP_LIST | ||
#include "circt/Dialect/BLIF/BLIF.cpp.inc" | ||
>(); | ||
} | ||
|
||
// Provide implementations for the enums we use. | ||
#include "circt/Dialect/BLIF/BLIFEnums.cpp.inc" | ||
|
||
#include "circt/Dialect/BLIF/BLIFDialect.cpp.inc" |
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.
Nit: overly long line