1 //===-- LanaiAluCode.h - ALU operator encoding ----------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // The encoding for ALU operators used in RM and RRM operands
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_LANAI_LANAIALUCODE_H
15 #define LLVM_LIB_TARGET_LANAI_LANAIALUCODE_H
17 #include "llvm/ADT/StringSwitch.h"
18 #include "llvm/CodeGen/ISDOpcodes.h"
19 #include "llvm/Support/ErrorHandling.h"
33 // Shift instructions are treated as SPECIAL when encoding the machine
34 // instruction, but kept distinct until lowering. The constant values are
35 // chosen to ease lowering.
40 // Indicates an unknown/unsupported operator
44 // Bits indicating post- and pre-operators should be tested and set using Is*
45 // and Make* utility functions
46 const int Lanai_PRE_OP = 0x40;
47 const int Lanai_POST_OP = 0x80;
49 inline static unsigned encodeLanaiAluCode(unsigned AluOp) {
50 unsigned const OP_ENCODING_MASK = 0x07;
51 return AluOp & OP_ENCODING_MASK;
54 inline static unsigned getAluOp(unsigned AluOp) {
55 unsigned const ALU_MASK = 0x3F;
56 return AluOp & ALU_MASK;
59 inline static bool isPreOp(unsigned AluOp) { return AluOp & Lanai_PRE_OP; }
61 inline static bool isPostOp(unsigned AluOp) { return AluOp & Lanai_POST_OP; }
63 inline static unsigned makePreOp(unsigned AluOp) {
64 assert(!isPostOp(AluOp) && "Operator can't be a post- and pre-op");
65 return AluOp | Lanai_PRE_OP;
68 inline static unsigned makePostOp(unsigned AluOp) {
69 assert(!isPreOp(AluOp) && "Operator can't be a post- and pre-op");
70 return AluOp | Lanai_POST_OP;
73 inline static bool modifiesOp(unsigned AluOp) {
74 return isPreOp(AluOp) | isPostOp(AluOp);
77 inline static const char *lanaiAluCodeToString(unsigned AluOp) {
78 switch (getAluOp(AluOp)) {
100 llvm_unreachable("Invalid ALU code.");
104 inline static AluCode stringToLanaiAluCode(StringRef S) {
105 return StringSwitch<AluCode>(S)
119 inline static AluCode isdToLanaiAluCode(ISD::NodeType Node_type) {
124 return AluCode::ADDC;
128 return AluCode::SUBB;
142 return AluCode::UNKNOWN;
148 #endif // LLVM_LIB_TARGET_LANAI_LANAIALUCODE_H