-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathSynthesisPipeline.cpp
More file actions
159 lines (148 loc) · 6.75 KB
/
SynthesisPipeline.cpp
File metadata and controls
159 lines (148 loc) · 6.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements the default synthesis pipeline from core dialect to AIG.
//
//===----------------------------------------------------------------------===//
#include "circt/Dialect/Synth/Transforms/SynthesisPipeline.h"
#include "circt/Conversion/CombToDatapath.h"
#include "circt/Conversion/CombToSynth.h"
#include "circt/Conversion/DatapathToComb.h"
#include "circt/Dialect/Comb/CombOps.h"
#include "circt/Dialect/Comb/CombPasses.h"
#include "circt/Dialect/Datapath/DatapathPasses.h"
#include "circt/Dialect/HW/HWOps.h"
#include "circt/Dialect/HW/HWPasses.h"
#include "circt/Dialect/Synth/Transforms/SynthPasses.h"
#include "circt/Support/Passes.h"
#include "circt/Transforms/Passes.h"
#include "mlir/Pass/PassManager.h"
#include "mlir/Transforms/Passes.h"
#include "llvm/ADT/SmallVector.h"
using namespace mlir;
using namespace circt;
using namespace circt::synth;
//===----------------------------------------------------------------------===//
// Pipeline Implementation
//===----------------------------------------------------------------------===//
/// Helper function to populate additional legal ops for partial legalization.
template <typename... AllowedOpTy>
static void addOpName(SmallVectorImpl<std::string> &ops) {
(ops.push_back(AllowedOpTy::getOperationName().str()), ...);
}
template <typename... OpToLowerTy>
static std::unique_ptr<Pass>
createLowerVariadicPass(bool timingAware, bool reuseSubsets = false) {
LowerVariadicOptions options;
addOpName<OpToLowerTy...>(options.opNames);
options.timingAware = timingAware;
options.reuseSubsets = reuseSubsets;
return createLowerVariadic(options);
}
void circt::synth::buildCombLoweringPipeline(
OpPassManager &pm, const CombLoweringPipelineOptions &options) {
{
if (!options.disableDatapath) {
// Lower variadic Mul into a binary op to enable datapath lowering.
pm.addPass(createLowerVariadicPass<comb::MulOp>(options.timingAware));
pm.addPass(createConvertCombToDatapath());
pm.addPass(createSimpleCanonicalizerPass());
if (options.synthesisStrategy == OptimizationStrategyTiming)
pm.addPass(datapath::createDatapathReduceDelay());
circt::ConvertDatapathToCombOptions datapathOptions;
datapathOptions.timingAware = options.timingAware;
pm.addPass(createConvertDatapathToComb(datapathOptions));
}
pm.addPass(createCSEPass());
pm.addPass(createSimpleCanonicalizerPass());
// Partially legalize Comb, then run CSE and canonicalization.
circt::ConvertCombToSynthOptions convOptions;
addOpName<comb::AndOp, comb::OrOp, comb::XorOp, comb::MuxOp, comb::ICmpOp,
hw::ArrayGetOp, hw::ArraySliceOp, hw::ArrayCreateOp,
hw::ArrayConcatOp, hw::AggregateConstantOp>(
convOptions.additionalLegalOps);
pm.addPass(circt::createConvertCombToSynth(convOptions));
}
pm.addPass(createCSEPass());
pm.addPass(createSimpleCanonicalizerPass());
// Balance mux chains. For area oriented flow, we want to keep the mux chains
// unless they are very deep.
comb::BalanceMuxOptions balanceOptions{OptimizationStrategyTiming ? 16 : 64};
pm.addPass(comb::createBalanceMux(balanceOptions));
// Lower variadic ops before running full lowering to target IR.
if (options.targetIR.getValue() == TargetIR::AIG) {
// For AIG, lower variadic XoR since AIG cannot keep variadic
// representation.
pm.addPass(createLowerVariadicPass<comb::XorOp>(
options.timingAware,
options.synthesisStrategy == OptimizationStrategyArea));
} else if (options.targetIR.getValue() == TargetIR::MIG) {
// For MIG, lower variadic And, Or, and Xor since MIG cannot keep variadic
// representation.
pm.addPass(createLowerVariadicPass<comb::AndOp, comb::OrOp, comb::XorOp>(
options.timingAware));
}
pm.addPass(circt::hw::createHWAggregateToComb());
circt::ConvertCombToSynthOptions convOptions;
convOptions.targetIR = options.targetIR.getValue() == TargetIR::AIG
? CombToSynthTargetIR::AIG
: CombToSynthTargetIR::MIG;
pm.addPass(circt::createConvertCombToSynth(convOptions));
pm.addPass(createCSEPass());
pm.addPass(createSimpleCanonicalizerPass());
pm.addPass(createCSEPass());
}
void circt::synth::buildSynthOptimizationPipeline(
OpPassManager &pm, const SynthOptimizationPipelineOptions &options) {
// LowerWordToBits may not be scalable for large designs so conditionally
// disable it. It's also worth considering keeping word-level representation
// for faster synthesis.
if (!options.disableWordToBits)
pm.addPass(synth::createLowerWordToBits());
pm.addPass(createCSEPass());
// Run after LowerWordToBits for more precise timing-info & scalability.
pm.addPass(createLowerVariadicPass(options.timingAware));
pm.addPass(createStructuralHash());
pm.addPass(createSimpleCanonicalizerPass());
pm.addPass(synth::createMaximumAndCover());
pm.addPass(createLowerVariadicPass(options.timingAware));
pm.addPass(createStructuralHash());
// SOP balancing.
if (!options.disableSOPBalancing) {
SOPBalancingOptions sopOptions;
// FIXME: The following is very small compared to the default value of ABC
// (6/8) and mockturtle(4/25) due to inefficient implementation of
// CutRewriter.
sopOptions.maxCutInputSize = 4;
sopOptions.maxCutsPerRoot = 4;
pm.addPass(synth::createSOPBalancing(sopOptions));
pm.addPass(createStructuralHash());
}
if (!options.abcCommands.empty()) {
synth::ABCRunnerOptions abcOptions;
abcOptions.abcPath = options.abcPath;
abcOptions.abcCommands.assign(options.abcCommands.begin(),
options.abcCommands.end());
abcOptions.continueOnFailure = options.ignoreAbcFailures;
pm.addPass(synth::createABCRunner(abcOptions));
}
// TODO: Add balancing, rewriting, FRAIG conversion, etc.
}
//===----------------------------------------------------------------------===//
// Pipeline Registration
//===----------------------------------------------------------------------===//
void circt::synth::registerSynthesisPipeline() {
PassPipelineRegistration<CombLoweringPipelineOptions>(
"synth-comb-lowering-pipeline",
"The default pipeline for until Comb lowering",
buildCombLoweringPipeline);
PassPipelineRegistration<SynthOptimizationPipelineOptions>(
"synth-optimization-pipeline",
"The default pipeline for AIG optimization pipeline",
buildSynthOptimizationPipeline);
}