]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/utils/TableGen/GlobalISel/GIMatchDagEdge.h
Merge ^/head r358075 through r358130.
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / utils / TableGen / GlobalISel / GIMatchDagEdge.h
1 //===- GIMatchDagEdge.h - Represent a shared operand list for nodes -------===//
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 #ifndef LLVM_UTILS_TABLEGEN_GIMATCHDAGEDGE_H
10 #define LLVM_UTILS_TABLEGEN_GIMATCHDAGEDGE_H
11
12 #include "llvm/ADT/StringRef.h"
13
14 namespace llvm {
15 class raw_ostream;
16 class GIMatchDagInstr;
17 class GIMatchDagOperand;
18
19 /// Represents an edge that connects two instructions together via a pair of
20 /// operands. For example:
21 ///     %a = FOO ...
22 ///     %0 = BAR %a
23 ///     %1 = BAZ %a
24 /// would have two edges for %a like so:
25 ///     BAR:Op#1 --[a]----> Op#0:FOO
26 ///                         ^
27 ///     BAZ:Op#1 --[a]------/
28 /// Ideally, all edges in the DAG are from a use to a def as this is a many
29 /// to one edge but edges from defs to uses are supported too.
30 class GIMatchDagEdge {
31   /// The name of the edge. For example,
32   ///     (FOO $a, $b, $c)
33   ///     (BAR $d, $e, $a)
34   /// will create an edge named 'a' to connect FOO to BAR. Although the name
35   /// refers to the edge, the canonical value of 'a' is the operand that defines
36   /// it.
37   StringRef Name;
38   const GIMatchDagInstr *FromMI;
39   const GIMatchDagOperand *FromMO;
40   const GIMatchDagInstr *ToMI;
41   const GIMatchDagOperand *ToMO;
42
43 public:
44   GIMatchDagEdge(StringRef Name, const GIMatchDagInstr *FromMI, const GIMatchDagOperand *FromMO,
45             const GIMatchDagInstr *ToMI, const GIMatchDagOperand *ToMO)
46       : Name(Name), FromMI(FromMI), FromMO(FromMO), ToMI(ToMI), ToMO(ToMO) {}
47
48   StringRef getName() const { return Name; }
49   const GIMatchDagInstr *getFromMI() const { return FromMI; }
50   const GIMatchDagOperand *getFromMO() const { return FromMO; }
51   const GIMatchDagInstr *getToMI() const { return ToMI; }
52   const GIMatchDagOperand *getToMO() const { return ToMO; }
53
54   /// Flip the direction of the edge.
55   void reverse();
56
57   /// Does this edge run from a def to (one of many) uses?
58   bool isDefToUse() const;
59
60   LLVM_DUMP_METHOD void print(raw_ostream &OS) const;
61
62 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
63   LLVM_DUMP_METHOD void dump() const;
64 #endif // if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
65 };
66
67 raw_ostream &operator<<(raw_ostream &OS, const GIMatchDagEdge &E);
68
69 } // end namespace llvm
70 #endif // ifndef LLVM_UTILS_TABLEGEN_GIMATCHDAGEDGE_H