CIRCT 20.0.0git
Loading...
Searching...
No Matches
LowerIntrinsics.cpp
Go to the documentation of this file.
1//===- LowerIntrinsics.cpp - Lower Intrinsics -------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the LowerIntrinsics pass. This pass processes FIRRTL
10// generic intrinsic operations and rewrites to their implementation.
11//
12//===----------------------------------------------------------------------===//
13
16#include "mlir/Pass/Pass.h"
17
18namespace circt {
19namespace firrtl {
20#define GEN_PASS_DEF_LOWERINTRINSICS
21#include "circt/Dialect/FIRRTL/Passes.h.inc"
22} // namespace firrtl
23} // namespace circt
24
25using namespace circt;
26using namespace firrtl;
27
28//===----------------------------------------------------------------------===//
29// Pass Infrastructure
30//===----------------------------------------------------------------------===//
31
32namespace {
33struct LowerIntrinsicsPass
34 : public circt::firrtl::impl::LowerIntrinsicsBase<LowerIntrinsicsPass> {
35 LogicalResult initialize(MLIRContext *context) override;
36 void runOnOperation() override;
37
38 std::shared_ptr<IntrinsicLowerings> lowering;
39};
40} // namespace
41
42/// Initialize the conversions for use during execution.
43LogicalResult LowerIntrinsicsPass::initialize(MLIRContext *context) {
44 IntrinsicLowerings lowering(context);
45
46 IntrinsicLoweringInterfaceCollection loweringCollection(context);
47 loweringCollection.populateIntrinsicLowerings(lowering);
48
49 this->lowering = std::make_shared<IntrinsicLowerings>(std::move(lowering));
50 return success();
51}
52
53// This is the main entrypoint for the lowering pass.
54void LowerIntrinsicsPass::runOnOperation() {
55 auto result = lowering->lower(getOperation());
56 if (failed(result))
57 return signalPassFailure();
58
59 numConverted += *result;
60
61 if (*result == 0)
62 markAllAnalysesPreserved();
63}
64
65/// This is the pass constructor.
66std::unique_ptr<mlir::Pass> circt::firrtl::createLowerIntrinsicsPass() {
67 return std::make_unique<LowerIntrinsicsPass>();
68}
Lowering helper which collects all intrinsic converters.
std::unique_ptr< mlir::Pass > createLowerIntrinsicsPass()
This is the pass constructor.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.