Skip to content

Commit

Permalink
[LLHD][NFC] Clean up some LLHD files (#7509)
Browse files Browse the repository at this point in the history
  • Loading branch information
maerhart authored Aug 11, 2024
1 parent 08fd04f commit 22eb6b5
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 336 deletions.
2 changes: 2 additions & 0 deletions include/circt/Dialect/LLHD/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ set(LLVM_TARGET_DEFINITIONS LLHD.td)
mlir_tablegen(LLHDEnums.h.inc -gen-enum-decls)
mlir_tablegen(LLHDEnums.cpp.inc -gen-enum-defs)
add_public_tablegen_target(CIRCTLLHDEnumsIncGen)
add_dependencies(circt-headers CIRCTLLHDEnumsIncGen)

mlir_tablegen(LLHDAttributes.h.inc -gen-attrdef-decls -attrdefs-dialect=llhd)
mlir_tablegen(LLHDAttributes.cpp.inc -gen-attrdef-defs -attrdefs-dialect=llhd)
add_public_tablegen_target(CIRCTLLHDAttributesIncGen)
add_dependencies(circt-headers CIRCTLLHDAttributesIncGen)
99 changes: 10 additions & 89 deletions include/circt/Dialect/LLHD/IR/LLHD.td
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef CIRCT_DIALECT_LLHD_IR_LLHD
#define CIRCT_DIALECT_LLHD_IR_LLHD
#ifndef CIRCT_DIALECT_LLHD_IR_LLHD_TD
#define CIRCT_DIALECT_LLHD_IR_LLHD_TD

include "circt/Dialect/HW/HWTypes.td"
include "mlir/IR/AttrTypeBase.td"
Expand All @@ -24,97 +24,18 @@ include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/Interfaces/FunctionInterfaces.td"
include "mlir/IR/SymbolInterfaces.td"

//===----------------------------------------------------------------------===//
// LLHD dialect definition
//===----------------------------------------------------------------------===//

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.
}];

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

// Opt-out of properties for now, must migrate by LLVM 19. #5273.
let usePropertiesForAttributes = 0;

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

//===----------------------------------------------------------------------===//
// Import HW Types
//===----------------------------------------------------------------------===//

include "circt/Dialect/LLHD/IR/LLHDDialect.td"
include "circt/Dialect/HW/HWTypes.td"

//===----------------------------------------------------------------------===//
// LLHD type definitions
//===----------------------------------------------------------------------===//

include "LLHDTypesImpl.td"

// LLHD Time Type
def LLHD_TimeType : DialectType<LLHD_Dialect,
CPred<"llvm::isa<TimeType>($_self)">, "LLHD time type", "TimeType">,
BuildableType<"TimeType::get($_builder.getContext())">;

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

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

def LLHD_AnyPtrType : LLHD_PtrType<[LLHD_AnyElementType]>;

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

//===----------------------------------------------------------------------===//
// LLHD op definition
//===----------------------------------------------------------------------===//

// Base class for all LLHD ops.
class LLHD_Op<string mnemonic, list<Trait> traits = []>
: Op<LLHD_Dialect, mnemonic, traits> {

// For each LLHD op, the following static functions need to be defined in
// LLHDOps.cpp:
//
// * static ParseResult parse<op-c++-class-name>(OpAsmParser &parser,
// OperationState &state);
// * static void print<op-c++-class-name>(OpAsmPrinter &p, <op-c++-class-name> op)
let hasCustomAssemblyFormat = 1;
}

//===----------------------------------------------------------------------===//
// LLHD trait definitions
//===----------------------------------------------------------------------===//

class SameTypeArbitraryWidth<string desc, string lhs, string rhs>
: PredOpTrait<desc, CPred<"sameKindArbitraryWidth(" # lhs # ".getType(),"
# rhs # ".getType())">>;
include "circt/Dialect/LLHD/IR/LLHDTypes.td"

//===----------------------------------------------------------------------===//
// LLHD Operations
//===----------------------------------------------------------------------===//

include "ValueOps.td"
include "SignalOps.td"
include "ExtractOps.td"
include "StructureOps.td"
include "MemoryOps.td"
include "circt/Dialect/LLHD/IR/LLHDValueOps.td"
include "circt/Dialect/LLHD/IR/LLHDSignalOps.td"
include "circt/Dialect/LLHD/IR/LLHDExtractOps.td"
include "circt/Dialect/LLHD/IR/LLHDStructureOps.td"
include "circt/Dialect/LLHD/IR/LLHDMemoryOps.td"

#endif // CIRCT_DIALECT_LLHD_IR_LLHD
#endif // CIRCT_DIALECT_LLHD_IR_LLHD_TD
49 changes: 49 additions & 0 deletions include/circt/Dialect/LLHD/IR/LLHDDialect.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//===- LLHDDialect.td - LLHD 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 LLHD dialect.
//
//===----------------------------------------------------------------------===//

#ifndef CIRCT_DIALECT_LLHD_IR_LLHDDIALECT_TD
#define CIRCT_DIALECT_LLHD_IR_LLHDDIALECT_TD

include "mlir/IR/DialectBase.td"

//===----------------------------------------------------------------------===//
// LLHD dialect definition
//===----------------------------------------------------------------------===//

def LLHDDialect : Dialect {
let name = "llhd";
let cppNamespace = "::circt::llhd";
let dependentDialects = ["circt::hw::HWDialect"];

let description = [{
A low-level hardware description dialect in MLIR.
}];

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

// Opt-out of properties for now, must migrate by LLVM 19. #5273.
let usePropertiesForAttributes = 0;

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

class LLHDOp<string mnemonic, list<Trait> traits = []>
: Op<LLHDDialect, mnemonic, traits>;

#endif // CIRCT_DIALECT_LLHD_IR_LLHDDIALECT_TD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===- ExtractOps.td - LLHD extract operations -------------*- tablegen -*-===//
//===- LLHDExtractOps.td - LLHD extract operations ---------*- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down Expand Up @@ -47,7 +47,7 @@ class SmallerOrEqualResultTypeWidthConstraint<string result, string input>
// Integer Operations
//===----------------------------------------------------------------------===//

def LLHD_SigExtractOp : LLHD_Op<"sig.extract",
def SigExtractOp : LLHDOp<"sig.extract",
[Pure,
SmallerOrEqualResultTypeWidthConstraint<"result", "input">,
SigPtrIndexBitWidthConstraint<"lowBit", "input">]> {
Expand All @@ -74,7 +74,7 @@ def LLHD_SigExtractOp : LLHD_Op<"sig.extract",
let hasFolder = true;
}

def LLHD_PtrExtractOp : LLHD_Op<"ptr.extract",
def PtrExtractOp : LLHDOp<"ptr.extract",
[Pure,
SmallerOrEqualResultTypeWidthConstraint<"result", "input">,
SigPtrIndexBitWidthConstraint<"lowBit", "input">]> {
Expand All @@ -86,9 +86,9 @@ def LLHD_PtrExtractOp : LLHD_Op<"ptr.extract",
operand. The result length is defined by the result type.
}];

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

let assemblyFormat = [{
$input `from` $lowBit attr-dict `:` functional-type($input, $result)
Expand All @@ -105,7 +105,7 @@ def LLHD_PtrExtractOp : LLHD_Op<"ptr.extract",
// Array Operations
//===----------------------------------------------------------------------===//

def LLHD_SigArraySliceOp : LLHD_Op<"sig.array_slice",
def SigArraySliceOp : LLHDOp<"sig.array_slice",
[Pure,
SmallerOrEqualResultTypeWidthConstraint<"result", "input">,
SameSigPtrArrayElementTypeConstraint<"result", "input">,
Expand Down Expand Up @@ -156,7 +156,7 @@ def LLHD_SigArraySliceOp : LLHD_Op<"sig.array_slice",
let hasCanonicalizeMethod = true;
}

def LLHD_PtrArraySliceOp : LLHD_Op<"ptr.array_slice",
def PtrArraySliceOp : LLHDOp<"ptr.array_slice",
[Pure,
SmallerOrEqualResultTypeWidthConstraint<"result", "input">,
SameSigPtrArrayElementTypeConstraint<"result", "input">,
Expand All @@ -183,9 +183,9 @@ def LLHD_PtrArraySliceOp : LLHD_Op<"ptr.array_slice",
```
}];

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

let assemblyFormat = [{
$input `at` $lowIndex attr-dict `:` functional-type($input, $result)
Expand All @@ -207,7 +207,7 @@ def LLHD_PtrArraySliceOp : LLHD_Op<"ptr.array_slice",
let hasCanonicalizeMethod = true;
}

def LLHD_SigArrayGetOp : LLHD_Op<"sig.array_get",
def SigArrayGetOp : LLHDOp<"sig.array_get",
[Pure,
SigPtrIndexBitWidthConstraint<"index", "input">,
SigArrayElementTypeConstraint<"result", "input">]> {
Expand Down Expand Up @@ -239,7 +239,7 @@ def LLHD_SigArrayGetOp : LLHD_Op<"sig.array_get",
}];
}

def LLHD_PtrArrayGetOp : LLHD_Op<"ptr.array_get",
def PtrArrayGetOp : LLHDOp<"ptr.array_get",
[Pure,
SigPtrIndexBitWidthConstraint<"index", "input">,
PtrArrayElementTypeConstraint<"result", "input">]> {
Expand All @@ -258,8 +258,8 @@ def LLHD_PtrArrayGetOp : LLHD_Op<"ptr.array_get",
```
}];

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

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

Expand All @@ -275,7 +275,7 @@ def LLHD_PtrArrayGetOp : LLHD_Op<"ptr.array_get",
// Structure Operations
//===----------------------------------------------------------------------===//

def LLHD_SigStructExtractOp : LLHD_Op<"sig.struct_extract", [Pure,
def SigStructExtractOp : LLHDOp<"sig.struct_extract", [Pure,
DeclareOpInterfaceMethods<InferTypeOpInterface>, InferTypeOpInterface]> {
let summary = "Extract a field from a signal of a struct.";
let description = [{
Expand Down Expand Up @@ -305,7 +305,7 @@ def LLHD_SigStructExtractOp : LLHD_Op<"sig.struct_extract", [Pure,
}];
}

def LLHD_PtrStructExtractOp : LLHD_Op<"ptr.struct_extract", [Pure,
def PtrStructExtractOp : LLHDOp<"ptr.struct_extract", [Pure,
DeclareOpInterfaceMethods<InferTypeOpInterface>, InferTypeOpInterface]> {
let summary = "Extract a field from a pointer to a struct.";
let description = [{
Expand All @@ -322,8 +322,8 @@ def LLHD_PtrStructExtractOp : LLHD_Op<"ptr.struct_extract", [Pure,
```
}];

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

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

Expand Down
Loading

0 comments on commit 22eb6b5

Please sign in to comment.