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 #include "ARCGenInstrInfo.inc" 30 31 #define GET_SUBTARGETINFO_MC_DESC 32 #include "ARCGenSubtargetInfo.inc" 33 34 #define GET_REGINFO_MC_DESC 35 #include "ARCGenRegisterInfo.inc" 36 37 static MCInstrInfo *createARCMCInstrInfo() { 38 auto *X = new MCInstrInfo(); 39 InitARCMCInstrInfo(X); 40 return X; 41 } 42 43 static MCRegisterInfo *createARCMCRegisterInfo(const Triple &TT) { 44 auto *X = new MCRegisterInfo(); 45 InitARCMCRegisterInfo(X, ARC::BLINK); 46 return X; 47 } 48 49 static MCSubtargetInfo *createARCMCSubtargetInfo(const Triple &TT, 50 StringRef CPU, StringRef FS) { 51 return createARCMCSubtargetInfoImpl(TT, CPU, /*TuneCPU=*/CPU, FS); 52 } 53 54 static MCAsmInfo *createARCMCAsmInfo(const MCRegisterInfo &MRI, 55 const Triple &TT, 56 const MCTargetOptions &Options) { 57 MCAsmInfo *MAI = new ARCMCAsmInfo(TT); 58 59 // Initial state of the frame pointer is SP. 60 MCCFIInstruction Inst = MCCFIInstruction::cfiDefCfa(nullptr, ARC::SP, 0); 61 MAI->addInitialFrameState(Inst); 62 63 return MAI; 64 } 65 66 static MCInstPrinter *createARCMCInstPrinter(const Triple &T, 67 unsigned SyntaxVariant, 68 const MCAsmInfo &MAI, 69 const MCInstrInfo &MII, 70 const MCRegisterInfo &MRI) { 71 return new ARCInstPrinter(MAI, MII, MRI); 72 } 73 74 ARCTargetStreamer::ARCTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {} 75 ARCTargetStreamer::~ARCTargetStreamer() = default; 76 77 static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S, 78 formatted_raw_ostream &OS, 79 MCInstPrinter *InstPrint, 80 bool isVerboseAsm) { 81 return new ARCTargetStreamer(S); 82 } 83 84 // Force static initialization. 85 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeARCTargetMC() { 86 // Register the MC asm info. 87 Target &TheARCTarget = getTheARCTarget(); 88 RegisterMCAsmInfoFn X(TheARCTarget, createARCMCAsmInfo); 89 90 // Register the MC instruction info. 91 TargetRegistry::RegisterMCInstrInfo(TheARCTarget, createARCMCInstrInfo); 92 93 // Register the MC register info. 94 TargetRegistry::RegisterMCRegInfo(TheARCTarget, createARCMCRegisterInfo); 95 96 // Register the MC subtarget info. 97 TargetRegistry::RegisterMCSubtargetInfo(TheARCTarget, 98 createARCMCSubtargetInfo); 99 100 // Register the MCInstPrinter 101 TargetRegistry::RegisterMCInstPrinter(TheARCTarget, createARCMCInstPrinter); 102 103 TargetRegistry::RegisterAsmTargetStreamer(TheARCTarget, 104 createTargetAsmStreamer); 105 } 106