xref: /llvm-project/llvm/lib/Target/PowerPC/MCTargetDesc/PPCPredicates.h (revision 2946cd701067404b99c39fb29dc9c74bd7193eb3)
111424445SEvan Cheng //===-- PPCPredicates.h - PPC Branch Predicate Information ------*- C++ -*-===//
211424445SEvan Cheng //
3*2946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*2946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
5*2946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
611424445SEvan Cheng //
711424445SEvan Cheng //===----------------------------------------------------------------------===//
811424445SEvan Cheng //
911424445SEvan Cheng // This file describes the PowerPC branch predicates.
1011424445SEvan Cheng //
1111424445SEvan Cheng //===----------------------------------------------------------------------===//
1211424445SEvan Cheng 
13a7c40ef0SBenjamin Kramer #ifndef LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCPREDICATES_H
14a7c40ef0SBenjamin Kramer #define LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCPREDICATES_H
1511424445SEvan Cheng 
16fb8ac2dfSRafael Espindola // GCC #defines PPC on Linux but we use it as our namespace name
17fb8ac2dfSRafael Espindola #undef PPC
18fb8ac2dfSRafael Espindola 
1937ef20d3SSylvestre Ledru // Generated files will use "namespace PPC". To avoid symbol clash,
2037ef20d3SSylvestre Ledru // undefine PPC here. PPC may be predefined on some hosts.
2137ef20d3SSylvestre Ledru #undef PPC
2237ef20d3SSylvestre Ledru 
2311424445SEvan Cheng namespace llvm {
2411424445SEvan Cheng namespace PPC {
2511424445SEvan Cheng   /// Predicate - These are "(BI << 5) | BO"  for various predicates.
2611424445SEvan Cheng   enum Predicate {
2711424445SEvan Cheng     PRED_LT       = (0 << 5) | 12,
2811424445SEvan Cheng     PRED_LE       = (1 << 5) |  4,
2911424445SEvan Cheng     PRED_EQ       = (2 << 5) | 12,
3011424445SEvan Cheng     PRED_GE       = (0 << 5) |  4,
3111424445SEvan Cheng     PRED_GT       = (1 << 5) | 12,
3211424445SEvan Cheng     PRED_NE       = (2 << 5) |  4,
3311424445SEvan Cheng     PRED_UN       = (3 << 5) | 12,
3486247b6eSUlrich Weigand     PRED_NU       = (3 << 5) |  4,
3586247b6eSUlrich Weigand     PRED_LT_MINUS = (0 << 5) | 14,
3686247b6eSUlrich Weigand     PRED_LE_MINUS = (1 << 5) |  6,
3786247b6eSUlrich Weigand     PRED_EQ_MINUS = (2 << 5) | 14,
3886247b6eSUlrich Weigand     PRED_GE_MINUS = (0 << 5) |  6,
3986247b6eSUlrich Weigand     PRED_GT_MINUS = (1 << 5) | 14,
4086247b6eSUlrich Weigand     PRED_NE_MINUS = (2 << 5) |  6,
4186247b6eSUlrich Weigand     PRED_UN_MINUS = (3 << 5) | 14,
4286247b6eSUlrich Weigand     PRED_NU_MINUS = (3 << 5) |  6,
4386247b6eSUlrich Weigand     PRED_LT_PLUS  = (0 << 5) | 15,
4486247b6eSUlrich Weigand     PRED_LE_PLUS  = (1 << 5) |  7,
4586247b6eSUlrich Weigand     PRED_EQ_PLUS  = (2 << 5) | 15,
4686247b6eSUlrich Weigand     PRED_GE_PLUS  = (0 << 5) |  7,
4786247b6eSUlrich Weigand     PRED_GT_PLUS  = (1 << 5) | 15,
4886247b6eSUlrich Weigand     PRED_NE_PLUS  = (2 << 5) |  7,
4986247b6eSUlrich Weigand     PRED_UN_PLUS  = (3 << 5) | 15,
50940ab934SHal Finkel     PRED_NU_PLUS  = (3 << 5) |  7,
51940ab934SHal Finkel 
52d52990c7SJustin Hibbits     // SPE scalar compare instructions always set the GT bit.
53d52990c7SJustin Hibbits     PRED_SPE      = PRED_GT,
54d52990c7SJustin Hibbits 
55940ab934SHal Finkel     // When dealing with individual condition-register bits, we have simple set
56940ab934SHal Finkel     // and unset predicates.
57b39a0475SHal Finkel     PRED_BIT_SET =   1024,
58b39a0475SHal Finkel     PRED_BIT_UNSET = 1025
5911424445SEvan Cheng   };
6011424445SEvan Cheng 
6165539e3cSHal Finkel   // Bit for branch taken (plus) or not-taken (minus) hint
6265539e3cSHal Finkel   enum BranchHintBit {
6365539e3cSHal Finkel     BR_NO_HINT       = 0x0,
6465539e3cSHal Finkel     BR_NONTAKEN_HINT = 0x2,
6565539e3cSHal Finkel     BR_TAKEN_HINT    = 0x3,
6665539e3cSHal Finkel     BR_HINT_MASK     = 0X3
6765539e3cSHal Finkel   };
6865539e3cSHal Finkel 
6911424445SEvan Cheng   /// Invert the specified predicate.  != -> ==, < -> >=.
7011424445SEvan Cheng   Predicate InvertPredicate(Predicate Opcode);
710f64e21bSHal Finkel 
720f64e21bSHal Finkel   /// Assume the condition register is set by MI(a,b), return the predicate if
730f64e21bSHal Finkel   /// we modify the instructions such that condition register is set by MI(b,a).
740f64e21bSHal Finkel   Predicate getSwappedPredicate(Predicate Opcode);
75967dc58aSHiroshi Inoue 
76967dc58aSHiroshi Inoue   /// Return the condition without hint bits.
getPredicateCondition(Predicate Opcode)77967dc58aSHiroshi Inoue   inline unsigned getPredicateCondition(Predicate Opcode) {
78967dc58aSHiroshi Inoue     return (unsigned)(Opcode & ~BR_HINT_MASK);
79967dc58aSHiroshi Inoue   }
80967dc58aSHiroshi Inoue 
81967dc58aSHiroshi Inoue   /// Return the hint bits of the predicate.
getPredicateHint(Predicate Opcode)82967dc58aSHiroshi Inoue   inline unsigned getPredicateHint(Predicate Opcode) {
83967dc58aSHiroshi Inoue     return (unsigned)(Opcode & BR_HINT_MASK);
84967dc58aSHiroshi Inoue   }
85967dc58aSHiroshi Inoue 
86967dc58aSHiroshi Inoue   /// Return predicate consisting of specified condition and hint bits.
getPredicate(unsigned Condition,unsigned Hint)87967dc58aSHiroshi Inoue   inline Predicate getPredicate(unsigned Condition, unsigned Hint) {
88967dc58aSHiroshi Inoue     return (Predicate)((Condition & ~BR_HINT_MASK) |
89967dc58aSHiroshi Inoue                        (Hint & BR_HINT_MASK));
90967dc58aSHiroshi Inoue   }
91f00654e3SAlexander Kornienko }
92f00654e3SAlexander Kornienko }
9311424445SEvan Cheng 
9411424445SEvan Cheng #endif
95