[firtool] Move width inference before canonicalization (#1147)

* Move the width inference pass up in the pipeline such that it runs
  before the canonicalization passes. This is useful since width
  inference itself does not depend on canonicalization, but in turn
  enables a lot of canonicalization patterns to run.
This commit is contained in:
Fabian Schuiki 2021-05-26 10:57:07 +02:00 committed by GitHub
parent abbcaef8dc
commit e539a7bcfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 9 deletions

View File

@ -177,6 +177,16 @@ processBuffer(std::unique_ptr<llvm::MemoryBuffer> ownedBuffer,
assert(inputFormat == InputMLIRFile);
module = parseSourceFile(sourceMgr, &context);
}
if (!module)
return failure();
// Allow optimizations to run multithreaded.
context.enableMultithreading(isMultithreaded);
// Width inference creates canonicalization opportunities.
if (inferWidths)
pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInferWidthsPass());
// The input mlir file could be firrtl dialect so we might need to clean
// things up.
if (!disableLowerTypes) {
@ -186,6 +196,7 @@ processBuffer(std::unique_ptr<llvm::MemoryBuffer> ownedBuffer,
if (expandWhens)
modulePM.addPass(firrtl::createExpandWhensPass());
}
// If we parsed a FIRRTL file and have optimizations enabled, clean it up.
if (!disableOptimization) {
auto &modulePM = pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>();
@ -193,15 +204,6 @@ processBuffer(std::unique_ptr<llvm::MemoryBuffer> ownedBuffer,
modulePM.addPass(createSimpleCanonicalizerPass());
}
if (!module)
return failure();
// Allow optimizations to run multithreaded.
context.enableMultithreading(isMultithreaded);
if (inferWidths)
pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInferWidthsPass());
if (inliner)
pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInlinerPass());