34 delete unwrap(passManager);
48 bool printBeforeAll,
bool printAfterAll,
49 bool printModuleScope,
50 bool printAfterOnlyOnChange,
51 bool printAfterOnlyOnFailure,
52 MlirOpPrintingFlags flags,
54 auto shouldPrintBeforePass = [printBeforeAll](
Pass *,
Operation *) {
55 return printBeforeAll;
57 auto shouldPrintAfterPass = [printAfterAll](
Pass *,
Operation *) {
60 if (
unwrap(treePrintingPath).empty())
62 ->enableIRPrinting(shouldPrintBeforePass, shouldPrintAfterPass,
63 printModuleScope, printAfterOnlyOnChange,
64 printAfterOnlyOnFailure, llvm::errs(),
68 ->enableIRPrintingToFileTree(shouldPrintBeforePass, shouldPrintAfterPass,
69 printModuleScope, printAfterOnlyOnChange,
70 printAfterOnlyOnFailure,
75 unwrap(passManager)->enableVerifier(enable);
89 unwrap(passManager)->addPass(std::unique_ptr<Pass>(
unwrap(pass)));
94 unwrap(passManager)->addPass(std::unique_ptr<Pass>(
unwrap(pass)));
109 unwrap(passManager)->printAsTextualPipeline(stream);
119 *
unwrap(passManager) = std::move(*pm);
138 StringRef description, std::optional<StringRef> opName,
141 :
Pass(passID, opName), id(passID), name(name), argument(argument),
142 description(description), dependentDialects(dependentDialects),
143 callbacks(callbacks), userData(userData) {
149 StringRef
getName()
const override {
return name; }
154 MlirDialectRegistry cRegistry =
wrap(®istry);
169 if (std::optional<StringRef> specifiedOpName =
getOpName())
179 void *clonedUserData = callbacks.
clone(userData);
180 return std::make_unique<ExternalPass>(
id, name, argument, description,
182 callbacks, clonedUserData);
188 std::string argument;
189 std::string description;
190 std::vector<MlirDialectHandle> dependentDialects;
199 intptr_t nDependentDialects,
205 opName.
length > 0 ? std::optional<StringRef>(
unwrap(opName))
207 {dependentDialects,
static_cast<size_t>(nDependentDialects)}, callbacks,
212 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)
Creates an external MlirPass that calls the supplied callbacks using the supplied 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.
MlirOpPassManager mlirPassManagerGetNestedUnder(MlirPassManager passManager, MlirStringRef operationName)
Nest an OpPassManager under the top-level PassManager, the nested passmanager will only run on operat...
void mlirPassManagerDestroy(MlirPassManager passManager)
Destroy the provided PassManager.
MlirLogicalResult mlirParsePassPipeline(MlirOpPassManager passManager, MlirStringRef pipeline, MlirStringCallback callback, void *userData)
Parse a textual MLIR pass pipeline and assign it to the provided OpPassManager.
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)
This signals that the pass has failed.
void mlirPrintPassPipeline(MlirOpPassManager passManager, MlirStringCallback callback, void *userData)
Print a textual MLIR pass pipeline by sending chunks of the string representation and forwarding user...
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.
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.
std::unique_ptr< Pass > clonePass() const override
Create a copy of this pass, ignoring statistics and options.
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,...
StringRef getStringRef() const
Return the name of this operation. This always succeeds.
Operation is the basic unit of execution within MLIR.
The main pass manager and pipeline builder.
The abstract base pass class.
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...
Operation * getOperation()
Return the current operation being transformed.
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...
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
MlirDiagnostic wrap(mlir::Diagnostic &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.
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.
Structure of external MlirPass callbacks.
void(* run)(MlirOperation op, MlirExternalPass pass, void *userData)
This callback is called when the pass is run.
void *(* clone)(void *userData)
This callback is called when the pass is cloned.
MlirLogicalResult(* initialize)(MlirContext ctx, void *userData)
This callback is optional.
void(* destruct)(void *userData)
This callback is called when the pass is destroyed This is analogous to a C++ pass destructor.
void(* construct)(void *userData)
This callback is called from the pass is created.
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.