mirror of https://github.com/llvm/circt.git
[RTG] Add array type (#8359)
This commit is contained in:
parent
39b4aa74af
commit
89420182cd
|
@ -89,6 +89,15 @@ MLIR_CAPI_EXPORTED MlirType rtgImmediateTypeGet(MlirContext ctx,
|
|||
/// Returns the width of the RTG immediate type.
|
||||
MLIR_CAPI_EXPORTED uint32_t rtgImmediateTypeGetWidth(MlirType type);
|
||||
|
||||
/// Creates an RTG array type in the context.
|
||||
MLIR_CAPI_EXPORTED MlirType rtgArrayTypeGet(MlirType elementType);
|
||||
|
||||
/// If the type is an RTG array.
|
||||
MLIR_CAPI_EXPORTED bool rtgTypeIsAArray(MlirType type);
|
||||
|
||||
/// Returns the element type of the RTG array.
|
||||
MLIR_CAPI_EXPORTED MlirType rtgArrayTypeGetElementType(MlirType type);
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Attribute API.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
|
@ -120,6 +120,19 @@ def DictType : RTGTypeDef<"Dict"> {
|
|||
let genVerifyDecl = 1;
|
||||
}
|
||||
|
||||
def ArrayType : RTGTypeDef<"Array"> {
|
||||
let summary = "an array type with dynamic size";
|
||||
let description = [{
|
||||
Represents an array type with dynamic size. The array contains elements of
|
||||
the specified type only.
|
||||
}];
|
||||
|
||||
let parameters = (ins "::mlir::Type":$elementType);
|
||||
|
||||
let mnemonic = "array";
|
||||
let assemblyFormat = "`<` $elementType `>`";
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Types for ISA targets
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
|
@ -218,3 +218,12 @@ with Context() as ctx, Location.unknown():
|
|||
print(f"value={immediate_attr.value}")
|
||||
# CHECK: #rtg.isa.immediate<32, 42>
|
||||
print(immediate_attr)
|
||||
|
||||
with Context() as ctx, Location.unknown():
|
||||
circt.register_dialects(ctx)
|
||||
indexTy = IndexType.get()
|
||||
arr = rtg.ArrayType.get(indexTy)
|
||||
# CHECK: element_type=index
|
||||
print(f"element_type={arr.element_type}")
|
||||
# CHECK: !rtg.array<index>
|
||||
print(arr)
|
||||
|
|
|
@ -100,6 +100,17 @@ void circt::python::populateDialectRTGSubmodule(nb::module_ &m) {
|
|||
std::vector<std::pair<MlirAttribute, MlirType>>(),
|
||||
nb::arg("ctxt") = nullptr);
|
||||
|
||||
mlir_type_subclass(m, "ArrayType", rtgTypeIsAArray)
|
||||
.def_classmethod(
|
||||
"get",
|
||||
[](nb::object cls, MlirType elementType, MlirContext ctxt) {
|
||||
return cls(rtgArrayTypeGet(elementType));
|
||||
},
|
||||
nb::arg("self"), nb::arg("element_type"), nb::arg("ctxt") = nullptr)
|
||||
.def_property_readonly("element_type", [](MlirType self) {
|
||||
return rtgArrayTypeGetElementType(self);
|
||||
});
|
||||
|
||||
// Types for ISA targets
|
||||
//===--------------------------------------------------------------------===//
|
||||
|
||||
|
|
|
@ -115,6 +115,20 @@ MlirType rtgDictTypeGet(MlirContext ctxt, intptr_t numEntries,
|
|||
return wrap(DictType::get(unwrap(ctxt), entries));
|
||||
}
|
||||
|
||||
// ArrayType
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
MlirType rtgArrayTypeGet(MlirType elementType) {
|
||||
return wrap(
|
||||
ArrayType::get(unwrap(elementType).getContext(), unwrap(elementType)));
|
||||
}
|
||||
|
||||
bool rtgTypeIsAArray(MlirType type) { return isa<ArrayType>(unwrap(type)); }
|
||||
|
||||
MlirType rtgArrayTypeGetElementType(MlirType type) {
|
||||
return wrap(cast<ArrayType>(unwrap(type)).getElementType());
|
||||
}
|
||||
|
||||
// ImmediateType
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
|
|
|
@ -103,6 +103,18 @@ static void testDictType(MlirContext ctx) {
|
|||
mlirTypeDump(emptyDictTy);
|
||||
}
|
||||
|
||||
static void testArrayType(MlirContext ctx) {
|
||||
MlirType i32Type = mlirIntegerTypeGet(ctx, 32);
|
||||
MlirType arrayTy = rtgArrayTypeGet(i32Type);
|
||||
|
||||
// CHECK: is_array
|
||||
fprintf(stderr, rtgTypeIsAArray(arrayTy) ? "is_array\n" : "isnot_array\n");
|
||||
// CHECK: i32
|
||||
mlirTypeDump(rtgArrayTypeGetElementType(arrayTy));
|
||||
// CHECK: !rtg.array<i32>
|
||||
mlirTypeDump(arrayTy);
|
||||
}
|
||||
|
||||
static void testLabelVisibilityAttr(MlirContext ctx) {
|
||||
MlirAttribute labelVisibility =
|
||||
rtgLabelVisibilityAttrGet(ctx, RTG_LABEL_VISIBILITY_GLOBAL);
|
||||
|
@ -174,6 +186,7 @@ int main(int argc, char **argv) {
|
|||
testSetType(ctx);
|
||||
testBagType(ctx);
|
||||
testDictType(ctx);
|
||||
testArrayType(ctx);
|
||||
|
||||
testLabelVisibilityAttr(ctx);
|
||||
testDefaultContextAttr(ctx);
|
||||
|
|
|
@ -153,3 +153,7 @@ rtg.test @interleaveSequences(seq0 = %seq0: !rtg.randomized_sequence, seq1 = %se
|
|||
// CHECK: rtg.interleave_sequences %seq0, %seq1 batch 4 {rtg.some_attr}
|
||||
rtg.interleave_sequences %seq0, %seq1 batch 4 {rtg.some_attr}
|
||||
}
|
||||
|
||||
// CHECK-LABEL: rtg.test @arrays
|
||||
// CHECK-SAME: (arr = {{%.+}}: !rtg.array<index>)
|
||||
rtg.test @arrays(arr = %arr: !rtg.array<index>) { }
|
||||
|
|
Loading…
Reference in New Issue