|
| 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 | + |
| 13 | +#include "circt/Tools/arcilator/pipelines.h" |
| 14 | + |
| 15 | +#include "circt/Conversion/ArcToLLVM.h" |
| 16 | +#include "circt/Conversion/CombToArith.h" |
| 17 | +#include "circt/Conversion/ConvertToArcs.h" |
| 18 | +#include "circt/Conversion/Passes.h" |
| 19 | +#include "circt/Conversion/SeqToSV.h" |
| 20 | +#include "circt/Dialect/Arc/ArcOps.h" |
| 21 | +#include "circt/Dialect/Arc/ArcPasses.h" |
| 22 | +#include "circt/Dialect/Emit/EmitPasses.h" |
| 23 | +#include "circt/Dialect/HW/HWPasses.h" |
| 24 | +#include "circt/Dialect/OM/OMPasses.h" |
| 25 | +#include "circt/Dialect/Seq/SeqPasses.h" |
| 26 | +#include "circt/Dialect/Sim/SimPasses.h" |
| 27 | +#include "circt/Support/Passes.h" |
| 28 | +#include "mlir/Transforms/Passes.h" |
| 29 | + |
| 30 | +using namespace mlir; |
| 31 | +using namespace circt; |
| 32 | +using namespace arc; |
| 33 | + |
| 34 | +void circt::populateArcPreprocessingPipeline( |
| 35 | + OpPassManager &pm, const ArcPreprocessingOptions &options) { |
| 36 | + pm.addPass(om::createStripOMPass()); |
| 37 | + pm.addPass(emit::createStripEmitPass()); |
| 38 | + pm.addPass(createLowerFirMemPass()); |
| 39 | + pm.addPass(createLowerVerifSimulationsPass()); |
| 40 | + { |
| 41 | + arc::AddTapsOptions opts; |
| 42 | + opts.tapPorts = options.observePorts; |
| 43 | + opts.tapWires = options.observeWires; |
| 44 | + opts.tapNamedValues = options.observeNamedValues; |
| 45 | + pm.addPass(arc::createAddTapsPass(opts)); |
| 46 | + } |
| 47 | + pm.addPass(arc::createStripSVPass()); |
| 48 | + { |
| 49 | + arc::InferMemoriesOptions opts; |
| 50 | + opts.tapPorts = options.observePorts; |
| 51 | + opts.tapMemories = options.observeMemories; |
| 52 | + pm.addPass(arc::createInferMemoriesPass(opts)); |
| 53 | + } |
| 54 | + pm.addPass(sim::createLowerDPIFunc()); |
| 55 | + pm.addPass(createCSEPass()); |
| 56 | + pm.addPass(arc::createArcCanonicalizerPass()); |
| 57 | +} |
| 58 | + |
| 59 | +void circt::populateArcConversionPipeline(OpPassManager &pm, |
| 60 | + const ArcConversionOptions &options) { |
| 61 | + { |
| 62 | + ConvertToArcsPassOptions opts; |
| 63 | + opts.tapRegisters = options.observeRegisters; |
| 64 | + pm.addPass(createConvertToArcsPass(opts)); |
| 65 | + } |
| 66 | + if (options.shouldDedup) |
| 67 | + pm.addPass(arc::createDedupPass()); |
| 68 | + pm.addPass(hw::createFlattenModules()); |
| 69 | + pm.addPass(createCSEPass()); |
| 70 | + pm.addPass(arc::createArcCanonicalizerPass()); |
| 71 | +} |
| 72 | + |
| 73 | +void circt::populateArcOptimizationPipeline( |
| 74 | + OpPassManager &pm, const ArcOptimizationOptions &options) { |
| 75 | + // Perform arc-level optimizations that are not specific to software |
| 76 | + // simulation. |
| 77 | + pm.addPass(arc::createSplitLoopsPass()); |
| 78 | + if (options.shouldDedup) |
| 79 | + pm.addPass(arc::createDedupPass()); |
| 80 | + { |
| 81 | + arc::InferStatePropertiesOptions opts; |
| 82 | + opts.detectEnables = options.shouldDetectEnables; |
| 83 | + opts.detectResets = options.shouldDetectResets; |
| 84 | + pm.addPass(arc::createInferStateProperties(opts)); |
| 85 | + } |
| 86 | + pm.addPass(createCSEPass()); |
| 87 | + pm.addPass(arc::createArcCanonicalizerPass()); |
| 88 | + pm.addNestedPass<hw::HWModuleOp>(arc::createMergeTaps()); |
| 89 | + if (options.shouldMakeLUTs) |
| 90 | + pm.addPass(arc::createMakeTablesPass()); |
| 91 | + pm.addPass(createCSEPass()); |
| 92 | + pm.addPass(arc::createArcCanonicalizerPass()); |
| 93 | + |
| 94 | + // Now some arguments may be unused because reset conditions are not passed as |
| 95 | + // inputs anymore pm.addPass(arc::createRemoveUnusedArcArgumentsPass()); |
| 96 | + // Because we replace a lot of StateOp inputs with constants in the enable |
| 97 | + // patterns we may be able to sink a lot of them |
| 98 | + // TODO: maybe merge RemoveUnusedArcArguments with SinkInputs? |
| 99 | + // pm.addPass(arc::createSinkInputsPass()); |
| 100 | + // pm.addPass(createCSEPass()); |
| 101 | + // pm.addPass(createSimpleCanonicalizerPass()); |
| 102 | + // Removing some muxes etc. may lead to additional dedup opportunities |
| 103 | + // if (options.shouldDedup) |
| 104 | + // pm.addPass(arc::createDedupPass()); |
| 105 | +} |
| 106 | + |
| 107 | +void circt::populateArcStateLoweringPipeline( |
| 108 | + OpPassManager &pm, const ArcStateLoweringOptions &options) { |
| 109 | + pm.addPass(arc::createLowerStatePass()); |
| 110 | + |
| 111 | + // TODO: LowerClocksToFuncsPass might not properly consider scf.if operations |
| 112 | + // (or nested regions in general) and thus errors out when muxes are also |
| 113 | + // converted in the hw.module or arc.model |
| 114 | + // TODO: InlineArcs seems to not properly handle scf.if operations, thus the |
| 115 | + // following is commented out |
| 116 | + // pm.addPass(arc::createMuxToControlFlowPass()); |
| 117 | + if (options.shouldInline) |
| 118 | + pm.addPass(arc::createInlineArcsPass()); |
| 119 | + |
| 120 | + pm.addPass(arc::createMergeIfsPass()); |
| 121 | + pm.addPass(createCSEPass()); |
| 122 | + pm.addPass(arc::createArcCanonicalizerPass()); |
| 123 | +} |
| 124 | + |
| 125 | +void circt::populateArcStateAllocationPipeline( |
| 126 | + OpPassManager &pm, const ArcStateAllocationOptions &options) { |
| 127 | + pm.addPass(arc::createLowerArcsToFuncsPass()); |
| 128 | + pm.nest<arc::ModelOp>().addPass(arc::createAllocateStatePass()); |
| 129 | + pm.addPass(arc::createLowerClocksToFuncsPass()); // no CSE between state alloc |
| 130 | + // and clock func lowering |
| 131 | + if (options.splitFuncsThreshold.getNumOccurrences()) { |
| 132 | + pm.addPass(arc::createSplitFuncs({options.splitFuncsThreshold})); |
| 133 | + } |
| 134 | + pm.addPass(createCSEPass()); |
| 135 | + pm.addPass(arc::createArcCanonicalizerPass()); |
| 136 | +} |
| 137 | + |
| 138 | +void circt::populateArcToLLVMPipeline(OpPassManager &pm) { |
| 139 | + pm.addPass(createLowerArcToLLVMPass()); |
| 140 | + pm.addPass(createCSEPass()); |
| 141 | + pm.addPass(arc::createArcCanonicalizerPass()); |
| 142 | +} |
0 commit comments