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

source code of mlir/test/lib/Analysis/TestCallGraph.cpp