CIRCT 23.0.0git
Loading...
Searching...
No Matches
pipelines.cpp
Go to the documentation of this file.
1//===- pipelines.cpp - Arcilator lowering pipelines -----------------------===//
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 implements the 'arcilator' lowering pipelines.
10//
11//===----------------------------------------------------------------------===//
12
14
28#include "mlir/Transforms/Passes.h"
29
30using namespace mlir;
31using namespace circt;
32using namespace arc;
33
35 OpPassManager &pm, const ArcPreprocessingOptions &options) {
36 pm.addPass(arc::createResolveXMRRef());
37 pm.addPass(om::createStripOMPass());
38 pm.addPass(emit::createStripEmitPass());
39 pm.addPass(createLowerFirMemPass());
40 pm.addPass(createLowerVerifSimulationsPass());
41 {
42 arc::AddTapsOptions opts;
43 opts.tapPorts = options.observePorts;
44 opts.tapWires = options.observeWires;
45 opts.tapNamedValues = options.observeNamedValues;
46 pm.addPass(arc::createAddTaps(opts));
47 }
48 pm.addPass(arc::createStripSV({options.asyncResetsAsSync}));
49 {
50 arc::InferMemoriesOptions opts;
51 opts.tapPorts = options.observePorts;
52 opts.tapMemories = options.observeMemories;
53 pm.addPass(arc::createInferMemories(opts));
54 }
55 pm.addPass(sim::createLowerDPIFunc());
56 pm.addPass(createCSEPass());
57 pm.addPass(arc::createArcCanonicalizer());
58}
59
60void circt::populateArcConversionPipeline(OpPassManager &pm,
61 const ArcConversionOptions &options) {
62 {
63 ConvertToArcsPassOptions opts;
64 opts.tapRegisters = options.observeRegisters;
65 pm.addPass(createConvertToArcsPass(opts));
66 }
67 if (options.shouldDedup)
68 pm.addPass(arc::createDedup());
69 pm.addPass(hw::createFlattenModules());
70 pm.addPass(createCSEPass());
71 pm.addPass(arc::createArcCanonicalizer());
72}
73
75 OpPassManager &pm, const ArcOptimizationOptions &options) {
76 // Perform arc-level optimizations that are not specific to software
77 // simulation.
78 pm.addPass(arc::createSplitLoops());
79 if (options.shouldDedup)
80 pm.addPass(arc::createDedup());
81 {
82 arc::InferStatePropertiesOptions opts;
83 opts.detectEnables = options.shouldDetectEnables;
84 opts.detectResets = options.shouldDetectResets;
85 pm.addPass(arc::createInferStateProperties(opts));
86 }
87 pm.addPass(createCSEPass());
88 pm.addPass(arc::createArcCanonicalizer());
89 pm.addNestedPass<hw::HWModuleOp>(arc::createMergeTaps());
90 if (options.shouldMakeLUTs)
91 pm.addPass(arc::createMakeTables());
92 pm.addPass(createCSEPass());
93 pm.addPass(arc::createArcCanonicalizer());
94
95 // Now some arguments may be unused because reset conditions are not passed as
96 // inputs anymore pm.addPass(arc::createRemoveUnusedArcArguments());
97 // Because we replace a lot of StateOp inputs with constants in the enable
98 // patterns we may be able to sink a lot of them
99 // TODO: maybe merge RemoveUnusedArcArguments with SinkInputs?
100 // pm.addPass(arc::createSinkInputs());
101 // pm.addPass(createCSEPass());
102 // pm.addPass(createSimpleCanonicalizerPass());
103 // Removing some muxes etc. may lead to additional dedup opportunities
104 // if (options.shouldDedup)
105 // pm.addPass(arc::createDedup());
106}
107
109 OpPassManager &pm, const ArcStateLoweringOptions &options) {
110 pm.addPass(arc::createLowerStatePass());
111
112 // TODO: LowerClocksToFuncsPass might not properly consider scf.if operations
113 // (or nested regions in general) and thus errors out when muxes are also
114 // converted in the hw.module or arc.model
115 // TODO: InlineArcs seems to not properly handle scf.if operations, thus the
116 // following is commented out
117 // pm.addPass(arc::createMuxToControlFlow());
118 if (options.shouldInline)
119 pm.addPass(arc::createInlineArcs());
120
121 pm.addPass(arc::createMergeIfsPass());
122 pm.addPass(createCSEPass());
123 pm.addPass(arc::createArcCanonicalizer());
124}
125
127 OpPassManager &pm, const ArcStateAllocationOptions &options) {
128 pm.addPass(arc::createLowerArcsToFuncs());
129 {
130 AllocateStateOptions allocStateOpts;
131 allocStateOpts.insertTraceTaps = options.insertTraceTaps;
132 pm.nest<arc::ModelOp>().addPass(arc::createAllocateState(allocStateOpts));
133 }
134 pm.nest<arc::ModelOp>().addPass(arc::createAllocateState());
135 pm.addPass(arc::createLowerClocksToFuncs()); // no CSE between state alloc
136 // and clock func lowering
137 if (options.splitFuncsThreshold.getNumOccurrences()) {
138 pm.addPass(arc::createSplitFuncs({options.splitFuncsThreshold}));
139 }
140 pm.addPass(createCSEPass());
141 pm.addPass(arc::createArcCanonicalizer());
142}
143
144void circt::populateArcToLLVMPipeline(OpPassManager &pm,
145 const ArcToLLVMOptions &options) {
146 {
147 hw::HWConvertBitcastsOptions options;
148 options.allowPartialConversion = false;
149 pm.addPass(hw::createHWConvertBitcasts(options));
150 }
151 if (!options.noRuntime) {
152 InsertRuntimeOptions opts;
153 opts.extraArgs = options.extraRuntimeArgs;
154 opts.traceFileName = options.traceFileName;
155 pm.addPass(createInsertRuntime(opts));
156 }
157 pm.addPass(createLowerArcToLLVMPass());
158 pm.addPass(createCSEPass());
159 pm.addPass(arc::createArcCanonicalizer());
160}
Definition arc.py:1
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
void populateArcStateLoweringPipeline(mlir::OpPassManager &pm, const ArcStateLoweringOptions &options={})
void populateArcToLLVMPipeline(mlir::OpPassManager &pm, const ArcToLLVMOptions &options={})
void populateArcOptimizationPipeline(mlir::OpPassManager &pm, const ArcOptimizationOptions &options={})
void populateArcConversionPipeline(mlir::OpPassManager &pm, const ArcConversionOptions &options={})
std::unique_ptr< mlir::Pass > createLowerFirMemPass()
std::unique_ptr< OperationPass< ModuleOp > > createLowerArcToLLVMPass()
void populateArcPreprocessingPipeline(mlir::OpPassManager &pm, const ArcPreprocessingOptions &options={})
void populateArcStateAllocationPipeline(mlir::OpPassManager &pm, const ArcStateAllocationOptions &options={})
Option< bool > observeRegisters
Definition pipelines.h:55
Option< bool > shouldDedup
Definition pipelines.h:59
Option< bool > shouldMakeLUTs
Definition pipelines.h:82
Option< bool > shouldDetectResets
Definition pipelines.h:77
Option< bool > shouldDetectEnables
Definition pipelines.h:72
Option< bool > observeNamedValues
Definition pipelines.h:35
Option< bool > observeMemories
Definition pipelines.h:40
Option< bool > asyncResetsAsSync
Definition pipelines.h:45
Option< unsigned > splitFuncsThreshold
Definition pipelines.h:101
Option< std::string > extraRuntimeArgs
Definition pipelines.h:121