-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RTG][RTGTest] Add CAPI and a basic lowering pipeline
- Loading branch information
Showing
20 changed files
with
771 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//===- 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); | ||
MLIR_CAPI_EXPORTED void registerRTGPasses(void); | ||
|
||
//===----------------------------------------------------------------------===// | ||
// 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 |
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,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 |
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,83 @@ | ||
//===-- 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(void); | ||
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 | ||
circtRtgToolOptionsUnsetSeed(CirctRtgToolOptions options); | ||
|
||
MLIR_CAPI_EXPORTED void | ||
circtRtgToolOptionsSetVerifyPasses(CirctRtgToolOptions options, bool enable); | ||
|
||
MLIR_CAPI_EXPORTED void | ||
circtRtgToolOptionsSetVerbosePassExecution(CirctRtgToolOptions options, | ||
bool enable); | ||
|
||
MLIR_CAPI_EXPORTED void | ||
circtRtgToolOptionsSetDebugMode(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 |
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,107 @@ | ||
//===- 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" | ||
#include <optional> | ||
|
||
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 }; | ||
|
||
void setOutputFormat(OutputFormat format) { outputFormat = format; } | ||
OutputFormat getOutputFormat() const { return outputFormat; } | ||
|
||
RtgToolOptions &setSeed(unsigned seed) { | ||
this->seed = seed; | ||
return *this; | ||
} | ||
RtgToolOptions &unsetSeed() { | ||
this->seed = std::nullopt; | ||
return *this; | ||
} | ||
bool hasSeed() const { return seed != std::nullopt; } | ||
unsigned getSeed() const { | ||
assert(hasSeed()); | ||
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 &setDebugMode(bool enable) { | ||
debugMode = enable; | ||
return *this; | ||
} | ||
bool getDebugMode() const { return debugMode; } | ||
|
||
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; | ||
std::optional<unsigned> seed = std::nullopt; | ||
bool verifyPasses = true; | ||
bool verbosePassExecution = false; | ||
bool debugMode = 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 |
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
Oops, something went wrong.