1 //===- TestCallGraph.cpp - Test callgraph construction and iteration ------===// 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 iterating over a 10 // callgraph. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "mlir/Analysis/CallGraph.h" 15 #include "mlir/IR/BuiltinOps.h" 16 #include "mlir/Pass/Pass.h" 17 18 using namespace mlir; 19 20 namespace { 21 struct TestCallGraphPass 22 : public PassWrapper<TestCallGraphPass, OperationPass<ModuleOp>> { MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID__anonf4aad34c0111::TestCallGraphPass23 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestCallGraphPass) 24 25 StringRef getArgument() const final { return "test-print-callgraph"; } getDescription__anonf4aad34c0111::TestCallGraphPass26 StringRef getDescription() const final { 27 return "Print the contents of a constructed callgraph."; 28 } runOnOperation__anonf4aad34c0111::TestCallGraphPass29 void runOnOperation() override { 30 llvm::errs() << "Testing : " 31 << getOperation()->getDiscardableAttr("test.name") << "\n"; 32 getAnalysis<CallGraph>().print(llvm::errs()); 33 } 34 }; 35 } // namespace 36 37 namespace mlir { 38 namespace test { registerTestCallGraphPass()39void registerTestCallGraphPass() { PassRegistration<TestCallGraphPass>(); } 40 } // namespace test 41 } // namespace mlir 42