Changeset View
Changeset View
Standalone View
Standalone View
mlir/lib/Transforms/OpStats.cpp
//===- OpStats.cpp - Prints stats of operations in module -----------------===// | //===- OpStats.cpp - Prints stats of operations in module -----------------===// | ||||
Lint: Lint: clang-format-diff not found in user's PATH; not linting file. | |||||
// | // | ||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||
// See https://llvm.org/LICENSE.txt for license information. | // See https://llvm.org/LICENSE.txt for license information. | ||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#include "mlir/IR/Module.h" | #include "mlir/IR/Module.h" | ||||
#include "mlir/IR/Operation.h" | #include "mlir/IR/Operation.h" | ||||
#include "mlir/IR/OperationSupport.h" | #include "mlir/IR/OperationSupport.h" | ||||
#include "mlir/Pass/Pass.h" | #include "mlir/Pass/Pass.h" | ||||
#include "mlir/Transforms/Passes.h" | #include "mlir/Transforms/Passes.h" | ||||
#include "llvm/ADT/DenseMap.h" | #include "llvm/ADT/DenseMap.h" | ||||
#include "llvm/Support/Format.h" | #include "llvm/Support/Format.h" | ||||
#include "llvm/Support/raw_ostream.h" | #include "llvm/Support/raw_ostream.h" | ||||
using namespace mlir; | using namespace mlir; | ||||
namespace { | namespace { | ||||
struct PrintOpStatsPass : public ModulePass<PrintOpStatsPass> { | struct PrintOpStatsPass : public OperationPass<PrintOpStatsPass, ModuleOp> { | ||||
/// Include the generated pass utilities. | /// Include the generated pass utilities. | ||||
#define GEN_PASS_PrintOpStats | #define GEN_PASS_PrintOpStats | ||||
#include "mlir/Transforms/Passes.h.inc" | #include "mlir/Transforms/Passes.h.inc" | ||||
explicit PrintOpStatsPass(raw_ostream &os = llvm::errs()) : os(os) {} | explicit PrintOpStatsPass(raw_ostream &os = llvm::errs()) : os(os) {} | ||||
// Prints the resultant operation statistics post iterating over the module. | // Prints the resultant operation statistics post iterating over the module. | ||||
void runOnModule() override; | void runOnOperation() override; | ||||
// Print summary of op stats. | // Print summary of op stats. | ||||
void printSummary(); | void printSummary(); | ||||
private: | private: | ||||
llvm::StringMap<int64_t> opCount; | llvm::StringMap<int64_t> opCount; | ||||
raw_ostream &os; | raw_ostream &os; | ||||
}; | }; | ||||
} // namespace | } // namespace | ||||
void PrintOpStatsPass::runOnModule() { | void PrintOpStatsPass::runOnOperation() { | ||||
opCount.clear(); | opCount.clear(); | ||||
// Compute the operation statistics for each function in the module. | // Compute the operation statistics for each function in the module. | ||||
for (auto &op : getModule()) | for (auto &op : getOperation()) | ||||
op.walk([&](Operation *op) { ++opCount[op->getName().getStringRef()]; }); | op.walk([&](Operation *op) { ++opCount[op->getName().getStringRef()]; }); | ||||
printSummary(); | printSummary(); | ||||
} | } | ||||
void PrintOpStatsPass::printSummary() { | void PrintOpStatsPass::printSummary() { | ||||
os << "Operations encountered:\n"; | os << "Operations encountered:\n"; | ||||
os << "-----------------------\n"; | os << "-----------------------\n"; | ||||
SmallVector<StringRef, 64> sorted(opCount.keys()); | SmallVector<StringRef, 64> sorted(opCount.keys()); | ||||
Show All 38 Lines |
clang-format-diff not found in user's PATH; not linting file.