aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ExecutionEngine
AgeCommit message (Collapse)AuthorFilesLines
2020-03-11[JITLink] Read symbol linkage from the correct field.Lang Hames1-1/+1
MachO symbol linkage is described by the desc field of the nlist entry, not the type field.
2020-03-11[ORC] Fix an overly aggressive assert.Lang Hames1-4/+6
It is ok to add dependencies on symbols that are ready, they should just be skipped.
2020-03-11[ORC] Add some extra debugging output.Lang Hames1-0/+8
2020-03-11Drop a StringMap.h include, NFCReid Kleckner1-0/+2
$ diff -u <(sort thedeps-before.txt) <(sort thedeps-after.txt) \ | grep '^[-+] ' | sort | uniq -c | sort -nr 231 - llvm/include/llvm/ADT/StringMap.h 171 - llvm/include/llvm/Support/AllocatorBase.h 142 - llvm/include/llvm/Support/PointerLikeTypeTraits.h
2020-03-10[RuntimeDyld][COFF] Build stubs for COFF dllimport symbols.Lang Hames7-58/+149
Summary: Enables JIT-linking by RuntimeDyld of COFF objects that contain references to dllimport symbols. This is done by recognizing symbols that start with the reserved "__imp_" prefix and building a pointer entry to the target symbol in the stubs area of the section. References to the "__imp_" symbol are updated to point to this pointer. Work in progress: The generic code is in place, but only RuntimeDyldCOFFX86_64 and RuntimeDyldCOFFI386 have been updated to look for and update references to dllimport symbols. Reviewers: compnerd Subscribers: hiraditya, ributzka, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75884
2020-03-10[RuntimeDyld] Allow multi-line rtdyld-check and jitlink-check expressions.Lang Hames1-3/+13
This patch allows rtdyld-check / jitlink-check expressions to be extended over multiple lines by terminating each line with a '\'. E.g. # llvm-rtdyld: *{8}X = \ # llvm-rtdyld: Y X: .quad Y This will be used to break up some long lines in upcoming test cases.
2020-03-10Give helpers internal linkage. NFC.Benjamin Kramer1-1/+1
2020-03-05Avoid dangling reference on SectionListserge-sans-paille1-1/+4
Bug spotted by https://cookieplmonster.github.io/2020/02/01/emulator-bug-llvm-bug/ Basically, holding references to object inside a resized vector is a bad idea. Differential Revision: https://reviews.llvm.org/D75110
2020-03-04[ORC] Remove hard dependency on libobjc when using MachOPlatform with LLJIT.Lang Hames2-8/+24
The LLJIT::MachOPlatformSupport class used to unconditionally attempt to register __objc_selrefs and __objc_classlist sections. If libobjc had not been loaded this resulted in an assertion, even if no objc sections were actually present. This patch replaces this unconditional registration with a check that no objce sections are present if libobjc has not been loaded. This will allow clients to use MachOPlatform with LLJIT without requiring libobjc for non-objc code.
2020-03-05[ORC] Decompose LazyCallThroughManager::callThroughToSymbol()Stefan Gränitz1-30/+24
Summary: Decompose callThroughToSymbol() into findReexport(), resolveSymbol(), notifyResolved() and reportCallThroughError(). This allows derived classes to reuse the functionality while adding their own code in between. Reviewers: lhames Reviewed By: lhames Subscribers: hiraditya, steven_wu, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75084
2020-03-04[ORC] Add some debugging output for initializers.Lang Hames2-6/+92
This output can be useful in tracking down initialization failures in the JIT.
2020-03-03[ORC] Skip ST_File symbols in MaterializationUnit interfaces / resolution.Lang Hames2-0/+19
ST_File symbols aren't relevant for linking purposes, but can end up shadowing real symbols if they're not filtered. No test case yet: The ideal testcase for this would be an ELF llvm-jitlink test, but llvm-jitlink support for ELF is still under development. We should add a testcase for this once support lands in tree.
2020-03-03[JITLink] Fix a pointer-to-integer cast in jitlink::InProcessMemoryManager.Lang Hames1-1/+1
reinterpret_cast'ing the block base address directly to a uint64_t leaves the high bits in an implementation-defined state, but JITLink expects them to be zero. Switching to pointerToJITTargetAddress for the cast should fix this. This should fix the jitlink test failures that we have seen on some of the 32-bit testers.
2020-03-03[ORC] Make sure we add initializers to the SymbolFlags map for objects.Lang Hames1-0/+1
2020-03-03[ORC] Remove an out-of-date FIXMELang Hames1-2/+2
2020-02-29Avoid including FileSystem.h from MemoryBuffer.hReid Kleckner1-0/+1
Lots of headers pass around MemoryBuffer objects, but very few open them. Let those that do include FileSystem.h. Saves ~250 includes of Chrono.h & FileSystem.h: $ diff -u thedeps-before.txt thedeps-after.txt | grep '^[-+] ' | sort | uniq -c | sort -nr 254 - ../llvm/include/llvm/Support/FileSystem.h 253 - ../llvm/include/llvm/Support/Chrono.h 237 - ../llvm/include/llvm/Support/NativeFormatting.h 237 - ../llvm/include/llvm/Support/FormatProviders.h 192 - ../llvm/include/llvm/ADT/StringSwitch.h 190 - ../llvm/include/llvm/Support/FormatVariadicDetails.h ... This requires duplicating the file_t typedef, which is unfortunate. I sunk the choice of mapping mode down into the cpp file using variable template specializations instead of class members in headers.
2020-02-29[ExecutionEngine] Add JITSymbolFlags::fromSummary(GlobalValueSummary*)Stefan Gränitz1-0/+17
Summary: A function that creates JITSymbolFlags from a GlobalValueSummary. Similar functions exist: fromGlobalValue(), fromObjectSymbol() Reviewers: lhames Reviewed By: lhames Subscribers: hiraditya, steven_wu, dexonsmith, arphaman, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75082
2020-02-25[ORC] Remove the JITDylib::SymbolTableEntry::isInMaterializingState() method.Lang Hames1-7/+12
It was being used inconsistently. Uses have been replaced with direct checks on the symbol state.
2020-02-24[ORC] Remove spammy debug printBenjamin Kramer1-2/+1
2020-02-23[JITLink] Add a MachO x86-64 GOT and Stub bypass optimization.Lang Hames4-92/+263
This optimization bypasses GOT loads and calls/branches through stubs when the ultimate target of the access/branch is found to be within range of the reference. Extra debugging output is also added to the generic JITLink algorithm and basic GOT and Stubs builder utility to aid debugging.
2020-02-22[ORC] Update LLJIT to automatically run specially named initializer functions.Lang Hames2-9/+54
The GenericLLVMIRPlatformSupport class runs a transform on all LLVM IR added to the LLJIT instance to replace instances of llvm.global_ctors with a specially named function that runs the corresponing static initializers (See (GlobalCtorDtorScraper from lib/ExecutionEngine/Orc/LLJIT.cpp). This patch updates the GenericIRPlatform class to check for this specially named function in other materialization units that are added to the JIT and, if found, add the function to the initializer work queue. Doing this allows object files that were compiled from IR and cached to be reloaded in subsequent JIT sessions without their initializers being skipped. To enable testing this patch also updates the lli tool's -jit-kind=orc-lazy mode to respect the -enable-cache-manager and -object-cache-dir options, and modifies the CompileOnDemandLayer to rename extracted submodules to include a hash of the names of their symbol definitions. This allows a simple object caching scheme based on module names (which was already implemented in lli) to work with the lazy JIT.
2020-02-22[ORC] Add errors for missing and extraneous symbol definitions.Lang Hames3-0/+54
This patch adds new errors and error checking to the ObjectLinkingLayer to catch cases where a compiled or loaded object either: (1) Contains definitions not covered by its responsibility set, or (2) Is missing definitions that are covered by its responsibility set. Proir to this patch providing the correct set of definitions was treated as an API contract requirement, however this requires that the client be confident in the correctness of the whole compiler / object-cache pipeline and results in difficult-to-debug assertions upon failure. Treating this as a recoverable error results in clearer diagnostics. The performance overhead of this check is one comparison of densemap keys (symbol string pointers) per linking object, which is minimal. If this overhead ever becomes a problem we can add the check under a flag that can be turned off if the client fully trusts the rest of the pipeline.
2020-02-20Add #include <condition_variable> to fix build after 85fb997659b5Hans Wennborg1-0/+1
See https://reviews.llvm.org/D74300#1884614
2020-02-19[ORC] Fix a missing move.Lang Hames1-1/+1
2020-02-19[ORC] Add generic initializer/deinitializer support.Lang Hames13-141/+1711
Initializers and deinitializers are used to implement C++ static constructors and destructors, runtime registration for some languages (e.g. with the Objective-C runtime for Objective-C/C++ code) and other tasks that would typically be performed when a shared-object/dylib is loaded or unloaded by a statically compiled program. MCJIT and ORC have historically provided limited support for discovering and running initializers/deinitializers by scanning the llvm.global_ctors and llvm.global_dtors variables and recording the functions to be run. This approach suffers from several drawbacks: (1) It only works for IR inputs, not for object files (including cached JIT'd objects). (2) It only works for initializers described by llvm.global_ctors and llvm.global_dtors, however not all initializers are described in this way (Objective-C, for example, describes initializers via specially named metadata sections). (3) To make the initializer/deinitializer functions described by llvm.global_ctors and llvm.global_dtors searchable they must be promoted to extern linkage, polluting the JIT symbol table (extra care must be taken to ensure this promotion does not result in symbol name clashes). This patch introduces several interdependent changes to ORCv2 to support the construction of new initialization schemes, and includes an implementation of a backwards-compatible llvm.global_ctor/llvm.global_dtor scanning scheme, and a MachO specific scheme that handles Objective-C runtime registration (if the Objective-C runtime is available) enabling execution of LLVM IR compiled from Objective-C and Swift. The major changes included in this patch are: (1) The MaterializationUnit and MaterializationResponsibility classes are extended to describe an optional "initializer" symbol for the module (see the getInitializerSymbol method on each class). The presence or absence of this symbol indicates whether the module contains any initializers or deinitializers. The initializer symbol otherwise behaves like any other: searching for it triggers materialization. (2) A new Platform interface is introduced in llvm/ExecutionEngine/Orc/Core.h which provides the following callback interface: - Error setupJITDylib(JITDylib &JD): Can be used to install standard symbols in JITDylibs upon creation. E.g. __dso_handle. - Error notifyAdding(JITDylib &JD, const MaterializationUnit &MU): Generally used to record initializer symbols. - Error notifyRemoving(JITDylib &JD, VModuleKey K): Used to notify a platform that a module is being removed. Platform implementations can use these callbacks to track outstanding initializers and implement a platform-specific approach for executing them. For example, the MachOPlatform installs a plugin in the JIT linker to scan for both __mod_inits sections (for C++ static constructors) and ObjC metadata sections. If discovered, these are processed in the usual platform order: Objective-C registration is carried out first, then static initializers are executed, ensuring that calls to Objective-C from static initializers will be safe. This patch updates LLJIT to use the new scheme for initialization. Two LLJIT::PlatformSupport classes are implemented: A GenericIR platform and a MachO platform. The GenericIR platform implements a modified version of the previous llvm.global-ctor scraping scheme to provide support for Windows and Linux. LLJIT's MachO platform uses the MachOPlatform class to provide MachO specific initialization as described above. Reviewers: sgraenitz, dblaikie Subscribers: mgorny, hiraditya, mgrang, ributzka, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D74300
2020-02-14[Support] On Windows, ensure hardware_concurrency() extends to all CPU ↵Alexandre Ganea1-1/+2
sockets and all NUMA groups The goal of this patch is to maximize CPU utilization on multi-socket or high core count systems, so that parallel computations such as LLD/ThinLTO can use all hardware threads in the system. Before this patch, on Windows, a maximum of 64 hardware threads could be used at most, in some cases dispatched only on one CPU socket. == Background == Windows doesn't have a flat cpu_set_t like Linux. Instead, it projects hardware CPUs (or NUMA nodes) to applications through a concept of "processor groups". A "processor" is the smallest unit of execution on a CPU, that is, an hyper-thread if SMT is active; a core otherwise. There's a limit of 32-bit processors on older 32-bit versions of Windows, which later was raised to 64-processors with 64-bit versions of Windows. This limit comes from the affinity mask, which historically is represented by the sizeof(void*). Consequently, the concept of "processor groups" was introduced for dealing with systems with more than 64 hyper-threads. By default, the Windows OS assigns only one "processor group" to each starting application, in a round-robin manner. If the application wants to use more processors, it needs to programmatically enable it, by assigning threads to other "processor groups". This also means that affinity cannot cross "processor group" boundaries; one can only specify a "preferred" group on start-up, but the application is free to allocate more groups if it wants to. This creates a peculiar situation, where newer CPUs like the AMD EPYC 7702P (64-cores, 128-hyperthreads) are projected by the OS as two (2) "processor groups". This means that by default, an application can only use half of the cores. This situation could only get worse in the years to come, as dies with more cores will appear on the market. == The problem == The heavyweight_hardware_concurrency() API was introduced so that only *one hardware thread per core* was used. Once that API returns, that original intention is lost, only the number of threads is retained. Consider a situation, on Windows, where the system has 2 CPU sockets, 18 cores each, each core having 2 hyper-threads, for a total of 72 hyper-threads. Both heavyweight_hardware_concurrency() and hardware_concurrency() currently return 36, because on Windows they are simply wrappers over std::thread::hardware_concurrency() -- which can only return processors from the current "processor group". == The changes in this patch == To solve this situation, we capture (and retain) the initial intention until the point of usage, through a new ThreadPoolStrategy class. The number of threads to use is deferred as late as possible, until the moment where the std::threads are created (ThreadPool in the case of ThinLTO). When using hardware_concurrency(), setting ThreadCount to 0 now means to use all the possible hardware CPU (SMT) threads. Providing a ThreadCount above to the maximum number of threads will have no effect, the maximum will be used instead. The heavyweight_hardware_concurrency() is similar to hardware_concurrency(), except that only one thread per hardware *core* will be used. When LLVM_ENABLE_THREADS is OFF, the threading APIs will always return 1, to ensure any caller loops will be exercised at least once. Differential Revision: https://reviews.llvm.org/D71775
2020-02-13[AsmPrinter] De-capitalize all AsmPrinter::Emit* but EmitInstructionFangrui Song1-3/+3
Similar to rL328848.
2020-02-11[ORC] Fix symbol dependence propagation algorithm in ObjectLinkingLayer.Lang Hames1-41/+67
ObjectLinkingLayer was not correctly propagating dependencies through local symbols within an object. This could cause symbol lookup to return before a searched-for symbol is ready if the following conditions are met: (1) The definition of the symbol being searched for transitively depends on a local symbol within the same object, and that local symbol in turn transitively depends on an external symbol provided by some other module in the JIT. (2) Concurrent compilation is enabled. (3) Thread scheduling causes the lookup of the searched-for symbol to return before all transitive dependencies of the looked-up symbol are emitted. This bug was found by inspection and has not been observed in practice. A jitlink test case has been added to verify that symbol dependencies are correctly propagated through local symbol definitions.
2020-02-11[ORC] Add debug logging to JITDylib::addDependencies.Lang Hames1-1/+6
2020-02-10Revert "Remove redundant "std::move"s in return statements"Bill Wendling11-45/+45
The build failed with error: call to deleted constructor of 'llvm::Error' errors. This reverts commit 1c2241a7936bf85aa68aef94bd40c3ba77d8ddf2.
2020-02-10Remove redundant "std::move"s in return statementsBill Wendling11-45/+45
2020-02-01Make StringRef's std::string conversion operator explicitSylvestre Ledru2-2/+2
The build is currenly broken when perf or ffi are enabled for llvm Just like in https://reviews.llvm.org/rG777180a32b61070a10dd330b4f038bf24e916af1
2020-01-29Another round of GCC5 fixes.Benjamin Kramer1-2/+2
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer9-28/+29
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-24[Alignment][NFC] Deprecate Align::None()Guillaume Chatelet1-1/+1
Summary: This is a follow up on https://reviews.llvm.org/D71473#inline-647262. There's a caveat here that `Align(1)` relies on the compiler understanding of `Log2_64` implementation to produce good code. One could use `Align()` as a replacement but I believe it is less clear that the alignment is one in that case. Reviewers: xbolva00, courbet, bollu Subscribers: arsenm, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, hiraditya, kbarton, jrtc27, atanasyan, jsji, Jim, kerbowa, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D73099
2020-01-21[ORC] Fix a missing move in ce2207abaf9.Lang Hames1-1/+1
This should fix the build failure at http://lab.llvm.org:8011/builders/clang-cmake-x86_64-sde-avx512-linux/builds/32524 and others.
2020-01-21[ORC] Add support for emulated TLS to ORCv2.Lang Hames6-50/+96
This commit adds a ManglingOptions struct to IRMaterializationUnit, and replaces IRCompileLayer::CompileFunction with a new IRCompileLayer::IRCompiler class. The ManglingOptions struct defines the emulated-TLS state (via a bool member, EmulatedTLS, which is true if emulated-TLS is enabled and false otherwise). The IRCompileLayer::IRCompiler class wraps an IRCompiler (the same way that the CompileFunction typedef used to), but adds a method to return the IRCompileLayer::ManglingOptions that the compiler will use. These changes allow us to correctly determine the symbols that will be produced when a thread local global variable defined at the IR level is compiled with or without emulated TLS. This is required for ORCv2, where MaterializationUnits must declare their interface up-front. Most ORCv2 clients should not require any changes. Clients writing custom IR compilers will need to wrap their compiler in an IRCompileLayer::IRCompiler, rather than an IRCompileLayer::CompileFunction, however this should be a straightforward change (see modifications to CompileUtils.* in this patch for an example).
2020-01-19[ORC] Add weak symbol support to defineMaterializing, fix for PR40074.Lang Hames3-28/+96
The MaterializationResponsibility::defineMaterializing method allows clients to add new definitions that are in the process of being materialized to the JIT. This patch adds support to defineMaterializing for symbols with weak linkage where the new definitions may be rejected if another materializer concurrently defines the same symbol. If a weak symbol is rejected it will not be added to the MaterializationResponsibility's responsibility set. Clients can check for membership in the responsibility set via the MaterializationResponsibility::getSymbols() method before resolving any such weak symbols. This patch also adds code to RTDyldObjectLinkingLayer to tag COFF comdat symbols introduced during codegen as weak, on the assumption that these are COFF comdat constants. This fixes http://llvm.org/PR40074.
2020-01-15[ORC] Set setCloneToNewContextOnEmit on LLJIT's transform layer when needed.Lang Hames1-3/+2
Based on Don Hinton's patch in https://reviews.llvm.org/D72406. This feature was accidentally left out of e9e26c01cd865da678b1af6ba5f417c713956a66, and would have pessimized concurrent compilation in the default case. Thanks for spotting this Don!
2020-01-15[ORC] Simplify use of lazyReexports with LLJIT.Lang Hames1-4/+4
This patch makes the target triple available via the LLJIT interface, and moves the IRTransformLayer from LLLazyJIT down into LLJIT. Together these changes make it easier to use the lazyReexports utility with LLJIT, and to apply IR transforms to code as it is compiled in LLJIT (rather than requiring transforms to be applied manually before code is added). An code example is added in llvm/examples/LLJITExamples/LLJITWithLazyReexports
2020-01-15[ORC] Update lazyReexports to support aliases with different symbol names.Lang Hames1-12/+9
A bug in the existing implementation meant that lazyReexports would not work if the aliased name differed from the alias's name, i.e. all lazy reexports had to be of the form (lib1, name) -> (lib2, name). This patch fixes the issue by capturing the alias's name in the NotifyResolved callback. To simplify this capture, and the LazyCallThroughManager code in general, the NotifyResolved callback is updated to use llvm::unique_function rather than a custom class. No test case yet: This can only be tested at runtime, and the only in-tree client (lli) always uses aliases with matching names. I will add a new LLJIT example shortly that will directly test the lazyReexports API and the non-trivial alias use case.
2020-01-11[Disassembler] Delete the VStream parameter of MCDisassembler::getInstruction()Fangrui Song1-1/+1
The argument is llvm::null() everywhere except llvm::errs() in llvm-objdump in -DLLVM_ENABLE_ASSERTIONS=On builds. It is used by no target but X86 in -DLLVM_ENABLE_ASSERTIONS=On builds. If we ever have the needs to add verbose log to disassemblers, we can record log with a member function, instead of passing it around as an argument.
2020-01-11[ORC] Fix argv handling in runAsMain / lli.Lang Hames1-1/+1
This fixes an off-by-one error in the argc value computed by runAsMain, and switches lli back to using the input bitcode (rather than the string "lli") as the effective program name. Thanks to Stefan Graenitz for spotting the bug.
2020-01-11[ExecutionEngine] Re-enable FastISel for non-iOS arm targets.Lang Hames1-7/+0
Patch by Nicolas Capens. Thanks Nicolas! https://reviews.llvm.org/D65015
2020-01-03[NFC][ORC] Fix typos and whitespaces in commentsStefan Gränitz1-1/+1
2020-01-01[NFC] Fixes -Wrange-loop-analysis warningsMark de Wever1-1/+1
This avoids new warnings due to D68912 adds -Wrange-loop-analysis to -Wall. Differential Revision: https://reviews.llvm.org/D71857
2019-12-24[MCJIT] Migrate function attribute "no-frame-pointer-elim" to "frame-pointer"Fangrui Song1-3/+3
2019-12-20[ORC] De-register eh-frames in the RTDyldObjectLinkingLayer destructor.Lang Hames1-0/+6
This matches the behavior of the legacy layer, which automatically deregistered frames.
2019-12-19[Orc][LLJIT] Re-apply 298e183e813 (use JITLink for LLJIT where supported).Lang Hames1-3/+7
Patch d9220b580b3 fixed the underlying issue that casued 298e183e813 to fail.
2019-12-19[JITLink][MachO] Fix common symbol size plumbing.Lang Hames1-1/+1
This fixes the underlying bug that was exposed by 298e183e813.