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

[LLHD] Use hw.inout instead of llhd.sig #7353

Merged
merged 1 commit into from
Jul 19, 2024
Merged
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
34 changes: 0 additions & 34 deletions include/circt/Conversion/HWToLLHD.h

This file was deleted.

1 change: 0 additions & 1 deletion include/circt/Conversion/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "circt/Conversion/FSMToSV.h"
#include "circt/Conversion/HWArithToHW.h"
#include "circt/Conversion/HWToBTOR2.h"
#include "circt/Conversion/HWToLLHD.h"
#include "circt/Conversion/HWToLLVM.h"
#include "circt/Conversion/HWToSMT.h"
#include "circt/Conversion/HWToSV.h"
Expand Down
14 changes: 0 additions & 14 deletions include/circt/Conversion/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -545,20 +545,6 @@ def HWArithToHW : Pass<"lower-hwarith-to-hw", "mlir::ModuleOp"> {
let dependentDialects = ["hw::HWDialect", "comb::CombDialect", "sv::SVDialect"];
}

//===----------------------------------------------------------------------===//
// HWToLLHD
//===----------------------------------------------------------------------===//

def ConvertHWToLLHD : Pass<"convert-hw-to-llhd", "mlir::ModuleOp"> {
let summary = "Convert HW to LLHD";
let description = [{
This pass translates a HW design into an equivalent structural LLHD
description.
}];
let constructor = "circt::createConvertHWToLLHDPass()";
let dependentDialects = ["llhd::LLHDDialect"];
}

//===----------------------------------------------------------------------===//
// HWToSystemC
//===----------------------------------------------------------------------===//
Expand Down
4 changes: 4 additions & 0 deletions include/circt/Dialect/HW/HWTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def InOutType : DialectType<HWDialect,
CPred<"::circt::hw::type_isa<circt::hw::InOutType>($_self)">,
"InOutType", "InOutType">;

class InOutTypeOf<list<Type> allowedTypes>
: ContainerType<AnyTypeOf<allowedTypes>, CPred<"::circt::hw::type_isa<::circt::hw::InOutType>($_self)">,
"::circt::hw::type_cast<::circt::hw::InOutType>($_self).getElementType()", "InOutType">;

// A handle to refer to circt::hw::ArrayType in ODS.
def ArrayType : DialectType<HWDialect,
CPred<"::circt::hw::type_isa<circt::hw::ArrayType>($_self)">,
Expand Down
52 changes: 26 additions & 26 deletions include/circt/Dialect/LLHD/IR/ExtractOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SigPtrIndexBitWidthConstraint<string index, string input>
class SigArrayElementTypeConstraint<string result, string input>
: TypesMatchWith<"result must be a signal of the array element type",
input, result,
"llhd::SigType::get(llhd::getLLHDElementType($_self))">;
"hw::InOutType::get(llhd::getLLHDElementType($_self))">;

class PtrArrayElementTypeConstraint<string result, string input>
: TypesMatchWith<"result must be a pointer of the array element type",
Expand Down Expand Up @@ -59,9 +59,9 @@ def LLHD_SigExtractOp : LLHD_Op<"sig.extract",
operand. The result length is defined by the result type.
}];

let arguments = (ins LLHD_SigType<[HWIntegerType]>:$input,
let arguments = (ins InOutTypeOf<[HWIntegerType]>:$input,
HWIntegerType:$lowBit);
let results = (outs LLHD_SigType<[HWIntegerType]>: $result);
let results = (outs InOutTypeOf<[HWIntegerType]>: $result);

let assemblyFormat = [{
$input `from` $lowBit attr-dict `:` functional-type($input, $result)
Expand Down Expand Up @@ -128,13 +128,13 @@ def LLHD_SigArraySliceOp : LLHD_Op<"sig.array_slice",

```mlir
%3 = llhd.sig.array_slice %input at %lowIndex :
(!llhd.sig<!hw.array<4xi8>>) -> !llhd.sig<!hw.array<2xi8>>
(!hw.inout<array<4xi8>>) -> !hw.inout<array<2xi8>>
```
}];

let arguments = (ins LLHD_SigType<[ArrayType]>: $input,
let arguments = (ins InOutTypeOf<[ArrayType]>: $input,
HWIntegerType: $lowIndex);
let results = (outs LLHD_SigType<[ArrayType]>: $result);
let results = (outs InOutTypeOf<[ArrayType]>: $result);

let assemblyFormat = [{
$input `at` $lowIndex attr-dict `:` functional-type($input, $result)
Expand All @@ -144,12 +144,12 @@ def LLHD_SigArraySliceOp : LLHD_Op<"sig.array_slice",
unsigned getResultWidth() { return getLLHDTypeWidth(getResult().getType()); }
unsigned getInputWidth() { return getLLHDTypeWidth(getInput().getType()); }
hw::ArrayType getInputArrayType() {
return llvm::cast<hw::ArrayType>(llvm::cast<llhd::SigType>(
getInput().getType()).getUnderlyingType());
return llvm::cast<hw::ArrayType>(llvm::cast<hw::InOutType>(
getInput().getType()).getElementType());
}
hw::ArrayType getResultArrayType() {
return llvm::cast<hw::ArrayType>(llvm::cast<llhd::SigType>(
getResult().getType()).getUnderlyingType());
return llvm::cast<hw::ArrayType>(llvm::cast<hw::InOutType>(
getResult().getType()).getElementType());
}
}];
let hasFolder = true;
Expand Down Expand Up @@ -196,11 +196,11 @@ def LLHD_PtrArraySliceOp : LLHD_Op<"ptr.array_slice",
unsigned getInputWidth() { return getLLHDTypeWidth(getInput().getType()); }
hw::ArrayType getInputArrayType() {
return llvm::cast<hw::ArrayType>(llvm::cast<llhd::PtrType>(
getInput().getType()).getUnderlyingType());
getInput().getType()).getElementType());
}
hw::ArrayType getResultArrayType() {
return llvm::cast<hw::ArrayType>(llvm::cast<llhd::PtrType>(
getResult().getType()).getUnderlyingType());
getResult().getType()).getElementType());
}
}];
let hasFolder = true;
Expand All @@ -221,20 +221,20 @@ def LLHD_SigArrayGetOp : LLHD_Op<"sig.array_get",
Example:

```mlir
// Returns a !llhd.sig<i8>
%0 = llhd.sig.array_get %arr[%index] : !llhd.sig<!hw.array<4xi8>>
// Returns a !hw.inout<i8>
%0 = llhd.sig.array_get %arr[%index] : !hw.inout<array<4xi8>>
```
}];

let arguments = (ins LLHD_SigType<[ArrayType]>:$input, HWIntegerType:$index);
let results = (outs LLHD_SigType<[HWNonInOutType]>: $result);
let arguments = (ins InOutTypeOf<[ArrayType]>:$input, HWIntegerType:$index);
let results = (outs InOutTypeOf<[HWNonInOutType]>: $result);

let assemblyFormat = "$input `[` $index `]` attr-dict `:` qualified(type($input))";

let extraClassDeclaration = [{
hw::ArrayType getArrayType() {
return llvm::cast<hw::ArrayType>(llvm::cast<llhd::SigType>(
getInput().getType()).getUnderlyingType());
return llvm::cast<hw::ArrayType>(llvm::cast<hw::InOutType>(
getInput().getType()).getElementType());
}
}];
}
Expand Down Expand Up @@ -266,7 +266,7 @@ def LLHD_PtrArrayGetOp : LLHD_Op<"ptr.array_get",
let extraClassDeclaration = [{
hw::ArrayType getArrayType() {
return llvm::cast<hw::ArrayType>(llvm::cast<llhd::PtrType>(
getInput().getType()).getUnderlyingType());
getInput().getType()).getElementType());
}
}];
}
Expand All @@ -286,21 +286,21 @@ def LLHD_SigStructExtractOp : LLHD_Op<"sig.struct_extract", [Pure,
Example:

```mlir
// Returns a !llhd.sig<i8>
// Returns a !hw.inout<i8>
%0 = llhd.sig.struct_extract %struct["foo"]
: !llhd.sig<!hw.struct<foo: i8, bar: i16>>
: !hw.inout<struct<foo: i8, bar: i16>>
```
}];

let arguments = (ins LLHD_SigType<[StructType]>:$input, StrAttr:$field);
let results = (outs LLHD_SigType<[HWNonInOutType]>:$result);
let arguments = (ins InOutTypeOf<[StructType]>:$input, StrAttr:$field);
let results = (outs InOutTypeOf<[HWNonInOutType]>:$result);

let assemblyFormat = "$input `[` $field `]` attr-dict `:` qualified(type($input))";

let extraClassDeclaration = [{
hw::StructType getStructType() {
return llvm::cast<hw::StructType>(llvm::cast<llhd::SigType>(
getInput().getType()).getUnderlyingType());
return llvm::cast<hw::StructType>(llvm::cast<hw::InOutType>(
getInput().getType()).getElementType());
}
}];
}
Expand Down Expand Up @@ -330,7 +330,7 @@ def LLHD_PtrStructExtractOp : LLHD_Op<"ptr.struct_extract", [Pure,
let extraClassDeclaration = [{
hw::StructType getStructType() {
return llvm::cast<hw::StructType>(llvm::cast<llhd::PtrType>(
getInput().getType()).getUnderlyingType());
getInput().getType()).getElementType());
}
}];
}
21 changes: 6 additions & 15 deletions include/circt/Dialect/LLHD/IR/LLHD.td
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef CIRCT_DIALECT_LLHD_IR_LLHD
#define CIRCT_DIALECT_LLHD_IR_LLHD

include "circt/Dialect/HW/HWTypes.td"
include "mlir/IR/AttrTypeBase.td"
include "mlir/IR/OpBase.td"
include "mlir/IR/PatternBase.td"
Expand All @@ -30,6 +31,7 @@ include "mlir/IR/SymbolInterfaces.td"
def LLHD_Dialect : Dialect {
let name = "llhd";
let cppNamespace = "::circt::llhd";
let dependentDialects = ["circt::hw::HWDialect"];

let description = [{
A low-level hardware description dialect in MLIR.
Expand Down Expand Up @@ -68,28 +70,17 @@ def LLHD_TimeType : DialectType<LLHD_Dialect,
BuildableType<"TimeType::get($_builder.getContext())">;

// Legal underlying types for signals and pointers.
def LLHD_AnyUnderlyingType :
def LLHD_AnyElementType :
AnyTypeOf<[HWIntegerType, ArrayType, StructType]>;

// LLHD sig type
class LLHD_SigType<list<Type> allowedTypes>
: ContainerType<AnyTypeOf<allowedTypes>, CPred<"llvm::isa<SigType>($_self)">,
"llvm::cast<SigType>($_self).getUnderlyingType()", "LLHD sig type">;

def LLHD_AnySigType : LLHD_SigType<[LLHD_AnyUnderlyingType]>;

// LLHD ptr type
class LLHD_PtrType<list<Type> allowedTypes>
: ContainerType<AnyTypeOf<allowedTypes>, CPred<"llvm::isa<PtrType>($_self)">,
"llvm::cast<PtrType>($_self).getUnderlyingType()", "LLHD pointer type">;

def LLHD_AnyPtrType : LLHD_PtrType<[LLHD_AnyUnderlyingType]>;
"llvm::cast<PtrType>($_self).getElementType()", "LLHD pointer type">;

// LLHD sig or ptr type
class LLHD_SigOrPtrType<list<Type> allowedTypes>
: AnyTypeOf<[LLHD_SigType<allowedTypes>, LLHD_PtrType<allowedTypes>]>;
def LLHD_AnyPtrType : LLHD_PtrType<[LLHD_AnyElementType]>;

def LLHD_AnySigOrPtrType : LLHD_SigOrPtrType<[LLHD_AnyUnderlyingType]>;
def LLHD_AnySigOrPtrType : AnyTypeOf<[LLHD_AnyPtrType, InOutType]>;

//===----------------------------------------------------------------------===//
// LLHD op definition
Expand Down
28 changes: 4 additions & 24 deletions include/circt/Dialect/LLHD/IR/LLHDTypesImpl.td
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,6 @@ class LLHDType<string name> : TypeDef<LLHD_Dialect, name> { }
// Type declarations
//===----------------------------------------------------------------------===//

// Declares the llhd::SigType in C++.
def SigTypeImpl : LLHDType<"Sig"> {
let summary = "signal type";
let description = [{
Signals correspond directly to wires in a physical design, and are used to
model propagation delays and timing. Signals are used to carry values across
time steps in the LLHD execution model.
}];

let mnemonic = "sig";
let parameters = (ins "::mlir::Type":$underlyingType);
let assemblyFormat = "`<` $underlyingType `>`";

let builders = [
AttrBuilderWithInferredContext<(ins "::mlir::Type":$underlyingType), [{
return $_get(underlyingType.getContext(), underlyingType);
}]>
];
}

// Declares the llhd::PtrType in C++.
def PtrTypeImpl : LLHDType<"Ptr"> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we might be able to use memrefs as a replacement for !llhd.ptr in the future?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory yes, but we might not want to pull in all the complexity of memref in practice.

let summary = "pointer type";
Expand All @@ -46,12 +26,12 @@ def PtrTypeImpl : LLHDType<"Ptr"> {
}];

let mnemonic = "ptr";
let parameters = (ins "::mlir::Type":$underlyingType);
let assemblyFormat = "`<` $underlyingType `>`";
let parameters = (ins "::mlir::Type":$elementType);
let assemblyFormat = "`<` $elementType `>`";

let builders = [
AttrBuilderWithInferredContext<(ins "::mlir::Type":$underlyingType), [{
return $_get(underlyingType.getContext(), underlyingType);
AttrBuilderWithInferredContext<(ins "::mlir::Type":$elementType), [{
return $_get(elementType.getContext(), elementType);
}]>
];
}
Expand Down
10 changes: 5 additions & 5 deletions include/circt/Dialect/LLHD/IR/MemoryOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def LLHD_VarOp : LLHD_Op<"var", [
```
}];

let arguments = (ins LLHD_AnyUnderlyingType: $init);
let arguments = (ins LLHD_AnyElementType: $init);
let results = (outs Res<LLHD_AnyPtrType, "the newly allocated reference",
[MemAlloc]>: $result);

Expand All @@ -42,7 +42,7 @@ def LLHD_VarOp : LLHD_Op<"var", [
def LLHD_LoadOp : LLHD_Op<"load", [
TypesMatchWith<
"type of 'result' and underlying type of 'pointer' have to match.",
"pointer", "result", "llvm::cast<PtrType>($_self).getUnderlyingType()">
"pointer", "result", "llvm::cast<PtrType>($_self).getElementType()">
]> {
let summary = "Load a value.";
let description = [{
Expand All @@ -64,15 +64,15 @@ def LLHD_LoadOp : LLHD_Op<"load", [

let arguments = (ins Arg<LLHD_AnyPtrType, "the reference to load from",
[MemRead]>: $pointer);
let results = (outs LLHD_AnyUnderlyingType: $result);
let results = (outs LLHD_AnyElementType: $result);

let assemblyFormat = "$pointer attr-dict `:` qualified(type($pointer))";
}

def LLHD_StoreOp : LLHD_Op<"store", [
TypesMatchWith<
"type of 'value' and underlying type of 'pointer' have to match.",
"pointer", "value", "llvm::cast<PtrType>($_self).getUnderlyingType()">
"pointer", "value", "llvm::cast<PtrType>($_self).getElementType()">
]> {
let summary = "Store a value.";
let description = [{
Expand All @@ -94,7 +94,7 @@ def LLHD_StoreOp : LLHD_Op<"store", [

let arguments = (ins Arg<LLHD_AnyPtrType, "the reference to store to",
[MemWrite]>: $pointer,
LLHD_AnyUnderlyingType: $value);
LLHD_AnyElementType: $value);

let assemblyFormat = "$pointer `,` $value attr-dict `:` qualified(type($pointer))";
}
Loading
Loading