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

[Draft] [OpLib] Create a Dialect for Representing Operator Libraries #7771

Draft
wants to merge 7 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
1 change: 1 addition & 0 deletions include/circt/Dialect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ add_subdirectory(LTL)
add_subdirectory(Moore)
add_subdirectory(MSFT)
add_subdirectory(OM)
add_subdirectory(OpLib)
add_subdirectory(Pipeline)
add_subdirectory(Ibis)
add_subdirectory(Seq)
Expand Down
2 changes: 1 addition & 1 deletion include/circt/Dialect/Calyx/CalyxPrimitives.td
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def SeqMemoryOp : CalyxPrimitive<"seq_mem", []> {
);

let results = (outs
Variadic<AnySignlessInteger>:$results
Variadic<AnyType>:$results
);

let assemblyFormat = [{
Expand Down
9 changes: 9 additions & 0 deletions include/circt/Dialect/OpLib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
add_circt_dialect(OpLib oplib)
add_circt_dialect_doc(OpLib oplib)

set(LLVM_TARGET_DEFINITIONS OpLib.td)

mlir_tablegen(OpLibAttributes.h.inc -gen-attrdef-decls)
mlir_tablegen(OpLibAttributes.cpp.inc -gen-attrdef-defs)
add_public_tablegen_target(CIRCTOpLibAttributesIncGen)
add_dependencies(circt-headers CIRCTOpLibAttributesIncGen)
30 changes: 30 additions & 0 deletions include/circt/Dialect/OpLib/OpLib.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//===- OpLib.td - OpLib Definitions ------------------*- 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
//
//===----------------------------------------------------------------------===//

#ifndef CIRCT_OPLIB_DIALECT_TD
#define CIRCT_OPLIB_DIALECT_TD

include "mlir/IR/DialectBase.td"

def OpLib_Dialect : Dialect {
let name = "oplib";
let cppNamespace = "::circt::oplib";
let summary = "Operator library dialect";

let useDefaultAttributePrinterParser = true;

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

include "circt/Dialect/OpLib/OpLibAttributes.td"
include "circt/Dialect/OpLib/OpLibOps.td"

#endif // CIRCT_OPLIB_DIALECT_TD
44 changes: 44 additions & 0 deletions include/circt/Dialect/OpLib/OpLibAttributes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//===- OpLibAttributes.h - OpLib attribute definitions ----*- 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 OpLib dialect attributes.
//
//===----------------------------------------------------------------------===//

#ifndef CIRCT_DIALECT_OPLIB_OPLIBATTRIBUTES_H
#define CIRCT_DIALECT_OPLIB_OPLIBATTRIBUTES_H

#include "circt/Dialect/OpLib/OpLibDialect.h"
#include "circt/Scheduling/Problems.h"
#include "circt/Support/LLVM.h"

#include "mlir/IR/OpImplementation.h"

#define GET_ATTRDEF_CLASSES
#include "circt/Dialect/OpLib/OpLibAttributes.h.inc"

namespace circt {
namespace oplib {

/// Parse an array of attributes while recognizing the properties of the
/// OpLib dialect even without a `#oplib.` prefix. Any attributes
/// supplied in \p alreadyParsed are prepended to the parsed ones.
mlir::OptionalParseResult
parseOptionalPropertyArray(ArrayAttr &attr, AsmParser &parser,
ArrayRef<Attribute> alreadyParsed = {});

/// Print an array attribute, suppressing the `#oplib.` prefix for properties
/// defined in the OpLib dialect. Attributes mentioned in \p alreadyPrinted
/// are skipped.
void printPropertyArray(ArrayAttr attr, AsmPrinter &p,
ArrayRef<Attribute> alreadyPrinted = {});

} // namespace oplib
} // namespace circt

#endif // CIRCT_DIALECT_OPLIB_OPLIBATTRIBUTES_H
59 changes: 59 additions & 0 deletions include/circt/Dialect/OpLib/OpLibAttributes.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//===- OpLibAttributes.td - OpLib attributes ---------*- 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 file defines the OpLib dialect attributes.
//
//===----------------------------------------------------------------------===//

//===----------------------------------------------------------------------===//
// Dialect attributes
//===----------------------------------------------------------------------===//

include "mlir/IR/AttrTypeBase.td"

class OperatorProperty<Dialect dialect,
string name, string type,
list<Trait> traits = []>
: AttrDef<dialect, name, traits> {

string propertyName = name;
string propertyType = type;

// Unwrap the data in this attribute's `$value` parameter in order to pass it
// to the corresponding setter on the problem class.
// code unwrapValue = [{ getValue() }];
// Wrap the `value` returned by the getter on the problem class in order to
// store it in this attribute's `$value` parameter.
// code wrapValue = [{ value }];

let summary = "Models the `" # propertyName # "` property for a OpLib operator.";

let parameters = (ins propertyType:$value);
let mnemonic = propertyName;
let assemblyFormat = [{ `<` $value `>` }];
}

def IncomingDelayProp : OperatorProperty<OpLib_Dialect,
"IncomingDelay", "::mlir::FloatAttr"> {
let mnemonic = "incDelay";
}

def OutgoingDelayProp : OperatorProperty<OpLib_Dialect,
"OutgoingDelay", "::mlir::FloatAttr"> {
let mnemonic = "outDelay";
}

def LimitProp : OperatorProperty<OpLib_Dialect,
"Limit", "unsigned"> {
let mnemonic = "limit";
}

def LatencyProp : OperatorProperty<OpLib_Dialect,
"Latency", "unsigned"> {
let mnemonic = "latency";
}
22 changes: 22 additions & 0 deletions include/circt/Dialect/OpLib/OpLibDialect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===- OpLibDialect.h - OpLib Definitions -----------------------*- 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 OpLib CIRCT dialect.
//
//===----------------------------------------------------------------------===//

#ifndef CIRCT_DIALECT_OPLIB_OPLIBDIALECT_H
#define CIRCT_DIALECT_OPLIB_OPLIBDIALECT_H

#include "circt/Support/LLVM.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/Dialect.h"

#include "circt/Dialect/OpLib/OpLibDialect.h.inc"

#endif // CIRCT_DIALECT_OPLIB_OPLIBDIALECT_H
31 changes: 31 additions & 0 deletions include/circt/Dialect/OpLib/OpLibOps.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//===- OpLibOps.h - OpLib Op Definitions ------------------------*- 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
//
//===----------------------------------------------------------------------===//

#ifndef CIRCT_DIALECT_OPLIB_OPLIBOPS_H
#define CIRCT_DIALECT_OPLIB_OPLIBOPS_H

#include "circt/Support/LLVM.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Dialect.h"
#include "mlir/IR/OpDefinition.h"
#include "mlir/IR/OpImplementation.h"
#include "mlir/IR/Operation.h"
#include "mlir/Interfaces/ControlFlowInterfaces.h"
#include "mlir/Interfaces/FunctionInterfaces.h"
#include "mlir/Interfaces/InferTypeOpInterface.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"

#include "circt/Dialect/OpLib/OpLibDialect.h"

#define GET_OP_CLASSES
#include "circt/Dialect/OpLib/OpLib.h.inc"

#endif // CIRCT_DIALECT_OPLIB_OPLIBOPS_H
Loading
Loading