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