LLVM: lib/MC/TargetRegistry.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
18#include
19#include
20using namespace llvm;
21
22
24
26 const Triple &T, MCContext &Ctx, std::unique_ptr TAB,
27 std::unique_ptr OW, std::unique_ptr Emitter,
30 switch (T.getObjectFormat()) {
34 assert((T.isOSWindows() || T.isUEFI()) &&
35 "only Windows and UEFI COFF are supported");
36 S = COFFStreamerCtorFn(Ctx, std::move(TAB), std::move(OW),
38 break;
40 if (MachOStreamerCtorFn)
41 S = MachOStreamerCtorFn(Ctx, std::move(TAB), std::move(OW),
43 else
45 std::move(Emitter), false);
46 break;
48 if (ELFStreamerCtorFn)
49 S = ELFStreamerCtorFn(T, Ctx, std::move(TAB), std::move(OW),
51 else
54 break;
58 break;
62 break;
64 S = XCOFFStreamerCtorFn(T, Ctx, std::move(TAB), std::move(OW),
66 break;
70 break;
74 break;
75 }
76 if (ObjectTargetStreamerCtorFn)
77 ObjectTargetStreamerCtorFn(*S, STI);
78 return S;
79}
80
82 const Triple &T, MCContext &Ctx, std::unique_ptr &&TAB,
83 std::unique_ptr &&OW,
85 bool, bool) const {
88}
89
91 std::unique_ptr<formatted_raw_ostream> OS,
93 std::unique_ptr CE,
94 std::unique_ptr TAB) const {
97 std::move(CE), std::move(TAB));
99 return S;
100}
101
103 std::unique_ptr<formatted_raw_ostream> OS,
104 bool IsVerboseAsm, bool UseDwarfDirectory,
106 std::unique_ptr &&CE,
107 std::unique_ptr &&TAB,
108 bool ShowInst) const {
110 std::move(TAB));
111}
112
115}
116
119 std::string &Error) {
120
121
122
123 const Target *TheTarget = nullptr;
124 if (!ArchName.empty()) {
126 [&](const Target &T) { return ArchName == T.getName(); });
127
129 Error = ("invalid target '" + ArchName + "'.").str();
130 return nullptr;
131 }
132
133 TheTarget = &*I;
134
135
136
140 } else {
141
142 std::string TempError;
144 if (!TheTarget) {
145 Error = "unable to get target for '" + TheTriple.getTriple() +
146 "', see --version and --triple.";
147 return nullptr;
148 }
149 }
150
151 return TheTarget;
152}
153
155
157 Error = "Unable to find target for this triple (no targets are registered)";
158 return nullptr;
159 }
161 auto ArchMatch = [&](const Target &T) { return T.ArchMatchFn(Arch); };
163
165 Error = ("No available targets are compatible with triple \"" + TT + "\"")
166 .str();
167 return nullptr;
168 }
169
170 auto J = std::find_if(std::next(I), targets().end(), ArchMatch);
171 if (J != targets().end()) {
172 Error = std::string("Cannot choose between targets \"") + I->Name +
173 "\" and \"" + J->Name + "\"";
174 return nullptr;
175 }
176
177 return &*I;
178}
179
181 const char *ShortDesc,
182 const char *BackendName,
184 bool HasJIT) {
185 assert(Name && ShortDesc && ArchMatchFn &&
186 "Missing required target information!");
187
188
189
190 if (T.Name)
191 return;
192
193
196
198 T.ShortDesc = ShortDesc;
199 T.BackendName = BackendName;
200 T.ArchMatchFn = ArchMatchFn;
201 T.HasJIT = HasJIT;
202}
203
205 const std::pair<StringRef, const Target *> *RHS) {
206 return LHS->first.compare(RHS->first);
207}
208
210 std::vector<std::pair<StringRef, const Target*> > Targets;
211 size_t Width = 0;
213 Targets.push_back(std::make_pair(T.getName(), &T));
214 Width = std::max(Width, Targets.back().first.size());
215 }
217
218 OS << "\n";
219 OS << " Registered Targets:\n";
220 for (const auto &Target : Targets) {
224 }
225 if (Targets.empty())
226 OS << " (none)\n";
227}
dxil DXContainer Global Emitter
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static Target * FirstTarget
static int TargetArraySortFn(const std::pair< StringRef, const Target * > *LHS, const std::pair< StringRef, const Target * > *RHS)
Lightweight error class with error context and mandatory checking.
Context object for machine code objects.
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Streaming machine code generation interface.
Generic base class for all target subtargets.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
Target - Wrapper for Target specific information.
MCTargetStreamer * createAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint) const
MCStreamer * createMCObjectStreamer(const Triple &T, MCContext &Ctx, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter, const MCSubtargetInfo &STI) const
Create a target specific MCStreamer.
bool(*)(Triple::ArchType Arch) ArchMatchFnTy
const char * getShortDescription() const
getShortDescription - Get a short description of the target.
MCStreamer * createAsmStreamer(MCContext &Ctx, std::unique_ptr< formatted_raw_ostream > OS, MCInstPrinter *IP, std::unique_ptr< MCCodeEmitter > CE, std::unique_ptr< MCAsmBackend > TAB) const
Triple - Helper class for working with autoconf configuration names.
static ArchType getArchTypeForLLVMName(StringRef Str)
The canonical type for the given LLVM architecture name (e.g., "x86").
ArchType getArch() const
Get the parsed architecture type of this triple.
const std::string & getTriple() const
void setArch(ArchType Kind, SubArchType SubArch=NoSubArch)
Set the architecture (first) component of the triple to a known type.
The instances of the Type class are immutable: once they are created, they are never changed.
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
MCStreamer * createAsmStreamer(MCContext &Ctx, std::unique_ptr< formatted_raw_ostream > OS, MCInstPrinter *InstPrint, std::unique_ptr< MCCodeEmitter > &&CE, std::unique_ptr< MCAsmBackend > &&TAB)
Create a machine code streamer which will print out assembly for the native target,...
MCStreamer * createELFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
MCStreamer * createMachOStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE, bool DWARFMustBeAtTheEnd, bool LabelSections=false)
MCStreamer * createDXContainerStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
MCStreamer * createWasmStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)
MCStreamer * createGOFFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
MCStreamer * createSPIRVStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)
static const Target * lookupTarget(StringRef Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
static void printRegisteredTargetsForVersion(raw_ostream &OS)
printRegisteredTargetsForVersion - Print the registered targets appropriately for inclusion in a tool...
static void RegisterTarget(Target &T, const char *Name, const char *ShortDesc, const char *BackendName, Target::ArchMatchFnTy ArchMatchFn, bool HasJIT=false)
RegisterTarget - Register the given target.
static iterator_range< iterator > targets()