CIRCT  20.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 
16 #include "mlir/Pass/Pass.h"
17 
18 namespace circt {
19 namespace firrtl {
20 #define GEN_PASS_DEF_LOWERINTRINSICS
21 #include "circt/Dialect/FIRRTL/Passes.h.inc"
22 } // namespace firrtl
23 } // namespace circt
24 
25 using namespace circt;
26 using namespace firrtl;
27 
28 //===----------------------------------------------------------------------===//
29 // Pass Infrastructure
30 //===----------------------------------------------------------------------===//
31 
32 namespace {
33 struct 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.
43 LogicalResult 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.
54 void 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.
66 std::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.
Definition: DebugAnalysis.h:21