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> { getArgument__anond21cefde0111::TestNumberOfBlockExecutionsPass23 StringRef getArgument() const final { 24 return "test-print-number-of-block-executions"; 25 } getDescription__anond21cefde0111::TestNumberOfBlockExecutionsPass26 StringRef getDescription() const final { 27 return "Print the contents of a constructed number of executions analysis " 28 "for " 29 "all blocks."; 30 } runOnFunction__anond21cefde0111::TestNumberOfBlockExecutionsPass31 void runOnFunction() override { 32 llvm::errs() << "Number of executions: " << getFunction().getName() << "\n"; 33 getAnalysis<NumberOfExecutions>().printBlockExecutions( 34 llvm::errs(), &getFunction().getBody()); 35 } 36 }; 37 38 struct TestNumberOfOperationExecutionsPass 39 : public PassWrapper<TestNumberOfOperationExecutionsPass, FunctionPass> { getArgument__anond21cefde0111::TestNumberOfOperationExecutionsPass40 StringRef getArgument() const final { 41 return "test-print-number-of-operation-executions"; 42 } getDescription__anond21cefde0111::TestNumberOfOperationExecutionsPass43 StringRef getDescription() const final { 44 return "Print the contents of a constructed number of executions analysis " 45 "for " 46 "all operations."; 47 } runOnFunction__anond21cefde0111::TestNumberOfOperationExecutionsPass48 void runOnFunction() override { 49 llvm::errs() << "Number of executions: " << getFunction().getName() << "\n"; 50 getAnalysis<NumberOfExecutions>().printOperationExecutions( 51 llvm::errs(), &getFunction().getBody()); 52 } 53 }; 54 55 } // end anonymous namespace 56 57 namespace mlir { 58 namespace test { registerTestNumberOfBlockExecutionsPass()59void registerTestNumberOfBlockExecutionsPass() { 60 PassRegistration<TestNumberOfBlockExecutionsPass>(); 61 } 62 registerTestNumberOfOperationExecutionsPass()63void registerTestNumberOfOperationExecutionsPass() { 64 PassRegistration<TestNumberOfOperationExecutionsPass>(); 65 } 66 } // namespace test 67 } // namespace mlir 68