Skip to content

Commit

Permalink
[RTG] Add ElaborationPass
Browse files Browse the repository at this point in the history
  • Loading branch information
maerhart committed Nov 22, 2024
1 parent ced48ea commit 36dfd4c
Show file tree
Hide file tree
Showing 10 changed files with 781 additions and 0 deletions.
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 "Dialects/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)
49 changes: 49 additions & 0 deletions include/circt/Dialect/RTG/Transforms/RTGPasses.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//===- 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_RTGPASSES_H
#define CIRCT_DIALECT_RTG_RTGPASSES_H

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

namespace circt {
namespace rtg {

/// Options for the ElaborationPass
struct ElaborationOptions {
/// The seed for any RNG constructs used in the pass. If `std::nullopt` is
/// passed, no seed is used and thus the IR after each invocation of this pass
/// will be different non-deterministically. However, if a nubmer is provided,
/// the pass is guaranteed to produce the same IR every time.
std::optional<unsigned> seed;

/// When in debug mode the pass queries the values that would otherwise be
/// provided by the RNG from an attribute attached to the operation called
/// 'rtg.elaboration'.
bool debugMode = false;
};

std::unique_ptr<mlir::Pass> createElaborationPass();
std::unique_ptr<mlir::Pass>
createElaborationPass(const ElaborationOptions &options);

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

} // namespace rtg
} // namespace circt

#endif // CIRCT_DIALECT_RTG_RTGPASSES_H
32 changes: 32 additions & 0 deletions include/circt/Dialect/RTG/Transforms/RTGPasses.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//===-- 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_RTGPASSES_TD
#define CIRCT_DIALECT_RTG_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.
}];

// Define a custom constructor to have more control over the pass options
// (e.g., std::optional options are not handled very well).
let constructor = "::circt::rtg::createElaborationPass()";
}

#endif // CIRCT_DIALECT_RTG_RTGPASSES_TD
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();
ibis::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)
14 changes: 14 additions & 0 deletions lib/Dialect/RTG/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
add_circt_dialect_library(CIRCTRTGTransforms
ElaborationPass.cpp

DEPENDS
CIRCTRTGTransformsIncGen

LINK_COMPONENTS
Support

LINK_LIBS PRIVATE
CIRCTRTGDialect
MLIRIR
)

Loading

0 comments on commit 36dfd4c

Please sign in to comment.