Skip to content

Commit

Permalink
[RTG] Add ElaborationPass (#7876)
Browse files Browse the repository at this point in the history
  • Loading branch information
maerhart authored Dec 9, 2024
1 parent cd02a73 commit e6e5dca
Show file tree
Hide file tree
Showing 13 changed files with 822 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/Dialects/RTG.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,7 @@ companion dialect to define any backends.
## Types

[include "Dialects/RTGTypes.md"]

## Passes

[include "RTGPasses.md"]
1 change: 1 addition & 0 deletions include/circt/Dialect/RTG/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(IR)
add_subdirectory(Transforms)
6 changes: 6 additions & 0 deletions include/circt/Dialect/RTG/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set(LLVM_TARGET_DEFINITIONS RTGPasses.td)
mlir_tablegen(RTGPasses.h.inc -gen-pass-decls)
add_public_tablegen_target(CIRCTRTGTransformsIncGen)

# Generate Pass documentation.
add_circt_doc(RTGPasses RTGPasses -gen-pass-doc)
31 changes: 31 additions & 0 deletions include/circt/Dialect/RTG/Transforms/RTGPasses.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//===- RTGPasses.h - RTG pass entry points ----------------------*- 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 prototypes that expose pass constructors.
//
//===----------------------------------------------------------------------===//

#ifndef CIRCT_DIALECT_RTG_TRANSFORMS_RTGPASSES_H
#define CIRCT_DIALECT_RTG_TRANSFORMS_RTGPASSES_H

#include "mlir/Pass/Pass.h"
#include <memory>

namespace circt {
namespace rtg {

/// Generate the code for registering passes.
#define GEN_PASS_REGISTRATION
#define GEN_PASS_DECL
#include "circt/Dialect/RTG/Transforms/RTGPasses.h.inc"
#undef GEN_PASS_REGISTRATION

} // namespace rtg
} // namespace circt

#endif // CIRCT_DIALECT_RTG_TRANSFORMS_RTGPASSES_H
35 changes: 35 additions & 0 deletions include/circt/Dialect/RTG/Transforms/RTGPasses.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//===-- RTGPasses.td - RTG pass definition file ------------*- 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 passes that operate on the RTG dialect.
//
//===----------------------------------------------------------------------===//

#ifndef CIRCT_DIALECT_RTG_TRANSFORMS_RTGPASSES_TD
#define CIRCT_DIALECT_RTG_TRANSFORMS_RTGPASSES_TD

include "mlir/Pass/PassBase.td"

def ElaborationPass : Pass<"rtg-elaborate", "mlir::ModuleOp"> {
let summary = "elaborate the randomization parts";
let description = [{
This pass interprets most RTG operations to perform the represented
randomization and in the process get rid of those operations. This means,
after this pass the IR does not contain any random constructs within tests
anymore.
}];

let options = [
Option<"seed", "seed", "unsigned", /*default=*/"",
"The seed for any RNG constructs used in the pass.">,
];

let dependentDialects = ["mlir::arith::ArithDialect"];
}

#endif // CIRCT_DIALECT_RTG_TRANSFORMS_RTGPASSES_TD
10 changes: 10 additions & 0 deletions include/circt/Dialect/RTGTest/IR/RTGTestOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,13 @@ def CPUDeclOp : RTGTestOp<"cpu_decl", [

let assemblyFormat = "$id attr-dict";
}

def ConstantTestOp : RTGTestOp<"constant_test", [
Pure, ConstantLike,
]> {
let arguments = (ins AnyAttr:$value);
let results = (outs AnyType:$result);

let assemblyFormat = "type($result) attr-dict";
let hasFolder = 1;
}
2 changes: 2 additions & 0 deletions include/circt/InitAllPasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "circt/Dialect/Moore/MoorePasses.h"
#include "circt/Dialect/OM/OMPasses.h"
#include "circt/Dialect/Pipeline/PipelinePasses.h"
#include "circt/Dialect/RTG/Transforms/RTGPasses.h"
#include "circt/Dialect/SSP/SSPPasses.h"
#include "circt/Dialect/SV/SVPasses.h"
#include "circt/Dialect/Seq/SeqPasses.h"
Expand Down Expand Up @@ -73,6 +74,7 @@ inline void registerAllPasses() {
sv::registerPasses();
handshake::registerPasses();
kanagawa::registerPasses();
rtg::registerPasses();
hw::registerPasses();
pipeline::registerPasses();
sim::registerPasses();
Expand Down
1 change: 1 addition & 0 deletions lib/Dialect/RTG/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(IR)
add_subdirectory(Transforms)
16 changes: 16 additions & 0 deletions lib/Dialect/RTG/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
add_circt_dialect_library(CIRCTRTGTransforms
ElaborationPass.cpp

DEPENDS
CIRCTRTGTransformsIncGen

LINK_COMPONENTS
Support

LINK_LIBS PRIVATE
CIRCTRTGDialect
MLIRArithDialect
MLIRIR
MLIRPass
)

Loading

0 comments on commit e6e5dca

Please sign in to comment.