Home | History | Annotate | Download | only in MCTargetDesc
      1 //===-- XCoreMCTargetDesc.cpp - XCore Target Descriptions -----------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file provides XCore specific target descriptions.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include "XCoreMCTargetDesc.h"
     15 #include "InstPrinter/XCoreInstPrinter.h"
     16 #include "XCoreMCAsmInfo.h"
     17 #include "XCoreTargetStreamer.h"
     18 #include "llvm/MC/MCInstrInfo.h"
     19 #include "llvm/MC/MCRegisterInfo.h"
     20 #include "llvm/MC/MCSubtargetInfo.h"
     21 #include "llvm/Support/ErrorHandling.h"
     22 #include "llvm/Support/FormattedStream.h"
     23 #include "llvm/Support/TargetRegistry.h"
     24 
     25 using namespace llvm;
     26 
     27 #define GET_INSTRINFO_MC_DESC
     28 #include "XCoreGenInstrInfo.inc"
     29 
     30 #define GET_SUBTARGETINFO_MC_DESC
     31 #include "XCoreGenSubtargetInfo.inc"
     32 
     33 #define GET_REGINFO_MC_DESC
     34 #include "XCoreGenRegisterInfo.inc"
     35 
     36 static MCInstrInfo *createXCoreMCInstrInfo() {
     37   MCInstrInfo *X = new MCInstrInfo();
     38   InitXCoreMCInstrInfo(X);
     39   return X;
     40 }
     41 
     42 static MCRegisterInfo *createXCoreMCRegisterInfo(const Triple &TT) {
     43   MCRegisterInfo *X = new MCRegisterInfo();
     44   InitXCoreMCRegisterInfo(X, XCore::LR);
     45   return X;
     46 }
     47 
     48 static MCSubtargetInfo *
     49 createXCoreMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
     50   return createXCoreMCSubtargetInfoImpl(TT, CPU, FS);
     51 }
     52 
     53 static MCAsmInfo *createXCoreMCAsmInfo(const MCRegisterInfo &MRI,
     54                                        const Triple &TT) {
     55   MCAsmInfo *MAI = new XCoreMCAsmInfo(TT);
     56 
     57   // Initial state of the frame pointer is SP.
     58   MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, XCore::SP, 0);
     59   MAI->addInitialFrameState(Inst);
     60 
     61   return MAI;
     62 }
     63 
     64 static void adjustCodeGenOpts(const Triple &TT, Reloc::Model RM,
     65                               CodeModel::Model &CM) {
     66   if (CM == CodeModel::Default) {
     67     CM = CodeModel::Small;
     68   }
     69   if (CM != CodeModel::Small && CM != CodeModel::Large)
     70     report_fatal_error("Target only supports CodeModel Small or Large");
     71 }
     72 
     73 static MCInstPrinter *createXCoreMCInstPrinter(const Triple &T,
     74                                                unsigned SyntaxVariant,
     75                                                const MCAsmInfo &MAI,
     76                                                const MCInstrInfo &MII,
     77                                                const MCRegisterInfo &MRI) {
     78   return new XCoreInstPrinter(MAI, MII, MRI);
     79 }
     80 
     81 XCoreTargetStreamer::XCoreTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
     82 XCoreTargetStreamer::~XCoreTargetStreamer() {}
     83 
     84 namespace {
     85 
     86 class XCoreTargetAsmStreamer : public XCoreTargetStreamer {
     87   formatted_raw_ostream &OS;
     88 public:
     89   XCoreTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
     90   void emitCCTopData(StringRef Name) override;
     91   void emitCCTopFunction(StringRef Name) override;
     92   void emitCCBottomData(StringRef Name) override;
     93   void emitCCBottomFunction(StringRef Name) override;
     94 };
     95 
     96 XCoreTargetAsmStreamer::XCoreTargetAsmStreamer(MCStreamer &S,
     97                                                formatted_raw_ostream &OS)
     98     : XCoreTargetStreamer(S), OS(OS) {}
     99 
    100 void XCoreTargetAsmStreamer::emitCCTopData(StringRef Name) {
    101   OS << "\t.cc_top " << Name << ".data," << Name << '\n';
    102 }
    103 
    104 void XCoreTargetAsmStreamer::emitCCTopFunction(StringRef Name) {
    105   OS << "\t.cc_top " << Name << ".function," << Name << '\n';
    106 }
    107 
    108 void XCoreTargetAsmStreamer::emitCCBottomData(StringRef Name) {
    109   OS << "\t.cc_bottom " << Name << ".data\n";
    110 }
    111 
    112 void XCoreTargetAsmStreamer::emitCCBottomFunction(StringRef Name) {
    113   OS << "\t.cc_bottom " << Name << ".function\n";
    114 }
    115 }
    116 
    117 static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S,
    118                                                  formatted_raw_ostream &OS,
    119                                                  MCInstPrinter *InstPrint,
    120                                                  bool isVerboseAsm) {
    121   return new XCoreTargetAsmStreamer(S, OS);
    122 }
    123 
    124 // Force static initialization.
    125 extern "C" void LLVMInitializeXCoreTargetMC() {
    126   // Register the MC asm info.
    127   RegisterMCAsmInfoFn X(TheXCoreTarget, createXCoreMCAsmInfo);
    128 
    129   // Register the MC codegen info.
    130   TargetRegistry::registerMCAdjustCodeGenOpts(TheXCoreTarget,
    131                                               adjustCodeGenOpts);
    132 
    133   // Register the MC instruction info.
    134   TargetRegistry::RegisterMCInstrInfo(TheXCoreTarget, createXCoreMCInstrInfo);
    135 
    136   // Register the MC register info.
    137   TargetRegistry::RegisterMCRegInfo(TheXCoreTarget, createXCoreMCRegisterInfo);
    138 
    139   // Register the MC subtarget info.
    140   TargetRegistry::RegisterMCSubtargetInfo(TheXCoreTarget,
    141                                           createXCoreMCSubtargetInfo);
    142 
    143   // Register the MCInstPrinter
    144   TargetRegistry::RegisterMCInstPrinter(TheXCoreTarget,
    145                                         createXCoreMCInstPrinter);
    146 
    147   TargetRegistry::RegisterAsmTargetStreamer(TheXCoreTarget,
    148                                             createTargetAsmStreamer);
    149 }
    150