10b57cec5SDimitry Andric //===-- MSP430MCTargetDesc.cpp - MSP430 Target Descriptions ---------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file provides MSP430 specific target descriptions.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric #include "MSP430MCTargetDesc.h"
140b57cec5SDimitry Andric #include "MSP430InstPrinter.h"
150b57cec5SDimitry Andric #include "MSP430MCAsmInfo.h"
160b57cec5SDimitry Andric #include "TargetInfo/MSP430TargetInfo.h"
17*06c3fb27SDimitry Andric #include "llvm/MC/MCDwarf.h"
180b57cec5SDimitry Andric #include "llvm/MC/MCInstrInfo.h"
190b57cec5SDimitry Andric #include "llvm/MC/MCRegisterInfo.h"
200b57cec5SDimitry Andric #include "llvm/MC/MCSubtargetInfo.h"
21349cc55cSDimitry Andric #include "llvm/MC/TargetRegistry.h"
220b57cec5SDimitry Andric
230b57cec5SDimitry Andric using namespace llvm;
240b57cec5SDimitry Andric
250b57cec5SDimitry Andric #define GET_INSTRINFO_MC_DESC
26753f127fSDimitry Andric #define ENABLE_INSTR_PREDICATE_VERIFIER
270b57cec5SDimitry Andric #include "MSP430GenInstrInfo.inc"
280b57cec5SDimitry Andric
290b57cec5SDimitry Andric #define GET_SUBTARGETINFO_MC_DESC
300b57cec5SDimitry Andric #include "MSP430GenSubtargetInfo.inc"
310b57cec5SDimitry Andric
320b57cec5SDimitry Andric #define GET_REGINFO_MC_DESC
330b57cec5SDimitry Andric #include "MSP430GenRegisterInfo.inc"
340b57cec5SDimitry Andric
createMSP430MCInstrInfo()350b57cec5SDimitry Andric static MCInstrInfo *createMSP430MCInstrInfo() {
360b57cec5SDimitry Andric MCInstrInfo *X = new MCInstrInfo();
370b57cec5SDimitry Andric InitMSP430MCInstrInfo(X);
380b57cec5SDimitry Andric return X;
390b57cec5SDimitry Andric }
400b57cec5SDimitry Andric
createMSP430MCRegisterInfo(const Triple & TT)410b57cec5SDimitry Andric static MCRegisterInfo *createMSP430MCRegisterInfo(const Triple &TT) {
420b57cec5SDimitry Andric MCRegisterInfo *X = new MCRegisterInfo();
430b57cec5SDimitry Andric InitMSP430MCRegisterInfo(X, MSP430::PC);
440b57cec5SDimitry Andric return X;
450b57cec5SDimitry Andric }
460b57cec5SDimitry Andric
createMSP430MCAsmInfo(const MCRegisterInfo & MRI,const Triple & TT,const MCTargetOptions & Options)47*06c3fb27SDimitry Andric static MCAsmInfo *createMSP430MCAsmInfo(const MCRegisterInfo &MRI,
48*06c3fb27SDimitry Andric const Triple &TT,
49*06c3fb27SDimitry Andric const MCTargetOptions &Options) {
50*06c3fb27SDimitry Andric MCAsmInfo *MAI = new MSP430MCAsmInfo(TT);
51*06c3fb27SDimitry Andric
52*06c3fb27SDimitry Andric // Initialize initial frame state.
53*06c3fb27SDimitry Andric int stackGrowth = -2;
54*06c3fb27SDimitry Andric
55*06c3fb27SDimitry Andric // Initial state of the frame pointer is sp+ptr_size.
56*06c3fb27SDimitry Andric MCCFIInstruction Inst = MCCFIInstruction::cfiDefCfa(
57*06c3fb27SDimitry Andric nullptr, MRI.getDwarfRegNum(MSP430::SP, true), -stackGrowth);
58*06c3fb27SDimitry Andric MAI->addInitialFrameState(Inst);
59*06c3fb27SDimitry Andric
60*06c3fb27SDimitry Andric // Add return address to move list
61*06c3fb27SDimitry Andric MCCFIInstruction Inst2 = MCCFIInstruction::createOffset(
62*06c3fb27SDimitry Andric nullptr, MRI.getDwarfRegNum(MSP430::PC, true), stackGrowth);
63*06c3fb27SDimitry Andric MAI->addInitialFrameState(Inst2);
64*06c3fb27SDimitry Andric
65*06c3fb27SDimitry Andric return MAI;
66*06c3fb27SDimitry Andric }
67*06c3fb27SDimitry Andric
680b57cec5SDimitry Andric static MCSubtargetInfo *
createMSP430MCSubtargetInfo(const Triple & TT,StringRef CPU,StringRef FS)690b57cec5SDimitry Andric createMSP430MCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
70e8d8bef9SDimitry Andric return createMSP430MCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
710b57cec5SDimitry Andric }
720b57cec5SDimitry Andric
createMSP430MCInstPrinter(const Triple & T,unsigned SyntaxVariant,const MCAsmInfo & MAI,const MCInstrInfo & MII,const MCRegisterInfo & MRI)730b57cec5SDimitry Andric static MCInstPrinter *createMSP430MCInstPrinter(const Triple &T,
740b57cec5SDimitry Andric unsigned SyntaxVariant,
750b57cec5SDimitry Andric const MCAsmInfo &MAI,
760b57cec5SDimitry Andric const MCInstrInfo &MII,
770b57cec5SDimitry Andric const MCRegisterInfo &MRI) {
780b57cec5SDimitry Andric if (SyntaxVariant == 0)
790b57cec5SDimitry Andric return new MSP430InstPrinter(MAI, MII, MRI);
800b57cec5SDimitry Andric return nullptr;
810b57cec5SDimitry Andric }
820b57cec5SDimitry Andric
LLVMInitializeMSP430TargetMC()83480093f4SDimitry Andric extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeMSP430TargetMC() {
840b57cec5SDimitry Andric Target &T = getTheMSP430Target();
850b57cec5SDimitry Andric
86*06c3fb27SDimitry Andric TargetRegistry::RegisterMCAsmInfo(T, createMSP430MCAsmInfo);
870b57cec5SDimitry Andric TargetRegistry::RegisterMCInstrInfo(T, createMSP430MCInstrInfo);
880b57cec5SDimitry Andric TargetRegistry::RegisterMCRegInfo(T, createMSP430MCRegisterInfo);
890b57cec5SDimitry Andric TargetRegistry::RegisterMCSubtargetInfo(T, createMSP430MCSubtargetInfo);
900b57cec5SDimitry Andric TargetRegistry::RegisterMCInstPrinter(T, createMSP430MCInstPrinter);
910b57cec5SDimitry Andric TargetRegistry::RegisterMCCodeEmitter(T, createMSP430MCCodeEmitter);
920b57cec5SDimitry Andric TargetRegistry::RegisterMCAsmBackend(T, createMSP430MCAsmBackend);
930b57cec5SDimitry Andric TargetRegistry::RegisterObjectTargetStreamer(
940b57cec5SDimitry Andric T, createMSP430ObjectTargetStreamer);
950b57cec5SDimitry Andric }
96