Repository navigation
Add statistics to Util/Transforms/FoldGlobals.cpp. - #7535
Conversation
| class FoldGlobalsPass | ||
| : public PassWrapper<FoldGlobalsPass, OperationPass<mlir::ModuleOp>> { | ||
| public: | ||
| explicit FoldGlobalsPass() {} |
There was a problem hiding this comment.
still needed {} for the copy constructor:
[build] C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\include\memory(3416): error C2280: 'mlir::iree_compiler::IREE::Util::`anonymous-namespace'::FoldGlobalsPass::FoldGlobalsPass(const mlir::iree_compiler::IREE::Util::`anonymous-namespace'::FoldGlobalsPass &)': attempting to reference a deleted function [build] D:\dev\projects\iree\iree\compiler\Dialect\Util\Transforms\FoldGlobals.cpp(360): note: see declaration of 'mlir::iree_compiler::IREE::Util::`anonymous-namespace'::FoldGlobalsPass::FoldGlobalsPass'
| FrozenRewritePatternSet frozenPatterns(std::move(patterns)); | ||
|
|
||
| auto moduleOp = getOperation(); | ||
| beforeFoldingGlobals = |
There was a problem hiding this comment.
use llvm::count for these - we don't want to be allocating a new vector and growing it several times just to get the size - especially because this won't be stripped in release builds when statistics are off (as it has side effects)
There was a problem hiding this comment.
Good point about stripping in builds with statistics being off.
This works, but there may be a simpler helper?
afterFoldingGlobals =
llvm::count_if(moduleOp.getOps<IREE::Util::GlobalOp>(),
[](IREE::Util::GlobalOp op) { return true; });There was a problem hiding this comment.
hmm ADT is always weird about these things - there's an llvm::size, but that may not work here (worth a shot) - otherwise would need to do something like std::distance, which doesn't take ranges, so could have a count helper:
template <typename R>
static size_t count(R &&range) {
return std::distance(range.begin(), range.end());
}
There was a problem hiding this comment.
(that should really be in the ADT as an llvm::distance that takes a range, but ehhh)
There was a problem hiding this comment.
beforeFoldingGlobals = llvm::size(moduleOp.getOps<IREE::Util::GlobalOp>());--->
[build] D:\dev\projects\iree\iree\compiler\Dialect\Util\Transforms\FoldGlobals.cpp(394): error C2672: 'llvm::size': no matching overloaded function found [build] D:\dev\projects\iree\iree\compiler\Dialect\Util\Transforms\FoldGlobals.cpp(394): error C2893: Failed to specialize function template 'auto llvm::size(R &&,enable_if<std::is_base_of<std::random_access_iterator_tag,std::iterator_traits<unknown-type>::iterator_category>::value,void>::type *)' [build] D:\dev\projects\iree\third_party\llvm-project\llvm\include\llvm/ADT/STLExtras.h(1532): note: see declaration of 'llvm::size' [build] D:\dev\projects\iree\iree\compiler\Dialect\Util\Transforms\FoldGlobals.cpp(394): note: With the following template arguments: [build] D:\dev\projects\iree\iree\compiler\Dialect\Util\Transforms\FoldGlobals.cpp(394): note: 'R=llvm::iterator_range<mlir::detail::op_iterator<OpT,mlir::Region::OpIterator>>'
count helper worked though :)
Following up on #7312 (comment), this adds more statistics to IREE's compiler passes. I personally build with the CMake option
-DLLVM_FORCE_ENABLE_STATS=ONso the-pass-statisticsflag works inRelWithDebInfobuilds, but we don't yet have anything like that configured on our CI or recommended in our developer documentation. See also #6161 (comment) for how this could be useful.Sample output on bert_encoder_unrolled_fake_weights.mlir (fake weights are folded aggressively 😛):