LLVM: lib/Target/TargetMachineC.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

27#include

28#include

29

30using namespace llvm;

31

32namespace llvm {

33

34

40 std::optionalReloc::Model RM;

41 std::optionalCodeModel::Model CM;

43};

44

45}

46

49

52}

54 return reinterpret_cast<Target*>(P);

55}

58}

61}

62

65 return nullptr;

66 }

67

69 return wrap(target);

70}

73}

74

78 [&](const Target &T) { return T.getName() == NameRef; });

80}

81

83 char **ErrorMessage) {

84 std::string Error;

85

87

88 if (!*T) {

89 if (ErrorMessage)

90 *ErrorMessage = strdup(Error.c_str());

91

92 return 1;

93 }

94

95 return 0;

96}

97

100}

101

104}

105

108}

109

112}

113

116}

117

120}

121

124}

125

127 const char *CPU) {

129}

130

132 const char *Features) {

134}

135

137 const char *ABI) {

139}

140

144

145 switch (Level) {

147 OL = CodeGenOptLevel::None;

148 break;

150 OL = CodeGenOptLevel::Less;

151 break;

153 OL = CodeGenOptLevel::Aggressive;

154 break;

156 OL = CodeGenOptLevel::Default;

157 break;

158 }

159

161}

162

165 std::optionalReloc::Model RM;

166

167 switch (Reloc) {

170 break;

173 break;

176 break;

179 break;

182 break;

185 break;

187 break;

188 }

189

191}

192

197}

198

206 TO, Opt->RM, Opt->CM, Opt->OL,

207 Opt->JIT));

208}

209

215

221

223

226}

227

229

231 const Target* target = &(unwrap(T)->getTarget());

232 return wrap(target);

233}

234

236 std::string StringRep = unwrap(T)->getTargetTriple().str();

237 return strdup(StringRep.c_str());

238}

239

241 std::string StringRep = std::string(unwrap(T)->getTargetCPU());

242 return strdup(StringRep.c_str());

243}

244

246 std::string StringRep = std::string(unwrap(T)->getTargetFeatureString());

247 return strdup(StringRep.c_str());

248}

249

252 unwrap(T)->Options.MCOptions.AsmVerbose = VerboseAsm;

253}

254

257}

258

261}

262

266 switch (Mode) {

268 AM = GlobalISelAbortMode::Disable;

269 break;

271 AM = GlobalISelAbortMode::Enable;

272 break;

274 AM = GlobalISelAbortMode::DisableWithDiag;

275 break;

276 }

277

278 unwrap(T)->setGlobalISelAbort(AM);

279}

280

284}

285

288}

289

293 char **ErrorMessage) {

296

298

299 std::string error;

300

301 Mod->setDataLayout(TM->createDataLayout());

302

304 switch (codegen) {

306 ft = CodeGenFileType::AssemblyFile;

307 break;

308 default:

309 ft = CodeGenFileType::ObjectFile;

310 break;

311 }

312 if (TM->addPassesToEmitFile(pass, OS, nullptr, ft)) {

313 error = "TargetMachine can't emit a file of this type";

314 *ErrorMessage = strdup(error.c_str());

315 return true;

316 }

317

319

321 return false;

322}

323

325 const char *Filename,

327 char **ErrorMessage) {

328 std::error_code EC;

330 if (EC) {

331 *ErrorMessage = strdup(EC.message().c_str());

332 return true;

333 }

336 return Result;

337}

338

345

347 *OutMemBuf =

349 return Result;

350}

351

354}

355

358}

359

362}

363

367 Features.AddFeature(Feature, IsEnabled);

368

369 return strdup(Features.getString().c_str());

370}

371

375}

#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)

COFF::MachineTypes Machine

global merge Global merge function pass

Module.h This file contains the declarations for the Module class.

static std::unique_ptr< TargetMachine > createTargetMachine(Function *F, CodeGenOptLevel OptLevel)

Create the TargetMachine object to query the backend for optimization preferences.

if(auto Err=PB.parsePassPipeline(MPM, Passes)) return wrap(std MPM run * Mod

static LLVMBool LLVMTargetMachineEmit(LLVMTargetMachineRef T, LLVMModuleRef M, raw_pwrite_stream &OS, LLVMCodeGenFileType codegen, char **ErrorMessage)

static LLVMTargetMachineRef wrap(const TargetMachine *P)

static Target * unwrap(LLVMTargetRef P)

This pass exposes codegen information to IR-level passes.

A parsed version of the target data layout string in and methods for querying it.

Lightweight error class with error context and mandatory checking.

A Module instance is used to store all the information related to an LLVM module.

SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...

StringRef - Represent a constant reference to a string, i.e.

Manages the enabling and disabling of subtarget specific features.

std::string getString() const

Returns features as a string.

void AddFeature(StringRef String, bool Enable=true)

Adds Features.

Primary interface to the complete machine description for the target machine.

MCTargetOptions MCOptions

Machine level options.

Target - Wrapper for Target specific information.

bool hasTargetMachine() const

hasTargetMachine - Check if this target supports code generation.

const char * getName() const

getName - Get the target name.

bool hasMCAsmBackend() const

hasMCAsmBackend - Check if this target supports .o generation.

const char * getShortDescription() const

getShortDescription - Get a short description of the target.

bool hasJIT() const

hasJIT - Check if this targets supports the just-in-time compilation.

Triple - Helper class for working with autoconf configuration names.

static std::string normalize(StringRef Str, CanonicalForm Form=CanonicalForm::ANY)

Turn an arbitrary machine specification into the canonical triple form (or something sensible that th...

PassManager manages ModulePassManagers.

A raw_ostream that writes to a file descriptor.

An abstract base class for streams implementations that also support a pwrite operation.

A raw_ostream that writes to an SmallVector or SmallString.

StringRef str() const

Return a StringRef for the vector contents.

LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData, size_t InputDataLength, const char *BufferName)

struct LLVMOpaquePassManager * LLVMPassManagerRef

struct LLVMOpaqueMemoryBuffer * LLVMMemoryBufferRef

LLVM uses a polymorphic type hierarchy which C cannot represent, therefore parameters must be passed ...

struct LLVMOpaqueModule * LLVMModuleRef

The top-level container for all other LLVM Intermediate Representation (IR) objects.

void LLVMTargetMachineOptionsSetCPU(LLVMTargetMachineOptionsRef Options, const char *CPU)

void LLVMTargetMachineOptionsSetFeatures(LLVMTargetMachineOptionsRef Options, const char *Features)

Set the list of features for the target machine.

void LLVMSetTargetMachineMachineOutliner(LLVMTargetMachineRef T, LLVMBool Enable)

Enable the MachineOutliner pass.

char * LLVMGetHostCPUFeatures(void)

Get the host CPU's features as a string.

void LLVMTargetMachineOptionsSetRelocMode(LLVMTargetMachineOptionsRef Options, LLVMRelocMode Reloc)

LLVMTargetRef LLVMGetFirstTarget()

Returns the first llvm::Target in the registered targets list.

struct LLVMTarget * LLVMTargetRef

char * LLVMGetHostCPUName(void)

Get the host CPU as a string.

struct LLVMOpaqueTargetMachine * LLVMTargetMachineRef

void LLVMTargetMachineOptionsSetCodeGenOptLevel(LLVMTargetMachineOptionsRef Options, LLVMCodeGenOptLevel Level)

char * LLVMGetTargetMachineCPU(LLVMTargetMachineRef T)

Returns the cpu used creating this target machine.

void LLVMDisposeTargetMachineOptions(LLVMTargetMachineOptionsRef Options)

Dispose of an LLVMTargetMachineOptionsRef instance.

const char * LLVMGetTargetName(LLVMTargetRef T)

Returns the name of a target.

struct LLVMOpaqueTargetMachineOptions * LLVMTargetMachineOptionsRef

void LLVMSetTargetMachineGlobalISel(LLVMTargetMachineRef T, LLVMBool Enable)

Enable global instruction selection.

void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM)

Adds the target-specific analysis passes to the pass manager.

LLVMTargetRef LLVMGetTargetFromName(const char *Name)

Finds the target corresponding to the given name and stores it in T.

void LLVMSetTargetMachineFastISel(LLVMTargetMachineRef T, LLVMBool Enable)

Enable fast-path instruction selection.

const char * LLVMGetTargetDescription(LLVMTargetRef T)

Returns the description of a target.

char * LLVMGetDefaultTargetTriple(void)

Get a triple for the host machine as a string.

void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T, LLVMBool VerboseAsm)

Set the target machine's ASM verbosity.

LLVMTargetMachineOptionsRef LLVMCreateTargetMachineOptions(void)

Create a new set of options for an llvm::TargetMachine.

LLVMBool LLVMGetTargetFromTriple(const char *TripleStr, LLVMTargetRef *T, char **ErrorMessage)

Finds the target corresponding to the given triple and stores it in T.

char * LLVMNormalizeTargetTriple(const char *triple)

Normalize a target triple.

LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T)

Returns if the target as an ASM backend (required for emitting output)

LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M, const char *Filename, LLVMCodeGenFileType codegen, char **ErrorMessage)

Emits an asm or object file for the given module to the filename.

char * LLVMGetTargetMachineTriple(LLVMTargetMachineRef T)

Returns the triple used creating this target machine.

LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple, const char *CPU, const char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, LLVMCodeModel CodeModel)

Creates a new llvm::TargetMachine.

void LLVMTargetMachineOptionsSetABI(LLVMTargetMachineOptionsRef Options, const char *ABI)

LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T)

Returns the next llvm::Target given a previous one (or null if there's none)

LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleRef M, LLVMCodeGenFileType codegen, char **ErrorMessage, LLVMMemoryBufferRef *OutMemBuf)

Compile the LLVM IR stored in M and store the result in OutMemBuf.

LLVMTargetDataRef LLVMCreateTargetDataLayout(LLVMTargetMachineRef T)

Create a DataLayout based on the targetMachine.

LLVMBool LLVMTargetHasTargetMachine(LLVMTargetRef T)

Returns if the target has a TargetMachine associated.

struct LLVMOpaqueTargetData * LLVMTargetDataRef

LLVMTargetMachineRef LLVMCreateTargetMachineWithOptions(LLVMTargetRef T, const char *Triple, LLVMTargetMachineOptionsRef Options)

Create a new llvm::TargetMachine.

LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T)

Returns the Target used in a TargetMachine.

void LLVMTargetMachineOptionsSetCodeModel(LLVMTargetMachineOptionsRef Options, LLVMCodeModel CodeModel)

void LLVMSetTargetMachineGlobalISelAbort(LLVMTargetMachineRef T, LLVMGlobalISelAbortMode Mode)

Set abort behaviour when global instruction selection fails to lower/select an instruction.

void LLVMDisposeTargetMachine(LLVMTargetMachineRef T)

Dispose the LLVMTargetMachineRef instance generated by LLVMCreateTargetMachine.

LLVMBool LLVMTargetHasJIT(LLVMTargetRef T)

Returns if the target has a JIT.

char * LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T)

Returns the feature string used creating this target machine.

@ LLVMCodeGenLevelAggressive

@ LLVMCodeGenLevelDefault

@ LLVMGlobalISelAbortDisableWithDiag

@ LLVMGlobalISelAbortDisable

@ LLVMGlobalISelAbortEnable

const StringMap< bool, MallocAllocator > getHostCPUFeatures()

getHostCPUFeatures - Get the LLVM names for the host CPU features.

StringRef getHostCPUName()

getHostCPUName - Get the LLVM name for the host CPU.

std::string getDefaultTargetTriple()

getDefaultTargetTriple() - Return the default target triple the compiler has been configured to produ...

This is an optimization pass for GlobalISel generic memory operations.

SmallVectorImpl< T >::const_pointer c_str(SmallVectorImpl< T > &str)

CodeGenFileType

These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...

CodeGenOptLevel

Code generation optimization level.

ImmutablePass * createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA)

Create an analysis pass wrapper around a TTI object.

auto find_if(R &&Range, UnaryPredicate P)

Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.

GlobalISelAbortMode

Enable abort calls when global instruction selection fails to lower/select an instruction.

Options for LLVMCreateTargetMachine().

std::optional< Reloc::Model > RM

std::optional< CodeModel::Model > CM

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

lookupTarget - Lookup a target based on a target triple.

static iterator_range< iterator > targets()