Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / tools / llvm-xray / xray-graph-diff.h
blobc2b2a938bfbc68658a157fa1e120919824dc7ad0
1 //===-- xray-graph-diff.h - XRay Graph Diff Renderer ------------*- C++ -*-===//
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 // Generate a DOT file to represent the difference between the function call
10 // graph of two differnent traces.
12 //===----------------------------------------------------------------------===//
14 #ifndef XRAY_GRAPH_DIFF_H
15 #define XRAY_GRAPH_DIFF_H
17 #include "xray-graph.h"
18 #include "llvm/XRay/Graph.h"
20 namespace llvm {
21 namespace xray {
23 // This class creates a graph representing the difference between two
24 // xray-graphs And allows you to print it to a dot file, with optional color
25 // coding.
26 class GraphDiffRenderer {
27 static const int N = 2;
29 public:
30 using StatType = GraphRenderer::StatType;
31 using TimeStat = GraphRenderer::TimeStat;
33 using GREdgeValueType = GraphRenderer::GraphT::EdgeValueType;
34 using GRVertexValueType = GraphRenderer::GraphT::VertexValueType;
36 struct EdgeAttribute {
37 std::array<const GREdgeValueType *, N> CorrEdgePtr = {};
40 struct VertexAttribute {
41 std::array<const GRVertexValueType *, N> CorrVertexPtr = {};
44 using GraphT = Graph<VertexAttribute, EdgeAttribute, StringRef>;
46 class Factory {
47 std::array<std::reference_wrapper<const GraphRenderer::GraphT>, N> G;
49 public:
50 template <typename... Ts> Factory(Ts &... Args) : G{{Args...}} {}
52 Expected<GraphDiffRenderer> getGraphDiffRenderer();
55 private:
56 GraphT G;
58 GraphDiffRenderer() = default;
60 public:
61 void exportGraphAsDOT(raw_ostream &OS, StatType EdgeLabel = StatType::NONE,
62 StatType EdgeColor = StatType::NONE,
63 StatType VertexLabel = StatType::NONE,
64 StatType VertexColor = StatType::NONE,
65 int TruncLen = 40);
67 const GraphT &getGraph() { return G; }
69 } // namespace xray
70 } // namespace llvm
72 #endif