Skip to content

Commit

Permalink
[RTGTest] Add RTGTest dialect
Browse files Browse the repository at this point in the history
Add a dialect to test and demonstrate the RTG dialect, its passes and interfaces.
This also adds a CMake flag called `CIRCT_INCLUDE_TESTS` analogous to MLIRs `MLIR_INCLUDE_TESTS` to not build and include this dialect in release builds.

Co-authored-by: Andrew Lenharth <andrew@lenharth.org>
  • Loading branch information
maerhart and darthscsi committed Nov 19, 2024
1 parent d67b2fd commit ef89957
Show file tree
Hide file tree
Showing 19 changed files with 367 additions and 5 deletions.
16 changes: 11 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ option(CIRCT_BUILD_TOOLS "Build the CIRCT tools. If OFF, just generate build tar
set(CIRCT_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH
"Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')")

option(CIRCT_INCLUDE_TESTS
"Generate build targets for the CIRCT unit tests." ON)

list(APPEND CMAKE_MODULE_PATH "${MLIR_MAIN_SRC_DIR}/cmake/modules")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
include(AddCIRCT)
Expand Down Expand Up @@ -618,16 +621,19 @@ endif()
# Directory setup
#-------------------------------------------------------------------------------

if (CIRCT_INCLUDE_TESTS)
add_definitions(-DCIRCT_INCLUDE_TESTS)
if (CIRCT_GTEST_AVAILABLE)
add_subdirectory(unittests)
endif()
add_subdirectory(test)
add_subdirectory(integration_test)
endif()
add_subdirectory(include/circt)
add_subdirectory(lib)
if(CIRCT_INCLUDE_TOOLS)
add_subdirectory(tools)
endif()
if (CIRCT_GTEST_AVAILABLE)
add_subdirectory(unittests)
endif()
add_subdirectory(test)
add_subdirectory(integration_test)
add_subdirectory(frontends)

option(CIRCT_INCLUDE_DOCS "Generate build targets for the CIRCT docs.")
Expand Down
3 changes: 3 additions & 0 deletions include/circt/Dialect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ add_subdirectory(MSFT)
add_subdirectory(OM)
add_subdirectory(Pipeline)
add_subdirectory(RTG)
if (CIRCT_INCLUDE_TESTS)
add_subdirectory(RTGTest)
endif()
add_subdirectory(Ibis)
add_subdirectory(Seq)
add_subdirectory(Sim)
Expand Down
1 change: 1 addition & 0 deletions include/circt/Dialect/RTGTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(IR)
6 changes: 6 additions & 0 deletions include/circt/Dialect/RTGTest/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
add_circt_dialect(RTGTest rtgtest)

set(LLVM_TARGET_DEFINITIONS RTGTest.td)

add_circt_dialect_doc(RTGTest rtgtest)

26 changes: 26 additions & 0 deletions include/circt/Dialect/RTGTest/IR/RTGTest.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===- RTGTest.td - RTGTest top-level definition -----------*- 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 is the top level file for the RTGTest dialect.
//
//===----------------------------------------------------------------------===//

#ifndef CIRCT_DIALECT_RTGTEST_IR_RTGTEST_TD
#define CIRCT_DIALECT_RTGTEST_IR_RTGTEST_TD

include "mlir/IR/OpBase.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/IR/OpAsmInterface.td"

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

include "circt/Dialect/RTGTest/IR/RTGTestDialect.td"
include "circt/Dialect/RTGTest/IR/RTGTestTypes.td"
include "circt/Dialect/RTGTest/IR/RTGTestOps.td"

#endif // CIRCT_DIALECT_RTGTEST_IR_RTGTEST_TD
24 changes: 24 additions & 0 deletions include/circt/Dialect/RTGTest/IR/RTGTestDialect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//===- RTGTestDialect.h - RTG Test dialect declaration ----------*- 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 RTGTest MLIR dialect. This dialect defines a minimal
// set of operations to use for testing the RTG dialect.
//
//===----------------------------------------------------------------------===//

#ifndef CIRCT_DIALECT_RTGTEST_IR_RTGTESTDIALECT_H
#define CIRCT_DIALECT_RTGTEST_IR_RTGTESTDIALECT_H

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

// Pull in the Dialect definition.
#include "circt/Dialect/RTGTest/IR/RTGTestDialect.h.inc"

#endif // CIRCT_DIALECT_RTGTEST_IR_RTGTESTDIALECT_H
36 changes: 36 additions & 0 deletions include/circt/Dialect/RTGTest/IR/RTGTestDialect.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//===- RTGTestDialect.td - RTG Test dialect definition -----*- 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 RTG Test dialect. This dialect provides a minimal
// set of operations to test the RTG dialect.
//
//===----------------------------------------------------------------------===//

#ifndef CIRCT_DIALECT_RTGTEST_IR_RTGTESTDIALECT_TD
#define CIRCT_DIALECT_RTGTEST_IR_RTGTESTDIALECT_TD

include "mlir/IR/DialectBase.td"

def RTGTestDialect : Dialect {
let name = "rtgtest";

let summary = "types and operations for random test generation testing";
let description = [{
This dialect defines the `rtgtest` dialect, which provides a set of
operation definitions to test the RTG dialect.
}];

let useDefaultTypePrinterParser = 1;
let cppNamespace = "::circt::rtgtest";

let extraClassDeclaration = [{
void registerTypes();
}];
}

#endif // CIRCT_DIALECT_RTGTEST_IR_RTGTESTDIALECT_TD
30 changes: 30 additions & 0 deletions include/circt/Dialect/RTGTest/IR/RTGTestOps.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//===- RTGTestOps.h - Declare RTGTest dialect operations --------*- 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 declares the operation classes for the RTGTest dialect.
//
//===----------------------------------------------------------------------===//

#ifndef CIRCT_DIALECT_RTGTEST_IR_RTGTESTOPS_H
#define CIRCT_DIALECT_RTGTEST_IR_RTGTESTOPS_H

#include "circt/Dialect/RTG/IR/RTGOpInterfaces.h"
#include "circt/Dialect/RTG/IR/RTGOps.h"
#include "circt/Dialect/RTGTest/IR/RTGTestDialect.h"
#include "circt/Dialect/RTGTest/IR/RTGTestTypes.h"
#include "circt/Support/LLVM.h"
#include "mlir/IR/OpImplementation.h"

//===----------------------------------------------------------------------===//
// TableGen generated logic.
//===----------------------------------------------------------------------===//

#define GET_OP_CLASSES
#include "circt/Dialect/RTGTest/IR/RTGTest.h.inc"

#endif // CIRCT_DIALECT_RTGTEST_IR_RTGTESTOPS_H
36 changes: 36 additions & 0 deletions include/circt/Dialect/RTGTest/IR/RTGTestOps.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//===- RTGTestOps.td - RTGTest operations ------------------*- 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 describes the RTGTest MLIR operations.
//
//===----------------------------------------------------------------------===//

include "mlir/IR/CommonAttrConstraints.td"
include "circt/Dialect/RTG/IR/RTGInterfaces.td"

// Base class for the operation in this dialect.
class RTGTestOp<string mnemonic, list<Trait> traits = []> :
Op<RTGTestDialect, mnemonic, traits>;


def CPUDeclOp : RTGTestOp<"cpu_decl", [
Pure,
ConstantLike,
DeclareOpInterfaceMethods<ContextResourceOpInterface>,
]> {
let summary = "declare a CPU";
let description = [{
This operation is used to test the `ContextResourceOpInterface` and passes
taking advantage of it.
}];

let arguments = (ins IndexAttr:$id);
let results = (outs CPUType:$cpu);

let assemblyFormat = "$id attr-dict";
}
21 changes: 21 additions & 0 deletions include/circt/Dialect/RTGTest/IR/RTGTestTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===- RTGTestTypes.h - RTG Test dialect types ------------------*- 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_RTGTEST_IR_RTGTESTTYPES_H
#define CIRCT_DIALECT_RTGTEST_IR_RTGTESTTYPES_H

#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Types.h"

#include "circt/Dialect/RTG/IR/RTGTypeInterfaces.h"

#define GET_TYPEDEF_CLASSES
#include "circt/Dialect/RTGTest/IR/RTGTestTypes.h.inc"

#endif // CIRCT_DIALECT_RTGTEST_IR_RTGTESTTYPES_H
35 changes: 35 additions & 0 deletions include/circt/Dialect/RTGTest/IR/RTGTestTypes.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//===- RTGTestTypes.td - RTGTest types ---------------------*- 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 describes the RTGTest types.
//
//===----------------------------------------------------------------------===//

#ifndef CIRCT_DIALECT_RTGTEST_IR_RTGTESTTYPES_TD
#define CIRCT_DIALECT_RTGTEST_IR_RTGTESTTYPES_TD

include "circt/Dialect/RTGTest/IR/RTGTestDialect.td"
include "circt/Dialect/RTG/IR/RTGInterfaces.td"
include "mlir/IR/AttrTypeBase.td"

class RTGTestTypeDef<string name, list<Trait> traits = []>
: TypeDef<RTGTestDialect, name, traits>;

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
taking context resources as operands (such as `on_context`) and other things
requiring a concrete instance of a `ContextResourceTypeInterface`.
}];

let mnemonic = "cpu";
let assemblyFormat = "";
}

#endif // CIRCT_DIALECT_RTGTEST_IR_RTGTESTTYPES_TD
6 changes: 6 additions & 0 deletions include/circt/InitAllDialects.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
#include "circt/Dialect/OM/OMDialect.h"
#include "circt/Dialect/Pipeline/PipelineDialect.h"
#include "circt/Dialect/RTG/IR/RTGDialect.h"
#ifdef CIRCT_INCLUDE_TESTS
#include "circt/Dialect/RTGTest/IR/RTGTestDialect.h"
#endif
#include "circt/Dialect/SMT/SMTDialect.h"
#include "circt/Dialect/SSP/SSPDialect.h"
#include "circt/Dialect/SV/SVDialect.h"
Expand Down Expand Up @@ -77,6 +80,9 @@ inline void registerAllDialects(mlir::DialectRegistry &registry) {
om::OMDialect,
pipeline::PipelineDialect,
rtg::RTGDialect,
#ifdef CIRCT_INCLUDE_TESTS
rtgtest::RTGTestDialect,
#endif
seq::SeqDialect,
sim::SimDialect,
smt::SMTDialect,
Expand Down
3 changes: 3 additions & 0 deletions lib/Dialect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ add_subdirectory(MSFT)
add_subdirectory(OM)
add_subdirectory(Pipeline)
add_subdirectory(RTG)
if (CIRCT_INCLUDE_TESTS)
add_subdirectory(RTGTest)
endif()
add_subdirectory(Seq)
add_subdirectory(Sim)
add_subdirectory(SMT)
Expand Down
1 change: 1 addition & 0 deletions lib/Dialect/RTGTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(IR)
15 changes: 15 additions & 0 deletions lib/Dialect/RTGTest/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
add_circt_dialect_library(CIRCTRTGTestDialect
RTGTestDialect.cpp
RTGTestOps.cpp
RTGTestTypes.cpp

ADDITIONAL_HEADER_DIRS
${CIRCT_MAIN_INCLUDE_DIR}/circt/Dialect/RTGTest/IR

DEPENDS
MLIRRTGTestIncGen

LINK_LIBS PUBLIC
MLIRIR
CIRCTRTGDialect
)
36 changes: 36 additions & 0 deletions lib/Dialect/RTGTest/IR/RTGTestDialect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//===- RTGTestDialect.cpp - Implement 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
//
//===----------------------------------------------------------------------===//
//
// This file implements the RTGTest dialect.
//
//===----------------------------------------------------------------------===//

#include "circt/Dialect/RTGTest/IR/RTGTestDialect.h"
#include "circt/Dialect/RTGTest/IR/RTGTestOps.h"
#include "circt/Dialect/RTGTest/IR/RTGTestTypes.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/DialectImplementation.h"

using namespace circt;
using namespace rtgtest;

//===----------------------------------------------------------------------===//
// Dialect specification.
//===----------------------------------------------------------------------===//

void RTGTestDialect::initialize() {
registerTypes();
// Register operations.
addOperations<
#define GET_OP_LIST
#include "circt/Dialect/RTGTest/IR/RTGTest.cpp.inc"
>();
}

#include "circt/Dialect/RTGTest/IR/RTGTestDialect.cpp.inc"
32 changes: 32 additions & 0 deletions lib/Dialect/RTGTest/IR/RTGTestOps.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//===- RTGTestOps.cpp - Implement the RTG operations ----------------------===//
//
// 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 implements the RTGTest ops.
//
//===----------------------------------------------------------------------===//

#include "circt/Dialect/RTGTest/IR/RTGTestOps.h"
#include "mlir/IR/Builders.h"
#include "llvm/ADT/APInt.h"

using namespace circt;
using namespace rtgtest;

//===----------------------------------------------------------------------===//
// CPUDeclOp
//===----------------------------------------------------------------------===//

size_t CPUDeclOp::getIdentifier(size_t idx) { return getId().getZExtValue(); }

//===----------------------------------------------------------------------===//
// TableGen generated logic.
//===----------------------------------------------------------------------===//

// Provide the autogenerated implementation guts for the Op classes.
#define GET_OP_CLASSES
#include "circt/Dialect/RTGTest/IR/RTGTest.cpp.inc"
Loading

0 comments on commit ef89957

Please sign in to comment.