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

Add the BLIF dialect. #8019

Draft
wants to merge 9 commits 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
21 changes: 21 additions & 0 deletions include/circt/Dialect/BLIF/BLIF.td
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
23 changes: 23 additions & 0 deletions include/circt/Dialect/BLIF/BLIFDialect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===- 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"

#endif // CIRCT_DIALECT_BLIF_BLIFDIALECT_H
33 changes: 33 additions & 0 deletions include/circt/Dialect/BLIF/BLIFDialect.td
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
27 changes: 27 additions & 0 deletions include/circt/Dialect/BLIF/BLIFOps.h
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;
70 changes: 70 additions & 0 deletions include/circt/Dialect/BLIF/BLIFOps.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//===- 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/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)>
];


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 /* IntArrayProperty<I8Property>:$func, */
Variadic<I1>:$inputs);
let results = (outs I1:$result);
}

def LatchGateOp: BLIFOp<"latch_gate", []> {
}

#endif // CIRCT_DIALECT_BLIF_BLIFOPS_TD
61 changes: 61 additions & 0 deletions include/circt/Dialect/BLIF/BLIFParser.h
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
3 changes: 3 additions & 0 deletions include/circt/Dialect/BLIF/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_circt_dialect(BLIF blif)

set(LLVM_TARGET_DEFINITIONS BLIF.td)
1 change: 1 addition & 0 deletions include/circt/Dialect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

add_subdirectory(AIG)
add_subdirectory(Arc)
add_subdirectory(BLIF)
add_subdirectory(Calyx)
add_subdirectory(Comb)
add_subdirectory(DC)
Expand Down
2 changes: 2 additions & 0 deletions include/circt/InitAllDialects.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "circt/Dialect/AIG/AIGDialect.h"
#include "circt/Dialect/Arc/ArcDialect.h"
#include "circt/Dialect/BLIF/BLIFDialect.h"
#include "circt/Dialect/Calyx/CalyxDialect.h"
#include "circt/Dialect/Comb/CombDialect.h"
#include "circt/Dialect/DC/DCDialect.h"
Expand Down Expand Up @@ -58,6 +59,7 @@ inline void registerAllDialects(mlir::DialectRegistry &registry) {
registry.insert<
aig::AIGDialect,
arc::ArcDialect,
blif::BLIFDialect,
calyx::CalyxDialect,
chirrtl::CHIRRTLDialect,
comb::CombDialect,
Expand Down
2 changes: 2 additions & 0 deletions include/circt/InitAllTranslations.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//

#include "circt/Dialect/Arc/ModelInfoExport.h"
#include "circt/Dialect/BLIF/BLIFParser.h"
#include "circt/Dialect/Calyx/CalyxEmitter.h"
#include "circt/Dialect/ESI/ESIDialect.h"
#include "circt/Dialect/FIRRTL/FIREmitter.h"
Expand All @@ -32,6 +33,7 @@ namespace circt {
inline void registerAllTranslations() {
static bool initOnce = []() {
arc::registerArcModelInfoTranslation();
blif::registerFromBLIFFileTranslation();
calyx::registerToCalyxTranslation();
firrtl::registerFromFIRFileTranslation();
firrtl::registerToFIRFileTranslation();
Expand Down
33 changes: 33 additions & 0 deletions lib/Dialect/BLIF/BLIFDialect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//===- 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"
>();
}

#include "circt/Dialect/BLIF/BLIFDialect.cpp.inc"
Loading
Loading