LLVM  3.7.0
XCoreMCTargetDesc.cpp
Go to the documentation of this file.
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"
16 #include "XCoreMCAsmInfo.h"
17 #include "XCoreTargetStreamer.h"
18 #include "llvm/MC/MCCodeGenInfo.h"
19 #include "llvm/MC/MCInstrInfo.h"
20 #include "llvm/MC/MCRegisterInfo.h"
25 
26 using namespace llvm;
27 
28 #define GET_INSTRINFO_MC_DESC
29 #include "XCoreGenInstrInfo.inc"
30 
31 #define GET_SUBTARGETINFO_MC_DESC
32 #include "XCoreGenSubtargetInfo.inc"
33 
34 #define GET_REGINFO_MC_DESC
35 #include "XCoreGenRegisterInfo.inc"
36 
38  MCInstrInfo *X = new MCInstrInfo();
39  InitXCoreMCInstrInfo(X);
40  return X;
41 }
42 
45  InitXCoreMCRegisterInfo(X, XCore::LR);
46  return X;
47 }
48 
49 static MCSubtargetInfo *
51  return createXCoreMCSubtargetInfoImpl(TT, CPU, FS);
52 }
53 
55  const Triple &TT) {
56  MCAsmInfo *MAI = new XCoreMCAsmInfo(TT);
57 
58  // Initial state of the frame pointer is SP.
59  MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, XCore::SP, 0);
60  MAI->addInitialFrameState(Inst);
61 
62  return MAI;
63 }
64 
68  CodeGenOpt::Level OL) {
69  MCCodeGenInfo *X = new MCCodeGenInfo();
70  if (RM == Reloc::Default) {
71  RM = Reloc::Static;
72  }
73  if (CM == CodeModel::Default) {
74  CM = CodeModel::Small;
75  }
76  if (CM != CodeModel::Small && CM != CodeModel::Large)
77  report_fatal_error("Target only supports CodeModel Small or Large");
78 
79  X->initMCCodeGenInfo(RM, CM, OL);
80  return X;
81 }
82 
84  unsigned SyntaxVariant,
85  const MCAsmInfo &MAI,
86  const MCInstrInfo &MII,
87  const MCRegisterInfo &MRI) {
88  return new XCoreInstPrinter(MAI, MII, MRI);
89 }
90 
93 
94 namespace {
95 
96 class XCoreTargetAsmStreamer : public XCoreTargetStreamer {
98 public:
99  XCoreTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
100  void emitCCTopData(StringRef Name) override;
101  void emitCCTopFunction(StringRef Name) override;
102  void emitCCBottomData(StringRef Name) override;
103  void emitCCBottomFunction(StringRef Name) override;
104 };
105 
106 XCoreTargetAsmStreamer::XCoreTargetAsmStreamer(MCStreamer &S,
108  : XCoreTargetStreamer(S), OS(OS) {}
109 
110 void XCoreTargetAsmStreamer::emitCCTopData(StringRef Name) {
111  OS << "\t.cc_top " << Name << ".data," << Name << '\n';
112 }
113 
114 void XCoreTargetAsmStreamer::emitCCTopFunction(StringRef Name) {
115  OS << "\t.cc_top " << Name << ".function," << Name << '\n';
116 }
117 
118 void XCoreTargetAsmStreamer::emitCCBottomData(StringRef Name) {
119  OS << "\t.cc_bottom " << Name << ".data\n";
120 }
121 
122 void XCoreTargetAsmStreamer::emitCCBottomFunction(StringRef Name) {
123  OS << "\t.cc_bottom " << Name << ".function\n";
124 }
125 }
126 
129  MCInstPrinter *InstPrint,
130  bool isVerboseAsm) {
131  return new XCoreTargetAsmStreamer(S, OS);
132 }
133 
134 // Force static initialization.
135 extern "C" void LLVMInitializeXCoreTargetMC() {
136  // Register the MC asm info.
138 
139  // Register the MC codegen info.
142 
143  // Register the MC instruction info.
145 
146  // Register the MC register info.
148 
149  // Register the MC subtarget info.
152 
153  // Register the MCInstPrinter
156 
159 }
static MCSubtargetInfo * createXCoreMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
Target specific streamer interface.
Definition: MCStreamer.h:73
void LLVMInitializeXCoreTargetMC()
static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn)
RegisterMCInstPrinter - Register a MCInstPrinter implementation for the given target.
static void RegisterAsmTargetStreamer(Target &T, Target::AsmTargetStreamerCtorTy Fn)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
static MCInstPrinter * createXCoreMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
static MCInstrInfo * createXCoreMCInstrInfo()
void addInitialFrameState(const MCCFIInstruction &Inst)
Definition: MCAsmInfo.h:534
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:58
Streaming machine code generation interface.
Definition: MCStreamer.h:157
static MCCFIInstruction createDefCfa(MCSymbol *L, unsigned Register, int Offset)
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it...
Definition: MCDwarf.h:354
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:24
static MCRegisterInfo * createXCoreMCRegisterInfo(const Triple &TT)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
static void RegisterMCCodeGenInfo(Target &T, Target::MCCodeGenInfoCtorFnTy Fn)
RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the given target.
static MCAsmInfo * createXCoreMCAsmInfo(const MCRegisterInfo &MRI, const Triple &TT)
static void RegisterMCSubtargetInfo(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for the given target...
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
static MCTargetStreamer * createTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint, bool isVerboseAsm)
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
RegisterMCAsmInfoFn - Helper template for registering a target assembly info implementation.
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:38
Target TheXCoreTarget
void initMCCodeGenInfo(Reloc::Model RM=Reloc::Default, CodeModel::Model CM=CodeModel::Default, CodeGenOpt::Level OL=CodeGenOpt::Default)
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target. ...
MCSubtargetInfo - Generic base class for all target subtargets.
This file contains the declaration of the XCoreInstPrinter class, which is used to print XCore MCInst...
static MCCodeGenInfo * createXCoreMCCodeGenInfo(const Triple &TT, Reloc::Model RM, CodeModel::Model CM, CodeGenOpt::Level OL)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40