Path: blob/main/contrib/llvm-project/llvm/lib/Target/Lanai/LanaiAluCode.h
35271 views
//===-- LanaiAluCode.h - ALU operator encoding ----------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// The encoding for ALU operators used in RM and RRM operands9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_LIB_TARGET_LANAI_LANAIALUCODE_H13#define LLVM_LIB_TARGET_LANAI_LANAIALUCODE_H1415#include "llvm/ADT/StringSwitch.h"16#include "llvm/Support/ErrorHandling.h"1718namespace llvm {19namespace LPAC {20enum AluCode {21ADD = 0x00,22ADDC = 0x01,23SUB = 0x02,24SUBB = 0x03,25AND = 0x04,26OR = 0x05,27XOR = 0x06,28SPECIAL = 0x07,2930// Shift instructions are treated as SPECIAL when encoding the machine31// instruction, but kept distinct until lowering. The constant values are32// chosen to ease lowering.33SHL = 0x17,34SRL = 0x27,35SRA = 0x37,3637// Indicates an unknown/unsupported operator38UNKNOWN = 0xFF,39};4041// Bits indicating post- and pre-operators should be tested and set using Is*42// and Make* utility functions43const int Lanai_PRE_OP = 0x40;44const int Lanai_POST_OP = 0x80;4546inline static unsigned encodeLanaiAluCode(unsigned AluOp) {47unsigned const OP_ENCODING_MASK = 0x07;48return AluOp & OP_ENCODING_MASK;49}5051inline static unsigned getAluOp(unsigned AluOp) {52unsigned const ALU_MASK = 0x3F;53return AluOp & ALU_MASK;54}5556inline static bool isPreOp(unsigned AluOp) { return AluOp & Lanai_PRE_OP; }5758inline static bool isPostOp(unsigned AluOp) { return AluOp & Lanai_POST_OP; }5960inline static unsigned makePreOp(unsigned AluOp) {61assert(!isPostOp(AluOp) && "Operator can't be a post- and pre-op");62return AluOp | Lanai_PRE_OP;63}6465inline static unsigned makePostOp(unsigned AluOp) {66assert(!isPreOp(AluOp) && "Operator can't be a post- and pre-op");67return AluOp | Lanai_POST_OP;68}6970inline static bool modifiesOp(unsigned AluOp) {71return isPreOp(AluOp) || isPostOp(AluOp);72}7374inline static const char *lanaiAluCodeToString(unsigned AluOp) {75switch (getAluOp(AluOp)) {76case ADD:77return "add";78case ADDC:79return "addc";80case SUB:81return "sub";82case SUBB:83return "subb";84case AND:85return "and";86case OR:87return "or";88case XOR:89return "xor";90case SHL:91return "sh";92case SRL:93return "sh";94case SRA:95return "sha";96default:97llvm_unreachable("Invalid ALU code.");98}99}100101inline static AluCode stringToLanaiAluCode(StringRef S) {102return StringSwitch<AluCode>(S)103.Case("add", ADD)104.Case("addc", ADDC)105.Case("sub", SUB)106.Case("subb", SUBB)107.Case("and", AND)108.Case("or", OR)109.Case("xor", XOR)110.Case("sh", SHL)111.Case("srl", SRL)112.Case("sha", SRA)113.Default(UNKNOWN);114}115} // namespace LPAC116} // namespace llvm117118#endif // LLVM_LIB_TARGET_LANAI_LANAIALUCODE_H119120121