mirror of https://github.com/llvm/circt.git
Introduce a new -simple-canonicalizer pass, which is currently just a clone of Canonicalize.
Canonicalize does a bunch of stuff that is slow and not useful for either the RTL or the firrtl dialects, because it is heavily focused on CFG-like things. We'll trim some of this fat out in our local clone, as the main MLIR canonicalizer is carrying some significant compatibility issues that make it difficult to improve.
This commit is contained in:
parent
560b53ea0b
commit
44dcc358cd
|
@ -1,2 +1,3 @@
|
|||
add_subdirectory(Conversion)
|
||||
add_subdirectory(Dialect)
|
||||
add_subdirectory(Transforms)
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "circt/Dialect/LLHD/Transforms/Passes.h"
|
||||
#include "circt/Dialect/SV/SVPasses.h"
|
||||
#include "circt/Dialect/Seq/SeqDialect.h"
|
||||
#include "circt/Transforms/Passes.h"
|
||||
|
||||
namespace circt {
|
||||
|
||||
|
@ -33,6 +34,7 @@ inline void registerAllPasses() {
|
|||
llhd::initLLHDTransformationPasses();
|
||||
seq::registerSeqPasses();
|
||||
sv::registerPasses();
|
||||
circt::registerPasses();
|
||||
}
|
||||
|
||||
} // namespace circt
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
set(LLVM_TARGET_DEFINITIONS Passes.td)
|
||||
mlir_tablegen(Passes.h.inc -gen-pass-decls)
|
||||
add_public_tablegen_target(CIRCTTransformsIncGen)
|
||||
add_circt_doc(Passes -gen-pass-doc Passes ./)
|
|
@ -0,0 +1,37 @@
|
|||
//===- Passes.h - Generic CIRCT Passes --------------------------*- 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. These
|
||||
// passes are dialect independent.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef CIRCT_TRANSFORMS_PASSES_H
|
||||
#define CIRCT_TRANSFORMS_PASSES_H
|
||||
|
||||
#include "mlir/Pass/Pass.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace mlir {
|
||||
class ModuleOp;
|
||||
template <typename T>
|
||||
class OperationPass;
|
||||
} // namespace mlir
|
||||
|
||||
namespace circt {
|
||||
|
||||
std::unique_ptr<mlir::Pass> createSimpleCanonicalizerPass();
|
||||
|
||||
/// Generate the code for registering passes.
|
||||
#define GEN_PASS_REGISTRATION
|
||||
#include "circt/Transforms/Passes.h.inc"
|
||||
|
||||
} // namespace circt
|
||||
|
||||
#endif // CIRCT_TRANSFORMS_PASSES_H
|
|
@ -0,0 +1,28 @@
|
|||
//===-- SVPasses.td - SV 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 contains definitions for passes that work on the SV dialect.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef CIRCT_DIALECT_SV_SVPASSES
|
||||
#define CIRCT_DIALECT_SV_SVPASSES
|
||||
|
||||
include "mlir/Pass/PassBase.td"
|
||||
|
||||
def SimpleCanonicalizer : Pass<"simple-canonicalizer"> {
|
||||
let summary = "Run operation canonicalization patterns";
|
||||
let description = [{
|
||||
This is a lighter-weight version of the standard MLIR canonicalization
|
||||
pass that doesn't do CFG optimizations and has other differences.
|
||||
}];
|
||||
|
||||
let constructor = "circt::createSimpleCanonicalizerPass()";
|
||||
}
|
||||
|
||||
#endif // CIRCT_DIALECT_SV_SVPASSES
|
|
@ -7,4 +7,5 @@ add_subdirectory(CAPI)
|
|||
add_subdirectory(Conversion)
|
||||
add_subdirectory(Dialect)
|
||||
add_subdirectory(Support)
|
||||
add_subdirectory(Transforms)
|
||||
add_subdirectory(Translation)
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
add_circt_library(CIRCTTransforms
|
||||
SimpleCanonicalizer.cpp
|
||||
|
||||
DEPENDS
|
||||
CIRCTTransformsIncGen
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRIR
|
||||
MLIRPass
|
||||
)
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
//===- SimpleCanonicalizer.cpp - A simplified Canonicalizer pass ----------===//
|
||||
//
|
||||
// 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 implements a simplified canonicalizer pass that doesn't do CFG
|
||||
// optimizations and other things that aren't helpful for many hardware IRs.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "circt/Transforms/Passes.h"
|
||||
|
||||
#include "circt/Support/LLVM.h"
|
||||
#include "mlir/Pass/Pass.h"
|
||||
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
|
||||
|
||||
using namespace circt;
|
||||
|
||||
#define GEN_PASS_CLASSES
|
||||
#include "circt/Transforms/Passes.h.inc"
|
||||
|
||||
namespace {
|
||||
/// Canonicalize operations in nested regions.
|
||||
struct SimpleCanonicalizer
|
||||
: public SimpleCanonicalizerBase<SimpleCanonicalizer> {
|
||||
/// Initialize the canonicalizer by building the set of patterns used during
|
||||
/// execution.
|
||||
LogicalResult initialize(MLIRContext *context) override {
|
||||
RewritePatternSet owningPatterns(context);
|
||||
for (auto *op : context->getRegisteredOperations())
|
||||
op->getCanonicalizationPatterns(owningPatterns, context);
|
||||
patterns = std::move(owningPatterns);
|
||||
return success();
|
||||
}
|
||||
void runOnOperation() override {
|
||||
(void)mlir::applyPatternsAndFoldGreedily(getOperation()->getRegions(),
|
||||
patterns, 10);
|
||||
}
|
||||
|
||||
mlir::FrozenRewritePatternSet patterns;
|
||||
};
|
||||
} // end anonymous namespace
|
||||
|
||||
/// Create a Canonicalizer pass.
|
||||
std::unique_ptr<Pass> circt::createSimpleCanonicalizerPass() {
|
||||
return std::make_unique<SimpleCanonicalizer>();
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
// RUN: circt-opt -canonicalize %s | FileCheck %s
|
||||
// RUN: circt-opt -simple-canonicalizer %s | FileCheck %s
|
||||
|
||||
firrtl.circuit "And" {
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ target_link_libraries(circt-opt
|
|||
CIRCTStaticLogicOps
|
||||
CIRCTSV
|
||||
CIRCTSVTransforms
|
||||
CIRCTTransforms
|
||||
|
||||
MLIRParser
|
||||
MLIRSupport
|
||||
|
|
Loading…
Reference in New Issue