[RTG][RTGTest] Add CAPI and a basic lowering pipeline (#7882)

This commit is contained in:
Martin Erhart 2024-12-04 21:39:10 +00:00 committed by GitHub
parent 885208b8d9
commit bb16f8968b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 734 additions and 4 deletions

View File

@ -0,0 +1,53 @@
//===- RTG.h - C interface for the for RTG dialect ----------------*- 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_C_DIALECT_RTG_H
#define CIRCT_C_DIALECT_RTG_H
#include "mlir-c/IR.h"
#ifdef __cplusplus
extern "C" {
#endif
//===----------------------------------------------------------------------===//
// Dialect API.
//===----------------------------------------------------------------------===//
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(RTG, rtg);
//===----------------------------------------------------------------------===//
// Type API.
//===----------------------------------------------------------------------===//
/// If the type is an RTG sequence.
MLIR_CAPI_EXPORTED bool rtgTypeIsASequence(MlirType type);
/// Creates an RTG sequence type in the context.
MLIR_CAPI_EXPORTED MlirType rtgSequenceTypeGet(MlirContext ctxt);
/// If the type is an RTG set.
MLIR_CAPI_EXPORTED bool rtgTypeIsASet(MlirType type);
/// Creates an RTG set type in the context.
MLIR_CAPI_EXPORTED MlirType rtgSetTypeGet(MlirType elementType);
/// If the type is an RTG dict.
MLIR_CAPI_EXPORTED bool rtgTypeIsADict(MlirType type);
/// Creates an RTG dict type in the context.
MLIR_CAPI_EXPORTED MlirType rtgDictTypeGet(MlirContext ctxt,
intptr_t numEntries,
MlirAttribute const *entryNames,
MlirType const *entryTypes);
#ifdef __cplusplus
}
#endif
#endif // CIRCT_C_DIALECT_RTG_H

View File

@ -0,0 +1,38 @@
//===- RTGTest.h - C interface for the for RTGTest dialect --------*- 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_C_DIALECT_RTGTEST_H
#define CIRCT_C_DIALECT_RTGTEST_H
#include "mlir-c/IR.h"
#ifdef __cplusplus
extern "C" {
#endif
//===----------------------------------------------------------------------===//
// Dialect API.
//===----------------------------------------------------------------------===//
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(RTGTest, rtgtest);
//===----------------------------------------------------------------------===//
// Type API.
//===----------------------------------------------------------------------===//
/// If the type is an RTGTest CPUType.
MLIR_CAPI_EXPORTED bool rtgtestTypeIsACPU(MlirType type);
/// Creates an RTGTest CPU type in the context.
MLIR_CAPI_EXPORTED MlirType rtgtestCPUTypeGet(MlirContext ctxt);
#ifdef __cplusplus
}
#endif
#endif // CIRCT_C_DIALECT_RTGTEST_H

79
include/circt-c/RtgTool.h Normal file
View File

@ -0,0 +1,79 @@
//===-- circt-c/RtgTool.h - C API for the rtgtool -----------------*- 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_C_RTGTOOL_H
#define CIRCT_C_RTGTOOL_H
#include "mlir-c/Pass.h"
#ifdef __cplusplus
extern "C" {
#endif
//===----------------------------------------------------------------------===//
// Tool Options API.
//===----------------------------------------------------------------------===//
#define DEFINE_C_API_STRUCT(name, storage) \
struct name { \
storage *ptr; \
}; \
typedef struct name name
DEFINE_C_API_STRUCT(CirctRtgToolOptions, void);
#undef DEFINE_C_API_STRUCT
// NOLINTNEXTLINE(modernize-use-using)
typedef enum CiretRtgToolOutputFormat {
CIRCT_RTGTOOL_OUTPUT_FORMAT_MLIR,
CIRCT_RTGTOOL_OUTPUT_FORMAT_ELABORATED_MLIR,
CIRCT_RTGTOOL_OUTPUT_FORMAT_ASM,
} CirctRtgToolOutputFormat;
MLIR_CAPI_EXPORTED CirctRtgToolOptions
circtRtgToolOptionsCreateDefault(unsigned seed);
MLIR_CAPI_EXPORTED void circtRtgToolOptionsDestroy(CirctRtgToolOptions options);
MLIR_CAPI_EXPORTED void
circtRtgToolOptionsSetOutputFormat(CirctRtgToolOptions options,
CirctRtgToolOutputFormat format);
MLIR_CAPI_EXPORTED void circtRtgToolOptionsSetSeed(CirctRtgToolOptions options,
unsigned seed);
MLIR_CAPI_EXPORTED void
circtRtgToolOptionsSetVerifyPasses(CirctRtgToolOptions options, bool enable);
MLIR_CAPI_EXPORTED void
circtRtgToolOptionsSetVerbosePassExecution(CirctRtgToolOptions options,
bool enable);
MLIR_CAPI_EXPORTED void circtRtgToolOptionsSetUnsupportedInstructions(
CirctRtgToolOptions options, unsigned numInstr,
const char **unsupportedInstructions);
MLIR_CAPI_EXPORTED void circtRtgToolOptionsAddUnsupportedInstruction(
CirctRtgToolOptions options, const char *unsupportedInstruction);
MLIR_CAPI_EXPORTED void
circtRtgToolOptionsSetUnsupportedInstructionsFile(CirctRtgToolOptions options,
const char *filename);
//===----------------------------------------------------------------------===//
// Pipeline Population API.
//===----------------------------------------------------------------------===//
MLIR_CAPI_EXPORTED void
circtRtgToolRandomizerPipeline(MlirPassManager pm, CirctRtgToolOptions options);
#ifdef __cplusplus
}
#endif
#endif // CIRCT_C_RTGTOOL_H

View File

@ -20,7 +20,7 @@ include "mlir/IR/AttrTypeBase.td"
class RTGTestTypeDef<string name, list<Trait> traits = []>
: TypeDef<RTGTestDialect, name, traits>;
def CPUType : RTGTestTypeDef<"cpu", [ContextResourceTypeInterface]> {
def CPUType : RTGTestTypeDef<"CPU", [ContextResourceTypeInterface]> {
let summary = "handle to a specific CPU";
let description = [{
This type implements a specific context resource to test RTG operations

View File

@ -0,0 +1,93 @@
//===- RtgToolOptions.h - Configuration Options for rtgtool -----*- 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 header file defines configuration options for the rtgtool.
//
//===----------------------------------------------------------------------===//
#ifndef CIRCT_TOOLS_RTGTOOL_RTGTOOLOPTIONS_H
#define CIRCT_TOOLS_RTGTOOL_RTGTOOLOPTIONS_H
#include "circt/Support/LLVM.h"
#include "mlir/Pass/PassManager.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"
namespace circt {
namespace rtg {
/// The set of options used to control the behavior of the RTG tool.
class RtgToolOptions {
public:
enum class OutputFormat { MLIR, ElaboratedMLIR, ASM };
RtgToolOptions(unsigned seed) : seed(seed) {}
void setOutputFormat(OutputFormat format) { outputFormat = format; }
OutputFormat getOutputFormat() const { return outputFormat; }
RtgToolOptions &setSeed(unsigned seed) {
this->seed = seed;
return *this;
}
unsigned getSeed() const { return seed; }
RtgToolOptions &setVerifyPasses(bool enable) {
verifyPasses = enable;
return *this;
}
bool getVerifyPasses() const { return verifyPasses; }
RtgToolOptions &setVerbosePassExecution(bool enable) {
verbosePassExecution = enable;
return *this;
}
bool getVerbosePassExecution() const { return verbosePassExecution; }
RtgToolOptions &setUnsupportedInstructions(SmallVector<std::string> &&instr) {
unsupportedInstructions = instr;
return *this;
}
RtgToolOptions &setUnsupportedInstructions(ArrayRef<std::string> instr) {
unsupportedInstructions = SmallVector<std::string>(instr);
return *this;
}
RtgToolOptions &addUnsupportedInstruction(const std::string &instr) {
unsupportedInstructions.push_back(instr);
return *this;
}
ArrayRef<std::string> getUnsupportedInstructions() const {
return unsupportedInstructions;
}
RtgToolOptions &setUnsupportedInstructionsFile(StringRef filename) {
unsupportedInstructionsFile = filename;
return *this;
}
std::string getUnsupportedInstructionsFile() const {
return unsupportedInstructionsFile;
}
private:
OutputFormat outputFormat = OutputFormat::ElaboratedMLIR;
unsigned seed;
bool verifyPasses = true;
bool verbosePassExecution = false;
SmallVector<std::string> unsupportedInstructions;
std::string unsupportedInstructionsFile;
};
/// Populates the passes necessary to lower IR with RTG randomization operations
/// to fully elaborated IR (i.e., IR without random constructs).
void populateRandomizerPipeline(mlir::PassManager &pm,
const RtgToolOptions &options);
} // namespace rtg
} // namespace circt
#endif // CIRCT_TOOLS_RTGTOOL_RTGTOOLOPTIONS_H

View File

@ -3,3 +3,4 @@ add_subdirectory(ExportFIRRTL)
add_subdirectory(ExportVerilog)
add_subdirectory(Dialect)
add_subdirectory(Firtool)
add_subdirectory(RtgTool)

View File

@ -17,6 +17,8 @@ set(LLVM_OPTIONAL_SOURCES
MSFT.cpp
Moore.cpp
OM.cpp
RTG.cpp
RTGTest.cpp
SV.cpp
Seq.cpp
Verif.cpp
@ -129,6 +131,24 @@ add_circt_public_c_api_library(CIRCTCAPIOM
CIRCTOMEvaluator
)
add_circt_public_c_api_library(CIRCTCAPIRTG
RTG.cpp
LINK_LIBS PUBLIC
MLIRCAPIIR
CIRCTRTGDialect
)
if(CIRCT_INCLUDE_TESTS)
add_circt_public_c_api_library(CIRCTCAPIRTGTest
RTGTest.cpp
LINK_LIBS PUBLIC
MLIRCAPIIR
CIRCTRTGTestDialect
)
endif()
add_circt_public_c_api_library(CIRCTCAPISeq
Seq.cpp

65
lib/CAPI/Dialect/RTG.cpp Normal file
View File

@ -0,0 +1,65 @@
//===- RTG.cpp - C interface for the RTG dialect --------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "circt-c/Dialect/RTG.h"
#include "circt/Dialect/RTG/IR/RTGDialect.h"
#include "circt/Dialect/RTG/IR/RTGTypes.h"
#include "mlir/CAPI/Registration.h"
using namespace circt;
using namespace circt::rtg;
//===----------------------------------------------------------------------===//
// Dialect API.
//===----------------------------------------------------------------------===//
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(RTG, rtg, RTGDialect)
//===----------------------------------------------------------------------===//
// Type API.
//===----------------------------------------------------------------------===//
// SequenceType
//===----------------------------------------------------------------------===//
bool rtgTypeIsASequence(MlirType type) {
return isa<SequenceType>(unwrap(type));
}
MlirType rtgSequenceTypeGet(MlirContext ctxt) {
return wrap(SequenceType::get(unwrap(ctxt)));
}
// SetType
//===----------------------------------------------------------------------===//
bool rtgTypeIsASet(MlirType type) { return isa<SetType>(unwrap(type)); }
MlirType rtgSetTypeGet(MlirType elementType) {
auto ty = unwrap(elementType);
return wrap(SetType::get(ty.getContext(), ty));
}
// DictType
//===----------------------------------------------------------------------===//
bool rtgTypeIsADict(MlirType type) { return isa<DictType>(unwrap(type)); }
MlirType rtgDictTypeGet(MlirContext ctxt, intptr_t numEntries,
MlirAttribute const *entryNames,
MlirType const *entryTypes) {
SmallVector<DictEntry> entries;
for (unsigned i = 0; i < numEntries; ++i) {
DictEntry entry;
entry.name = cast<StringAttr>(unwrap(entryNames[i]));
entry.type = unwrap(entryTypes[i]);
entries.emplace_back(entry);
}
return wrap(DictType::get(unwrap(ctxt), entries));
}

View File

@ -0,0 +1,32 @@
//===- RTGTest.cpp - C interface for the RTGTest dialect ------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "circt-c/Dialect/RTGTest.h"
#include "circt/Dialect/RTGTest/IR/RTGTestDialect.h"
#include "circt/Dialect/RTGTest/IR/RTGTestTypes.h"
#include "mlir/CAPI/Registration.h"
using namespace circt;
using namespace circt::rtgtest;
//===----------------------------------------------------------------------===//
// Dialect API.
//===----------------------------------------------------------------------===//
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(RTGTest, rtgtest, RTGTestDialect)
//===----------------------------------------------------------------------===//
// Type API.
//===----------------------------------------------------------------------===//
bool rtgtestTypeIsACPU(MlirType type) { return isa<CPUType>(unwrap(type)); }
MlirType rtgtestCPUTypeGet(MlirContext ctxt) {
return wrap(CPUType::get(unwrap(ctxt)));
}

View File

@ -0,0 +1,7 @@
add_circt_public_c_api_library(CIRCTCAPIRtgTool
RtgTool.cpp
LINK_LIBS PUBLIC
CIRCTRtgToolLib
MLIRCAPIIR
)

View File

@ -0,0 +1,92 @@
//===- RtgTool.cpp - C Interface for the rtgtool --------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "circt-c/RtgTool.h"
#include "circt/Tools/rtgtool/RtgToolOptions.h"
#include "mlir/CAPI/Pass.h"
#include <string>
using namespace circt;
using namespace circt::rtg;
//===----------------------------------------------------------------------===//
// Tool Option API.
//===----------------------------------------------------------------------===//
DEFINE_C_API_PTR_METHODS(CirctRtgToolOptions, RtgToolOptions)
CirctRtgToolOptions circtRtgToolOptionsCreateDefault(unsigned seed) {
auto *options = new RtgToolOptions(seed);
return wrap(options);
}
void circtRtgToolOptionsDestroy(CirctRtgToolOptions options) {
delete unwrap(options);
}
void circtRtgToolOptionsSetOutputFormat(CirctRtgToolOptions options,
CirctRtgToolOutputFormat format) {
RtgToolOptions::OutputFormat converted;
switch (format) {
case CIRCT_RTGTOOL_OUTPUT_FORMAT_MLIR:
converted = RtgToolOptions::OutputFormat::MLIR;
break;
case CIRCT_RTGTOOL_OUTPUT_FORMAT_ELABORATED_MLIR:
converted = RtgToolOptions::OutputFormat::ElaboratedMLIR;
break;
case CIRCT_RTGTOOL_OUTPUT_FORMAT_ASM:
converted = RtgToolOptions::OutputFormat::ASM;
break;
}
unwrap(options)->setOutputFormat(converted);
}
void circtRtgToolOptionsSetSeed(CirctRtgToolOptions options, unsigned seed) {
unwrap(options)->setSeed(seed);
}
void circtRtgToolOptionsSetVerifyPasses(CirctRtgToolOptions options,
bool enable) {
unwrap(options)->setVerifyPasses(enable);
}
void circtRtgToolOptionsSetVerbosePassExecution(CirctRtgToolOptions options,
bool enable) {
unwrap(options)->setVerbosePassExecution(enable);
}
void circtRtgToolOptionsSetUnsupportedInstructions(
CirctRtgToolOptions options, unsigned numInstr,
const char **unsupportedInstructions) {
SmallVector<std::string> instr;
for (unsigned i = 0; i < numInstr; ++i)
instr.push_back(std::string(unsupportedInstructions[i]));
unwrap(options)->setUnsupportedInstructions(std::move(instr));
}
void circtRtgToolOptionsAddUnsupportedInstruction(
CirctRtgToolOptions options, const char *unsupportedInstruction) {
unwrap(options)->addUnsupportedInstruction(
std::string(unsupportedInstruction));
}
void circtRtgToolOptionsSetUnsupportedInstructionsFile(
CirctRtgToolOptions options, const char *filename) {
unwrap(options)->setUnsupportedInstructionsFile(std::string(filename));
}
//===----------------------------------------------------------------------===//
// Pipeline Population API.
//===----------------------------------------------------------------------===//
void circtRtgToolRandomizerPipeline(MlirPassManager pm,
CirctRtgToolOptions options) {
populateRandomizerPipeline(*unwrap(pm), *unwrap(options));
}

View File

@ -1,2 +1,3 @@
add_subdirectory(circt-bmc)
add_subdirectory(circt-lec)
add_subdirectory(rtgtool)

View File

@ -0,0 +1,10 @@
add_circt_library(CIRCTRtgToolLib
RtgToolOptions.cpp
LINK_LIBS PUBLIC
CIRCTSupport
MLIRIR
MLIRPass
MLIRTransforms
)

View File

@ -0,0 +1,35 @@
//===- RtgToolOptions.cpp -------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "circt/Tools/rtgtool/RtgToolOptions.h"
#include "circt/Support/Passes.h"
#include "mlir/Transforms/Passes.h"
using namespace circt;
using namespace circt::rtg;
//===----------------------------------------------------------------------===//
// RTG Tool Pipelines
//===----------------------------------------------------------------------===//
void rtg::populateRandomizerPipeline(mlir::PassManager &pm,
const RtgToolOptions &options) {
pm.enableVerifier(options.getVerifyPasses());
if (options.getVerbosePassExecution())
pm.addInstrumentation(
std::make_unique<VerbosePassInstrumentation<mlir::ModuleOp>>(
"rtgtool"));
pm.addPass(createSimpleCanonicalizerPass());
if (options.getOutputFormat() != RtgToolOptions::OutputFormat::MLIR) {
// TODO: add elaboration pass here
pm.addPass(mlir::createCSEPass());
pm.addPass(createSimpleCanonicalizerPass());
}
}

View File

@ -69,3 +69,43 @@ target_link_libraries(circt-capi-arc-test
MLIRCAPIIR
CIRCTCAPIArc
)
add_llvm_executable(circt-capi-rtg-pipelines-test
PARTIAL_SOURCES_INTENDED
rtg-pipelines.c
)
llvm_update_compile_flags(circt-capi-rtg-pipelines-test)
target_link_libraries(circt-capi-rtg-pipelines-test
PRIVATE
MLIRCAPIIR
CIRCTCAPIRTG
CIRCTCAPIRtgTool
)
add_llvm_executable(circt-capi-rtg-test
PARTIAL_SOURCES_INTENDED
rtg.c
)
llvm_update_compile_flags(circt-capi-rtg-test)
target_link_libraries(circt-capi-rtg-test
PRIVATE
MLIRCAPIIR
CIRCTCAPIRTG
)
add_llvm_executable(circt-capi-rtgtest-test
PARTIAL_SOURCES_INTENDED
rtgtest.c
)
llvm_update_compile_flags(circt-capi-rtgtest-test)
target_link_libraries(circt-capi-rtgtest-test
PRIVATE
MLIRCAPIIR
CIRCTCAPIRTGTest
)

56
test/CAPI/rtg-pipelines.c Normal file
View File

@ -0,0 +1,56 @@
//===- rtg-pipelines.c - RTG pipeline CAPI unit tests ---------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
// RUN: circt-capi-rtg-pipelines-test 2>&1 | FileCheck %s
#include <stdio.h>
#include "circt-c/Dialect/RTG.h"
#include "circt-c/RtgTool.h"
int main(int argc, char **argv) {
MlirContext ctx = mlirContextCreate();
mlirDialectHandleRegisterDialect(mlirGetDialectHandle__rtg__(), ctx);
MlirModule moduleOp = mlirModuleCreateParse(
ctx, mlirStringRefCreateFromCString("rtg.sequence @seq {\n"
"}\n"
"rtg.test @test : !rtg.dict<> {\n"
" %0 = rtg.sequence_closure @seq\n"
"}\n"));
if (mlirModuleIsNull(moduleOp)) {
printf("ERROR: Could not parse.\n");
mlirContextDestroy(ctx);
return 1;
}
MlirPassManager pm = mlirPassManagerCreate(ctx);
CirctRtgToolOptions options = circtRtgToolOptionsCreateDefault(/*seed=*/0);
circtRtgToolRandomizerPipeline(pm, options);
MlirOperation op = mlirModuleGetOperation(moduleOp);
if (mlirLogicalResultIsFailure(mlirPassManagerRunOnOp(pm, op))) {
printf("ERROR: Pipeline run failed.\n");
mlirModuleDestroy(moduleOp);
mlirPassManagerDestroy(pm);
circtRtgToolOptionsDestroy(options);
mlirContextDestroy(ctx);
return 1;
}
// CHECK-LABEL: rtg.test @test
// CHECK-NEXT: }
mlirOperationDump(op);
mlirModuleDestroy(moduleOp);
mlirPassManagerDestroy(pm);
circtRtgToolOptionsDestroy(options);
mlirContextDestroy(ctx);
return 0;
}

70
test/CAPI/rtg.c Normal file
View File

@ -0,0 +1,70 @@
//===- rtg.c - RTG Dialect CAPI unit tests --------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
// RUN: circt-capi-rtg-test 2>&1 | FileCheck %s
#include <stdio.h>
#include "circt-c/Dialect/RTG.h"
#include "mlir-c/BuiltinAttributes.h"
#include "mlir-c/BuiltinTypes.h"
static void testSequenceType(MlirContext ctx) {
MlirType sequenceTy = rtgSequenceTypeGet(ctx);
// CHECK: is_sequence
fprintf(stderr, rtgTypeIsASequence(sequenceTy) ? "is_sequence\n"
: "isnot_sequence\n");
// CHECK: !rtg.sequence
mlirTypeDump(sequenceTy);
}
static void testSetType(MlirContext ctx) {
MlirType elTy = mlirIntegerTypeGet(ctx, 32);
MlirType setTy = rtgSetTypeGet(elTy);
// CHECK: is_set
fprintf(stderr, rtgTypeIsASet(setTy) ? "is_set\n" : "isnot_set\n");
// CHECK: !rtg.set<i32>
mlirTypeDump(setTy);
}
static void testDictType(MlirContext ctx) {
MlirType elTy = mlirIntegerTypeGet(ctx, 32);
MlirAttribute name0 =
mlirStringAttrGet(ctx, mlirStringRefCreateFromCString("entry0"));
MlirAttribute name1 =
mlirStringAttrGet(ctx, mlirStringRefCreateFromCString("entry1"));
const MlirAttribute names[] = {name0, name1};
const MlirType types[] = {elTy, elTy};
MlirType dictTy = rtgDictTypeGet(ctx, 2, names, types);
// CHECK: is_dict
fprintf(stderr, rtgTypeIsADict(dictTy) ? "is_dict\n" : "isnot_dict\n");
// CHECK: !rtg.dict<entry0: i32, entry1: i32>
mlirTypeDump(dictTy);
MlirType emptyDictTy = rtgDictTypeGet(ctx, 0, NULL, NULL);
// CHECK: is_dict
fprintf(stderr, rtgTypeIsADict(dictTy) ? "is_dict\n" : "isnot_dict\n");
// CHECK: !rtg.dict<>
mlirTypeDump(emptyDictTy);
}
int main(int argc, char **argv) {
MlirContext ctx = mlirContextCreate();
mlirDialectHandleLoadDialect(mlirGetDialectHandle__rtg__(), ctx);
testSequenceType(ctx);
testSetType(ctx);
testDictType(ctx);
mlirContextDestroy(ctx);
return 0;
}

33
test/CAPI/rtgtest.c Normal file
View File

@ -0,0 +1,33 @@
//===- rtgtest.c - RTGTest Dialect CAPI unit tests ------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
// RUN: circt-capi-rtgtest-test 2>&1 | FileCheck %s
#include <stdio.h>
#include "circt-c/Dialect/RTGTest.h"
static void testCPUType(MlirContext ctx) {
MlirType cpuTy = rtgtestCPUTypeGet(ctx);
// CHECK: is_cpu
fprintf(stderr, rtgtestTypeIsACPU(cpuTy) ? "is_cpu\n" : "isnot_cpu\n");
// CHECK: !rtgtest.cpu
mlirTypeDump(cpuTy);
}
int main(int argc, char **argv) {
MlirContext ctx = mlirContextCreate();
mlirDialectHandleLoadDialect(mlirGetDialectHandle__rtgtest__(), ctx);
testCPUType(ctx);
mlirContextDestroy(ctx);
return 0;
}

View File

@ -22,6 +22,9 @@ set(CIRCT_TEST_DEPENDS
circt-capi-om-test
circt-capi-firrtl-test
circt-capi-firtool-test
circt-capi-rtg-pipelines-test
circt-capi-rtg-test
circt-capi-rtgtest-test
circt-as
circt-dis
circt-lec

View File

@ -59,9 +59,11 @@ tool_dirs = [
]
tools = [
'arcilator', 'circt-as', 'circt-capi-ir-test', 'circt-capi-om-test',
'circt-capi-firrtl-test', 'circt-capi-firtool-test', 'circt-dis',
'circt-lec', 'circt-reduce', 'circt-synth', 'circt-test', 'circt-translate',
'firtool', 'hlstool', 'om-linker', 'kanagawatool'
'circt-capi-firrtl-test', 'circt-capi-firtool-test',
'circt-capi-rtg-pipelines-test', 'circt-capi-rtg-test',
'circt-capi-rtgtest-test', 'circt-dis', 'circt-lec', 'circt-reduce',
'circt-synth', 'circt-test', 'circt-translate', 'firtool', 'hlstool',
'om-linker', 'kanagawatool'
]
if "CIRCT_OPT_CHECK_IR_ROUNDTRIP" in os.environ: