GIMatchDagPredicate.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //===- GIMatchDagPredicate.cpp - Represent a predicate to check -----------===//
  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. #include "GIMatchDagPredicate.h"
  9. #include "llvm/TableGen/Record.h"
  10. #include "../CodeGenInstruction.h"
  11. #include "GIMatchDag.h"
  12. using namespace llvm;
  13. void GIMatchDagPredicate::print(raw_ostream &OS) const {
  14. OS << "<<";
  15. printDescription(OS);
  16. OS << ">>:$" << Name;
  17. }
  18. void GIMatchDagPredicate::printDescription(raw_ostream &OS) const { OS << ""; }
  19. GIMatchDagOpcodePredicate::GIMatchDagOpcodePredicate(
  20. GIMatchDagContext &Ctx, StringRef Name, const CodeGenInstruction &Instr)
  21. : GIMatchDagPredicate(GIMatchDagPredicateKind_Opcode, Name,
  22. Ctx.makeMIPredicateOperandList()),
  23. Instr(Instr) {}
  24. void GIMatchDagOpcodePredicate::printDescription(raw_ostream &OS) const {
  25. OS << "$mi.getOpcode() == " << Instr.TheDef->getName();
  26. }
  27. GIMatchDagOneOfOpcodesPredicate::GIMatchDagOneOfOpcodesPredicate(
  28. GIMatchDagContext &Ctx, StringRef Name)
  29. : GIMatchDagPredicate(GIMatchDagPredicateKind_OneOfOpcodes, Name,
  30. Ctx.makeMIPredicateOperandList()) {}
  31. void GIMatchDagOneOfOpcodesPredicate::printDescription(raw_ostream &OS) const {
  32. OS << "$mi.getOpcode() == oneof(";
  33. StringRef Separator = "";
  34. for (const CodeGenInstruction *Instr : Instrs) {
  35. OS << Separator << Instr->TheDef->getName();
  36. Separator = ",";
  37. }
  38. OS << ")";
  39. }
  40. GIMatchDagSameMOPredicate::GIMatchDagSameMOPredicate(GIMatchDagContext &Ctx,
  41. StringRef Name)
  42. : GIMatchDagPredicate(GIMatchDagPredicateKind_SameMO, Name,
  43. Ctx.makeTwoMOPredicateOperandList()) {}
  44. void GIMatchDagSameMOPredicate::printDescription(raw_ostream &OS) const {
  45. OS << "$mi0 == $mi1";
  46. }
  47. raw_ostream &llvm::operator<<(raw_ostream &OS, const GIMatchDagPredicate &N) {
  48. N.print(OS);
  49. return OS;
  50. }
  51. raw_ostream &llvm::operator<<(raw_ostream &OS,
  52. const GIMatchDagOpcodePredicate &N) {
  53. N.print(OS);
  54. return OS;
  55. }