Skip to content

Commit 6737163

Browse files
committed
chore: drop extern symbol in favor of optional parameter
External symbols in the binary will cause problems for static library builds. Switch to using an additional parameter to pass the parameter if it exists. Signed-off-by: Tianrui Wei <[email protected]>
1 parent c0524d5 commit 6737163

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

include/circt/Reduce/GenericReductions.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@
1010
#define CIRCT_REDUCE_GENERICREDUCTIONS_H
1111

1212
#include "circt/Reduce/Reduction.h"
13+
#include <optional>
1314

1415
namespace circt {
1516

1617
/// Populate reduction patterns that are not specific to certain operations or
17-
/// dialects
18-
void populateGenericReducePatterns(MLIRContext *context,
19-
ReducePatternSet &patterns);
18+
/// dialects.
19+
///
20+
/// The optional `maxNumRewrites` parameter allows callers to override the
21+
/// greedy rewrite budget used by reductions that rely on the canonicalizer
22+
/// pass.
23+
void populateGenericReducePatterns(
24+
MLIRContext *context, ReducePatternSet &patterns,
25+
std::optional<int64_t> maxNumRewrites = std::nullopt);
2026

2127
} // namespace circt
2228

lib/Reduce/GenericReductions.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@
1111
#include "mlir/IR/SymbolTable.h"
1212
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
1313
#include "mlir/Transforms/Passes.h"
14-
#include "llvm/Support/CommandLine.h"
1514

1615
using namespace mlir;
1716
using namespace circt;
1817

19-
extern llvm::cl::opt<int64_t> maxGreedyRewrites;
20-
2118
//===----------------------------------------------------------------------===//
2219
// Reduction Patterns
2320
//===----------------------------------------------------------------------===//
@@ -99,20 +96,23 @@ struct MakeSymbolsPrivate : public Reduction {
9996
// Reduction Registration
10097
//===----------------------------------------------------------------------===//
10198

102-
static std::unique_ptr<Pass> createSimpleCanonicalizerPass() {
99+
static std::unique_ptr<Pass>
100+
createSimpleCanonicalizerPass(std::optional<int64_t> maxNumRewrites) {
103101
GreedyRewriteConfig config;
104102
config.setUseTopDownTraversal(true);
105103
config.setRegionSimplificationLevel(
106104
mlir::GreedySimplifyRegionLevel::Disabled);
107-
if (maxGreedyRewrites >= 0)
108-
config.setMaxNumRewrites(maxGreedyRewrites);
105+
if (maxNumRewrites)
106+
config.setMaxNumRewrites(*maxNumRewrites);
109107
return createCanonicalizerPass(config);
110108
}
111109

112-
void circt::populateGenericReducePatterns(MLIRContext *context,
113-
ReducePatternSet &patterns) {
110+
void circt::populateGenericReducePatterns(
111+
MLIRContext *context, ReducePatternSet &patterns,
112+
std::optional<int64_t> maxNumRewrites) {
114113
patterns.add<PassReduction, 103>(context, createSymbolDCEPass());
115-
patterns.add<PassReduction, 102>(context, createSimpleCanonicalizerPass());
114+
patterns.add<PassReduction, 102>(
115+
context, createSimpleCanonicalizerPass(maxNumRewrites));
116116
patterns.add<PassReduction, 101>(context, createCSEPass());
117117
patterns.add<MakeSymbolsPrivate, 100>();
118118
patterns.add<UnusedSymbolPruner, 99>();

tools/circt-reduce/circt-reduce.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ static cl::opt<bool> verbose("v", cl::init(true),
104104
cl::desc("Print reduction progress to stderr"),
105105
cl::cat(mainCategory));
106106

107-
cl::opt<int64_t> maxGreedyRewrites(
108-
"max-greedy-rewrites", cl::init(-1),
107+
cl::opt<int64_t> maxNumRewrites(
108+
"max-num-rewrites", cl::init(-1),
109109
cl::desc("Maximum number of rewrites GreedyPatternRewriteDriver may "
110110
"apply (negative value keeps the default)"),
111111
cl::cat(mainCategory));
@@ -199,7 +199,10 @@ static LogicalResult execute(MLIRContext &context) {
199199

200200
// Gather a list of reduction patterns that we should try.
201201
ReducePatternSet patterns;
202-
populateGenericReducePatterns(&context, patterns);
202+
std::optional<int64_t> maxNumRewritesOpt;
203+
if (maxNumRewrites >= 0)
204+
maxNumRewritesOpt = maxNumRewrites;
205+
populateGenericReducePatterns(&context, patterns, maxNumRewritesOpt);
203206
ReducePatternInterfaceCollection reducePatternCollection(&context);
204207
reducePatternCollection.populateReducePatterns(patterns);
205208
auto reductionFilter = [&](const Reduction &reduction) {

0 commit comments

Comments
 (0)