xref: /freebsd/contrib/llvm-project/llvm/lib/Target/VE/MCTargetDesc/VEMCTargetDesc.cpp (revision 7ef62cebc2f965b0f640263e179276928885e33d)
1 //===-- VEMCTargetDesc.cpp - VE 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 VE specific target descriptions.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "VEMCTargetDesc.h"
14 #include "TargetInfo/VETargetInfo.h"
15 #include "VEInstPrinter.h"
16 #include "VEMCAsmInfo.h"
17 #include "VETargetStreamer.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 #include "llvm/Support/ErrorHandling.h"
23 
24 using namespace llvm;
25 
26 #define GET_INSTRINFO_MC_DESC
27 #define ENABLE_INSTR_PREDICATE_VERIFIER
28 #include "VEGenInstrInfo.inc"
29 
30 #define GET_SUBTARGETINFO_MC_DESC
31 #include "VEGenSubtargetInfo.inc"
32 
33 #define GET_REGINFO_MC_DESC
34 #include "VEGenRegisterInfo.inc"
35 
36 static MCAsmInfo *createVEMCAsmInfo(const MCRegisterInfo &MRI, const Triple &TT,
37                                     const MCTargetOptions &Options) {
38   MCAsmInfo *MAI = new VEELFMCAsmInfo(TT);
39   unsigned Reg = MRI.getDwarfRegNum(VE::SX11, true);
40   MCCFIInstruction Inst = MCCFIInstruction::cfiDefCfa(nullptr, Reg, 0);
41   MAI->addInitialFrameState(Inst);
42   return MAI;
43 }
44 
45 static MCInstrInfo *createVEMCInstrInfo() {
46   MCInstrInfo *X = new MCInstrInfo();
47   InitVEMCInstrInfo(X);
48   return X;
49 }
50 
51 static MCRegisterInfo *createVEMCRegisterInfo(const Triple &TT) {
52   MCRegisterInfo *X = new MCRegisterInfo();
53   InitVEMCRegisterInfo(X, VE::SX10);
54   return X;
55 }
56 
57 static MCSubtargetInfo *createVEMCSubtargetInfo(const Triple &TT, StringRef CPU,
58                                                 StringRef FS) {
59   if (CPU.empty())
60     CPU = "generic";
61   return createVEMCSubtargetInfoImpl(TT, CPU, /*TuneCPU=*/CPU, FS);
62 }
63 
64 static MCTargetStreamer *
65 createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
66   return new VETargetELFStreamer(S);
67 }
68 
69 static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S,
70                                                  formatted_raw_ostream &OS,
71                                                  MCInstPrinter *InstPrint,
72                                                  bool isVerboseAsm) {
73   return new VETargetAsmStreamer(S, OS);
74 }
75 
76 static MCInstPrinter *createVEMCInstPrinter(const Triple &T,
77                                             unsigned SyntaxVariant,
78                                             const MCAsmInfo &MAI,
79                                             const MCInstrInfo &MII,
80                                             const MCRegisterInfo &MRI) {
81   return new VEInstPrinter(MAI, MII, MRI);
82 }
83 
84 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeVETargetMC() {
85   // Register the MC asm info.
86   RegisterMCAsmInfoFn X(getTheVETarget(), createVEMCAsmInfo);
87 
88   for (Target *T : {&getTheVETarget()}) {
89     // Register the MC instruction info.
90     TargetRegistry::RegisterMCInstrInfo(*T, createVEMCInstrInfo);
91 
92     // Register the MC register info.
93     TargetRegistry::RegisterMCRegInfo(*T, createVEMCRegisterInfo);
94 
95     // Register the MC subtarget info.
96     TargetRegistry::RegisterMCSubtargetInfo(*T, createVEMCSubtargetInfo);
97 
98     // Register the MC Code Emitter.
99     TargetRegistry::RegisterMCCodeEmitter(*T, createVEMCCodeEmitter);
100 
101     // Register the asm backend.
102     TargetRegistry::RegisterMCAsmBackend(*T, createVEAsmBackend);
103 
104     // Register the object target streamer.
105     TargetRegistry::RegisterObjectTargetStreamer(*T,
106                                                  createObjectTargetStreamer);
107 
108     // Register the asm streamer.
109     TargetRegistry::RegisterAsmTargetStreamer(*T, createTargetAsmStreamer);
110 
111     // Register the MCInstPrinter
112     TargetRegistry::RegisterMCInstPrinter(*T, createVEMCInstPrinter);
113   }
114 }
115