1 //===- TestNumberOfExecutions.cpp - Test number of executions analysis ----===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains test passes for constructing and resolving number of
10 // executions information.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "mlir/Analysis/NumberOfExecutions.h"
15 #include "mlir/Pass/Pass.h"
16 
17 using namespace mlir;
18 
19 namespace {
20 
21 struct TestNumberOfBlockExecutionsPass
22     : public PassWrapper<TestNumberOfBlockExecutionsPass, FunctionPass> {
runOnFunction__anon890809cb0111::TestNumberOfBlockExecutionsPass23   void runOnFunction() override {
24     llvm::errs() << "Number of executions: " << getFunction().getName() << "\n";
25     getAnalysis<NumberOfExecutions>().printBlockExecutions(
26         llvm::errs(), &getFunction().getBody());
27   }
28 };
29 
30 struct TestNumberOfOperationExecutionsPass
31     : public PassWrapper<TestNumberOfOperationExecutionsPass, FunctionPass> {
runOnFunction__anon890809cb0111::TestNumberOfOperationExecutionsPass32   void runOnFunction() override {
33     llvm::errs() << "Number of executions: " << getFunction().getName() << "\n";
34     getAnalysis<NumberOfExecutions>().printOperationExecutions(
35         llvm::errs(), &getFunction().getBody());
36   }
37 };
38 
39 } // end anonymous namespace
40 
41 namespace mlir {
42 namespace test {
registerTestNumberOfBlockExecutionsPass()43 void registerTestNumberOfBlockExecutionsPass() {
44   PassRegistration<TestNumberOfBlockExecutionsPass>(
45       "test-print-number-of-block-executions",
46       "Print the contents of a constructed number of executions analysis for "
47       "all blocks.");
48 }
49 
registerTestNumberOfOperationExecutionsPass()50 void registerTestNumberOfOperationExecutionsPass() {
51   PassRegistration<TestNumberOfOperationExecutionsPass>(
52       "test-print-number-of-operation-executions",
53       "Print the contents of a constructed number of executions analysis for "
54       "all operations.");
55 }
56 } // namespace test
57 } // namespace mlir
58