-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for circt's comb and hw dialect
Signed-off-by: Asra Ali <[email protected]> make some more fixes Signed-off-by: Asra Ali <[email protected]> remove spurious includes Signed-off-by: Asra Ali <[email protected]>
- Loading branch information
Showing
124 changed files
with
22,539 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// RUN: heir-opt %s -verify-diagnostics | ||
|
||
module { | ||
func.func @comb(%a: i1, %b: i1) -> () { | ||
%0 = comb.truth_table %a, %b -> [true, false, true, false] | ||
return | ||
} | ||
} |
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,4 @@ | ||
package( | ||
default_applicable_licenses = ["@heir//:license"], | ||
default_visibility = ["//visibility:public"], | ||
) |
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,149 @@ | ||
load("@llvm-project//mlir:tblgen.bzl", "gentbl_cc_library", "td_library") | ||
|
||
package( | ||
default_applicable_licenses = ["@heir//:license"], | ||
default_visibility = ["//visibility:public"], | ||
) | ||
|
||
exports_files( | ||
glob(["*.h"]), | ||
) | ||
|
||
cc_library( | ||
name = "headers", | ||
hdrs = [ | ||
"CombDialect.h", | ||
"CombOps.h", | ||
"CombPasses.h", | ||
"CombVisitors.h", | ||
], | ||
deps = [ | ||
"@heir//third_party/circt/include/circt/Dialect/Comb:dialect_inc_gen", | ||
"@heir//third_party/circt/include/circt/Dialect/Comb:enum_inc_gen", | ||
"@heir//third_party/circt/include/circt/Dialect/Comb:ops_inc_gen", | ||
"@heir//third_party/circt/include/circt/Dialect/Comb:type_inc_gen", | ||
"@heir//third_party/circt/lib/Support", | ||
], | ||
) | ||
|
||
td_library( | ||
name = "td_files", | ||
srcs = [ | ||
"Comb.td", | ||
"Combinational.td", | ||
], | ||
includes = ["/third_party/circt/include"], | ||
deps = [ | ||
"@heir//third_party/circt/include/circt/Dialect/HW:td_files", | ||
"@llvm-project//mlir:BuiltinDialectTdFiles", | ||
"@llvm-project//mlir:ControlFlowInterfacesTdFiles", | ||
"@llvm-project//mlir:FunctionInterfacesTdFiles", | ||
"@llvm-project//mlir:InferTypeOpInterfaceTdFiles", | ||
"@llvm-project//mlir:OpBaseTdFiles", | ||
"@llvm-project//mlir:SideEffectInterfacesTdFiles", | ||
], | ||
) | ||
|
||
gentbl_cc_library( | ||
name = "dialect_inc_gen", | ||
includes = ["/third_party/circt/include"], | ||
strip_include_prefix = "/third_party/circt/include", | ||
tbl_outs = [ | ||
( | ||
[ | ||
"-gen-dialect-decls", | ||
"-dialect=comb", | ||
], | ||
"CombDialect.h.inc", | ||
), | ||
( | ||
[ | ||
"-gen-dialect-defs", | ||
"-dialect=comb", | ||
], | ||
"CombDialect.cpp.inc", | ||
), | ||
], | ||
tblgen = "@llvm-project//mlir:mlir-tblgen", | ||
td_file = "Comb.td", | ||
deps = [ | ||
":td_files", | ||
], | ||
) | ||
|
||
gentbl_cc_library( | ||
name = "ops_inc_gen", | ||
includes = ["/third_party/circt/include"], | ||
strip_include_prefix = "/third_party/circt/include", | ||
tbl_outs = [ | ||
( | ||
[ | ||
"-gen-op-decls", | ||
], | ||
"Comb.h.inc", | ||
), | ||
( | ||
[ | ||
"-gen-op-defs", | ||
], | ||
"Comb.cpp.inc", | ||
), | ||
], | ||
tblgen = "@llvm-project//mlir:mlir-tblgen", | ||
td_file = "Comb.td", | ||
deps = [ | ||
":dialect_inc_gen", | ||
":td_files", | ||
], | ||
) | ||
|
||
gentbl_cc_library( | ||
name = "type_inc_gen", | ||
includes = ["/third_party/circt/include"], | ||
strip_include_prefix = "/third_party/circt/include", | ||
tbl_outs = [ | ||
( | ||
[ | ||
"-gen-typedef-decls", | ||
], | ||
"CombTypes.h.inc", | ||
), | ||
( | ||
[ | ||
"-gen-typedef-defs", | ||
], | ||
"CombTypes.cpp.inc", | ||
), | ||
], | ||
tblgen = "@llvm-project//mlir:mlir-tblgen", | ||
td_file = "Comb.td", | ||
deps = [ | ||
":td_files", | ||
], | ||
) | ||
|
||
gentbl_cc_library( | ||
name = "enum_inc_gen", | ||
includes = ["/third_party/circt/include"], | ||
strip_include_prefix = "/third_party/circt/include", | ||
tbl_outs = [ | ||
( | ||
[ | ||
"-gen-enum-decls", | ||
], | ||
"CombEnums.h.inc", | ||
), | ||
( | ||
[ | ||
"-gen-enum-defs", | ||
], | ||
"CombEnums.cpp.inc", | ||
), | ||
], | ||
tblgen = "@llvm-project//mlir:mlir-tblgen", | ||
td_file = "Comb.td", | ||
deps = [ | ||
":dialect_inc_gen", | ||
":td_files", | ||
], | ||
) |
14 changes: 14 additions & 0 deletions
14
third_party/circt/include/circt/Dialect/Comb/CMakeLists.txt
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,14 @@ | ||
add_circt_dialect(Comb comb) | ||
add_circt_dialect_doc(Comb comb) | ||
|
||
set(LLVM_TARGET_DEFINITIONS Comb.td) | ||
mlir_tablegen(CombEnums.h.inc -gen-enum-decls) | ||
mlir_tablegen(CombEnums.cpp.inc -gen-enum-defs) | ||
add_public_tablegen_target(MLIRCombEnumsIncGen) | ||
|
||
set(LLVM_TARGET_DEFINITIONS Passes.td) | ||
mlir_tablegen(Passes.h.inc -gen-pass-decls) | ||
add_public_tablegen_target(CIRCTCombTransformsIncGen) | ||
|
||
# Generate Pass documentation. | ||
add_circt_doc(Passes CombPasses -gen-pass-doc) |
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,44 @@ | ||
//===- Comb.td - Comb 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 Comb dialect. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef COMB_TD | ||
#define COMB_TD | ||
|
||
include "mlir/IR/OpBase.td" | ||
include "mlir/Interfaces/SideEffectInterfaces.td" | ||
include "mlir/IR/OpAsmInterface.td" | ||
include "mlir/IR/SymbolInterfaces.td" | ||
|
||
def CombDialect : Dialect { | ||
let name = "comb"; | ||
|
||
let summary = "Types and operations for comb dialect"; | ||
let description = [{ | ||
This dialect defines the `comb` dialect, which is intended to be a generic | ||
representation of combinational logic outside of a particular use-case. | ||
}]; | ||
let hasConstantMaterializer = 1; | ||
let cppNamespace = "::circt::comb"; | ||
|
||
// This will be the default after next LLVM bump. | ||
let usePropertiesForAttributes = 1; | ||
|
||
} | ||
|
||
// Base class for the operation in this dialect. | ||
class CombOp<string mnemonic, list<Trait> traits = []> : | ||
Op<CombDialect, mnemonic, traits>; | ||
|
||
include "circt/Dialect/HW/HWTypes.td" | ||
include "circt/Dialect/Comb/Combinational.td" | ||
|
||
#endif // COMB_TD |
25 changes: 25 additions & 0 deletions
25
third_party/circt/include/circt/Dialect/Comb/CombDialect.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,25 @@ | ||
//===- CombDialect.h - Comb 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 the Combinational MLIR dialect. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef CIRCT_DIALECT_COMB_COMBDIALECT_H | ||
#define CIRCT_DIALECT_COMB_COMBDIALECT_H | ||
|
||
#include "mlir/IR/BuiltinAttributes.h" | ||
#include "mlir/IR/Dialect.h" | ||
|
||
// Pull in the Dialect definition. | ||
#include "circt/Dialect/Comb/CombDialect.h.inc" | ||
|
||
// Pull in all enum type definitions and utility function declarations. | ||
#include "circt/Dialect/Comb/CombEnums.h.inc" | ||
|
||
#endif // CIRCT_DIALECT_COMB_COMBDIALECT_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,63 @@ | ||
//===- CombOps.h - Declare Comb 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 Comb dialect. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef CIRCT_DIALECT_COMB_COMBOPS_H | ||
#define CIRCT_DIALECT_COMB_COMBOPS_H | ||
|
||
#include "circt/Dialect/Comb/CombDialect.h" | ||
#include "circt/Dialect/HW/HWTypes.h" | ||
#include "circt/Support/LLVM.h" | ||
#include "mlir/Bytecode/BytecodeOpInterface.h" | ||
#include "mlir/IR/BuiltinOps.h" | ||
#include "mlir/IR/OpImplementation.h" | ||
#include "mlir/Interfaces/FunctionInterfaces.h" | ||
#include "mlir/Interfaces/InferTypeOpInterface.h" | ||
#include "mlir/Interfaces/SideEffectInterfaces.h" | ||
|
||
namespace llvm { | ||
struct KnownBits; | ||
} | ||
|
||
namespace mlir { | ||
class PatternRewriter; | ||
} | ||
|
||
#define GET_OP_CLASSES | ||
#include "circt/Dialect/Comb/Comb.h.inc" | ||
|
||
namespace circt { | ||
namespace comb { | ||
|
||
using llvm::KnownBits; | ||
|
||
/// Compute "known bits" information about the specified value - the set of bits | ||
/// that are guaranteed to always be zero, and the set of bits that are | ||
/// guaranteed to always be one (these must be exclusive!). A bit that exists | ||
/// in neither set is unknown. | ||
KnownBits computeKnownBits(Value value); | ||
|
||
/// Create a sign extension operation from a value of integer type to an equal | ||
/// or larger integer type. | ||
Value createOrFoldSExt(Location loc, Value value, Type destTy, | ||
OpBuilder &builder); | ||
Value createOrFoldSExt(Value value, Type destTy, ImplicitLocOpBuilder &builder); | ||
|
||
/// Create a ``Not'' gate on a value. | ||
Value createOrFoldNot(Location loc, Value value, OpBuilder &builder, | ||
bool twoState = false); | ||
Value createOrFoldNot(Value value, ImplicitLocOpBuilder &builder, | ||
bool twoState = false); | ||
|
||
} // namespace comb | ||
} // namespace circt | ||
|
||
#endif // CIRCT_DIALECT_COMB_COMBOPS_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 @@ | ||
//===- Passes.h - Comb pass entry points ------------------------*- 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 header file defines prototypes that expose pass constructors. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef CIRCT_DIALECT_COMB_COMBPASSES_H | ||
#define CIRCT_DIALECT_COMB_COMBPASSES_H | ||
|
||
#include <memory> | ||
#include <optional> | ||
|
||
#include "mlir/Pass/Pass.h" | ||
#include "mlir/Pass/PassRegistry.h" | ||
|
||
namespace circt { | ||
namespace comb { | ||
|
||
/// Generate the code for registering passes. | ||
#define GEN_PASS_DECL | ||
#define GEN_PASS_REGISTRATION | ||
#include "circt/Dialect/Comb/Passes.h.inc" | ||
|
||
} // namespace comb | ||
} // namespace circt | ||
|
||
#endif // CIRCT_DIALECT_COMB_COMBPASSES_H |
Oops, something went wrong.