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