1 //===- GIMatchDagEdge.h - Represent a shared operand list for nodes -------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_UTILS_TABLEGEN_GIMATCHDAGEDGE_H
10 #define LLVM_UTILS_TABLEGEN_GIMATCHDAGEDGE_H
12 #include "llvm/ADT/StringRef.h"
16 class GIMatchDagInstr
;
17 class GIMatchDagOperand
;
19 /// Represents an edge that connects two instructions together via a pair of
20 /// operands. For example:
24 /// would have two edges for %a like so:
25 /// BAR:Op#1 --[a]----> Op#0:FOO
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,
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
38 const GIMatchDagInstr
*FromMI
;
39 const GIMatchDagOperand
*FromMO
;
40 const GIMatchDagInstr
*ToMI
;
41 const GIMatchDagOperand
*ToMO
;
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
) {}
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
; }
54 /// Flip the direction of the edge.
57 /// Does this edge run from a def to (one of many) uses?
58 bool isDefToUse() const;
60 LLVM_DUMP_METHOD
void print(raw_ostream
&OS
) const;
62 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
63 LLVM_DUMP_METHOD
void dump() const;
64 #endif // if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
67 raw_ostream
&operator<<(raw_ostream
&OS
, const GIMatchDagEdge
&E
);
69 } // end namespace llvm
70 #endif // ifndef LLVM_UTILS_TABLEGEN_GIMATCHDAGEDGE_H