LLVM  4.0.0
SparcMCTargetDesc.cpp
Go to the documentation of this file.
1 //===-- SparcMCTargetDesc.cpp - Sparc 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 Sparc specific target descriptions.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "SparcMCTargetDesc.h"
16 #include "SparcMCAsmInfo.h"
17 #include "SparcTargetStreamer.h"
18 #include "llvm/MC/MCInstrInfo.h"
19 #include "llvm/MC/MCRegisterInfo.h"
23 
24 using namespace llvm;
25 
26 #define GET_INSTRINFO_MC_DESC
27 #include "SparcGenInstrInfo.inc"
28 
29 #define GET_SUBTARGETINFO_MC_DESC
30 #include "SparcGenSubtargetInfo.inc"
31 
32 #define GET_REGINFO_MC_DESC
33 #include "SparcGenRegisterInfo.inc"
34 
36  const Triple &TT) {
37  MCAsmInfo *MAI = new SparcELFMCAsmInfo(TT);
38  unsigned Reg = MRI.getDwarfRegNum(SP::O6, true);
39  MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, Reg, 0);
40  MAI->addInitialFrameState(Inst);
41  return MAI;
42 }
43 
45  const Triple &TT) {
46  MCAsmInfo *MAI = new SparcELFMCAsmInfo(TT);
47  unsigned Reg = MRI.getDwarfRegNum(SP::O6, true);
48  MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, Reg, 2047);
49  MAI->addInitialFrameState(Inst);
50  return MAI;
51 }
52 
54  MCInstrInfo *X = new MCInstrInfo();
55  InitSparcMCInstrInfo(X);
56  return X;
57 }
58 
61  InitSparcMCRegisterInfo(X, SP::O7);
62  return X;
63 }
64 
65 static MCSubtargetInfo *
67  if (CPU.empty())
68  CPU = (TT.getArch() == Triple::sparcv9) ? "v9" : "v8";
69  return createSparcMCSubtargetInfoImpl(TT, CPU, FS);
70 }
71 
72 // Code models. Some only make sense for 64-bit code.
73 //
74 // SunCC Reloc CodeModel Constraints
75 // abs32 Static Small text+data+bss linked below 2^32 bytes
76 // abs44 Static Medium text+data+bss linked below 2^44 bytes
77 // abs64 Static Large text smaller than 2^31 bytes
78 // pic13 PIC_ Small GOT < 2^13 bytes
79 // pic32 PIC_ Medium GOT < 2^32 bytes
80 //
81 // All code models require that the text segment is smaller than 2GB.
82 
83 static void adjustCodeGenOpts(const Triple &TT, Reloc::Model RM,
84  CodeModel::Model &CM) {
85  // The default 32-bit code model is abs32/pic32 and the default 32-bit
86  // code model for JIT is abs32.
87  switch (CM) {
88  default: break;
89  case CodeModel::Default:
90  case CodeModel::JITDefault: CM = CodeModel::Small; break;
91  }
92 }
93 
94 static void adjustCodeGenOptsV9(const Triple &TT, Reloc::Model RM,
95  CodeModel::Model &CM) {
96  // The default 64-bit code model is abs44/pic32 and the default 64-bit
97  // code model for JIT is abs64.
98  switch (CM) {
99  default: break;
100  case CodeModel::Default:
102  break;
104  CM = CodeModel::Large;
105  break;
106  }
107 }
108 
109 static MCTargetStreamer *
111  return new SparcTargetELFStreamer(S);
112 }
113 
116  MCInstPrinter *InstPrint,
117  bool isVerboseAsm) {
118  return new SparcTargetAsmStreamer(S, OS);
119 }
120 
122  unsigned SyntaxVariant,
123  const MCAsmInfo &MAI,
124  const MCInstrInfo &MII,
125  const MCRegisterInfo &MRI) {
126  return new SparcInstPrinter(MAI, MII, MRI);
127 }
128 
129 extern "C" void LLVMInitializeSparcTargetMC() {
130  // Register the MC asm info.
134 
135  for (Target *T :
137  // Register the MC instruction info.
139 
140  // Register the MC register info.
142 
143  // Register the MC subtarget info.
145 
146  // Register the MC Code Emitter.
148 
149  // Register the asm backend.
151 
152  // Register the object target streamer.
155 
156  // Register the asm streamer.
158 
159  // Register the MCInstPrinter
161  }
162 
163  // Register the MC codegen info.
170 }
int getDwarfRegNum(unsigned RegNum, bool isEH) const
Map a target register to an equivalent dwarf register number.
MCCodeEmitter * createSparcMCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &Ctx)
void LLVMInitializeSparcTargetMC()
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
static MCTargetStreamer * createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn)
RegisterMCInstPrinter - Register a MCInstPrinter implementation for the given target.
static MCRegisterInfo * createSparcMCRegisterInfo(const Triple &TT)
static void RegisterAsmTargetStreamer(Target &T, Target::AsmTargetStreamerCtorTy Fn)
static MCTargetStreamer * createTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint, bool isVerboseAsm)
Reg
All possible values of the reg field in the ModR/M byte.
void addInitialFrameState(const MCCFIInstruction &Inst)
Definition: MCAsmInfo.h:565
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:270
Target & getTheSparcTarget()
static void adjustCodeGenOptsV9(const Triple &TT, Reloc::Model RM, CodeModel::Model &CM)
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
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
RegisterMCAsmBackend - Register a MCAsmBackend implementation for the given target.
MCAsmBackend * createSparcAsmBackend(const Target &T, const MCRegisterInfo &MRI, const Triple &TT, StringRef CPU, const MCTargetOptions &Options)
Streaming machine code generation interface.
Definition: MCStreamer.h:161
static MCInstPrinter * createSparcMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
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
static MCAsmInfo * createSparcMCAsmInfo(const MCRegisterInfo &MRI, const Triple &TT)
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:24
Target & getTheSparcelTarget()
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
static void registerMCAdjustCodeGenOpts(Target &T, Target::MCAdjustCodeGenOptsFnTy Fn)
static void RegisterMCSubtargetInfo(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for the given target...
static void RegisterObjectTargetStreamer(Target &T, Target::ObjectTargetStreamerCtorTy Fn)
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
static MCInstrInfo * createSparcMCInstrInfo()
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
static void adjustCodeGenOpts(const Triple &TT, Reloc::Model RM, CodeModel::Model &CM)
Target - Wrapper for Target specific information.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:130
Target & getTheSparcV9Target()
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 RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target. ...
MCSubtargetInfo - Generic base class for all target subtargets.
static MCAsmInfo * createSparcV9MCAsmInfo(const MCRegisterInfo &MRI, const Triple &TT)
static MCSubtargetInfo * createSparcMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")