LLVM  4.0.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/MCInstrInfo.h"
19 #include "llvm/MC/MCRegisterInfo.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 
37  MCInstrInfo *X = new MCInstrInfo();
38  InitXCoreMCInstrInfo(X);
39  return X;
40 }
41 
44  InitXCoreMCRegisterInfo(X, XCore::LR);
45  return X;
46 }
47 
48 static MCSubtargetInfo *
50  return createXCoreMCSubtargetInfoImpl(TT, CPU, FS);
51 }
52 
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 
74  unsigned SyntaxVariant,
75  const MCAsmInfo &MAI,
76  const MCInstrInfo &MII,
77  const MCRegisterInfo &MRI) {
78  return new XCoreInstPrinter(MAI, MII, MRI);
79 }
80 
83 
84 namespace {
85 
86 class XCoreTargetAsmStreamer : public XCoreTargetStreamer {
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,
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 
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.
128 
129  // Register the MC codegen info.
132 
133  // Register the MC instruction info.
136 
137  // Register the MC register info.
140 
141  // Register the MC subtarget info.
144 
145  // Register the MCInstPrinter
148 
151 }
static MCSubtargetInfo * createXCoreMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
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)
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:565
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:57
Streaming machine code generation interface.
Definition: MCStreamer.h:161
unsigned const MachineRegisterInfo * MRI
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:369
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 registerMCAdjustCodeGenOpts(Target &T, Target::MCAdjustCodeGenOptsFnTy Fn)
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
Target & getTheXCoreTarget()
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:41
static void adjustCodeGenOpts(const Triple &TT, Reloc::Model RM, CodeModel::Model &CM)
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...
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47