Path: blob/main/contrib/llvm-project/llvm/lib/Target/M68k/MCTargetDesc/M68kBaseInfo.h
35294 views
//===-- M68kBaseInfo.h - Top level definitions for M68k MC ------*- 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/// \file9/// This file contains small standalone helper functions and enum definitions10/// for the M68k target useful for the compiler back-end and the MC11/// libraries. As such, it deliberately does not include references to LLVM12/// core code gen types, passes, etc..13///14//===----------------------------------------------------------------------===//1516#ifndef LLVM_LIB_TARGET_M68K_MCTARGETDESC_M68KBASEINFO_H17#define LLVM_LIB_TARGET_M68K_MCTARGETDESC_M68KBASEINFO_H1819#include "M68kMCTargetDesc.h"2021#include "llvm/MC/MCExpr.h"22#include "llvm/Support/DataTypes.h"23#include "llvm/Support/Endian.h"24#include "llvm/Support/ErrorHandling.h"2526#define GET_INSTRINFO_MI_OPS_INFO27#define GET_INSTRINFO_OPERAND_TYPES_ENUM28#define GET_INSTRINFO_LOGICAL_OPERAND_SIZE_MAP29#include "M68kGenInstrInfo.inc"3031namespace llvm {3233namespace M68k {3435/// Enums for memory operand decoding. Supports these forms:36/// (d,An)37/// (d,An,Xn)38/// ([bd,An],Xn,od)39/// ([bd,An,Xn],od)40/// TODO Implement scaling other than 141enum { MemDisp = 0, MemBase = 1, MemIndex = 2, MemOuter = 3 };4243/// Enums for pc-relative memory operand decoding. Supports these forms:44/// (d,PC)45/// (d,PC,Xn)46/// ([bd,PC],Xn,od)47/// ([bd,PC,Xn],od)48enum { PCRelDisp = 0, PCRelIndex = 1, PCRelOuter = 2 };4950enum class MemAddrModeKind : unsigned {51j = 1, // (An)52o, // (An)+53e, // -(An)54p, // (d,An)55f, // (d,An,Xn.L)56F, // (d,An,Xn.W)57g, // (d,An,Xn.L,SCALE)58G, // (d,An,Xn.W,SCALE)59u, // ([bd,An],Xn.L,SCALE,od)60U, // ([bd,An],Xn.W,SCALE,od)61v, // ([bd,An,Xn.L,SCALE],od)62V, // ([bd,An,Xn.W,SCALE],od)63b, // abs.L64B, // abs.W65q, // (d,PC)66k, // (d,PC,Xn.L)67K, // (d,PC,Xn.W)68l, // (d,PC,Xn.L,SCALE)69L, // (d,PC,Xn.W,SCALE)70x, // ([bd,PC],Xn.L,SCALE,od)71X, // ([bd,PC],Xn.W,SCALE,od)72y, // ([bd,PC,Xn.L,SCALE],od)73Y // ([bd,PC,Xn.W,SCALE],od)74};7576// On a LE host:77// MSB LSB MSB LSB78// | 0x12 0x34 | 0xAB 0xCD | -> | 0xAB 0xCD | 0x12 0x34 |79// (On a BE host nothing changes)80template <typename value_t> value_t swapWord(value_t Val) {81const unsigned NumWords = sizeof(Val) / 2;82if (NumWords <= 1)83return Val;84Val = support::endian::byte_swap(Val, llvm::endianness::big);85value_t NewVal = 0;86for (unsigned i = 0U; i != NumWords; ++i) {87uint16_t Part = (Val >> (i * 16)) & 0xFFFF;88Part = support::endian::byte_swap(Part, llvm::endianness::big);89NewVal |= (Part << (i * 16));90}91return NewVal;92}93} // namespace M68k9495namespace M68kBeads {96enum {97Ctrl = 0x0,98Bits1 = 0x1,99Bits2 = 0x2,100Bits3 = 0x3,101Bits4 = 0x4,102DAReg = 0x5,103DA = 0x6,104Reg = 0x7,105DReg = 0x8,106Disp8 = 0x9,107Imm8 = 0xA,108Imm16 = 0xB,109Imm32 = 0xC,110Imm3 = 0xD,111};112113// Ctrl payload114enum {115Term = 0x0,116Ignore = 0x1,117};118} // namespace M68kBeads119120/// This namespace holds all of the target specific flags that instruction info121/// tracks.122namespace M68kII {123/// Target Operand Flag enum.124enum TOF {125126MO_NO_FLAG,127128/// On a symbol operand this indicates that the immediate is the absolute129/// address of the symbol.130MO_ABSOLUTE_ADDRESS,131132/// On a symbol operand this indicates that the immediate is the pc-relative133/// address of the symbol.134MO_PC_RELATIVE_ADDRESS,135136/// On a symbol operand this indicates that the immediate is the offset to137/// the GOT entry for the symbol name from the base of the GOT.138///139/// name@GOT140MO_GOT,141142/// On a symbol operand this indicates that the immediate is the offset to143/// the location of the symbol name from the base of the GOT.144///145/// name@GOTOFF146MO_GOTOFF,147148/// On a symbol operand this indicates that the immediate is offset to the149/// GOT entry for the symbol name from the current code location.150///151/// name@GOTPCREL152MO_GOTPCREL,153154/// On a symbol operand this indicates that the immediate is offset to the155/// PLT entry of symbol name from the current code location.156///157/// name@PLT158MO_PLT,159160/// On a symbol operand, this indicates that the immediate is the offset to161/// the slot in GOT which stores the information for accessing the TLS162/// variable. This is used when operating in Global Dynamic mode.163/// name@TLSGD164MO_TLSGD,165166/// On a symbol operand, this indicates that the immediate is the offset to167/// variable within the thread local storage when operating in Local Dynamic168/// mode.169/// name@TLSLD170MO_TLSLD,171172/// On a symbol operand, this indicates that the immediate is the offset to173/// the slot in GOT which stores the information for accessing the TLS174/// variable. This is used when operating in Local Dynamic mode.175/// name@TLSLDM176MO_TLSLDM,177178/// On a symbol operand, this indicates that the immediate is the offset to179/// the variable within the thread local storage when operating in Initial180/// Exec mode.181/// name@TLSIE182MO_TLSIE,183184/// On a symbol operand, this indicates that the immediate is the offset to185/// the variable within in the thread local storage when operating in Local186/// Exec mode.187/// name@TLSLE188MO_TLSLE,189190}; // enum TOF191192/// Return true if the specified TargetFlag operand is a reference to a stub193/// for a global, not the global itself.194inline static bool isGlobalStubReference(unsigned char TargetFlag) {195switch (TargetFlag) {196default:197return false;198case M68kII::MO_GOTPCREL: // pc-relative GOT reference.199case M68kII::MO_GOT: // normal GOT reference.200return true;201}202}203204/// Return True if the specified GlobalValue is a direct reference for a205/// symbol.206inline static bool isDirectGlobalReference(unsigned char Flag) {207switch (Flag) {208default:209return false;210case M68kII::MO_NO_FLAG:211case M68kII::MO_ABSOLUTE_ADDRESS:212case M68kII::MO_PC_RELATIVE_ADDRESS:213return true;214}215}216217/// Return true if the specified global value reference is relative to a 32-bit218/// PIC base (M68kISD::GLOBAL_BASE_REG). If this is true, the addressing mode219/// has the PIC base register added in.220inline static bool isGlobalRelativeToPICBase(unsigned char TargetFlag) {221switch (TargetFlag) {222default:223return false;224case M68kII::MO_GOTOFF: // isPICStyleGOT: local global.225case M68kII::MO_GOT: // isPICStyleGOT: other global.226return true;227}228}229230/// Return True if the specified GlobalValue requires PC addressing mode.231inline static bool isPCRelGlobalReference(unsigned char Flag) {232switch (Flag) {233default:234return false;235case M68kII::MO_GOTPCREL:236case M68kII::MO_PC_RELATIVE_ADDRESS:237return true;238}239}240241/// Return True if the Block is referenced using PC242inline static bool isPCRelBlockReference(unsigned char Flag) {243switch (Flag) {244default:245return false;246case M68kII::MO_PC_RELATIVE_ADDRESS:247return true;248}249}250251static inline bool isAddressRegister(unsigned RegNo) {252switch (RegNo) {253case M68k::WA0:254case M68k::WA1:255case M68k::WA2:256case M68k::WA3:257case M68k::WA4:258case M68k::WA5:259case M68k::WA6:260case M68k::WSP:261case M68k::A0:262case M68k::A1:263case M68k::A2:264case M68k::A3:265case M68k::A4:266case M68k::A5:267case M68k::A6:268case M68k::SP:269return true;270default:271return false;272}273}274275static inline bool hasMultiMIOperands(unsigned Op, unsigned LogicalOpIdx) {276return M68k::getLogicalOperandSize(Op, LogicalOpIdx) > 1;277}278279static inline unsigned getMaskedSpillRegister(unsigned order) {280switch (order) {281default:282return 0;283case 0:284return M68k::D0;285case 1:286return M68k::D1;287case 2:288return M68k::D2;289case 3:290return M68k::D3;291case 4:292return M68k::D4;293case 5:294return M68k::D5;295case 6:296return M68k::D6;297case 7:298return M68k::D7;299case 8:300return M68k::A0;301case 9:302return M68k::A1;303case 10:304return M68k::A2;305case 11:306return M68k::A3;307case 12:308return M68k::A4;309case 13:310return M68k::A5;311case 14:312return M68k::A6;313case 15:314return M68k::SP;315}316}317318} // namespace M68kII319320} // namespace llvm321322#endif // LLVM_LIB_TARGET_M68K_MCTARGETDESC_M68KBASEINFO_H323324325