PredicateExpander.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //===--------------------- PredicateExpander.h ----------------------------===//
  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. /// \file
  9. /// Functionalities used by the Tablegen backends to expand machine predicates.
  10. ///
  11. /// See file llvm/Target/TargetInstrPredicate.td for a full list and description
  12. /// of all the supported MCInstPredicate classes.
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #ifndef LLVM_UTILS_TABLEGEN_PREDICATEEXPANDER_H
  16. #define LLVM_UTILS_TABLEGEN_PREDICATEEXPANDER_H
  17. #include "llvm/ADT/StringRef.h"
  18. #include <vector>
  19. namespace llvm {
  20. class raw_ostream;
  21. class Record;
  22. class PredicateExpander {
  23. bool EmitCallsByRef;
  24. bool NegatePredicate;
  25. bool ExpandForMC;
  26. unsigned IndentLevel;
  27. StringRef TargetName;
  28. PredicateExpander(const PredicateExpander &) = delete;
  29. PredicateExpander &operator=(const PredicateExpander &) = delete;
  30. public:
  31. PredicateExpander(StringRef Target)
  32. : EmitCallsByRef(true), NegatePredicate(false), ExpandForMC(false),
  33. IndentLevel(1U), TargetName(Target) {}
  34. bool isByRef() const { return EmitCallsByRef; }
  35. bool shouldNegate() const { return NegatePredicate; }
  36. bool shouldExpandForMC() const { return ExpandForMC; }
  37. unsigned getIndentLevel() const { return IndentLevel; }
  38. StringRef getTargetName() const { return TargetName; }
  39. void setByRef(bool Value) { EmitCallsByRef = Value; }
  40. void flipNegatePredicate() { NegatePredicate = !NegatePredicate; }
  41. void setNegatePredicate(bool Value) { NegatePredicate = Value; }
  42. void setExpandForMC(bool Value) { ExpandForMC = Value; }
  43. void setIndentLevel(unsigned Level) { IndentLevel = Level; }
  44. void increaseIndentLevel() { ++IndentLevel; }
  45. void decreaseIndentLevel() { --IndentLevel; }
  46. using RecVec = std::vector<Record *>;
  47. void expandTrue(raw_ostream &OS);
  48. void expandFalse(raw_ostream &OS);
  49. void expandCheckImmOperand(raw_ostream &OS, int OpIndex, int ImmVal,
  50. StringRef FunctionMapper);
  51. void expandCheckImmOperand(raw_ostream &OS, int OpIndex, StringRef ImmVal,
  52. StringRef FunctionMapperer);
  53. void expandCheckImmOperandSimple(raw_ostream &OS, int OpIndex,
  54. StringRef FunctionMapper);
  55. void expandCheckRegOperand(raw_ostream &OS, int OpIndex, const Record *Reg,
  56. StringRef FunctionMapper);
  57. void expandCheckRegOperandSimple(raw_ostream &OS, int OpIndex,
  58. StringRef FunctionMapper);
  59. void expandCheckSameRegOperand(raw_ostream &OS, int First, int Second);
  60. void expandCheckNumOperands(raw_ostream &OS, int NumOps);
  61. void expandCheckOpcode(raw_ostream &OS, const Record *Inst);
  62. void expandCheckPseudo(raw_ostream &OS, const RecVec &Opcodes);
  63. void expandCheckOpcode(raw_ostream &OS, const RecVec &Opcodes);
  64. void expandPredicateSequence(raw_ostream &OS, const RecVec &Sequence,
  65. bool IsCheckAll);
  66. void expandTIIFunctionCall(raw_ostream &OS, StringRef MethodName);
  67. void expandCheckIsRegOperand(raw_ostream &OS, int OpIndex);
  68. void expandCheckIsImmOperand(raw_ostream &OS, int OpIndex);
  69. void expandCheckInvalidRegOperand(raw_ostream &OS, int OpIndex);
  70. void expandCheckFunctionPredicate(raw_ostream &OS, StringRef MCInstFn,
  71. StringRef MachineInstrFn);
  72. void expandCheckFunctionPredicateWithTII(raw_ostream &OS, StringRef MCInstFn,
  73. StringRef MachineInstrFn,
  74. StringRef TIIPtr);
  75. void expandCheckNonPortable(raw_ostream &OS, StringRef CodeBlock);
  76. void expandPredicate(raw_ostream &OS, const Record *Rec);
  77. void expandReturnStatement(raw_ostream &OS, const Record *Rec);
  78. void expandOpcodeSwitchCase(raw_ostream &OS, const Record *Rec);
  79. void expandOpcodeSwitchStatement(raw_ostream &OS, const RecVec &Cases,
  80. const Record *Default);
  81. void expandStatement(raw_ostream &OS, const Record *Rec);
  82. };
  83. // Forward declarations.
  84. class STIPredicateFunction;
  85. class OpcodeGroup;
  86. class STIPredicateExpander : public PredicateExpander {
  87. StringRef ClassPrefix;
  88. bool ExpandDefinition;
  89. STIPredicateExpander(const PredicateExpander &) = delete;
  90. STIPredicateExpander &operator=(const PredicateExpander &) = delete;
  91. void expandHeader(raw_ostream &OS, const STIPredicateFunction &Fn);
  92. void expandPrologue(raw_ostream &OS, const STIPredicateFunction &Fn);
  93. void expandOpcodeGroup(raw_ostream &OS, const OpcodeGroup &Group,
  94. bool ShouldUpdateOpcodeMask);
  95. void expandBody(raw_ostream &OS, const STIPredicateFunction &Fn);
  96. void expandEpilogue(raw_ostream &OS, const STIPredicateFunction &Fn);
  97. public:
  98. STIPredicateExpander(StringRef Target)
  99. : PredicateExpander(Target), ExpandDefinition(false) {}
  100. bool shouldExpandDefinition() const { return ExpandDefinition; }
  101. StringRef getClassPrefix() const { return ClassPrefix; }
  102. void setClassPrefix(StringRef S) { ClassPrefix = S; }
  103. void setExpandDefinition(bool Value) { ExpandDefinition = Value; }
  104. void expandSTIPredicate(raw_ostream &OS, const STIPredicateFunction &Fn);
  105. };
  106. } // namespace llvm
  107. #endif