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/Pass/Pass.h"
16 
17 using namespace mlir;
18 
19 namespace {
20 struct TestCallGraphPass
21     : public PassWrapper<TestCallGraphPass, OperationPass<ModuleOp>> {
22   MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestCallGraphPass)
23 
24   StringRef getArgument() const final { return "test-print-callgraph"; }
25   StringRef getDescription() const final {
26     return "Print the contents of a constructed callgraph.";
27   }
28   void runOnOperation() override {
29     llvm::errs() << "Testing : " << getOperation()->getAttr("test.name")
30                  << "\n";
31     getAnalysis<CallGraph>().print(llvm::errs());
32   }
33 };
34 } // namespace
35 
36 namespace mlir {
37 namespace test {
38 void registerTestCallGraphPass() { PassRegistration<TestCallGraphPass>(); }
39 } // namespace test
40 } // namespace mlir
41