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 sim::SquashSimTriggeredOptions opts;
64 opts.convertToHW = true;
65 pm.addNestedPass<hw::HWModuleOp>(sim::createSquashSimTriggered(opts));
66 }
67 {
68 ConvertToArcsPassOptions opts;
69 opts.tapRegisters = options.observeRegisters;
70 pm.addPass(createConvertToArcsPass(opts));
71 }
72 if (options.shouldDedup)
73 pm.addPass(arc::createDedup());
74 pm.addPass(hw::createFlattenModules());
75 pm.addPass(createCSEPass());
76 pm.addPass(arc::createArcCanonicalizer());
77}
78
80 OpPassManager &pm, const ArcOptimizationOptions &options) {
81 // Perform arc-level optimizations that are not specific to software
82 // simulation.
83 pm.addPass(arc::createSplitLoops());
84 if (options.shouldDedup)
85 pm.addPass(arc::createDedup());
86 {
87 arc::InferStatePropertiesOptions opts;
88 opts.detectEnables = options.shouldDetectEnables;
89 opts.detectResets = options.shouldDetectResets;
90 pm.addPass(arc::createInferStateProperties(opts));
91 }
92 pm.addPass(createCSEPass());
93 pm.addPass(arc::createArcCanonicalizer());
94 pm.addNestedPass<hw::HWModuleOp>(arc::createMergeTaps());
95 if (options.shouldMakeLUTs)
96 pm.addPass(arc::createMakeTables());
97 pm.addPass(createCSEPass());
98 pm.addPass(arc::createArcCanonicalizer());
99
100 // Now some arguments may be unused because reset conditions are not passed as
101 // inputs anymore pm.addPass(arc::createRemoveUnusedArcArguments());
102 // Because we replace a lot of StateOp inputs with constants in the enable
103 // patterns we may be able to sink a lot of them
104 // TODO: maybe merge RemoveUnusedArcArguments with SinkInputs?
105 // pm.addPass(arc::createSinkInputs());
106 // pm.addPass(createCSEPass());
107 // pm.addPass(createSimpleCanonicalizerPass());
108 // Removing some muxes etc. may lead to additional dedup opportunities
109 // if (options.shouldDedup)
110 // pm.addPass(arc::createDedup());
111}
112
114 OpPassManager &pm, const ArcStateLoweringOptions &options) {
115 pm.addPass(arc::createLowerStatePass());
116
117 // TODO: LowerClocksToFuncsPass might not properly consider scf.if operations
118 // (or nested regions in general) and thus errors out when muxes are also
119 // converted in the hw.module or arc.model
120 // TODO: InlineArcs seems to not properly handle scf.if operations, thus the
121 // following is commented out
122 // pm.addPass(arc::createMuxToControlFlow());
123 if (options.shouldInline)
124 pm.addPass(arc::createInlineArcs());
125
126 pm.addPass(arc::createMergeIfsPass());
127 pm.addPass(createCSEPass());
128 pm.addPass(arc::createArcCanonicalizer());
129}
130
132 OpPassManager &pm, const ArcStateAllocationOptions &options) {
133 pm.addPass(arc::createLowerArcsToFuncs());
134 pm.addPass(arc::createRemoveI0Types());
135 {
136 AllocateStateOptions allocStateOpts;
137 allocStateOpts.insertTraceTaps = options.insertTraceTaps;
138 pm.nest<arc::ModelOp>().addPass(arc::createAllocateState(allocStateOpts));
139 }
140 pm.nest<arc::ModelOp>().addPass(arc::createAllocateState());
141 pm.addPass(arc::createLowerClocksToFuncs()); // no CSE between state alloc
142 // and clock func lowering
143 if (options.splitFuncsThreshold.getNumOccurrences()) {
144 pm.addPass(arc::createSplitFuncs({options.splitFuncsThreshold}));
145 }
146 pm.addPass(createCSEPass());
147 pm.addPass(arc::createArcCanonicalizer());
148}
149
150void circt::populateArcToLLVMPipeline(OpPassManager &pm,
151 const ArcToLLVMOptions &options) {
152 {
153 hw::HWConvertBitcastsOptions options;
154 options.allowPartialConversion = false;
155 pm.addPass(hw::createHWConvertBitcasts(options));
156 }
157 if (!options.noRuntime) {
158 InsertRuntimeOptions opts;
159 opts.extraArgs = options.extraRuntimeArgs;
160 opts.traceFileName = options.traceFileName;
161 pm.addPass(createInsertRuntime(opts));
162 }
163 if (options.bufferizeArrays) {
164 pm.addPass(createLowerArrays());
165 }
166 pm.addPass(createLowerArcToLLVMPass());
167 pm.addPass(createCSEPass());
168 pm.addPass(arc::createArcCanonicalizer());
169}
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