Skip to content

Commit

Permalink
[RTGTest] Add integer register type API (#8141)
Browse files Browse the repository at this point in the history
  • Loading branch information
maerhart authored Feb 3, 2025
1 parent 518f3a1 commit deb88ba
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
6 changes: 6 additions & 0 deletions include/circt-c/Dialect/RTGTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ MLIR_CAPI_EXPORTED bool rtgtestTypeIsACPU(MlirType type);
/// Creates an RTGTest CPU type in the context.
MLIR_CAPI_EXPORTED MlirType rtgtestCPUTypeGet(MlirContext ctxt);

/// If the type is an RTGTest IntegerRegisterType.
MLIR_CAPI_EXPORTED bool rtgtestTypeIsAIntegerRegister(MlirType type);

/// Creates an RTGTest IntegerRegisterType in the context.
MLIR_CAPI_EXPORTED MlirType rtgtestIntegerRegisterTypeGet(MlirContext ctxt);

// Immediates.
//===----------------------------------------------------------------------===//

Expand Down
6 changes: 4 additions & 2 deletions integration_test/Bindings/Python/dialects/rtg.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@
labelTy = rtg.LabelType.get()
setTy = rtg.SetType.get(indexTy)
bagTy = rtg.BagType.get(indexTy)
ireg = rtgtest.IntegerRegisterType.get()
seq = rtg.SequenceOp('seq')
Block.create_at_start(seq.bodyRegion, [sequenceTy, labelTy, setTy, bagTy])
Block.create_at_start(seq.bodyRegion,
[sequenceTy, labelTy, setTy, bagTy, ireg])

# CHECK: rtg.sequence @seq
# CHECK: (%{{.*}}: !rtg.sequence, %{{.*}}: !rtg.label, %{{.*}}: !rtg.set<index>, %{{.*}}: !rtg.bag<index>):
# CHECK: (%{{.*}}: !rtg.sequence, %{{.*}}: !rtg.label, %{{.*}}: !rtg.set<index>, %{{.*}}: !rtg.bag<index>, %{{.*}}: !rtgtest.ireg):
print(m)

with Context() as ctx, Location.unknown():
Expand Down
8 changes: 8 additions & 0 deletions lib/Bindings/Python/RTGTestModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ void circt::python::populateDialectRTGTestSubmodule(nb::module_ &m) {
},
nb::arg("self"), nb::arg("ctxt") = nullptr);

mlir_type_subclass(m, "IntegerRegisterType", rtgtestTypeIsAIntegerRegister)
.def_classmethod(
"get",
[](nb::object cls, MlirContext ctxt) {
return cls(rtgtestIntegerRegisterTypeGet(ctxt));
},
nb::arg("self"), nb::arg("ctxt") = nullptr);

mlir_type_subclass(m, "Imm12Type", rtgtestTypeIsAImm12)
.def_classmethod(
"get",
Expand Down
8 changes: 8 additions & 0 deletions lib/CAPI/Dialect/RTGTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ MlirType rtgtestCPUTypeGet(MlirContext ctxt) {
return wrap(CPUType::get(unwrap(ctxt)));
}

bool rtgtestTypeIsAIntegerRegister(MlirType type) {
return isa<IntegerRegisterType>(unwrap(type));
}

MlirType rtgtestIntegerRegisterTypeGet(MlirContext ctxt) {
return wrap(IntegerRegisterType::get(unwrap(ctxt)));
}

// Immediates.
//===----------------------------------------------------------------------===//

Expand Down
11 changes: 11 additions & 0 deletions test/CAPI/rtgtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ static void testCPUType(MlirContext ctx) {
mlirTypeDump(cpuTy);
}

static void testIntegerRegisterType(MlirContext ctx) {
MlirType iregTy = rtgtestIntegerRegisterTypeGet(ctx);

// CHECK: is_ireg
fprintf(stderr,
rtgtestTypeIsAIntegerRegister(iregTy) ? "is_ireg\n" : "isnot_ireg\n");
// CHECK: !rtgtest.ireg
mlirTypeDump(iregTy);
}

static void testCPUAttr(MlirContext ctx) {
MlirAttribute cpuAttr = rtgtestCPUAttrGet(ctx, 3);

Expand Down Expand Up @@ -322,6 +332,7 @@ int main(int argc, char **argv) {
mlirDialectHandleLoadDialect(mlirGetDialectHandle__rtgtest__(), ctx);

testCPUType(ctx);
testIntegerRegisterType(ctx);
testCPUAttr(ctx);
testRegisters(ctx);
testImmediates(ctx);
Expand Down

0 comments on commit deb88ba

Please sign in to comment.