GIMatchDagEdge.h 2.4 KB

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