Skip to content

Commit

Permalink
[NNPA] Call ScrubDisposablePass before ZHighConstPropagation (#2583) (#…
Browse files Browse the repository at this point in the history
…2588)

Cherry pick of #2583 to previous release
  • Loading branch information
cjvolzka committed Nov 6, 2023
1 parent ca5af9a commit 40615b3
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/Accelerators/NNPA/Compiler/NNPACompilerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ void addONNXToZHighPasses(
pm.addNestedPass<func::FuncOp>(onnx_mlir::createShapeInferencePass());
// There are more opportunities for const propagation once all zhigh ops were
// generated.
pm.addNestedPass<func::FuncOp>(onnx_mlir::createDecomposeONNXToONNXPass());
pm.addNestedPass<func::FuncOp>(onnx_mlir::createConstPropONNXToONNXPass());
pm.addPass(mlir::createCanonicalizerPass());
// Layout propagation at ZHighIR.
Expand All @@ -103,13 +104,6 @@ void addONNXToZHighPasses(
if (nnpaEnableZHighToOnnx)
pm.addNestedPass<func::FuncOp>(onnx_mlir::createZHighToONNXPass());

// Constant propagation at ZHighIR: constant stickify.
// Only support BE machines.
bool isBE = llvm::support::endian::system_endianness() ==
llvm::support::endianness::big;
if (isBE)
pm.addNestedPass<func::FuncOp>(
onnx_mlir::zhigh::createZHighConstPropagationPass());
// One more call to ONNX shape inference/canonicalization/... to update shape
// if possible.
if (enableONNXHybridPass) {
Expand All @@ -121,6 +115,19 @@ void addONNXToZHighPasses(
pm.addPass(mlir::createCanonicalizerPass());
pm.addNestedPass<func::FuncOp>(onnx_mlir::createShapeInferencePass());
}

// Replace every DisposableElementsAttr with DenseElementsAttr.
// ZHighConstPropagation currently assumes that DenseElementsAttr is used.
pm.addPass(createScrubDisposablePass());

// Constant propagation at ZHighIR: constant stickify.
// Only support BE machines.
bool isBE = llvm::support::endian::system_endianness() ==
llvm::support::endianness::big;
if (isBE)
pm.addNestedPass<func::FuncOp>(
onnx_mlir::zhigh::createZHighConstPropagationPass());

// Remove common sub-expressions.
pm.addPass(mlir::createCSEPass());

Expand Down

0 comments on commit 40615b3

Please sign in to comment.