1 //===-- LanaiAluCode.h - ALU operator encoding ----------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // The encoding for ALU operators used in RM and RRM operands
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_TARGET_LANAI_LANAIALUCODE_H
14 #define LLVM_LIB_TARGET_LANAI_LANAIALUCODE_H
16 #include "llvm/ADT/StringSwitch.h"
17 #include "llvm/CodeGen/ISDOpcodes.h"
18 #include "llvm/Support/ErrorHandling.h"
32 // Shift instructions are treated as SPECIAL when encoding the machine
33 // instruction, but kept distinct until lowering. The constant values are
34 // chosen to ease lowering.
39 // Indicates an unknown/unsupported operator
43 // Bits indicating post- and pre-operators should be tested and set using Is*
44 // and Make* utility functions
45 const int Lanai_PRE_OP
= 0x40;
46 const int Lanai_POST_OP
= 0x80;
48 inline static unsigned encodeLanaiAluCode(unsigned AluOp
) {
49 unsigned const OP_ENCODING_MASK
= 0x07;
50 return AluOp
& OP_ENCODING_MASK
;
53 inline static unsigned getAluOp(unsigned AluOp
) {
54 unsigned const ALU_MASK
= 0x3F;
55 return AluOp
& ALU_MASK
;
58 inline static bool isPreOp(unsigned AluOp
) { return AluOp
& Lanai_PRE_OP
; }
60 inline static bool isPostOp(unsigned AluOp
) { return AluOp
& Lanai_POST_OP
; }
62 inline static unsigned makePreOp(unsigned AluOp
) {
63 assert(!isPostOp(AluOp
) && "Operator can't be a post- and pre-op");
64 return AluOp
| Lanai_PRE_OP
;
67 inline static unsigned makePostOp(unsigned AluOp
) {
68 assert(!isPreOp(AluOp
) && "Operator can't be a post- and pre-op");
69 return AluOp
| Lanai_POST_OP
;
72 inline static bool modifiesOp(unsigned AluOp
) {
73 return isPreOp(AluOp
) | isPostOp(AluOp
);
76 inline static const char *lanaiAluCodeToString(unsigned AluOp
) {
77 switch (getAluOp(AluOp
)) {
99 llvm_unreachable("Invalid ALU code.");
103 inline static AluCode
stringToLanaiAluCode(StringRef S
) {
104 return StringSwitch
<AluCode
>(S
)
118 inline static AluCode
isdToLanaiAluCode(ISD::NodeType Node_type
) {
123 return AluCode::ADDC
;
127 return AluCode::SUBB
;
141 return AluCode::UNKNOWN
;
147 #endif // LLVM_LIB_TARGET_LANAI_LANAIALUCODE_H