Skip to content

Commit

Permalink
[Backport 3.10] Reduce memory usage in pulse sequencing (#336) (#338)
Browse files Browse the repository at this point in the history
Builds on #335.

Co-authored-by: Thomas Alexander <[email protected]>
  • Loading branch information
bcdonovan and taalexander authored Jul 30, 2024
1 parent d78b3dd commit 3534640
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
8 changes: 5 additions & 3 deletions include/Utils/SymbolCacheAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ namespace qssc::utils {
// .addToCache<SequenceOp>();
//
// This analysis is intended to be used with MLIR's getAnalysis
// framework. It has been designed to reused the chached value
// framework. It has been designed to reuse the cached value
// and will not be invalidated automatically with each pass.
// If a pass manipulates the symbols that are cached with this
// analysis then it should use the addCallee method to update the
// map or call invalidate after appying updates.
// map or call invalidate after applying updates.
// Note this analysis should always be used by reference or
// via a pointer to ensure that updates are applied to the maps
// stored by the MLIR analysis framework.
Expand Down Expand Up @@ -95,6 +95,8 @@ class SymbolCacheAnalysis {

op->walk([&](CalleeOp op) {
symbolOpsMap[op.getSymName()] = op.getOperation();
// Don't recurse symbols
return mlir::WalkResult::skip();
});
cachedTypes.insert(typeName);
invalid = false;
Expand Down Expand Up @@ -193,7 +195,7 @@ class SymbolCacheAnalysis {

private:
llvm::StringMap<mlir::Operation *> symbolOpsMap;
std::unordered_map<mlir::Operation *, mlir::Operation *> callMap;
llvm::DenseMap<mlir::Operation *, mlir::Operation *> callMap;
std::unordered_set<std::string> cachedTypes;
mlir::Operation *topOp{nullptr};
bool invalid{true};
Expand Down
3 changes: 2 additions & 1 deletion lib/Dialect/QUIR/Utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ auto getMainFunction(Operation *moduleOperation) -> Operation * {
mainFunc = funcOp.getOperation();
return WalkResult::interrupt();
}
return WalkResult::advance();
// Don't process nested values
return WalkResult::skip();
});
if (!mainFunc)
llvm::errs() << "Error: Main function not found!\n";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
features:
- |
Symbol cache now uses llvm::DenseMap for performance reasons.

0 comments on commit 3534640

Please sign in to comment.