xref: /freebsd/contrib/llvm-project/llvm/lib/Target/ARC/MCTargetDesc/ARCMCTargetDesc.cpp (revision ebacd8013fe5f7fdf9f6a5b286f6680dd2891036)
1 //===- ARCMCTargetDesc.cpp - ARC Target Descriptions ------------*- C++ -*-===//
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 ARC specific target descriptions.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "ARCMCTargetDesc.h"
14 #include "ARCInstPrinter.h"
15 #include "ARCMCAsmInfo.h"
16 #include "ARCTargetStreamer.h"
17 #include "TargetInfo/ARCTargetInfo.h"
18 #include "llvm/MC/MCDwarf.h"
19 #include "llvm/MC/MCInstrInfo.h"
20 #include "llvm/MC/MCRegisterInfo.h"
21 #include "llvm/MC/MCSubtargetInfo.h"
22 #include "llvm/MC/TargetRegistry.h"
23 #include "llvm/Support/ErrorHandling.h"
24 #include "llvm/Support/FormattedStream.h"
25 
26 using namespace llvm;
27 
28 #define GET_INSTRINFO_MC_DESC
29 #define ENABLE_INSTR_PREDICATE_VERIFIER
30 #include "ARCGenInstrInfo.inc"
31 
32 #define GET_SUBTARGETINFO_MC_DESC
33 #include "ARCGenSubtargetInfo.inc"
34 
35 #define GET_REGINFO_MC_DESC
36 #include "ARCGenRegisterInfo.inc"
37 
38 static MCInstrInfo *createARCMCInstrInfo() {
39   auto *X = new MCInstrInfo();
40   InitARCMCInstrInfo(X);
41   return X;
42 }
43 
44 static MCRegisterInfo *createARCMCRegisterInfo(const Triple &TT) {
45   auto *X = new MCRegisterInfo();
46   InitARCMCRegisterInfo(X, ARC::BLINK);
47   return X;
48 }
49 
50 static MCSubtargetInfo *createARCMCSubtargetInfo(const Triple &TT,
51                                                  StringRef CPU, StringRef FS) {
52   return createARCMCSubtargetInfoImpl(TT, CPU, /*TuneCPU=*/CPU, FS);
53 }
54 
55 static MCAsmInfo *createARCMCAsmInfo(const MCRegisterInfo &MRI,
56                                      const Triple &TT,
57                                      const MCTargetOptions &Options) {
58   MCAsmInfo *MAI = new ARCMCAsmInfo(TT);
59 
60   // Initial state of the frame pointer is SP.
61   MCCFIInstruction Inst = MCCFIInstruction::cfiDefCfa(nullptr, ARC::SP, 0);
62   MAI->addInitialFrameState(Inst);
63 
64   return MAI;
65 }
66 
67 static MCInstPrinter *createARCMCInstPrinter(const Triple &T,
68                                              unsigned SyntaxVariant,
69                                              const MCAsmInfo &MAI,
70                                              const MCInstrInfo &MII,
71                                              const MCRegisterInfo &MRI) {
72   return new ARCInstPrinter(MAI, MII, MRI);
73 }
74 
75 ARCTargetStreamer::ARCTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
76 ARCTargetStreamer::~ARCTargetStreamer() = default;
77 
78 static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S,
79                                                  formatted_raw_ostream &OS,
80                                                  MCInstPrinter *InstPrint,
81                                                  bool isVerboseAsm) {
82   return new ARCTargetStreamer(S);
83 }
84 
85 // Force static initialization.
86 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeARCTargetMC() {
87   // Register the MC asm info.
88   Target &TheARCTarget = getTheARCTarget();
89   RegisterMCAsmInfoFn X(TheARCTarget, createARCMCAsmInfo);
90 
91   // Register the MC instruction info.
92   TargetRegistry::RegisterMCInstrInfo(TheARCTarget, createARCMCInstrInfo);
93 
94   // Register the MC register info.
95   TargetRegistry::RegisterMCRegInfo(TheARCTarget, createARCMCRegisterInfo);
96 
97   // Register the MC subtarget info.
98   TargetRegistry::RegisterMCSubtargetInfo(TheARCTarget,
99                                           createARCMCSubtargetInfo);
100 
101   // Register the MCInstPrinter
102   TargetRegistry::RegisterMCInstPrinter(TheARCTarget, createARCMCInstPrinter);
103 
104   TargetRegistry::RegisterAsmTargetStreamer(TheARCTarget,
105                                             createTargetAsmStreamer);
106 }
107