Path: blob/main/contrib/llvm-project/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.cpp
35294 views
//===-- SystemZMCTargetDesc.cpp - SystemZ target descriptions -------------===//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//===----------------------------------------------------------------------===//78#include "SystemZMCTargetDesc.h"9#include "SystemZInstPrinter.h"10#include "SystemZMCAsmInfo.h"11#include "SystemZTargetStreamer.h"12#include "TargetInfo/SystemZTargetInfo.h"13#include "llvm/MC/MCContext.h"14#include "llvm/MC/MCDwarf.h"15#include "llvm/MC/MCInst.h"16#include "llvm/MC/MCInstrInfo.h"17#include "llvm/MC/MCRegisterInfo.h"18#include "llvm/MC/MCStreamer.h"19#include "llvm/MC/MCSubtargetInfo.h"20#include "llvm/MC/TargetRegistry.h"2122using namespace llvm;2324#define GET_INSTRINFO_MC_DESC25#define ENABLE_INSTR_PREDICATE_VERIFIER26#include "SystemZGenInstrInfo.inc"2728#define GET_SUBTARGETINFO_MC_DESC29#include "SystemZGenSubtargetInfo.inc"3031#define GET_REGINFO_MC_DESC32#include "SystemZGenRegisterInfo.inc"3334const unsigned SystemZMC::GR32Regs[16] = {35SystemZ::R0L, SystemZ::R1L, SystemZ::R2L, SystemZ::R3L,36SystemZ::R4L, SystemZ::R5L, SystemZ::R6L, SystemZ::R7L,37SystemZ::R8L, SystemZ::R9L, SystemZ::R10L, SystemZ::R11L,38SystemZ::R12L, SystemZ::R13L, SystemZ::R14L, SystemZ::R15L39};4041const unsigned SystemZMC::GRH32Regs[16] = {42SystemZ::R0H, SystemZ::R1H, SystemZ::R2H, SystemZ::R3H,43SystemZ::R4H, SystemZ::R5H, SystemZ::R6H, SystemZ::R7H,44SystemZ::R8H, SystemZ::R9H, SystemZ::R10H, SystemZ::R11H,45SystemZ::R12H, SystemZ::R13H, SystemZ::R14H, SystemZ::R15H46};4748const unsigned SystemZMC::GR64Regs[16] = {49SystemZ::R0D, SystemZ::R1D, SystemZ::R2D, SystemZ::R3D,50SystemZ::R4D, SystemZ::R5D, SystemZ::R6D, SystemZ::R7D,51SystemZ::R8D, SystemZ::R9D, SystemZ::R10D, SystemZ::R11D,52SystemZ::R12D, SystemZ::R13D, SystemZ::R14D, SystemZ::R15D53};5455const unsigned SystemZMC::GR128Regs[16] = {56SystemZ::R0Q, 0, SystemZ::R2Q, 0,57SystemZ::R4Q, 0, SystemZ::R6Q, 0,58SystemZ::R8Q, 0, SystemZ::R10Q, 0,59SystemZ::R12Q, 0, SystemZ::R14Q, 060};6162const unsigned SystemZMC::FP32Regs[16] = {63SystemZ::F0S, SystemZ::F1S, SystemZ::F2S, SystemZ::F3S,64SystemZ::F4S, SystemZ::F5S, SystemZ::F6S, SystemZ::F7S,65SystemZ::F8S, SystemZ::F9S, SystemZ::F10S, SystemZ::F11S,66SystemZ::F12S, SystemZ::F13S, SystemZ::F14S, SystemZ::F15S67};6869const unsigned SystemZMC::FP64Regs[16] = {70SystemZ::F0D, SystemZ::F1D, SystemZ::F2D, SystemZ::F3D,71SystemZ::F4D, SystemZ::F5D, SystemZ::F6D, SystemZ::F7D,72SystemZ::F8D, SystemZ::F9D, SystemZ::F10D, SystemZ::F11D,73SystemZ::F12D, SystemZ::F13D, SystemZ::F14D, SystemZ::F15D74};7576const unsigned SystemZMC::FP128Regs[16] = {77SystemZ::F0Q, SystemZ::F1Q, 0, 0,78SystemZ::F4Q, SystemZ::F5Q, 0, 0,79SystemZ::F8Q, SystemZ::F9Q, 0, 0,80SystemZ::F12Q, SystemZ::F13Q, 0, 081};8283const unsigned SystemZMC::VR32Regs[32] = {84SystemZ::F0S, SystemZ::F1S, SystemZ::F2S, SystemZ::F3S,85SystemZ::F4S, SystemZ::F5S, SystemZ::F6S, SystemZ::F7S,86SystemZ::F8S, SystemZ::F9S, SystemZ::F10S, SystemZ::F11S,87SystemZ::F12S, SystemZ::F13S, SystemZ::F14S, SystemZ::F15S,88SystemZ::F16S, SystemZ::F17S, SystemZ::F18S, SystemZ::F19S,89SystemZ::F20S, SystemZ::F21S, SystemZ::F22S, SystemZ::F23S,90SystemZ::F24S, SystemZ::F25S, SystemZ::F26S, SystemZ::F27S,91SystemZ::F28S, SystemZ::F29S, SystemZ::F30S, SystemZ::F31S92};9394const unsigned SystemZMC::VR64Regs[32] = {95SystemZ::F0D, SystemZ::F1D, SystemZ::F2D, SystemZ::F3D,96SystemZ::F4D, SystemZ::F5D, SystemZ::F6D, SystemZ::F7D,97SystemZ::F8D, SystemZ::F9D, SystemZ::F10D, SystemZ::F11D,98SystemZ::F12D, SystemZ::F13D, SystemZ::F14D, SystemZ::F15D,99SystemZ::F16D, SystemZ::F17D, SystemZ::F18D, SystemZ::F19D,100SystemZ::F20D, SystemZ::F21D, SystemZ::F22D, SystemZ::F23D,101SystemZ::F24D, SystemZ::F25D, SystemZ::F26D, SystemZ::F27D,102SystemZ::F28D, SystemZ::F29D, SystemZ::F30D, SystemZ::F31D103};104105const unsigned SystemZMC::VR128Regs[32] = {106SystemZ::V0, SystemZ::V1, SystemZ::V2, SystemZ::V3,107SystemZ::V4, SystemZ::V5, SystemZ::V6, SystemZ::V7,108SystemZ::V8, SystemZ::V9, SystemZ::V10, SystemZ::V11,109SystemZ::V12, SystemZ::V13, SystemZ::V14, SystemZ::V15,110SystemZ::V16, SystemZ::V17, SystemZ::V18, SystemZ::V19,111SystemZ::V20, SystemZ::V21, SystemZ::V22, SystemZ::V23,112SystemZ::V24, SystemZ::V25, SystemZ::V26, SystemZ::V27,113SystemZ::V28, SystemZ::V29, SystemZ::V30, SystemZ::V31114};115116const unsigned SystemZMC::AR32Regs[16] = {117SystemZ::A0, SystemZ::A1, SystemZ::A2, SystemZ::A3,118SystemZ::A4, SystemZ::A5, SystemZ::A6, SystemZ::A7,119SystemZ::A8, SystemZ::A9, SystemZ::A10, SystemZ::A11,120SystemZ::A12, SystemZ::A13, SystemZ::A14, SystemZ::A15121};122123const unsigned SystemZMC::CR64Regs[16] = {124SystemZ::C0, SystemZ::C1, SystemZ::C2, SystemZ::C3,125SystemZ::C4, SystemZ::C5, SystemZ::C6, SystemZ::C7,126SystemZ::C8, SystemZ::C9, SystemZ::C10, SystemZ::C11,127SystemZ::C12, SystemZ::C13, SystemZ::C14, SystemZ::C15128};129130unsigned SystemZMC::getFirstReg(unsigned Reg) {131static unsigned Map[SystemZ::NUM_TARGET_REGS];132static bool Initialized = false;133if (!Initialized) {134for (unsigned I = 0; I < 16; ++I) {135Map[GR32Regs[I]] = I;136Map[GRH32Regs[I]] = I;137Map[GR64Regs[I]] = I;138Map[GR128Regs[I]] = I;139Map[FP128Regs[I]] = I;140Map[AR32Regs[I]] = I;141}142for (unsigned I = 0; I < 32; ++I) {143Map[VR32Regs[I]] = I;144Map[VR64Regs[I]] = I;145Map[VR128Regs[I]] = I;146}147}148assert(Reg < SystemZ::NUM_TARGET_REGS);149return Map[Reg];150}151152static MCAsmInfo *createSystemZMCAsmInfo(const MCRegisterInfo &MRI,153const Triple &TT,154const MCTargetOptions &Options) {155if (TT.isOSzOS())156return new SystemZMCAsmInfoGOFF(TT);157158MCAsmInfo *MAI = new SystemZMCAsmInfoELF(TT);159MCCFIInstruction Inst = MCCFIInstruction::cfiDefCfa(160nullptr, MRI.getDwarfRegNum(SystemZ::R15D, true),161SystemZMC::ELFCFAOffsetFromInitialSP);162MAI->addInitialFrameState(Inst);163return MAI;164}165166static MCInstrInfo *createSystemZMCInstrInfo() {167MCInstrInfo *X = new MCInstrInfo();168InitSystemZMCInstrInfo(X);169return X;170}171172static MCRegisterInfo *createSystemZMCRegisterInfo(const Triple &TT) {173MCRegisterInfo *X = new MCRegisterInfo();174InitSystemZMCRegisterInfo(X, SystemZ::R14D);175return X;176}177178static MCSubtargetInfo *179createSystemZMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {180return createSystemZMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);181}182183static MCInstPrinter *createSystemZMCInstPrinter(const Triple &T,184unsigned SyntaxVariant,185const MCAsmInfo &MAI,186const MCInstrInfo &MII,187const MCRegisterInfo &MRI) {188return new SystemZInstPrinter(MAI, MII, MRI);189}190191void SystemZTargetStreamer::emitConstantPools() {192// Emit EXRL target instructions.193if (EXRLTargets2Sym.empty())194return;195// Switch to the .text section.196const MCObjectFileInfo &OFI = *Streamer.getContext().getObjectFileInfo();197Streamer.switchSection(OFI.getTextSection());198for (auto &I : EXRLTargets2Sym) {199Streamer.emitLabel(I.second);200const MCInstSTIPair &MCI_STI = I.first;201Streamer.emitInstruction(MCI_STI.first, *MCI_STI.second);202}203EXRLTargets2Sym.clear();204}205206namespace {207class SystemZTargetAsmStreamer : public SystemZTargetStreamer {208formatted_raw_ostream &OS;209210public:211SystemZTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS)212: SystemZTargetStreamer(S), OS(OS) {}213void emitMachine(StringRef CPU) override {214OS << "\t.machine " << CPU << "\n";215}216};217218class SystemZTargetELFStreamer : public SystemZTargetStreamer {219public:220SystemZTargetELFStreamer(MCStreamer &S) : SystemZTargetStreamer(S) {}221void emitMachine(StringRef CPU) override {}222};223} // end namespace224225static MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,226formatted_raw_ostream &OS,227MCInstPrinter *InstPrint) {228return new SystemZTargetAsmStreamer(S, OS);229}230231static MCTargetStreamer *232createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {233return new SystemZTargetELFStreamer(S);234}235236static MCTargetStreamer *237createNullTargetStreamer(MCStreamer &S) {238return new SystemZTargetStreamer(S);239}240241extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSystemZTargetMC() {242// Register the MCAsmInfo.243TargetRegistry::RegisterMCAsmInfo(getTheSystemZTarget(),244createSystemZMCAsmInfo);245246// Register the MCCodeEmitter.247TargetRegistry::RegisterMCCodeEmitter(getTheSystemZTarget(),248createSystemZMCCodeEmitter);249250// Register the MCInstrInfo.251TargetRegistry::RegisterMCInstrInfo(getTheSystemZTarget(),252createSystemZMCInstrInfo);253254// Register the MCRegisterInfo.255TargetRegistry::RegisterMCRegInfo(getTheSystemZTarget(),256createSystemZMCRegisterInfo);257258// Register the MCSubtargetInfo.259TargetRegistry::RegisterMCSubtargetInfo(getTheSystemZTarget(),260createSystemZMCSubtargetInfo);261262// Register the MCAsmBackend.263TargetRegistry::RegisterMCAsmBackend(getTheSystemZTarget(),264createSystemZMCAsmBackend);265266// Register the MCInstPrinter.267TargetRegistry::RegisterMCInstPrinter(getTheSystemZTarget(),268createSystemZMCInstPrinter);269270// Register the asm streamer.271TargetRegistry::RegisterAsmTargetStreamer(getTheSystemZTarget(),272createAsmTargetStreamer);273274// Register the obj streamer275TargetRegistry::RegisterObjectTargetStreamer(getTheSystemZTarget(),276createObjectTargetStreamer);277278// Register the null streamer279TargetRegistry::RegisterNullTargetStreamer(getTheSystemZTarget(),280createNullTargetStreamer);281}282283284