16#include "llvm/Support/ErrorHandling.h"
35 delete unwrap(passManager);
49 bool printBeforeAll,
bool printAfterAll,
50 bool printModuleScope,
51 bool printAfterOnlyOnChange,
52 bool printAfterOnlyOnFailure,
53 MlirOpPrintingFlags flags,
55 auto shouldPrintBeforePass = [printBeforeAll](
Pass *,
Operation *) {
56 return printBeforeAll;
58 auto shouldPrintAfterPass = [printAfterAll](
Pass *,
Operation *) {
61 if (
unwrap(treePrintingPath).empty())
63 ->enableIRPrinting(shouldPrintBeforePass, shouldPrintAfterPass,
64 printModuleScope, printAfterOnlyOnChange,
65 printAfterOnlyOnFailure, llvm::errs(),
69 ->enableIRPrintingToFileTree(shouldPrintBeforePass, shouldPrintAfterPass,
70 printModuleScope, printAfterOnlyOnChange,
71 printAfterOnlyOnFailure,
76 unwrap(passManager)->enableVerifier(enable);
80 unwrap(passManager)->enableTiming();
86 switch (displayMode) {
94 unwrap(passManager)->enableStatistics(mode);
108 unwrap(passManager)->addPass(std::unique_ptr<Pass>(
unwrap(pass)));
113 unwrap(passManager)->addPass(std::unique_ptr<Pass>(
unwrap(pass)));
128 unwrap(passManager)->printAsTextualPipeline(stream);
138 *
unwrap(passManager) = std::move(*pm);
157 StringRef description, std::optional<StringRef> opName,
159 MlirExternalPassCallbacks callbacks,
void *userData)
160 :
Pass(passID, opName), id(passID), name(name), argument(argument),
161 description(description), dependentDialects(dependentDialects),
162 callbacks(callbacks), userData(userData) {
163 if (callbacks.construct)
164 callbacks.construct(userData);
168 if (callbacks.destruct)
169 callbacks.destruct(userData);
172 StringRef
getName()
const override {
return name; }
177 MlirDialectRegistry cRegistry =
wrap(®istry);
186 if (callbacks.initialize)
187 return unwrap(callbacks.initialize(
wrap(ctx), userData));
192 if (std::optional<StringRef> specifiedOpName =
getOpName())
193 return opName.getStringRef() == specifiedOpName;
202 void *clonedUserData = callbacks.clone(userData);
203 return std::make_unique<ExternalPass>(
id, name, argument, description,
205 callbacks, clonedUserData);
211 std::string argument;
212 std::string description;
213 std::vector<MlirDialectHandle> dependentDialects;
214 MlirExternalPassCallbacks callbacks;
222 intptr_t nDependentDialects,
224 MlirExternalPassCallbacks callbacks,
228 opName.
length > 0 ? std::optional<StringRef>(
unwrap(opName))
230 {dependentDialects,
static_cast<size_t>(nDependentDialects)}, callbacks,
235 unwrap(pass)->signalPassFailure();
MlirOpPassManager mlirOpPassManagerGetNestedUnder(MlirOpPassManager passManager, MlirStringRef operationName)
Nest an OpPassManager under the provided OpPassManager, the nested passmanager will only run on opera...
MlirPass mlirCreateExternalPass(MlirTypeID passID, MlirStringRef name, MlirStringRef argument, MlirStringRef description, MlirStringRef opName, intptr_t nDependentDialects, MlirDialectHandle *dependentDialects, MlirExternalPassCallbacks callbacks, void *userData)
MlirPassManager mlirPassManagerCreate(MlirContext ctx)
Create a new top-level PassManager with the default anchor.
void mlirPassManagerEnableVerifier(MlirPassManager passManager, bool enable)
Enable / disable verify-each.
void mlirPassManagerEnableStatistics(MlirPassManager passManager, MlirPassDisplayMode displayMode)
Enable pass statistics.
MlirOpPassManager mlirPassManagerGetNestedUnder(MlirPassManager passManager, MlirStringRef operationName)
Nest an OpPassManager under the top-level PassManager, the nested passmanager will only run on operat...
void mlirPassManagerEnableTiming(MlirPassManager passManager)
Enable pass timing.
void mlirPassManagerDestroy(MlirPassManager passManager)
Destroy the provided PassManager.
MlirLogicalResult mlirParsePassPipeline(MlirOpPassManager passManager, MlirStringRef pipeline, MlirStringCallback callback, void *userData)
MlirOpPassManager mlirPassManagerGetAsOpPassManager(MlirPassManager passManager)
Cast a top-level PassManager to a generic OpPassManager.
MlirLogicalResult mlirPassManagerRunOnOp(MlirPassManager passManager, MlirOperation op)
Run the provided passManager on the given op.
void mlirOpPassManagerAddOwnedPass(MlirOpPassManager passManager, MlirPass pass)
Add a pass and transfer ownership to the provided mlirOpPassManager.
void mlirExternalPassSignalFailure(MlirExternalPass pass)
Print a textual MLIR pass pipeline by sending chunks of the string representation and forwarding user...
void mlirPrintPassPipeline(MlirOpPassManager passManager, MlirStringCallback callback, void *userData)
void mlirPassManagerAddOwnedPass(MlirPassManager passManager, MlirPass pass)
Add a pass and transfer ownership to the provided top-level mlirPassManager.
MlirPassManager mlirPassManagerCreateOnOperation(MlirContext ctx, MlirStringRef anchorOp)
Create a new top-level PassManager anchored on anchorOp.
MlirLogicalResult mlirOpPassManagerAddPipeline(MlirOpPassManager passManager, MlirStringRef pipelineElements, MlirStringCallback callback, void *userData)
Parse a sequence of textual MLIR pass pipeline elements and add them to the provided OpPassManager.
void mlirPassManagerEnableIRPrinting(MlirPassManager passManager, bool printBeforeAll, bool printAfterAll, bool printModuleScope, bool printAfterOnlyOnChange, bool printAfterOnlyOnFailure, MlirOpPrintingFlags flags, MlirStringRef treePrintingPath)
Enable IR printing.
#define DEFINE_C_API_PTR_METHODS(name, cpptype)
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
This pass class wraps external passes defined in other languages using the MLIR C-interface.
std::unique_ptr< Pass > clonePass() const override
Create a copy of this pass, ignoring statistics and options.
StringRef getArgument() const override
Return the command line argument used when registering this pass.
ExternalPass(TypeID passID, StringRef name, StringRef argument, StringRef description, std::optional< StringRef > opName, ArrayRef< MlirDialectHandle > dependentDialects, MlirExternalPassCallbacks callbacks, void *userData)
StringRef getDescription() const override
Return the command line description used when registering this pass.
bool canScheduleOn(RegisteredOperationName opName) const override
Indicate if the current pass can be scheduled on the given operation type.
void runOnOperation() override
The polymorphic API that runs the pass over the currently held operation.
StringRef getName() const override
Returns the derived pass name.
LogicalResult initialize(MLIRContext *ctx) override
Initialize any complex state necessary for running this pass.
void getDependentDialects(DialectRegistry ®istry) const override
Register dependent dialects for the current pass.
MLIRContext is the top-level object for a collection of MLIR operations.
This class represents a pass manager that runs passes on either a specific operation type,...
Operation is the basic unit of execution within MLIR.
The main pass manager and pipeline builder.
The abstract base pass class.
Pass(TypeID passID, std::optional< StringRef > opName=std::nullopt)
Operation * getOperation()
Return the current operation being transformed.
std::optional< StringRef > getOpName() const
Returns the name of the operation that this pass operates on, or std::nullopt if this is a generic Op...
void signalPassFailure()
Signal that some invariant was broken when running.
This is a "type erased" representation of a registered operation.
This class provides an efficient unique identifier for a specific C++ type.
A simple raw ostream subclass that forwards write_impl calls to the user-supplied callback together w...
MlirPassDisplayMode
Enumerated type of pass display modes.
@ MLIR_PASS_DISPLAY_MODE_LIST
@ MLIR_PASS_DISPLAY_MODE_PIPELINE
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
MLIR_CAPI_EXPORTED void mlirDialectHandleInsertDialect(MlirDialectHandle, MlirDialectRegistry)
Inserts the dialect associated with the provided dialect handle into the provided dialect registry.
void(* MlirStringCallback)(MlirStringRef, void *)
A callback for returning string references.
Include the generated interface declarations.
PassDisplayMode
An enum describing the different display modes for the information within the pass manager.
LogicalResult parsePassPipeline(StringRef pipeline, OpPassManager &pm, raw_ostream &errorStream=llvm::errs())
Parse the textual representation of a pass pipeline, adding the result to 'pm' on success.
A logical result value, essentially a boolean with named states.
A pointer to a sized fragment of a string, not necessarily null-terminated.
size_t length
Length of the fragment.