-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
19 changed files
with
367 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_subdirectory(IR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_subdirectory(IR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Oops, something went wrong.