Skip to content

Align the bufferization pipeline according to the upstream doc #295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lib/gc/Transforms/Pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,28 @@ void populateVectorPasses(mlir::OpPassManager &pm) {

// scf + arith + math + vector + memref + linalg.brgemm
void populateBufferizationPasses(mlir::OpPassManager &pm) {
// The flow follows https://mlir.llvm.org/docs/Bufferization/#overview
pm.addPass(bufferization::createEmptyTensorEliminationPass());
bufferization::OneShotBufferizationOptions options;
options.bufferizeFunctionBoundaries = true;
options.setFunctionBoundaryTypeConversion(
bufferization::LayoutMapOption::IdentityLayoutMap);
pm.addPass(bufferization::createOneShotBufferizePass(options));
pm.addPass(createCanonicalizerPass());
pm.addPass(createCSEPass());
pm.addPass(createCanonicalizerPass());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L101 is already CanonicalizerPass, do we really need to do it again after CSE?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the first CanonicalizerPass is mainly used to canonicalize the scf.for and scf.forall to the canonical form in memref, exposing more CSE optimization opportunities. The CSE pass is used to eliminate the common memref.subview so there will be some useless memref.copy memref.copy %a, %a. The last CanonicalizerPass is used to eliminate the useless memref.copy which copies from A to A like memref.copy %a, %a

pm.addNestedPass<func::FuncOp>(bufferization::createBufferHoistingPass());
pm.addNestedPass<func::FuncOp>(bufferization::createBufferLoopHoistingPass());
// todo: buffer schedule pass
// todo: Need to improve this pass to support nested parallel.
bufferization::BufferResultsToOutParamsOpts opt{};
opt.hoistStaticAllocs = true;
pm.addPass(bufferization::createBufferResultsToOutParamsPass(opt));
// todo: buffer schedule pass
// todo: Need to improve this pass to support nested parallel.
pm.addNestedPass<func::FuncOp>(bufferization::createBufferHoistingPass());
pm.addNestedPass<func::FuncOp>(bufferization::createBufferLoopHoistingPass());
pm.addNestedPass<func::FuncOp>(bufferization::createBufferDeallocationPass());
pm.addPass(bufferization::createDropEquivalentBufferResultsPass());
pm.addNestedPass<func::FuncOp>(
bufferization::createPromoteBuffersToStackPass());
bufferization::BufferDeallocationPipelineOptions deallocOption;
bufferization::buildBufferDeallocationPipeline(pm, deallocOption);
pm.addPass(createBufferizationToMemRefPass());
populateCleanUpPasses(pm);
}
Expand Down