Chris Lattner | 8c6a41e | 2006-11-17 22:10:59 +0000 | [diff] [blame] | 1 | //===-- PPCPredicates.h - PPC Branch Predicate Information ------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | 8c6a41e | 2006-11-17 22:10:59 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file describes the PowerPC branch predicates. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 14 | #ifndef LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCPREDICATES_H |
| 15 | #define LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCPREDICATES_H |
Chris Lattner | 8c6a41e | 2006-11-17 22:10:59 +0000 | [diff] [blame] | 16 | |
Rafael Espindola | fb8ac2d | 2012-12-20 05:13:09 +0000 | [diff] [blame] | 17 | // GCC #defines PPC on Linux but we use it as our namespace name |
| 18 | #undef PPC |
| 19 | |
Sylvestre Ledru | 37ef20d | 2013-03-17 12:40:42 +0000 | [diff] [blame] | 20 | // Generated files will use "namespace PPC". To avoid symbol clash, |
| 21 | // undefine PPC here. PPC may be predefined on some hosts. |
| 22 | #undef PPC |
| 23 | |
Chris Lattner | 8c6a41e | 2006-11-17 22:10:59 +0000 | [diff] [blame] | 24 | namespace llvm { |
| 25 | namespace PPC { |
| 26 | /// Predicate - These are "(BI << 5) | BO" for various predicates. |
| 27 | enum Predicate { |
Ulrich Weigand | 86247b6 | 2013-06-24 16:52:04 +0000 | [diff] [blame] | 28 | PRED_LT = (0 << 5) | 12, |
| 29 | PRED_LE = (1 << 5) | 4, |
| 30 | PRED_EQ = (2 << 5) | 12, |
| 31 | PRED_GE = (0 << 5) | 4, |
| 32 | PRED_GT = (1 << 5) | 12, |
| 33 | PRED_NE = (2 << 5) | 4, |
| 34 | PRED_UN = (3 << 5) | 12, |
| 35 | PRED_NU = (3 << 5) | 4, |
| 36 | PRED_LT_MINUS = (0 << 5) | 14, |
| 37 | PRED_LE_MINUS = (1 << 5) | 6, |
| 38 | PRED_EQ_MINUS = (2 << 5) | 14, |
| 39 | PRED_GE_MINUS = (0 << 5) | 6, |
| 40 | PRED_GT_MINUS = (1 << 5) | 14, |
| 41 | PRED_NE_MINUS = (2 << 5) | 6, |
| 42 | PRED_UN_MINUS = (3 << 5) | 14, |
| 43 | PRED_NU_MINUS = (3 << 5) | 6, |
| 44 | PRED_LT_PLUS = (0 << 5) | 15, |
| 45 | PRED_LE_PLUS = (1 << 5) | 7, |
| 46 | PRED_EQ_PLUS = (2 << 5) | 15, |
| 47 | PRED_GE_PLUS = (0 << 5) | 7, |
| 48 | PRED_GT_PLUS = (1 << 5) | 15, |
| 49 | PRED_NE_PLUS = (2 << 5) | 7, |
| 50 | PRED_UN_PLUS = (3 << 5) | 15, |
Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 51 | PRED_NU_PLUS = (3 << 5) | 7, |
| 52 | |
| 53 | // When dealing with individual condition-register bits, we have simple set |
| 54 | // and unset predicates. |
Hal Finkel | b39a047 | 2014-02-28 00:45:27 +0000 | [diff] [blame] | 55 | PRED_BIT_SET = 1024, |
| 56 | PRED_BIT_UNSET = 1025 |
Chris Lattner | 8c6a41e | 2006-11-17 22:10:59 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
Hal Finkel | 65539e3 | 2015-12-12 00:32:00 +0000 | [diff] [blame] | 59 | // Bit for branch taken (plus) or not-taken (minus) hint |
| 60 | enum BranchHintBit { |
| 61 | BR_NO_HINT = 0x0, |
| 62 | BR_NONTAKEN_HINT = 0x2, |
| 63 | BR_TAKEN_HINT = 0x3, |
| 64 | BR_HINT_MASK = 0X3 |
| 65 | }; |
| 66 | |
Chris Lattner | 8c6a41e | 2006-11-17 22:10:59 +0000 | [diff] [blame] | 67 | /// Invert the specified predicate. != -> ==, < -> >=. |
| 68 | Predicate InvertPredicate(Predicate Opcode); |
Hal Finkel | 0f64e21 | 2013-04-20 05:16:26 +0000 | [diff] [blame] | 69 | |
| 70 | /// Assume the condition register is set by MI(a,b), return the predicate if |
| 71 | /// we modify the instructions such that condition register is set by MI(b,a). |
| 72 | Predicate getSwappedPredicate(Predicate Opcode); |
Hiroshi Inoue | 967dc58 | 2017-07-27 08:14:48 +0000 | [diff] [blame] | 73 | |
| 74 | /// Return the condition without hint bits. |
| 75 | inline unsigned getPredicateCondition(Predicate Opcode) { |
| 76 | return (unsigned)(Opcode & ~BR_HINT_MASK); |
| 77 | } |
| 78 | |
| 79 | /// Return the hint bits of the predicate. |
| 80 | inline unsigned getPredicateHint(Predicate Opcode) { |
| 81 | return (unsigned)(Opcode & BR_HINT_MASK); |
| 82 | } |
| 83 | |
| 84 | /// Return predicate consisting of specified condition and hint bits. |
| 85 | inline Predicate getPredicate(unsigned Condition, unsigned Hint) { |
| 86 | return (Predicate)((Condition & ~BR_HINT_MASK) | |
| 87 | (Hint & BR_HINT_MASK)); |
| 88 | } |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 89 | } |
| 90 | } |
Chris Lattner | 8c6a41e | 2006-11-17 22:10:59 +0000 | [diff] [blame] | 91 | |
| 92 | #endif |