LLVM: lib/MC/TargetRegistry.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

19#include

20#include

21using namespace llvm;

22

23

25

27 const Triple &T, MCContext &Ctx, std::unique_ptr TAB,

28 std::unique_ptr OW, std::unique_ptr Emitter,

31 switch (T.getObjectFormat()) {

35 assert((T.isOSWindows() || T.isUEFI()) &&

36 "only Windows and UEFI COFF are supported");

37 S = COFFStreamerCtorFn(Ctx, std::move(TAB), std::move(OW),

39 break;

41 if (MachOStreamerCtorFn)

42 S = MachOStreamerCtorFn(Ctx, std::move(TAB), std::move(OW),

44 else

46 std::move(Emitter), false);

47 break;

49 if (ELFStreamerCtorFn)

50 S = ELFStreamerCtorFn(T, Ctx, std::move(TAB), std::move(OW),

52 else

55 break;

59 break;

63 break;

65 S = XCOFFStreamerCtorFn(T, Ctx, std::move(TAB), std::move(OW),

67 break;

71 break;

75 break;

76 }

77 if (ObjectTargetStreamerCtorFn)

78 ObjectTargetStreamerCtorFn(*S, STI);

79 return S;

80}

81

83 std::unique_ptr<formatted_raw_ostream> OS,

84 std::unique_ptr IP,

85 std::unique_ptr CE,

86 std::unique_ptr TAB) const {

90 if (AsmStreamerCtorFn)

91 S = AsmStreamerCtorFn(Ctx, std::move(OS), std::move(IP), std::move(CE),

92 std::move(TAB));

93 else

95 std::move(CE), std::move(TAB));

96

98 return S;

99}

100

104

107 std::string &Error) {

108

109

110

111 const Target *TheTarget = nullptr;

112 if (!ArchName.empty()) {

114 [&](const Target &T) { return ArchName == T.getName(); });

115

117 Error = ("invalid target '" + ArchName + "'.").str();

118 return nullptr;

119 }

120

121 TheTarget = &*I;

122

123

124

128 } else {

129

130 std::string TempError;

132 if (!TheTarget) {

133 Error = "unable to get target for '" + TheTriple.getTriple() +

134 "', see --version and --triple.";

135 return nullptr;

136 }

137 }

138

139 return TheTarget;

140}

141

143 std::string &Error) {

144

146 Error = "Unable to find target for this triple (no targets are registered)";

147 return nullptr;

148 }

150 auto ArchMatch = [&](const Target &T) { return T.ArchMatchFn(Arch); };

152

155 "No available targets are compatible with triple \"" + TT.str() + "\"";

156 return nullptr;

157 }

158

159 auto J = std::find_if(std::next(I), targets().end(), ArchMatch);

160 if (J != targets().end()) {

161 Error = std::string("Cannot choose between targets \"") + I->Name +

162 "\" and \"" + J->Name + "\"";

163 return nullptr;

164 }

165

166 return &*I;

167}

168

170 const char *ShortDesc,

171 const char *BackendName,

173 bool HasJIT) {

174 assert(Name && ShortDesc && ArchMatchFn &&

175 "Missing required target information!");

176

177

178

179 if (T.Name)

180 return;

181

182

185

186 T.Name = Name;

187 T.ShortDesc = ShortDesc;

188 T.BackendName = BackendName;

189 T.ArchMatchFn = ArchMatchFn;

190 T.HasJIT = HasJIT;

191}

192

194 const std::pair<StringRef, const Target *> *RHS) {

195 return LHS->first.compare(RHS->first);

196}

197

199 std::vector<std::pair<StringRef, const Target*> > Targets;

200 size_t Width = 0;

202 Targets.push_back(std::make_pair(T.getName(), &T));

203 Width = std::max(Width, Targets.back().first.size());

204 }

206

207 OS << "\n";

208 OS << " Registered Targets:\n";

209 for (const auto &Target : Targets) {

210 OS << " " << Target.first;

213 }

214 if (Targets.empty())

215 OS << " (none)\n";

216}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

dxil DXContainer Global Emitter

dxil pretty DXIL Metadata Pretty Printer

static Target * FirstTarget

Definition TargetRegistry.cpp:24

static int TargetArraySortFn(const std::pair< StringRef, const Target * > *LHS, const std::pair< StringRef, const Target * > *RHS)

Definition TargetRegistry.cpp:193

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.

LLVM_ABI MCStreamer * createAsmStreamer(MCContext &Ctx, std::unique_ptr< formatted_raw_ostream > OS, std::unique_ptr< MCInstPrinter > IP, std::unique_ptr< MCCodeEmitter > CE, std::unique_ptr< MCAsmBackend > TAB) const

Definition TargetRegistry.cpp:82

MCTargetStreamer * createAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint) const

LLVM_ABI 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.

Definition TargetRegistry.cpp:26

bool(*)(Triple::ArchType Arch) ArchMatchFnTy

const char * getShortDescription() const

getShortDescription - Get a short description of the target.

Triple - Helper class for working with autoconf configuration names.

static LLVM_ABI ArchType getArchTypeForLLVMName(StringRef Str)

The canonical type for the given LLVM architecture name (e.g., "x86").

const std::string & getTriple() const

LLVM_ABI 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.

LLVM_ABI 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.

LLVM_ABI MCStreamer * createAsmStreamer(MCContext &Ctx, std::unique_ptr< formatted_raw_ostream > OS, std::unique_ptr< 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,...

LLVM_ABI MCStreamer * createMachOStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE, bool DWARFMustBeAtTheEnd, bool LabelSections=false)

LLVM_ABI 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.

LLVM_ABI MCStreamer * createWasmStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)

LLVM_ABI 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.

LLVM_ABI MCStreamer * createSPIRVStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)

static const Target * lookupTarget(StringRef TripleStr, std::string &Error)

lookupTarget - Lookup a target based on a target triple.

static LLVM_ABI void printRegisteredTargetsForVersion(raw_ostream &OS)

printRegisteredTargetsForVersion - Print the registered targets appropriately for inclusion in a tool...

Definition TargetRegistry.cpp:198

static LLVM_ABI void RegisterTarget(Target &T, const char *Name, const char *ShortDesc, const char *BackendName, Target::ArchMatchFnTy ArchMatchFn, bool HasJIT=false)

RegisterTarget - Register the given target.

Definition TargetRegistry.cpp:169

static LLVM_ABI iterator_range< iterator > targets()

Definition TargetRegistry.cpp:101