LLVM  7.0.0svn
LTOModule.cpp
Go to the documentation of this file.
1 //===-- LTOModule.cpp - LLVM Link Time Optimizer --------------------------===//
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 implements the Link Time Optimization library. This library is
11 // intended to be used by linker to optimize code at link time.
12 //
13 //===----------------------------------------------------------------------===//
14 
16 #include "llvm/ADT/Triple.h"
21 #include "llvm/IR/Constants.h"
22 #include "llvm/IR/LLVMContext.h"
23 #include "llvm/IR/Mangler.h"
24 #include "llvm/IR/Metadata.h"
25 #include "llvm/IR/Module.h"
26 #include "llvm/MC/MCExpr.h"
27 #include "llvm/MC/MCInst.h"
29 #include "llvm/MC/MCSection.h"
31 #include "llvm/MC/MCSymbol.h"
34 #include "llvm/Object/ObjectFile.h"
36 #include "llvm/Support/Host.h"
38 #include "llvm/Support/Path.h"
39 #include "llvm/Support/SourceMgr.h"
43 #include <system_error>
44 using namespace llvm;
45 using namespace llvm::object;
46 
47 LTOModule::LTOModule(std::unique_ptr<Module> M, MemoryBufferRef MBRef,
49  : Mod(std::move(M)), MBRef(MBRef), _target(TM) {
50  SymTab.addModule(Mod.get());
51 }
52 
54 
55 /// isBitcodeFile - Returns 'true' if the file (or memory contents) is LLVM
56 /// bitcode.
57 bool LTOModule::isBitcodeFile(const void *Mem, size_t Length) {
58  Expected<MemoryBufferRef> BCData = IRObjectFile::findBitcodeInMemBuffer(
59  MemoryBufferRef(StringRef((const char *)Mem, Length), "<mem>"));
60  return !errorToBool(BCData.takeError());
61 }
62 
66  if (!BufferOrErr)
67  return false;
68 
69  Expected<MemoryBufferRef> BCData = IRObjectFile::findBitcodeInMemBuffer(
70  BufferOrErr.get()->getMemBufferRef());
71  return !errorToBool(BCData.takeError());
72 }
73 
76  if (!Result) {
77  logAllUnhandledErrors(Result.takeError(), errs(), "");
78  return false;
79  }
80  return Result->IsThinLTO;
81 }
82 
84  StringRef TriplePrefix) {
86  IRObjectFile::findBitcodeInMemBuffer(Buffer->getMemBufferRef());
87  if (errorToBool(BCOrErr.takeError()))
88  return false;
89  LLVMContext Context;
90  ErrorOr<std::string> TripleOrErr =
92  if (!TripleOrErr)
93  return false;
94  return StringRef(*TripleOrErr).startswith(TriplePrefix);
95 }
96 
99  IRObjectFile::findBitcodeInMemBuffer(Buffer->getMemBufferRef());
100  if (errorToBool(BCOrErr.takeError()))
101  return "";
102  LLVMContext Context;
104  Context, getBitcodeProducerString(*BCOrErr));
105  if (!ProducerOrErr)
106  return "";
107  return *ProducerOrErr;
108 }
109 
112  const TargetOptions &options) {
114  MemoryBuffer::getFile(path);
115  if (std::error_code EC = BufferOrErr.getError()) {
116  Context.emitError(EC.message());
117  return EC;
118  }
119  std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOrErr.get());
120  return makeLTOModule(Buffer->getMemBufferRef(), options, Context,
121  /* ShouldBeLazy*/ false);
122 }
123 
126  size_t size, const TargetOptions &options) {
127  return createFromOpenFileSlice(Context, fd, path, size, 0, options);
128 }
129 
132  size_t map_size, off_t offset,
133  const TargetOptions &options) {
135  MemoryBuffer::getOpenFileSlice(fd, path, map_size, offset);
136  if (std::error_code EC = BufferOrErr.getError()) {
137  Context.emitError(EC.message());
138  return EC;
139  }
140  std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOrErr.get());
141  return makeLTOModule(Buffer->getMemBufferRef(), options, Context,
142  /* ShouldBeLazy */ false);
143 }
144 
146 LTOModule::createFromBuffer(LLVMContext &Context, const void *mem,
147  size_t length, const TargetOptions &options,
148  StringRef path) {
149  StringRef Data((const char *)mem, length);
150  MemoryBufferRef Buffer(Data, path);
151  return makeLTOModule(Buffer, options, Context, /* ShouldBeLazy */ false);
152 }
153 
155 LTOModule::createInLocalContext(std::unique_ptr<LLVMContext> Context,
156  const void *mem, size_t length,
157  const TargetOptions &options, StringRef path) {
158  StringRef Data((const char *)mem, length);
159  MemoryBufferRef Buffer(Data, path);
160  // If we own a context, we know this is being used only for symbol extraction,
161  // not linking. Be lazy in that case.
163  makeLTOModule(Buffer, options, *Context, /* ShouldBeLazy */ true);
164  if (Ret)
165  (*Ret)->OwnedContext = std::move(Context);
166  return Ret;
167 }
168 
171  bool ShouldBeLazy) {
172  // Find the buffer.
173  Expected<MemoryBufferRef> MBOrErr =
174  IRObjectFile::findBitcodeInMemBuffer(Buffer);
175  if (Error E = MBOrErr.takeError()) {
176  std::error_code EC = errorToErrorCode(std::move(E));
177  Context.emitError(EC.message());
178  return EC;
179  }
180 
181  if (!ShouldBeLazy) {
182  // Parse the full file.
183  return expectedToErrorOrAndEmitErrors(Context,
184  parseBitcodeFile(*MBOrErr, Context));
185  }
186 
187  // Parse lazily.
189  Context,
190  getLazyBitcodeModule(*MBOrErr, Context, true /*ShouldLazyLoadMetadata*/));
191 }
192 
194 LTOModule::makeLTOModule(MemoryBufferRef Buffer, const TargetOptions &options,
195  LLVMContext &Context, bool ShouldBeLazy) {
197  parseBitcodeFileImpl(Buffer, Context, ShouldBeLazy);
198  if (std::error_code EC = MOrErr.getError())
199  return EC;
200  std::unique_ptr<Module> &M = *MOrErr;
201 
202  std::string TripleStr = M->getTargetTriple();
203  if (TripleStr.empty())
204  TripleStr = sys::getDefaultTargetTriple();
205  llvm::Triple Triple(TripleStr);
206 
207  // find machine architecture for this module
208  std::string errMsg;
209  const Target *march = TargetRegistry::lookupTarget(TripleStr, errMsg);
210  if (!march)
211  return std::unique_ptr<LTOModule>(nullptr);
212 
213  // construct LTOModule, hand over ownership of module and target
215  Features.getDefaultSubtargetFeatures(Triple);
216  std::string FeatureStr = Features.getString();
217  // Set a default CPU for Darwin triples.
218  std::string CPU;
219  if (Triple.isOSDarwin()) {
220  if (Triple.getArch() == llvm::Triple::x86_64)
221  CPU = "core2";
222  else if (Triple.getArch() == llvm::Triple::x86)
223  CPU = "yonah";
224  else if (Triple.getArch() == llvm::Triple::aarch64)
225  CPU = "cyclone";
226  }
227 
228  TargetMachine *target =
229  march->createTargetMachine(TripleStr, CPU, FeatureStr, options, None);
230 
231  std::unique_ptr<LTOModule> Ret(new LTOModule(std::move(M), Buffer, target));
232  Ret->parseSymbols();
233  Ret->parseMetadata();
234 
235  return std::move(Ret);
236 }
237 
238 /// Create a MemoryBuffer from a memory range with an optional name.
239 std::unique_ptr<MemoryBuffer>
240 LTOModule::makeBuffer(const void *mem, size_t length, StringRef name) {
241  const char *startPtr = (const char*)mem;
242  return MemoryBuffer::getMemBuffer(StringRef(startPtr, length), name, false);
243 }
244 
245 /// objcClassNameFromExpression - Get string that the data pointer points to.
246 bool
247 LTOModule::objcClassNameFromExpression(const Constant *c, std::string &name) {
248  if (const ConstantExpr *ce = dyn_cast<ConstantExpr>(c)) {
249  Constant *op = ce->getOperand(0);
250  if (GlobalVariable *gvn = dyn_cast<GlobalVariable>(op)) {
251  Constant *cn = gvn->getInitializer();
252  if (ConstantDataArray *ca = dyn_cast<ConstantDataArray>(cn)) {
253  if (ca->isCString()) {
254  name = (".objc_class_name_" + ca->getAsCString()).str();
255  return true;
256  }
257  }
258  }
259  }
260  return false;
261 }
262 
263 /// addObjCClass - Parse i386/ppc ObjC class data structure.
264 void LTOModule::addObjCClass(const GlobalVariable *clgv) {
266  if (!c) return;
267 
268  // second slot in __OBJC,__class is pointer to superclass name
269  std::string superclassName;
270  if (objcClassNameFromExpression(c->getOperand(1), superclassName)) {
271  auto IterBool =
272  _undefines.insert(std::make_pair(superclassName, NameAndAttributes()));
273  if (IterBool.second) {
274  NameAndAttributes &info = IterBool.first->second;
275  info.name = IterBool.first->first();
276  info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
277  info.isFunction = false;
278  info.symbol = clgv;
279  }
280  }
281 
282  // third slot in __OBJC,__class is pointer to class name
283  std::string className;
284  if (objcClassNameFromExpression(c->getOperand(2), className)) {
285  auto Iter = _defines.insert(className).first;
286 
287  NameAndAttributes info;
288  info.name = Iter->first();
289  info.attributes = LTO_SYMBOL_PERMISSIONS_DATA |
291  info.isFunction = false;
292  info.symbol = clgv;
293  _symbols.push_back(info);
294  }
295 }
296 
297 /// addObjCCategory - Parse i386/ppc ObjC category data structure.
298 void LTOModule::addObjCCategory(const GlobalVariable *clgv) {
300  if (!c) return;
301 
302  // second slot in __OBJC,__category is pointer to target class name
303  std::string targetclassName;
304  if (!objcClassNameFromExpression(c->getOperand(1), targetclassName))
305  return;
306 
307  auto IterBool =
308  _undefines.insert(std::make_pair(targetclassName, NameAndAttributes()));
309 
310  if (!IterBool.second)
311  return;
312 
313  NameAndAttributes &info = IterBool.first->second;
314  info.name = IterBool.first->first();
315  info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
316  info.isFunction = false;
317  info.symbol = clgv;
318 }
319 
320 /// addObjCClassRef - Parse i386/ppc ObjC class list data structure.
321 void LTOModule::addObjCClassRef(const GlobalVariable *clgv) {
322  std::string targetclassName;
323  if (!objcClassNameFromExpression(clgv->getInitializer(), targetclassName))
324  return;
325 
326  auto IterBool =
327  _undefines.insert(std::make_pair(targetclassName, NameAndAttributes()));
328 
329  if (!IterBool.second)
330  return;
331 
332  NameAndAttributes &info = IterBool.first->second;
333  info.name = IterBool.first->first();
334  info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
335  info.isFunction = false;
336  info.symbol = clgv;
337 }
338 
339 void LTOModule::addDefinedDataSymbol(ModuleSymbolTable::Symbol Sym) {
340  SmallString<64> Buffer;
341  {
342  raw_svector_ostream OS(Buffer);
343  SymTab.printSymbolName(OS, Sym);
344  Buffer.c_str();
345  }
346 
347  const GlobalValue *V = Sym.get<GlobalValue *>();
348  addDefinedDataSymbol(Buffer, V);
349 }
350 
351 void LTOModule::addDefinedDataSymbol(StringRef Name, const GlobalValue *v) {
352  // Add to list of defined symbols.
353  addDefinedSymbol(Name, v, false);
354 
355  if (!v->hasSection() /* || !isTargetDarwin */)
356  return;
357 
358  // Special case i386/ppc ObjC data structures in magic sections:
359  // The issue is that the old ObjC object format did some strange
360  // contortions to avoid real linker symbols. For instance, the
361  // ObjC class data structure is allocated statically in the executable
362  // that defines that class. That data structures contains a pointer to
363  // its superclass. But instead of just initializing that part of the
364  // struct to the address of its superclass, and letting the static and
365  // dynamic linkers do the rest, the runtime works by having that field
366  // instead point to a C-string that is the name of the superclass.
367  // At runtime the objc initialization updates that pointer and sets
368  // it to point to the actual super class. As far as the linker
369  // knows it is just a pointer to a string. But then someone wanted the
370  // linker to issue errors at build time if the superclass was not found.
371  // So they figured out a way in mach-o object format to use an absolute
372  // symbols (.objc_class_name_Foo = 0) and a floating reference
373  // (.reference .objc_class_name_Bar) to cause the linker into erroring when
374  // a class was missing.
375  // The following synthesizes the implicit .objc_* symbols for the linker
376  // from the ObjC data structures generated by the front end.
377 
378  // special case if this data blob is an ObjC class definition
379  if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(v)) {
380  StringRef Section = GV->getSection();
381  if (Section.startswith("__OBJC,__class,")) {
382  addObjCClass(GV);
383  }
384 
385  // special case if this data blob is an ObjC category definition
386  else if (Section.startswith("__OBJC,__category,")) {
387  addObjCCategory(GV);
388  }
389 
390  // special case if this data blob is the list of referenced classes
391  else if (Section.startswith("__OBJC,__cls_refs,")) {
392  addObjCClassRef(GV);
393  }
394  }
395 }
396 
397 void LTOModule::addDefinedFunctionSymbol(ModuleSymbolTable::Symbol Sym) {
398  SmallString<64> Buffer;
399  {
400  raw_svector_ostream OS(Buffer);
401  SymTab.printSymbolName(OS, Sym);
402  Buffer.c_str();
403  }
404 
405  const Function *F = cast<Function>(Sym.get<GlobalValue *>());
406  addDefinedFunctionSymbol(Buffer, F);
407 }
408 
409 void LTOModule::addDefinedFunctionSymbol(StringRef Name, const Function *F) {
410  // add to list of defined symbols
411  addDefinedSymbol(Name, F, true);
412 }
413 
414 void LTOModule::addDefinedSymbol(StringRef Name, const GlobalValue *def,
415  bool isFunction) {
416  // set alignment part log2() can have rounding errors
417  uint32_t align = def->getAlignment();
418  uint32_t attr = align ? countTrailingZeros(align) : 0;
419 
420  // set permissions part
421  if (isFunction) {
423  } else {
424  const GlobalVariable *gv = dyn_cast<GlobalVariable>(def);
425  if (gv && gv->isConstant())
427  else
429  }
430 
431  // set definition part
432  if (def->hasWeakLinkage() || def->hasLinkOnceLinkage())
434  else if (def->hasCommonLinkage())
436  else
438 
439  // set scope part
440  if (def->hasLocalLinkage())
441  // Ignore visibility if linkage is local.
443  else if (def->hasHiddenVisibility())
444  attr |= LTO_SYMBOL_SCOPE_HIDDEN;
445  else if (def->hasProtectedVisibility())
447  else if (canBeOmittedFromSymbolTable(def))
449  else
450  attr |= LTO_SYMBOL_SCOPE_DEFAULT;
451 
452  if (def->hasComdat())
453  attr |= LTO_SYMBOL_COMDAT;
454 
455  if (isa<GlobalAlias>(def))
456  attr |= LTO_SYMBOL_ALIAS;
457 
458  auto Iter = _defines.insert(Name).first;
459 
460  // fill information structure
461  NameAndAttributes info;
462  StringRef NameRef = Iter->first();
463  info.name = NameRef;
464  assert(NameRef.data()[NameRef.size()] == '\0');
465  info.attributes = attr;
466  info.isFunction = isFunction;
467  info.symbol = def;
468 
469  // add to table of symbols
470  _symbols.push_back(info);
471 }
472 
473 /// addAsmGlobalSymbol - Add a global symbol from module-level ASM to the
474 /// defined list.
475 void LTOModule::addAsmGlobalSymbol(StringRef name,
476  lto_symbol_attributes scope) {
477  auto IterBool = _defines.insert(name);
478 
479  // only add new define if not already defined
480  if (!IterBool.second)
481  return;
482 
483  NameAndAttributes &info = _undefines[IterBool.first->first()];
484 
485  if (info.symbol == nullptr) {
486  // FIXME: This is trying to take care of module ASM like this:
487  //
488  // module asm ".zerofill __FOO, __foo, _bar_baz_qux, 0"
489  //
490  // but is gross and its mother dresses it funny. Have the ASM parser give us
491  // more details for this type of situation so that we're not guessing so
492  // much.
493 
494  // fill information structure
495  info.name = IterBool.first->first();
496  info.attributes =
498  info.isFunction = false;
499  info.symbol = nullptr;
500 
501  // add to table of symbols
502  _symbols.push_back(info);
503  return;
504  }
505 
506  if (info.isFunction)
507  addDefinedFunctionSymbol(info.name, cast<Function>(info.symbol));
508  else
509  addDefinedDataSymbol(info.name, info.symbol);
510 
511  _symbols.back().attributes &= ~LTO_SYMBOL_SCOPE_MASK;
512  _symbols.back().attributes |= scope;
513 }
514 
515 /// addAsmGlobalSymbolUndef - Add a global symbol from module-level ASM to the
516 /// undefined list.
517 void LTOModule::addAsmGlobalSymbolUndef(StringRef name) {
518  auto IterBool = _undefines.insert(std::make_pair(name, NameAndAttributes()));
519 
520  _asm_undefines.push_back(IterBool.first->first());
521 
522  // we already have the symbol
523  if (!IterBool.second)
524  return;
525 
527  attr |= LTO_SYMBOL_SCOPE_DEFAULT;
528  NameAndAttributes &info = IterBool.first->second;
529  info.name = IterBool.first->first();
530  info.attributes = attr;
531  info.isFunction = false;
532  info.symbol = nullptr;
533 }
534 
535 /// Add a symbol which isn't defined just yet to a list to be resolved later.
536 void LTOModule::addPotentialUndefinedSymbol(ModuleSymbolTable::Symbol Sym,
537  bool isFunc) {
539  {
540  raw_svector_ostream OS(name);
541  SymTab.printSymbolName(OS, Sym);
542  name.c_str();
543  }
544 
545  auto IterBool = _undefines.insert(std::make_pair(name, NameAndAttributes()));
546 
547  // we already have the symbol
548  if (!IterBool.second)
549  return;
550 
551  NameAndAttributes &info = IterBool.first->second;
552 
553  info.name = IterBool.first->first();
554 
555  const GlobalValue *decl = Sym.dyn_cast<GlobalValue *>();
556 
557  if (decl->hasExternalWeakLinkage())
558  info.attributes = LTO_SYMBOL_DEFINITION_WEAKUNDEF;
559  else
560  info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
561 
562  info.isFunction = isFunc;
563  info.symbol = decl;
564 }
565 
566 void LTOModule::parseSymbols() {
567  for (auto Sym : SymTab.symbols()) {
568  auto *GV = Sym.dyn_cast<GlobalValue *>();
569  uint32_t Flags = SymTab.getSymbolFlags(Sym);
571  continue;
572 
573  bool IsUndefined = Flags & object::BasicSymbolRef::SF_Undefined;
574 
575  if (!GV) {
576  SmallString<64> Buffer;
577  {
578  raw_svector_ostream OS(Buffer);
579  SymTab.printSymbolName(OS, Sym);
580  Buffer.c_str();
581  }
582  StringRef Name(Buffer);
583 
584  if (IsUndefined)
585  addAsmGlobalSymbolUndef(Name);
586  else if (Flags & object::BasicSymbolRef::SF_Global)
587  addAsmGlobalSymbol(Name, LTO_SYMBOL_SCOPE_DEFAULT);
588  else
589  addAsmGlobalSymbol(Name, LTO_SYMBOL_SCOPE_INTERNAL);
590  continue;
591  }
592 
593  auto *F = dyn_cast<Function>(GV);
594  if (IsUndefined) {
595  addPotentialUndefinedSymbol(Sym, F != nullptr);
596  continue;
597  }
598 
599  if (F) {
600  addDefinedFunctionSymbol(Sym);
601  continue;
602  }
603 
604  if (isa<GlobalVariable>(GV)) {
605  addDefinedDataSymbol(Sym);
606  continue;
607  }
608 
609  assert(isa<GlobalAlias>(GV));
610  addDefinedDataSymbol(Sym);
611  }
612 
613  // make symbols for all undefines
614  for (StringMap<NameAndAttributes>::iterator u =_undefines.begin(),
615  e = _undefines.end(); u != e; ++u) {
616  // If this symbol also has a definition, then don't make an undefine because
617  // it is a tentative definition.
618  if (_defines.count(u->getKey())) continue;
619  NameAndAttributes info = u->getValue();
620  _symbols.push_back(info);
621  }
622 }
623 
624 /// parseMetadata - Parse metadata from the module
625 void LTOModule::parseMetadata() {
626  raw_string_ostream OS(LinkerOpts);
627 
628  // Linker Options
629  if (NamedMDNode *LinkerOptions =
630  getModule().getNamedMetadata("llvm.linker.options")) {
631  for (unsigned i = 0, e = LinkerOptions->getNumOperands(); i != e; ++i) {
632  MDNode *MDOptions = LinkerOptions->getOperand(i);
633  for (unsigned ii = 0, ie = MDOptions->getNumOperands(); ii != ie; ++ii) {
634  MDString *MDOption = cast<MDString>(MDOptions->getOperand(ii));
635  OS << " " << MDOption->getString();
636  }
637  }
638  }
639 
640  // Globals - we only need to do this for COFF.
641  const Triple TT(_target->getTargetTriple());
642  if (!TT.isOSBinFormatCOFF())
643  return;
644  Mangler M;
645  for (const NameAndAttributes &Sym : _symbols) {
646  if (!Sym.symbol)
647  continue;
648  emitLinkerFlagsForGlobalCOFF(OS, Sym.symbol, TT, M);
649  }
650 
651  // Add other interesting metadata here.
652 }
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS).
Definition: Triple.h:470
static ErrorOr< std::unique_ptr< MemoryBuffer > > getOpenFileSlice(int FD, const Twine &Filename, uint64_t MapSize, int64_t Offset, bool IsVolatile=false)
Given an already-open file descriptor, map some slice of it into a MemoryBuffer.
Represents either an error or a value T.
Definition: ErrorOr.h:69
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
bool hasLocalLinkage() const
Definition: GlobalValue.h:435
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
Expected< std::unique_ptr< Module > > getLazyBitcodeModule(MemoryBufferRef Buffer, LLVMContext &Context, bool ShouldLazyLoadMetadata=false, bool IsImporting=false)
Read the header of the specified bitcode buffer and prepare for lazy deserialization of function bodi...
TargetMachine * createTargetMachine(StringRef TT, StringRef CPU, StringRef Features, const TargetOptions &Options, Optional< Reloc::Model > RM, Optional< CodeModel::Model > CM=None, CodeGenOpt::Level OL=CodeGenOpt::Default, bool JIT=false) const
createTargetMachine - Create a target specific machine implementation for the specified Triple...
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner)
Log all errors (if any) in E to OS.
Definition: Error.cpp:57
static ErrorOr< std::unique_ptr< LTOModule > > createFromFile(LLVMContext &Context, StringRef path, const TargetOptions &options)
Create an LTOModule.
Definition: LTOModule.cpp:111
bool canBeOmittedFromSymbolTable(const GlobalValue *GV)
True if GV can be left out of the object symbol table.
Definition: ObjectUtils.h:22
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
std::string getDefaultTargetTriple()
getDefaultTargetTriple() - Return the default target triple the compiler has been configured to produ...
This file contains the declarations for metadata subclasses.
bool isThinLTO()
Returns &#39;true&#39; if the Module is produced for ThinLTO.
Definition: LTOModule.cpp:74
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:489
static ErrorOr< std::unique_ptr< LTOModule > > createFromOpenFileSlice(LLVMContext &Context, int fd, StringRef path, size_t map_size, off_t offset, const TargetOptions &options)
Definition: LTOModule.cpp:131
Metadata node.
Definition: Metadata.h:862
F(f)
static std::string getProducerString(MemoryBuffer *Buffer)
Returns a string representing the producer identification stored in the bitcode, or "" if the bitcode...
Definition: LTOModule.cpp:97
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1067
bool hasExternalWeakLinkage() const
Definition: GlobalValue.h:436
Error takeError()
Take ownership of the stored error.
Definition: Error.h:537
static const Target * lookupTarget(const std::string &Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
#define op(i)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:128
bool hasSection() const
Definition: GlobalValue.h:269
A tuple of MDNodes.
Definition: Metadata.h:1323
Definition: BitVector.h:921
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
bool hasCommonLinkage() const
Definition: GlobalValue.h:439
void emitError(unsigned LocCookie, const Twine &ErrorStr)
emitError - Emit an error message to the currently installed error handler with optional location inf...
static ErrorOr< std::unique_ptr< LTOModule > > createFromOpenFile(LLVMContext &Context, int fd, StringRef path, size_t size, const TargetOptions &options)
Definition: LTOModule.cpp:125
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:267
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:867
static ErrorOr< std::unique_ptr< Module > > parseBitcodeFileImpl(MemoryBufferRef Buffer, LLVMContext &Context, bool ShouldBeLazy)
Definition: LTOModule.cpp:170
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:285
unsigned getAlignment() const
Definition: Globals.cpp:97
bool hasLinkOnceLinkage() const
Definition: GlobalValue.h:425
static bool isBitcodeForTarget(MemoryBuffer *memBuffer, StringRef triplePrefix)
Returns &#39;true&#39; if the memory buffer is LLVM bitcode for the specified triple.
Definition: LTOModule.cpp:83
Value * getOperand(unsigned i) const
Definition: User.h:154
StringRef getString() const
Definition: Metadata.cpp:464
Expected< std::string > getBitcodeProducerString(MemoryBufferRef Buffer)
Read the header of the specified bitcode buffer and extract just the producer string information...
bool hasProtectedVisibility() const
Definition: GlobalValue.h:235
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0&#39;s from the least significant bit to the most stopping at the first 1...
Definition: MathExtras.h:112
An array constant whose element type is a simple 1/2/4/8-byte integer or float/double, and whose elements are just simple data values (i.e.
Definition: Constants.h:686
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
bool errorToBool(Error Err)
Helper for converting an Error to a bool.
Definition: Error.h:971
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Definition: Constant.h:42
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::error_code getError() const
Definition: ErrorOr.h:172
void emitLinkerFlagsForGlobalCOFF(raw_ostream &OS, const GlobalValue *GV, const Triple &TT, Mangler &Mangler)
Definition: Mangler.cpp:177
Expected< std::string > getBitcodeTargetTriple(MemoryBufferRef Buffer)
Read the header of the specified bitcode buffer and extract just the triple information.
lazy value info
C++ class which implements the opaque lto_module_t type.
Definition: LTOModule.h:38
T dyn_cast() const
Returns the current pointer if it is of the specified pointer type, otherwises returns null...
Definition: PointerUnion.h:142
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
bool hasWeakLinkage() const
Definition: GlobalValue.h:429
bool hasComdat() const
Definition: GlobalValue.h:225
Module.h This file contains the declarations for the Module class.
MemoryBufferRef getMemBufferRef() const
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:41
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:222
Target - Wrapper for Target specific information.
Manages the enabling and disabling of subtarget specific features.
bool hasHiddenVisibility() const
Definition: GlobalValue.h:234
The access may modify the value stored in memory.
Expected< std::unique_ptr< Module > > parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context)
Read the specified bitcode file, returning the module.
Expected< BitcodeLTOInfo > getBitcodeLTOInfo(MemoryBufferRef Buffer)
Returns LTO information for the specified bitcode file.
ErrorOr< T > expectedToErrorOrAndEmitErrors(LLVMContext &Ctx, Expected< T > Val)
Definition: BitcodeReader.h:42
iterator begin()
Definition: StringMap.h:317
lto_symbol_attributes
Definition: lto.h:52
const char * c_str()
Definition: SmallString.h:270
static std::unique_ptr< MemoryBuffer > makeBuffer(const void *mem, size_t length, StringRef name="")
Create a MemoryBuffer from a memory range with an optional name.
Definition: LTOModule.cpp:240
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
static bool isBitcodeFile(const void *mem, size_t length)
Returns &#39;true&#39; if the file or memory contents is LLVM bitcode.
Definition: LTOModule.cpp:57
T get() const
Returns the value of the specified pointer type.
Definition: PointerUnion.h:135
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:462
static const char * name
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
const FeatureBitset Features
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:59
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
A single uniqued string.
Definition: Metadata.h:602
static ErrorOr< std::unique_ptr< LTOModule > > createInLocalContext(std::unique_ptr< LLVMContext > Context, const void *mem, size_t length, const TargetOptions &options, StringRef path)
Definition: LTOModule.cpp:155
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1073
std::error_code errorToErrorCode(Error Err)
Helper for converting an ECError to a std::error_code.
Definition: Error.cpp:84
reference get()
Definition: ErrorOr.h:169
A discriminated union of two pointer types, with the discriminator in the low bit of the pointer...
Definition: PointerUnion.h:87
static ErrorOr< std::unique_ptr< LTOModule > > createFromBuffer(LLVMContext &Context, const void *mem, size_t length, const TargetOptions &options, StringRef path="")
Definition: LTOModule.cpp:146