xref: /freebsd/contrib/llvm-project/llvm/lib/Target/MSP430/MCTargetDesc/MSP430MCTargetDesc.cpp (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1 //===-- MSP430MCTargetDesc.cpp - MSP430 Target Descriptions ---------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides MSP430 specific target descriptions.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "MSP430MCTargetDesc.h"
14 #include "MSP430InstPrinter.h"
15 #include "MSP430MCAsmInfo.h"
16 #include "TargetInfo/MSP430TargetInfo.h"
17 #include "llvm/MC/MCDwarf.h"
18 #include "llvm/MC/MCInstrInfo.h"
19 #include "llvm/MC/MCRegisterInfo.h"
20 #include "llvm/MC/MCSubtargetInfo.h"
21 #include "llvm/MC/TargetRegistry.h"
22 
23 using namespace llvm;
24 
25 #define GET_INSTRINFO_MC_DESC
26 #define ENABLE_INSTR_PREDICATE_VERIFIER
27 #include "MSP430GenInstrInfo.inc"
28 
29 #define GET_SUBTARGETINFO_MC_DESC
30 #include "MSP430GenSubtargetInfo.inc"
31 
32 #define GET_REGINFO_MC_DESC
33 #include "MSP430GenRegisterInfo.inc"
34 
createMSP430MCInstrInfo()35 static MCInstrInfo *createMSP430MCInstrInfo() {
36   MCInstrInfo *X = new MCInstrInfo();
37   InitMSP430MCInstrInfo(X);
38   return X;
39 }
40 
createMSP430MCRegisterInfo(const Triple & TT)41 static MCRegisterInfo *createMSP430MCRegisterInfo(const Triple &TT) {
42   MCRegisterInfo *X = new MCRegisterInfo();
43   InitMSP430MCRegisterInfo(X, MSP430::PC);
44   return X;
45 }
46 
createMSP430MCAsmInfo(const MCRegisterInfo & MRI,const Triple & TT,const MCTargetOptions & Options)47 static MCAsmInfo *createMSP430MCAsmInfo(const MCRegisterInfo &MRI,
48                                         const Triple &TT,
49                                         const MCTargetOptions &Options) {
50   MCAsmInfo *MAI = new MSP430MCAsmInfo(TT);
51 
52   // Initialize initial frame state.
53   int stackGrowth = -2;
54 
55   // Initial state of the frame pointer is sp+ptr_size.
56   MCCFIInstruction Inst = MCCFIInstruction::cfiDefCfa(
57       nullptr, MRI.getDwarfRegNum(MSP430::SP, true), -stackGrowth);
58   MAI->addInitialFrameState(Inst);
59 
60   // Add return address to move list
61   MCCFIInstruction Inst2 = MCCFIInstruction::createOffset(
62       nullptr, MRI.getDwarfRegNum(MSP430::PC, true), stackGrowth);
63   MAI->addInitialFrameState(Inst2);
64 
65   return MAI;
66 }
67 
68 static MCSubtargetInfo *
createMSP430MCSubtargetInfo(const Triple & TT,StringRef CPU,StringRef FS)69 createMSP430MCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
70   return createMSP430MCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
71 }
72 
createMSP430MCInstPrinter(const Triple & T,unsigned SyntaxVariant,const MCAsmInfo & MAI,const MCInstrInfo & MII,const MCRegisterInfo & MRI)73 static MCInstPrinter *createMSP430MCInstPrinter(const Triple &T,
74                                                 unsigned SyntaxVariant,
75                                                 const MCAsmInfo &MAI,
76                                                 const MCInstrInfo &MII,
77                                                 const MCRegisterInfo &MRI) {
78   if (SyntaxVariant == 0)
79     return new MSP430InstPrinter(MAI, MII, MRI);
80   return nullptr;
81 }
82 
LLVMInitializeMSP430TargetMC()83 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeMSP430TargetMC() {
84   Target &T = getTheMSP430Target();
85 
86   TargetRegistry::RegisterMCAsmInfo(T, createMSP430MCAsmInfo);
87   TargetRegistry::RegisterMCInstrInfo(T, createMSP430MCInstrInfo);
88   TargetRegistry::RegisterMCRegInfo(T, createMSP430MCRegisterInfo);
89   TargetRegistry::RegisterMCSubtargetInfo(T, createMSP430MCSubtargetInfo);
90   TargetRegistry::RegisterMCInstPrinter(T, createMSP430MCInstPrinter);
91   TargetRegistry::RegisterMCCodeEmitter(T, createMSP430MCCodeEmitter);
92   TargetRegistry::RegisterMCAsmBackend(T, createMSP430MCAsmBackend);
93   TargetRegistry::RegisterObjectTargetStreamer(
94       T, createMSP430ObjectTargetStreamer);
95 }
96