Go to the documentation of this file.
42 #include <system_error>
49 assert(_target &&
"target machine is null");
50 SymTab.addModule(
Mod.get());
70 BufferOrErr.
get()->getMemBufferRef());
80 return Result->IsThinLTO;
107 return *ProducerOrErr;
115 if (std::error_code EC = BufferOrErr.
getError()) {
119 std::unique_ptr<MemoryBuffer> Buffer =
std::move(BufferOrErr.
get());
132 size_t map_size, off_t offset,
137 if (std::error_code EC = BufferOrErr.
getError()) {
141 std::unique_ptr<MemoryBuffer> Buffer =
std::move(BufferOrErr.
get());
157 const void *mem,
size_t length,
175 IRObjectFile::findBitcodeInMemBuffer(Buffer);
199 if (std::error_code EC = MOrErr.
getError())
201 std::unique_ptr<Module> &
M = *MOrErr;
203 std::string TripleStr =
M->getTargetTriple();
204 if (TripleStr.empty())
217 std::string FeatureStr = Features.
getString();
237 Ret->parseMetadata();
243 std::unique_ptr<MemoryBuffer>
245 const char *startPtr = (
const char*)mem;
251 LTOModule::objcClassNameFromExpression(
const Constant *
c, std::string &
name) {
255 Constant *cn = gvn->getInitializer();
257 if (ca->isCString()) {
258 name = (
".objc_class_name_" + ca->getAsCString()).str();
273 std::string superclassName;
274 if (objcClassNameFromExpression(
c->getOperand(1), superclassName)) {
276 _undefines.
insert(std::make_pair(superclassName, NameAndAttributes()));
277 if (IterBool.second) {
278 NameAndAttributes &
info = IterBool.first->second;
279 info.name = IterBool.first->first();
281 info.isFunction =
false;
287 std::string className;
288 if (objcClassNameFromExpression(
c->getOperand(2), className)) {
289 auto Iter = _defines.
insert(className).first;
291 NameAndAttributes
info;
292 info.name = Iter->first();
295 info.isFunction =
false;
297 _symbols.push_back(
info);
307 std::string targetclassName;
308 if (!objcClassNameFromExpression(
c->getOperand(1), targetclassName))
312 _undefines.
insert(std::make_pair(targetclassName, NameAndAttributes()));
314 if (!IterBool.second)
317 NameAndAttributes &
info = IterBool.first->second;
318 info.name = IterBool.first->first();
320 info.isFunction =
false;
326 std::string targetclassName;
327 if (!objcClassNameFromExpression(clgv->
getInitializer(), targetclassName))
331 _undefines.
insert(std::make_pair(targetclassName, NameAndAttributes()));
333 if (!IterBool.second)
336 NameAndAttributes &
info = IterBool.first->second;
337 info.name = IterBool.first->first();
339 info.isFunction =
false;
352 addDefinedDataSymbol(Buffer, V);
357 addDefinedSymbol(Name, v,
false);
385 if (
Section.startswith(
"__OBJC,__class,")) {
390 else if (
Section.startswith(
"__OBJC,__category,")) {
395 else if (
Section.startswith(
"__OBJC,__cls_refs,")) {
410 addDefinedFunctionSymbol(Buffer,
F);
415 addDefinedSymbol(Name,
F,
true);
458 if (isa<GlobalAlias>(def))
461 auto Iter = _defines.
insert(Name).first;
464 NameAndAttributes
info;
468 info.attributes = attr;
473 _symbols.push_back(
info);
483 if (!IterBool.second)
486 NameAndAttributes &
info = _undefines[IterBool.first->first()];
488 if (
info.symbol ==
nullptr) {
498 info.name = IterBool.first->first();
501 info.isFunction =
false;
502 info.symbol =
nullptr;
505 _symbols.push_back(
info);
510 addDefinedFunctionSymbol(
info.name, cast<Function>(
info.symbol));
512 addDefinedDataSymbol(
info.name,
info.symbol);
515 _symbols.back().attributes |= scope;
521 auto IterBool = _undefines.
insert(std::make_pair(
name, NameAndAttributes()));
523 _asm_undefines.push_back(IterBool.first->first());
526 if (!IterBool.second)
531 NameAndAttributes &
info = IterBool.first->second;
532 info.name = IterBool.first->first();
533 info.attributes = attr;
534 info.isFunction =
false;
535 info.symbol =
nullptr;
549 _undefines.
insert(std::make_pair(
name.str(), NameAndAttributes()));
552 if (!IterBool.second)
555 NameAndAttributes &
info = IterBool.first->second;
557 info.name = IterBool.first->first();
566 info.isFunction = isFunc;
570 void LTOModule::parseSymbols() {
571 for (
auto Sym : SymTab.
symbols()) {
589 addAsmGlobalSymbolUndef(Name);
597 auto *
F = dyn_cast<Function>(GV);
599 addPotentialUndefinedSymbol(Sym,
F !=
nullptr);
604 addDefinedFunctionSymbol(Sym);
608 if (isa<GlobalVariable>(GV)) {
609 addDefinedDataSymbol(Sym);
613 assert(isa<GlobalAlias>(GV));
614 addDefinedDataSymbol(Sym);
619 e = _undefines.
end(); u !=
e; ++u) {
622 if (_defines.
count(u->getKey()))
continue;
623 NameAndAttributes
info = u->getValue();
624 _symbols.push_back(
info);
629 void LTOModule::parseMetadata() {
634 getModule().getNamedMetadata(
"llvm.linker.options")) {
635 for (
unsigned i = 0,
e = LinkerOptions->getNumOperands();
i !=
e; ++
i) {
637 for (
unsigned ii = 0, ie = MDOptions->
getNumOperands(); ii != ie; ++ii) {
645 const Triple TT(_target->getTargetTriple());
646 if (!
TT.isOSBinFormatCOFF())
649 for (
const NameAndAttributes &Sym : _symbols) {
657 size_t buffer_size,
const char *path,
658 std::string &outErr) {
666 return ObjOrErr->release();
668 outErr = std::string(path) +
674 return input->getDependentLibraries().size();
693 for (
auto Sym : SymTab.
symbols()) {
696 if (Name.consume_front(
"llvm.global_")) {
697 if (Name.equals(
"ctors") || Name.equals(
"dtors"))
ErrorOr< T > expectedToErrorOrAndEmitErrors(LLVMContext &Ctx, Expected< T > Val)
@ LTO_SYMBOL_SCOPE_DEFAULT
@ LTO_SYMBOL_SCOPE_PROTECTED
static bool isFunction(SDValue Op)
static ErrorOr< std::unique_ptr< LTOModule > > createInLocalContext(std::unique_ptr< LLVMContext > Context, const void *mem, size_t length, const TargetOptions &options, StringRef path)
This is an optimization pass for GlobalISel generic memory operations.
void emitError(uint64_t LocCookie, const Twine &ErrorStr)
emitError - Emit an error message to the currently installed error handler with optional location inf...
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
bool hasCommonLinkage() const
@ LTO_SYMBOL_DEFINITION_TENTATIVE
bool hasProtectedVisibility() const
Expected< std::string > getBitcodeProducerString(MemoryBufferRef Buffer)
Read the header of the specified bitcode buffer and extract just the producer string information.
A raw_ostream that writes to an std::string.
Target - Wrapper for Target specific information.
bool hasWeakLinkage() const
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
static ErrorOr< std::unique_ptr< LTOModule > > createFromFile(LLVMContext &Context, StringRef path, const TargetOptions &options)
Create an LTOModule.
Triple - Helper class for working with autoconf configuration names.
bool hasHiddenVisibility() const
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
Expected< std::unique_ptr< Module > > parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context, ParserCallbacks Callbacks={})
Read the specified bitcode file, returning the module.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
static ErrorOr< std::unique_ptr< LTOModule > > createFromOpenFileSlice(LLVMContext &Context, int fd, StringRef path, size_t map_size, off_t offset, const TargetOptions &options)
std::pair< typename Base::iterator, bool > insert(StringRef key)
Tagged union holding either a T or a Error.
static const Target * lookupTarget(const std::string &Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
T get() const
Returns the value of the specified pointer type.
bool isThinLTO()
Returns 'true' if the Module is produced for ThinLTO.
bool hasExternalWeakLinkage() const
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Expected< uint32_t > getCPUType(const Triple &T)
unsigned getNumOperands() const
Return number of MDNode operands.
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
@ LTO_SYMBOL_DEFINITION_WEAKUNDEF
bool startswith(StringRef Prefix) const
static size_t getDependentLibraryCount(lto::InputFile *input)
@ LTO_SYMBOL_PERMISSIONS_RODATA
static bool isBitcodeFile(const void *mem, size_t length)
Returns 'true' if the file or memory contents is LLVM bitcode.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
bool isOSDarwin() const
Is this a "Darwin" OS (macOS, iOS, tvOS, watchOS, or DriverKit).
unsigned Log2(Align A)
Returns the log2 of the alignment.
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
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.
Manages the enabling and disabling of subtarget specific features.
std::error_code getError() const
bool hasCtorDtor() const
Returns true if the module has either the @llvm.global_ctors or the @llvm.global_dtors symbol.
static lto::InputFile * createInputFile(const void *buffer, size_t buffer_size, const char *path, std::string &out_error)
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
void printSymbolName(raw_ostream &OS, Symbol S) const
@ LTO_SYMBOL_DEFINITION_UNDEFINED
Expected< uint32_t > getCPUSubType(const Triple &T)
The initial backend is deliberately restricted to z10 We should add support for later architectures at some point If an asm ties an i32 r result to an i64 input
ArrayRef< Symbol > symbols() const
ArchType getArch() const
Get the parsed architecture type of this triple.
void getDefaultSubtargetFeatures(const Triple &Triple)
Adds the default features for the specified target triple.
the resulting code requires compare and branches when and if the revised code is with conditional branches instead of More there is a byte word extend before each where there should be only and the condition codes are not remembered when the same two values are compared twice More LSR enhancements i8 and i32 load store addressing modes are identical int int c
@ LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
const MDOperand & getOperand(unsigned I) const
std::string getString() const
Returns features as a string.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
This is an important base class in LLVM.
static ErrorOr< std::unique_ptr< Module > > parseBitcodeFileImpl(MemoryBufferRef Buffer, LLVMContext &Context, bool ShouldBeLazy)
static bool isBitcodeForTarget(MemoryBuffer *memBuffer, StringRef triplePrefix)
Returns 'true' if the memory buffer is LLVM bitcode for the specified triple.
Expected< std::unique_ptr< Module > > getLazyBitcodeModule(MemoryBufferRef Buffer, LLVMContext &Context, bool ShouldLazyLoadMetadata=false, bool IsImporting=false, ParserCallbacks Callbacks={})
Read the header of the specified bitcode buffer and prepare for lazy deserialization of function bodi...
static ErrorOr< std::unique_ptr< MemoryBuffer > > getOpenFileSlice(sys::fs::file_t FD, const Twine &Filename, uint64_t MapSize, int64_t Offset, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Given an already-open file descriptor, map some slice of it into a MemoryBuffer.
An array constant whose element type is a simple 1/2/4/8-byte integer or float/double,...
T dyn_cast() const
Returns the current pointer if it is of the specified pointer type, otherwise returns null.
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
MemoryBufferRef getMemBufferRef() const
This is an important class for using LLVM in a threaded context.
static const char * getDependentLibrary(lto::InputFile *input, size_t index, size_t *size)
Expected< uint32_t > getMachOCPUSubType() const
TargetMachine * createTargetMachine(StringRef TT, StringRef CPU, StringRef Features, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM=std::nullopt, CodeGenOpt::Level OL=CodeGenOpt::Default, bool JIT=false) const
createTargetMachine - Create a target specific machine implementation for the specified Triple.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Primary interface to the complete machine description for the target machine.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
@ LTO_SYMBOL_DEFINITION_WEAK
bool hasLocalLinkage() const
@ LTO_SYMBOL_DEFINITION_REGULAR
bool errorToBool(Error Err)
Helper for converting an Error to a bool.
static std::string getProducerString(MemoryBuffer *Buffer)
Returns a string representing the producer identification stored in the bitcode, or "" if the bitcode...
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
bool canBeOmittedFromSymbolTable() const
True if GV can be left out of the object symbol table.
std::string getDefaultTargetTriple()
getDefaultTargetTriple() - Return the default target triple the compiler has been configured to produ...
const Module & getModule() const
StringRef - Represent a constant reference to a string, i.e.
Expected< std::string > getBitcodeTargetTriple(MemoryBufferRef Buffer)
Read the header of the specified bitcode buffer and extract just the triple information.
static ErrorOr< std::unique_ptr< LTOModule > > createFromBuffer(LLVMContext &Context, const void *mem, size_t length, const TargetOptions &options, StringRef path="")
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
@ LTO_SYMBOL_SCOPE_INTERNAL
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
uint32_t getSymbolFlags(Symbol S) const
std::error_code make_error_code(BitcodeError E)
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
constexpr size_t size() const
size - Get the string size.
file_t convertFDToNativeFile(int FD)
Converts from a Posix file descriptor number to a native file handle.
A constant value that is initialized with an expression using other constant values.
@ LTO_SYMBOL_SCOPE_HIDDEN
const char * toString(DWARFSectionKind Kind)
Lightweight error class with error context and mandatory checking.
The object format emitted by the WebAssembly backed is documented see the home and packaging for producing WebAssembly applications that can run in browsers and other environments wasi sdk provides a more minimal C C SDK based on llvm and a libc based on for producing WebAssemmbly applictions that use the WASI ABI Rust provides WebAssembly support integrated into Cargo There are two main options
bool isArm64e() const
Tests whether the target is the Apple "arm64e" AArch64 subarch.
static ErrorOr< std::unique_ptr< LTOModule > > createFromOpenFile(LLVMContext &Context, int fd, StringRef path, size_t size, const TargetOptions &options)
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
@ LTO_SYMBOL_PERMISSIONS_DATA
std::error_code errorToErrorCode(Error Err)
Helper for converting an ECError to a std::error_code.
Error takeError()
Take ownership of the stored error.
void emitLinkerFlagsForGlobalCOFF(raw_ostream &OS, const GlobalValue *GV, const Triple &TT, Mangler &Mangler)
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
Represents either an error or a value T.
A raw_ostream that writes to an SmallVector or SmallString.
bool hasLinkOnceLinkage() const
@ LTO_SYMBOL_PERMISSIONS_CODE
const char LLVMTargetMachineRef TM
Expected< uint32_t > getMachOCPUType() const
Expected< BitcodeLTOInfo > getBitcodeLTOInfo(MemoryBufferRef Buffer)
Returns LTO information for the specified bitcode file.
StringRef getString() const
C++ class which implements the opaque lto_module_t type.