Skip to content

Commit

Permalink
Polygeist canonicalize
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanradanov committed Sep 28, 2023
1 parent e584e5d commit baf893e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/polygeist/Passes/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def PolygeistCanonicalize : Pass<"canonicalize-polygeist"> {
"arith::ArithDialect",
"cf::ControlFlowDialect",
"scf::SCFDialect",
"polygeist::PolygeistDialect",
];
let options = [
Option<"topDownProcessingEnabled", "top-down", "bool",
Expand Down
9 changes: 5 additions & 4 deletions lib/polygeist/Passes/PolygeistCanonicalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/Dialect/SCF/Transforms/Passes.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include "polygeist/Dialect.h"
#include "polygeist/Ops.h"
#include "polygeist/Passes/Passes.h"

Expand Down Expand Up @@ -57,16 +58,16 @@ struct PolygeistCanonicalizePass
config.maxIterations = maxIterations;
config.maxNumRewrites = maxNumRewrites;

// The polygeist dialect is marked as a dependency to this pass and that
// causes all of the custom canonicalizers (which are not neccessarily only
// for polygeist ops) to get imported

RewritePatternSet owningPatterns(context);
for (auto *dialect : context->getLoadedDialects())
dialect->getCanonicalizationPatterns(owningPatterns);
for (RegisteredOperationName op : context->getRegisteredOperations())
op.getCanonicalizationPatterns(owningPatterns, context);

// A hack to add custom canonicalization patterns for non-polygeist ops
polygeist::TypeAlignOp::getCanonicalizationPatterns(owningPatterns,
context);

patterns = std::make_shared<FrozenRewritePatternSet>(
std::move(owningPatterns), disabledPatterns, enabledPatterns);
return success();
Expand Down

0 comments on commit baf893e

Please sign in to comment.