CIRCT  19.0.0git
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 
17 #include "mlir/Pass/Pass.h"
18 
19 namespace circt {
20 namespace firrtl {
21 #define GEN_PASS_DEF_LOWERINTRINSICS
22 #include "circt/Dialect/FIRRTL/Passes.h.inc"
23 } // namespace firrtl
24 } // namespace circt
25 
26 using namespace circt;
27 using namespace firrtl;
28 
29 //===----------------------------------------------------------------------===//
30 // Pass Infrastructure
31 //===----------------------------------------------------------------------===//
32 
33 namespace {
34 struct LowerIntrinsicsPass
35  : public circt::firrtl::impl::LowerIntrinsicsBase<LowerIntrinsicsPass> {
36  LogicalResult initialize(MLIRContext *context) override;
37  void runOnOperation() override;
38 
39  std::shared_ptr<IntrinsicLowerings> lowering;
40 };
41 } // namespace
42 
43 /// Initialize the conversions for use during execution.
44 LogicalResult LowerIntrinsicsPass::initialize(MLIRContext *context) {
45  IntrinsicLowerings lowering(context);
46 
47  IntrinsicLoweringInterfaceCollection loweringCollection(context);
48  loweringCollection.populateIntrinsicLowerings(lowering);
49 
50  this->lowering = std::make_shared<IntrinsicLowerings>(std::move(lowering));
51  return success();
52 }
53 
54 // This is the main entrypoint for the lowering pass.
55 void LowerIntrinsicsPass::runOnOperation() {
56  auto result = lowering->lower(getOperation());
57  if (failed(result))
58  return signalPassFailure();
59 
60  numConverted += *result;
61 
62  if (*result == 0)
63  markAllAnalysesPreserved();
64 }
65 
66 /// This is the pass constructor.
67 std::unique_ptr<mlir::Pass> circt::firrtl::createLowerIntrinsicsPass() {
68  return std::make_unique<LowerIntrinsicsPass>();
69 }
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.
Definition: DebugAnalysis.h:21