Skip to content

Commit d439b8c

Browse files
committed
[RTG] Add context resource attribute interface
1 parent 90fac44 commit d439b8c

18 files changed

+160
-4
lines changed

include/circt/Dialect/RTG/IR/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ mlir_tablegen(RTGTypeInterfaces.cpp.inc -gen-type-interface-defs)
1818
add_public_tablegen_target(CIRCTRTGTypeInterfacesIncGen)
1919
add_dependencies(circt-headers CIRCTRTGTypeInterfacesIncGen)
2020

21+
mlir_tablegen(RTGAttrInterfaces.h.inc -gen-attr-interface-decls)
22+
mlir_tablegen(RTGAttrInterfaces.cpp.inc -gen-attr-interface-defs)
23+
add_public_tablegen_target(CIRCTRTGAttrInterfacesIncGen)
24+
add_dependencies(circt-headers CIRCTRTGAttrInterfacesIncGen)
25+
2126
set(LLVM_TARGET_DEFINITIONS RTGISAAssemblyInterfaces.td)
2227
mlir_tablegen(RTGISAAssemblyOpInterfaces.h.inc -gen-op-interface-decls)
2328
mlir_tablegen(RTGISAAssemblyOpInterfaces.cpp.inc -gen-op-interface-defs)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===- RTGAttrInterfaces.h - Declare RTG attr interfaces --------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file declares attr interfaces for the RTG Dialect.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef CIRCT_DIALECT_RTG_IR_RTGATTRINTERFACES_H
14+
#define CIRCT_DIALECT_RTG_IR_RTGATTRINTERFACES_H
15+
16+
#include "circt/Support/LLVM.h"
17+
#include "mlir/IR/Attributes.h"
18+
#include "mlir/IR/BuiltinAttributeInterfaces.h"
19+
20+
#include "circt/Dialect/RTG/IR/RTGAttrInterfaces.h.inc"
21+
22+
#endif // CIRCT_DIALECT_RTG_IR_RTGATTRINTERFACES_H

include/circt/Dialect/RTG/IR/RTGInterfaces.td

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
include "mlir/IR/Interfaces.td"
1313
include "mlir/IR/OpBase.td"
14+
include "mlir/IR/BuiltinAttributeInterfaces.td"
1415

1516
def ContextResourceOpInterface : OpInterface<"ContextResourceOpInterface"> {
1617
let description = [{
@@ -50,4 +51,18 @@ def ContextResourceTypeInterface : TypeInterface<
5051
let cppNamespace = "::circt::rtg";
5152
}
5253

54+
def ContextResourceAttrInterface : AttrInterface<
55+
"ContextResourceAttrInterface", [TypedAttrInterface]> {
56+
let description = [{
57+
This interface should be implemented by attributes that represent context
58+
resources.
59+
Any attribute implementing this interface must be of a type implementing
60+
the `ContextResourceTypeInterface`.
61+
62+
TODO: properly verify this; unfortunately, we don't have a 'verify' field
63+
here like the 'OpInterface' has.
64+
}];
65+
let cppNamespace = "::circt::rtg";
66+
}
67+
5368
#endif // CIRCT_DIALECT_RTG_IR_RTGINTERFACES_TD

include/circt/Dialect/RTG/IR/RTGOps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef CIRCT_DIALECT_RTG_IR_RTGOPS_H
1414
#define CIRCT_DIALECT_RTG_IR_RTGOPS_H
1515

16+
#include "circt/Dialect/RTG/IR/RTGAttrInterfaces.h"
1617
#include "circt/Dialect/RTG/IR/RTGDialect.h"
1718
#include "circt/Dialect/RTG/IR/RTGTypeInterfaces.h"
1819
#include "circt/Dialect/RTG/IR/RTGTypes.h"

include/circt/Dialect/RTGTest/IR/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ set(LLVM_TARGET_DEFINITIONS RTGTestAttributes.td)
88
mlir_tablegen(RTGTestEnums.h.inc -gen-enum-decls)
99
mlir_tablegen(RTGTestEnums.cpp.inc -gen-enum-defs)
1010
add_public_tablegen_target(CIRCTRTGTestEnumsIncGen)
11+
12+
mlir_tablegen(RTGTestAttributes.h.inc -gen-attrdef-decls)
13+
mlir_tablegen(RTGTestAttributes.cpp.inc -gen-attrdef-defs)
14+
add_public_tablegen_target(CIRCTRTGTestAttributeIncGen)

include/circt/Dialect/RTGTest/IR/RTGTest.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ include "circt/Dialect/RTG/IR/RTGInterfaces.td"
2222
include "circt/Dialect/RTGTest/IR/RTGTestDialect.td"
2323
include "circt/Dialect/RTGTest/IR/RTGTestAttributes.td"
2424
include "circt/Dialect/RTGTest/IR/RTGTestTypes.td"
25+
include "circt/Dialect/RTGTest/IR/RTGTestAttributes.td"
2526
include "circt/Dialect/RTGTest/IR/RTGTestOps.td"
2627

2728
#endif // CIRCT_DIALECT_RTGTEST_IR_RTGTEST_TD
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===- RTGTestAttributes.h - RTG Test dialect attributes --------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef CIRCT_DIALECT_RTGTEST_IR_RTGTESTATTRIBUTES_H
10+
#define CIRCT_DIALECT_RTGTEST_IR_RTGTESTATTRIBUTES_H
11+
12+
#include "circt/Dialect/RTGTest/IR/RTGTestTypes.h"
13+
#include "mlir/IR/Attributes.h"
14+
#include "mlir/IR/BuiltinAttributes.h"
15+
16+
#include "circt/Dialect/RTG/IR/RTGAttrInterfaces.h"
17+
18+
#define GET_ATTRDEF_CLASSES
19+
#include "circt/Dialect/RTGTest/IR/RTGTestAttributes.h.inc"
20+
21+
#endif // CIRCT_DIALECT_RTGTEST_IR_RTGTESTATTRIBUTES_H

include/circt/Dialect/RTGTest/IR/RTGTestAttributes.td

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#ifndef CIRCT_DIALECT_RTGTEST_IR_RTGTESTATTRIBUTES_TD
1414
#define CIRCT_DIALECT_RTGTEST_IR_RTGTESTATTRIBUTES_TD
1515

16+
include "circt/Dialect/RTGTest/IR/RTGTestDialect.td"
17+
include "circt/Dialect/RTG/IR/RTGInterfaces.td"
1618
include "mlir/IR/AttrTypeBase.td"
1719
include "mlir/IR/EnumAttr.td"
1820

@@ -57,4 +59,21 @@ def RegisterAttr : I32EnumAttr<
5759
let cppNamespace = "::circt::rtgtest";
5860
}
5961

62+
class RTGTestAttrDef<string name, list<Trait> traits = []>
63+
: AttrDef<RTGTestDialect, name, traits>;
64+
65+
def CPUAttr : RTGTestAttrDef<"CPU", [ContextResourceAttrInterface]> {
66+
let summary = "this attribute represents a CPU referred to by the core ID";
67+
68+
let parameters = (ins "size_t":$id);
69+
70+
let mnemonic = "cpu";
71+
let assemblyFormat = "`<` $id `>`";
72+
73+
let extraClassDeclaration = [{
74+
// TypedAttrInterface
75+
Type getType() const;
76+
}];
77+
}
78+
6079
#endif // CIRCT_DIALECT_RTGTEST_IR_RTGTESTATTRIBUTES_TD

include/circt/Dialect/RTGTest/IR/RTGTestDialect.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ def RTGTestDialect : Dialect {
2626
}];
2727

2828
let useDefaultTypePrinterParser = 1;
29+
let useDefaultAttributePrinterParser = 1;
2930
let cppNamespace = "::circt::rtgtest";
3031

3132
let extraClassDeclaration = [{
33+
void registerAttributes();
3234
void registerTypes();
3335
}];
3436
}

include/circt/Dialect/RTGTest/IR/RTGTestOps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "circt/Dialect/RTG/IR/RTGISAAssemblyOpInterfaces.h"
1717
#include "circt/Dialect/RTG/IR/RTGOpInterfaces.h"
1818
#include "circt/Dialect/RTG/IR/RTGOps.h"
19+
#include "circt/Dialect/RTGTest/IR/RTGTestAttributes.h"
1920
#include "circt/Dialect/RTGTest/IR/RTGTestDialect.h"
2021
#include "circt/Dialect/RTGTest/IR/RTGTestTypes.h"
2122
#include "circt/Support/LLVM.h"

0 commit comments

Comments
 (0)