PPCPredicates.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //===-- PPCPredicates.h - PPC Branch Predicate Information ------*- C++ -*-===//
  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. // This file describes the PowerPC branch predicates.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCPREDICATES_H
  13. #define LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCPREDICATES_H
  14. // GCC #defines PPC on Linux but we use it as our namespace name
  15. #undef PPC
  16. // Generated files will use "namespace PPC". To avoid symbol clash,
  17. // undefine PPC here. PPC may be predefined on some hosts.
  18. #undef PPC
  19. namespace llvm {
  20. namespace PPC {
  21. /// Predicate - These are "(BI << 5) | BO" for various predicates.
  22. enum Predicate {
  23. PRED_LT = (0 << 5) | 12,
  24. PRED_LE = (1 << 5) | 4,
  25. PRED_EQ = (2 << 5) | 12,
  26. PRED_GE = (0 << 5) | 4,
  27. PRED_GT = (1 << 5) | 12,
  28. PRED_NE = (2 << 5) | 4,
  29. PRED_UN = (3 << 5) | 12,
  30. PRED_NU = (3 << 5) | 4,
  31. PRED_LT_MINUS = (0 << 5) | 14,
  32. PRED_LE_MINUS = (1 << 5) | 6,
  33. PRED_EQ_MINUS = (2 << 5) | 14,
  34. PRED_GE_MINUS = (0 << 5) | 6,
  35. PRED_GT_MINUS = (1 << 5) | 14,
  36. PRED_NE_MINUS = (2 << 5) | 6,
  37. PRED_UN_MINUS = (3 << 5) | 14,
  38. PRED_NU_MINUS = (3 << 5) | 6,
  39. PRED_LT_PLUS = (0 << 5) | 15,
  40. PRED_LE_PLUS = (1 << 5) | 7,
  41. PRED_EQ_PLUS = (2 << 5) | 15,
  42. PRED_GE_PLUS = (0 << 5) | 7,
  43. PRED_GT_PLUS = (1 << 5) | 15,
  44. PRED_NE_PLUS = (2 << 5) | 7,
  45. PRED_UN_PLUS = (3 << 5) | 15,
  46. PRED_NU_PLUS = (3 << 5) | 7,
  47. // SPE scalar compare instructions always set the GT bit.
  48. PRED_SPE = PRED_GT,
  49. // When dealing with individual condition-register bits, we have simple set
  50. // and unset predicates.
  51. PRED_BIT_SET = 1024,
  52. PRED_BIT_UNSET = 1025
  53. };
  54. // Bit for branch taken (plus) or not-taken (minus) hint
  55. enum BranchHintBit {
  56. BR_NO_HINT = 0x0,
  57. BR_NONTAKEN_HINT = 0x2,
  58. BR_TAKEN_HINT = 0x3,
  59. BR_HINT_MASK = 0X3
  60. };
  61. /// Invert the specified predicate. != -> ==, < -> >=.
  62. Predicate InvertPredicate(Predicate Opcode);
  63. /// Assume the condition register is set by MI(a,b), return the predicate if
  64. /// we modify the instructions such that condition register is set by MI(b,a).
  65. Predicate getSwappedPredicate(Predicate Opcode);
  66. /// Return the condition without hint bits.
  67. inline unsigned getPredicateCondition(Predicate Opcode) {
  68. return (unsigned)(Opcode & ~BR_HINT_MASK);
  69. }
  70. /// Return the hint bits of the predicate.
  71. inline unsigned getPredicateHint(Predicate Opcode) {
  72. return (unsigned)(Opcode & BR_HINT_MASK);
  73. }
  74. /// Return predicate consisting of specified condition and hint bits.
  75. inline Predicate getPredicate(unsigned Condition, unsigned Hint) {
  76. return (Predicate)((Condition & ~BR_HINT_MASK) |
  77. (Hint & BR_HINT_MASK));
  78. }
  79. }
  80. }
  81. #endif