Path: blob/main/contrib/llvm-project/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.h
35294 views
//===-- PPCMCTargetDesc.h - PowerPC Target Descriptions ---------*- 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 provides PowerPC specific target descriptions.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCTARGETDESC_H13#define LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCTARGETDESC_H1415// GCC #defines PPC on Linux but we use it as our namespace name16#undef PPC1718#include "llvm/MC/MCRegisterInfo.h"19#include "llvm/Support/MathExtras.h"20#include <cstdint>21#include <memory>2223namespace llvm {2425class MCAsmBackend;26class MCCodeEmitter;27class MCContext;28class MCInstrDesc;29class MCInstrInfo;30class MCObjectTargetWriter;31class MCRegisterInfo;32class MCSubtargetInfo;33class MCTargetOptions;34class Target;3536namespace PPC {37/// stripRegisterPrefix - This method strips the character prefix from a38/// register name so that only the number is left. Used by for linux asm.39const char *stripRegisterPrefix(const char *RegName);4041/// getRegNumForOperand - some operands use different numbering schemes42/// for the same registers. For example, a VSX instruction may have any of43/// vs0-vs63 allocated whereas an Altivec instruction could only have44/// vs32-vs63 allocated (numbered as v0-v31). This function returns the actual45/// register number needed for the opcode/operand number combination.46/// The operand number argument will be useful when we need to extend this47/// to instructions that use both Altivec and VSX numbering (for different48/// operands).49unsigned getRegNumForOperand(const MCInstrDesc &Desc, unsigned Reg,50unsigned OpNo);5152} // namespace PPC5354MCCodeEmitter *createPPCMCCodeEmitter(const MCInstrInfo &MCII,55MCContext &Ctx);5657MCAsmBackend *createPPCAsmBackend(const Target &T, const MCSubtargetInfo &STI,58const MCRegisterInfo &MRI,59const MCTargetOptions &Options);6061/// Construct an PPC ELF object writer.62std::unique_ptr<MCObjectTargetWriter> createPPCELFObjectWriter(bool Is64Bit,63uint8_t OSABI);64/// Construct a PPC Mach-O object writer.65std::unique_ptr<MCObjectTargetWriter>66createPPCMachObjectWriter(bool Is64Bit, uint32_t CPUType, uint32_t CPUSubtype);6768/// Construct a PPC XCOFF object writer.69std::unique_ptr<MCObjectTargetWriter> createPPCXCOFFObjectWriter(bool Is64Bit);7071/// Returns true iff Val consists of one contiguous run of 1s with any number of72/// 0s on either side. The 1s are allowed to wrap from LSB to MSB, so73/// 0x000FFF0, 0x0000FFFF, and 0xFF0000FF are all runs. 0x0F0F0000 is not,74/// since all 1s are not contiguous.75static inline bool isRunOfOnes(unsigned Val, unsigned &MB, unsigned &ME) {76if (!Val)77return false;7879if (isShiftedMask_32(Val)) {80// look for the first non-zero bit81MB = llvm::countl_zero(Val);82// look for the first zero bit after the run of ones83ME = llvm::countl_zero((Val - 1) ^ Val);84return true;85} else {86Val = ~Val; // invert mask87if (isShiftedMask_32(Val)) {88// effectively look for the first zero bit89ME = llvm::countl_zero(Val) - 1;90// effectively look for the first one bit after the run of zeros91MB = llvm::countl_zero((Val - 1) ^ Val) + 1;92return true;93}94}95// no run present96return false;97}9899static inline bool isRunOfOnes64(uint64_t Val, unsigned &MB, unsigned &ME) {100if (!Val)101return false;102103if (isShiftedMask_64(Val)) {104// look for the first non-zero bit105MB = llvm::countl_zero(Val);106// look for the first zero bit after the run of ones107ME = llvm::countl_zero((Val - 1) ^ Val);108return true;109} else {110Val = ~Val; // invert mask111if (isShiftedMask_64(Val)) {112// effectively look for the first zero bit113ME = llvm::countl_zero(Val) - 1;114// effectively look for the first one bit after the run of zeros115MB = llvm::countl_zero((Val - 1) ^ Val) + 1;116return true;117}118}119// no run present120return false;121}122123/// PPCII - This namespace holds all of the PowerPC target-specific124/// per-instruction flags. These must match the corresponding definitions in125/// PPC.td and PPCInstrFormats.td.126namespace PPCII {127enum {128// PPC970 Instruction Flags. These flags describe the characteristics of the129// PowerPC 970 (aka G5) dispatch groups and how they are formed out of130// raw machine instructions.131132/// PPC970_First - This instruction starts a new dispatch group, so it will133/// always be the first one in the group.134PPC970_First = 0x1,135136/// PPC970_Single - This instruction starts a new dispatch group and137/// terminates it, so it will be the sole instruction in the group.138PPC970_Single = 0x2,139140/// PPC970_Cracked - This instruction is cracked into two pieces, requiring141/// two dispatch pipes to be available to issue.142PPC970_Cracked = 0x4,143144/// PPC970_Mask/Shift - This is a bitmask that selects the pipeline type that145/// an instruction is issued to.146PPC970_Shift = 3,147PPC970_Mask = 0x07 << PPC970_Shift148};149enum PPC970_Unit {150/// These are the various PPC970 execution unit pipelines. Each instruction151/// is one of these.152PPC970_Pseudo = 0 << PPC970_Shift, // Pseudo instruction153PPC970_FXU = 1 << PPC970_Shift, // Fixed Point (aka Integer/ALU) Unit154PPC970_LSU = 2 << PPC970_Shift, // Load Store Unit155PPC970_FPU = 3 << PPC970_Shift, // Floating Point Unit156PPC970_CRU = 4 << PPC970_Shift, // Control Register Unit157PPC970_VALU = 5 << PPC970_Shift, // Vector ALU158PPC970_VPERM = 6 << PPC970_Shift, // Vector Permute Unit159PPC970_BRU = 7 << PPC970_Shift // Branch Unit160};161162enum {163/// Shift count to bypass PPC970 flags164NewDef_Shift = 6,165166/// This instruction is an X-Form memory operation.167XFormMemOp = 0x1 << NewDef_Shift,168/// This instruction is prefixed.169Prefixed = 0x1 << (NewDef_Shift + 1),170/// This instruction produced a sign extended result.171SExt32To64 = 0x1 << (NewDef_Shift + 2),172/// This instruction produced a zero extended result.173ZExt32To64 = 0x1 << (NewDef_Shift + 3)174};175} // end namespace PPCII176177} // end namespace llvm178179// Defines symbolic names for PowerPC registers. This defines a mapping from180// register name to register number.181//182#define GET_REGINFO_ENUM183#include "PPCGenRegisterInfo.inc"184185// Defines symbolic names for the PowerPC instructions.186//187#define GET_INSTRINFO_ENUM188#define GET_INSTRINFO_SCHED_ENUM189#define GET_INSTRINFO_MC_HELPER_DECLS190#include "PPCGenInstrInfo.inc"191192#define GET_SUBTARGETINFO_ENUM193#include "PPCGenSubtargetInfo.inc"194195#define PPC_REGS0_7(X) \196{ \197X##0, X##1, X##2, X##3, X##4, X##5, X##6, X##7 \198}199200#define PPC_REGS0_31(X) \201{ \202X##0, X##1, X##2, X##3, X##4, X##5, X##6, X##7, X##8, X##9, X##10, X##11, \203X##12, X##13, X##14, X##15, X##16, X##17, X##18, X##19, X##20, X##21, \204X##22, X##23, X##24, X##25, X##26, X##27, X##28, X##29, X##30, X##31 \205}206207#define PPC_REGS_EVEN0_30(X) \208{ \209X##0, X##2, X##4, X##6, X##8, X##10, X##12, X##14, X##16, X##18, X##20, \210X##22, X##24, X##26, X##28, X##30 \211}212213#define PPC_REGS0_63(X) \214{ \215X##0, X##1, X##2, X##3, X##4, X##5, X##6, X##7, X##8, X##9, X##10, X##11, \216X##12, X##13, X##14, X##15, X##16, X##17, X##18, X##19, X##20, X##21, \217X##22, X##23, X##24, X##25, X##26, X##27, X##28, X##29, X##30, X##31, \218X##32, X##33, X##34, X##35, X##36, X##37, X##38, X##39, X##40, X##41, \219X##42, X##43, X##44, X##45, X##46, X##47, X##48, X##49, X##50, X##51, \220X##52, X##53, X##54, X##55, X##56, X##57, X##58, X##59, X##60, X##61, \221X##62, X##63 \222}223224#define PPC_REGS_NO0_31(Z, X) \225{ \226Z, X##1, X##2, X##3, X##4, X##5, X##6, X##7, X##8, X##9, X##10, X##11, \227X##12, X##13, X##14, X##15, X##16, X##17, X##18, X##19, X##20, X##21, \228X##22, X##23, X##24, X##25, X##26, X##27, X##28, X##29, X##30, X##31 \229}230231#define PPC_REGS_LO_HI(LO, HI) \232{ \233LO##0, LO##1, LO##2, LO##3, LO##4, LO##5, LO##6, LO##7, LO##8, LO##9, \234LO##10, LO##11, LO##12, LO##13, LO##14, LO##15, LO##16, LO##17, \235LO##18, LO##19, LO##20, LO##21, LO##22, LO##23, LO##24, LO##25, \236LO##26, LO##27, LO##28, LO##29, LO##30, LO##31, HI##0, HI##1, HI##2, \237HI##3, HI##4, HI##5, HI##6, HI##7, HI##8, HI##9, HI##10, HI##11, \238HI##12, HI##13, HI##14, HI##15, HI##16, HI##17, HI##18, HI##19, \239HI##20, HI##21, HI##22, HI##23, HI##24, HI##25, HI##26, HI##27, \240HI##28, HI##29, HI##30, HI##31 \241}242243#define PPC_REGS0_7(X) \244{ \245X##0, X##1, X##2, X##3, X##4, X##5, X##6, X##7 \246}247248#define PPC_REGS0_3(X) \249{ \250X##0, X##1, X##2, X##3 \251}252253using llvm::MCPhysReg;254255#define DEFINE_PPC_REGCLASSES \256static const MCPhysReg RRegs[32] = PPC_REGS0_31(PPC::R); \257static const MCPhysReg XRegs[32] = PPC_REGS0_31(PPC::X); \258static const MCPhysReg FRegs[32] = PPC_REGS0_31(PPC::F); \259static const MCPhysReg FpRegs[16] = PPC_REGS_EVEN0_30(PPC::Fpair); \260static const MCPhysReg VSRpRegs[32] = PPC_REGS0_31(PPC::VSRp); \261static const MCPhysReg SPERegs[32] = PPC_REGS0_31(PPC::S); \262static const MCPhysReg VFRegs[32] = PPC_REGS0_31(PPC::VF); \263static const MCPhysReg VRegs[32] = PPC_REGS0_31(PPC::V); \264static const MCPhysReg RRegsNoR0[32] = PPC_REGS_NO0_31(PPC::ZERO, PPC::R); \265static const MCPhysReg XRegsNoX0[32] = PPC_REGS_NO0_31(PPC::ZERO8, PPC::X); \266static const MCPhysReg VSRegs[64] = PPC_REGS_LO_HI(PPC::VSL, PPC::V); \267static const MCPhysReg VSFRegs[64] = PPC_REGS_LO_HI(PPC::F, PPC::VF); \268static const MCPhysReg VSSRegs[64] = PPC_REGS_LO_HI(PPC::F, PPC::VF); \269static const MCPhysReg CRBITRegs[32] = { \270PPC::CR0LT, PPC::CR0GT, PPC::CR0EQ, PPC::CR0UN, PPC::CR1LT, PPC::CR1GT, \271PPC::CR1EQ, PPC::CR1UN, PPC::CR2LT, PPC::CR2GT, PPC::CR2EQ, PPC::CR2UN, \272PPC::CR3LT, PPC::CR3GT, PPC::CR3EQ, PPC::CR3UN, PPC::CR4LT, PPC::CR4GT, \273PPC::CR4EQ, PPC::CR4UN, PPC::CR5LT, PPC::CR5GT, PPC::CR5EQ, PPC::CR5UN, \274PPC::CR6LT, PPC::CR6GT, PPC::CR6EQ, PPC::CR6UN, PPC::CR7LT, PPC::CR7GT, \275PPC::CR7EQ, PPC::CR7UN}; \276static const MCPhysReg CRRegs[8] = PPC_REGS0_7(PPC::CR); \277static const MCPhysReg ACCRegs[8] = PPC_REGS0_7(PPC::ACC); \278static const MCPhysReg WACCRegs[8] = PPC_REGS0_7(PPC::WACC); \279static const MCPhysReg WACC_HIRegs[8] = PPC_REGS0_7(PPC::WACC_HI); \280static const MCPhysReg DMRROWpRegs[32] = PPC_REGS0_31(PPC::DMRROWp); \281static const MCPhysReg DMRROWRegs[64] = PPC_REGS0_63(PPC::DMRROW); \282static const MCPhysReg DMRRegs[8] = PPC_REGS0_7(PPC::DMR); \283static const MCPhysReg DMRpRegs[4] = PPC_REGS0_3(PPC::DMRp);284285namespace llvm {286namespace PPC {287static inline bool isVFRegister(unsigned Reg) {288return Reg >= PPC::VF0 && Reg <= PPC::VF31;289}290291static inline bool isVRRegister(unsigned Reg) {292return Reg >= PPC::V0 && Reg <= PPC::V31;293}294} // namespace PPC295} // namespace llvm296297#endif // LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCTARGETDESC_H298299300