Path: blob/main/contrib/llvm-project/llvm/lib/Target/VE/VE.h
35266 views
//===-- VE.h - Top-level interface for VE representation --------*- C++ -*-===//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// This file contains the entry points for global functions defined in the LLVM9// VE back-end.10//11//===----------------------------------------------------------------------===//1213#ifndef LLVM_LIB_TARGET_VE_VE_H14#define LLVM_LIB_TARGET_VE_VE_H1516#include "MCTargetDesc/VEMCTargetDesc.h"17#include "llvm/ADT/StringSwitch.h"18#include "llvm/Support/ErrorHandling.h"19#include "llvm/Target/TargetMachine.h"2021namespace llvm {22class AsmPrinter;23class FunctionPass;24class MCInst;25class MachineInstr;26class PassRegistry;27class VETargetMachine;2829FunctionPass *createVEISelDag(VETargetMachine &TM);30FunctionPass *createLVLGenPass();31void initializeVEDAGToDAGISelLegacyPass(PassRegistry &);3233void LowerVEMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI,34AsmPrinter &AP);35} // namespace llvm3637namespace llvm {38// Enums corresponding to VE condition codes, both icc's and fcc's. These39// values must be kept in sync with the ones in the .td file.40namespace VECC {41enum CondCode {42// Integer comparison43CC_IG = 0, // Greater44CC_IL = 1, // Less45CC_INE = 2, // Not Equal46CC_IEQ = 3, // Equal47CC_IGE = 4, // Greater or Equal48CC_ILE = 5, // Less or Equal4950// Floating point comparison51CC_AF = 0 + 6, // Never52CC_G = 1 + 6, // Greater53CC_L = 2 + 6, // Less54CC_NE = 3 + 6, // Not Equal55CC_EQ = 4 + 6, // Equal56CC_GE = 5 + 6, // Greater or Equal57CC_LE = 6 + 6, // Less or Equal58CC_NUM = 7 + 6, // Number59CC_NAN = 8 + 6, // NaN60CC_GNAN = 9 + 6, // Greater or NaN61CC_LNAN = 10 + 6, // Less or NaN62CC_NENAN = 11 + 6, // Not Equal or NaN63CC_EQNAN = 12 + 6, // Equal or NaN64CC_GENAN = 13 + 6, // Greater or Equal or NaN65CC_LENAN = 14 + 6, // Less or Equal or NaN66CC_AT = 15 + 6, // Always67UNKNOWN68};69}70// Enums corresponding to VE Rounding Mode. These values must be kept in71// sync with the ones in the .td file.72namespace VERD {73enum RoundingMode {74RD_NONE = 0, // According to PSW75RD_RZ = 8, // Round toward Zero76RD_RP = 9, // Round toward Plus infinity77RD_RM = 10, // Round toward Minus infinity78RD_RN = 11, // Round to Nearest (ties to Even)79RD_RA = 12, // Round to Nearest (ties to Away)80UNKNOWN81};82}8384inline static const char *VECondCodeToString(VECC::CondCode CC) {85switch (CC) {86case VECC::CC_IG: return "gt";87case VECC::CC_IL: return "lt";88case VECC::CC_INE: return "ne";89case VECC::CC_IEQ: return "eq";90case VECC::CC_IGE: return "ge";91case VECC::CC_ILE: return "le";92case VECC::CC_AF: return "af";93case VECC::CC_G: return "gt";94case VECC::CC_L: return "lt";95case VECC::CC_NE: return "ne";96case VECC::CC_EQ: return "eq";97case VECC::CC_GE: return "ge";98case VECC::CC_LE: return "le";99case VECC::CC_NUM: return "num";100case VECC::CC_NAN: return "nan";101case VECC::CC_GNAN: return "gtnan";102case VECC::CC_LNAN: return "ltnan";103case VECC::CC_NENAN: return "nenan";104case VECC::CC_EQNAN: return "eqnan";105case VECC::CC_GENAN: return "genan";106case VECC::CC_LENAN: return "lenan";107case VECC::CC_AT: return "at";108default:109llvm_unreachable("Invalid cond code");110}111}112113inline static VECC::CondCode stringToVEICondCode(StringRef S) {114return StringSwitch<VECC::CondCode>(S)115.Case("gt", VECC::CC_IG)116.Case("lt", VECC::CC_IL)117.Case("ne", VECC::CC_INE)118.Case("eq", VECC::CC_IEQ)119.Case("ge", VECC::CC_IGE)120.Case("le", VECC::CC_ILE)121.Case("af", VECC::CC_AF)122.Case("at", VECC::CC_AT)123.Case("", VECC::CC_AT)124.Default(VECC::UNKNOWN);125}126127inline static VECC::CondCode stringToVEFCondCode(StringRef S) {128return StringSwitch<VECC::CondCode>(S)129.Case("gt", VECC::CC_G)130.Case("lt", VECC::CC_L)131.Case("ne", VECC::CC_NE)132.Case("eq", VECC::CC_EQ)133.Case("ge", VECC::CC_GE)134.Case("le", VECC::CC_LE)135.Case("num", VECC::CC_NUM)136.Case("nan", VECC::CC_NAN)137.Case("gtnan", VECC::CC_GNAN)138.Case("ltnan", VECC::CC_LNAN)139.Case("nenan", VECC::CC_NENAN)140.Case("eqnan", VECC::CC_EQNAN)141.Case("genan", VECC::CC_GENAN)142.Case("lenan", VECC::CC_LENAN)143.Case("af", VECC::CC_AF)144.Case("at", VECC::CC_AT)145.Case("", VECC::CC_AT)146.Default(VECC::UNKNOWN);147}148149inline static bool isIntVECondCode(VECC::CondCode CC) {150return CC < VECC::CC_AF;151}152153inline static unsigned VECondCodeToVal(VECC::CondCode CC) {154switch (CC) {155case VECC::CC_IG:156return 1;157case VECC::CC_IL:158return 2;159case VECC::CC_INE:160return 3;161case VECC::CC_IEQ:162return 4;163case VECC::CC_IGE:164return 5;165case VECC::CC_ILE:166return 6;167case VECC::CC_AF:168return 0;169case VECC::CC_G:170return 1;171case VECC::CC_L:172return 2;173case VECC::CC_NE:174return 3;175case VECC::CC_EQ:176return 4;177case VECC::CC_GE:178return 5;179case VECC::CC_LE:180return 6;181case VECC::CC_NUM:182return 7;183case VECC::CC_NAN:184return 8;185case VECC::CC_GNAN:186return 9;187case VECC::CC_LNAN:188return 10;189case VECC::CC_NENAN:190return 11;191case VECC::CC_EQNAN:192return 12;193case VECC::CC_GENAN:194return 13;195case VECC::CC_LENAN:196return 14;197case VECC::CC_AT:198return 15;199default:200llvm_unreachable("Invalid cond code");201}202}203204inline static VECC::CondCode VEValToCondCode(unsigned Val, bool IsInteger) {205if (IsInteger) {206switch (Val) {207case 0:208return VECC::CC_AF;209case 1:210return VECC::CC_IG;211case 2:212return VECC::CC_IL;213case 3:214return VECC::CC_INE;215case 4:216return VECC::CC_IEQ;217case 5:218return VECC::CC_IGE;219case 6:220return VECC::CC_ILE;221case 15:222return VECC::CC_AT;223}224} else {225switch (Val) {226case 0:227return VECC::CC_AF;228case 1:229return VECC::CC_G;230case 2:231return VECC::CC_L;232case 3:233return VECC::CC_NE;234case 4:235return VECC::CC_EQ;236case 5:237return VECC::CC_GE;238case 6:239return VECC::CC_LE;240case 7:241return VECC::CC_NUM;242case 8:243return VECC::CC_NAN;244case 9:245return VECC::CC_GNAN;246case 10:247return VECC::CC_LNAN;248case 11:249return VECC::CC_NENAN;250case 12:251return VECC::CC_EQNAN;252case 13:253return VECC::CC_GENAN;254case 14:255return VECC::CC_LENAN;256case 15:257return VECC::CC_AT;258}259}260llvm_unreachable("Invalid cond code");261}262263inline static const char *VERDToString(VERD::RoundingMode R) {264switch (R) {265case VERD::RD_NONE:266return "";267case VERD::RD_RZ:268return ".rz";269case VERD::RD_RP:270return ".rp";271case VERD::RD_RM:272return ".rm";273case VERD::RD_RN:274return ".rn";275case VERD::RD_RA:276return ".ra";277default:278llvm_unreachable("Invalid branch predicate");279}280}281282inline static VERD::RoundingMode stringToVERD(StringRef S) {283return StringSwitch<VERD::RoundingMode>(S)284.Case("", VERD::RD_NONE)285.Case(".rz", VERD::RD_RZ)286.Case(".rp", VERD::RD_RP)287.Case(".rm", VERD::RD_RM)288.Case(".rn", VERD::RD_RN)289.Case(".ra", VERD::RD_RA)290.Default(VERD::UNKNOWN);291}292293inline static unsigned VERDToVal(VERD::RoundingMode R) {294switch (R) {295case VERD::RD_NONE:296case VERD::RD_RZ:297case VERD::RD_RP:298case VERD::RD_RM:299case VERD::RD_RN:300case VERD::RD_RA:301return static_cast<unsigned>(R);302default:303break;304}305llvm_unreachable("Invalid branch predicates");306}307308inline static VERD::RoundingMode VEValToRD(unsigned Val) {309switch (Val) {310case static_cast<unsigned>(VERD::RD_NONE):311return VERD::RD_NONE;312case static_cast<unsigned>(VERD::RD_RZ):313return VERD::RD_RZ;314case static_cast<unsigned>(VERD::RD_RP):315return VERD::RD_RP;316case static_cast<unsigned>(VERD::RD_RM):317return VERD::RD_RM;318case static_cast<unsigned>(VERD::RD_RN):319return VERD::RD_RN;320case static_cast<unsigned>(VERD::RD_RA):321return VERD::RD_RA;322default:323break;324}325llvm_unreachable("Invalid branch predicates");326}327328// MImm - Special immediate value of sequential bit stream of 0 or 1.329// See VEInstrInfo.td for details.330inline static bool isMImmVal(uint64_t Val) {331if (Val == 0) {332// (0)1 is 0333return true;334}335if (isMask_64(Val)) {336// (m)0 patterns337return true;338}339// (m)1 patterns340return (Val & (UINT64_C(1) << 63)) && isShiftedMask_64(Val);341}342343inline static bool isMImm32Val(uint32_t Val) {344if (Val == 0) {345// (0)1 is 0346return true;347}348if (isMask_32(Val)) {349// (m)0 patterns350return true;351}352// (m)1 patterns353return (Val & (UINT32_C(1) << 31)) && isShiftedMask_32(Val);354}355356/// val2MImm - Convert an integer immediate value to target MImm immediate.357inline static uint64_t val2MImm(uint64_t Val) {358if (Val == 0)359return 0; // (0)1360if (Val & (UINT64_C(1) << 63))361return llvm::countl_one(Val); // (m)1362return llvm::countl_zero(Val) | 0x40; // (m)0363}364365/// mimm2Val - Convert a target MImm immediate to an integer immediate value.366inline static uint64_t mimm2Val(uint64_t Val) {367if (Val == 0)368return 0; // (0)1369if ((Val & 0x40) == 0)370return (uint64_t)((INT64_C(1) << 63) >> (Val & 0x3f)); // (m)1371return ((uint64_t)INT64_C(-1) >> (Val & 0x3f)); // (m)0372}373374inline unsigned M0(unsigned Val) { return Val + 64; }375inline unsigned M1(unsigned Val) { return Val; }376377static const unsigned StandardVectorWidth = 256;378static const unsigned PackedVectorWidth = 512;379380} // namespace llvm381#endif382383384