aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/gold
AgeCommit message (Collapse)AuthorFilesLines
2024-04-04[CMake] Install LLVMgold.so for LLVM_INSTALL_TOOLCHAIN_ONLY=on (#87567)Fangrui Song1-1/+1
LLVMgold.so can be used with GNU ar, gold, ld, and nm to process LLVM bitcode files. Install it in LLVM_INSTALL_TOOLCHAIN_ONLY=on builds like we install libLTO.so. Suggested by @emelife Fix #84271
2024-03-06[MC] Move CompressDebugSections/RelaxELFRelocations from ↵Fangrui Song1-1/+1
TargetOptions/MCAsmInfo to MCTargetOptions The convention is for such MC-specific options to reside in MCTargetOptions. However, CompressDebugSections/RelaxELFRelocations do not follow the convention: `CompressDebugSections` is defined in both TargetOptions and MCAsmInfo and there is forwarding complexity. Move the option to MCTargetOptions and hereby simplify the code. Rename the misleading RelaxELFRelocations to X86RelaxRelocations. llvm-mc -relax-relocations and llc -x86-relax-relocations can now be unified.
2023-11-10[gold] Enable `MCTargetOptions::AsmVerbose` along with `emit-asm` (#71606)Min-Yih Hsu1-0/+1
Print comments into assembly output if we're using `emit-asm`.
2023-09-14[NFC][CodeGen] Change CodeGenOpt::Level/CodeGenFileType into enum classes ↵Arthur Eubanks1-2/+2
(#66295) This will make it easy for callers to see issues with and fix up calls to createTargetMachine after a future change to the params of TargetMachine. This matches other nearby enums. For downstream users, this should be a fairly straightforward replacement, e.g. s/CodeGenOpt::Aggressive/CodeGenOptLevel::Aggressive or s/CGFT_/CodeGenFileType::
2023-09-06[lld/ELF,gold] Remove transitionary opaque pointer flags (#65529)aeubanks1-2/+0
This was only useful during the transition when mixing non-opaque-pointer and opaque-pointer IR, now everything uses opaque pointers.
2023-08-18Reland "[gold] Add preliminary FatLTO support to the Gold plugin""Paul Kirth1-8/+0
This changes the definition if isSectionBitcode to only be valid for the .llvm.lto section, since this API is only called from LTO, and the .llvmbc section was not intended to be used for LTO. This allows the gold plugin to keep its existing behavior without introducing any significant changes. Reviewed By: MaskRay, nikic Differential Revision: https://reviews.llvm.org/D152973
2023-07-20Revert "[gold] Add preliminary FatLTO support to the Gold plugin"Paul Kirth1-0/+8
This reverts commit 421e4026111315d002879b1e7a0cf3aacd00f488. One of the test needs a requires line, but we've also seen some issues for downstream projects that may need coordination, so I'm reverting this for until we can address those issues. see https://reviews.llvm.org/D152973#4520240 for context.
2023-07-19[gold] Add preliminary FatLTO support to the Gold pluginPaul Kirth1-8/+0
This changes the definition if `isSectionBitcode` to only be valid for the `.llvm.lto` section, since this API is only called from LTO, and the `.llvmbc` section was not intended to be used for LTO. This allows the gold plugin to keep its existing behavior without introducing any significant changes. Depends on D146778 Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D152973
2023-04-04[lld] Support separate native object file path in --thinlto-prefix-replaceIvan Tadeu Ferreira Antunes Filho1-3/+6
Currently, the --thinlto-prefix-replace="oldpath;newpath" option is used during distributed ThinLTO thin links to specify the mapping of the input bitcode object files' directory tree (oldpath) to the directory tree (newpath) used for both: 1) the output files of the thin link itself (the .thinlto.bc index files and the optional .imports files) 2) the specified object file paths written to the response file given in the --thinlto-index-only=${response} option, which is used by the final native link and must match the paths of the native object files that will be produced by ThinLTO backend compiles. This patch expands the --thinlto-prefix-replace option to allow a separate directory tree mapping to be specified for the object file paths written to the response file (number 2 above). This is important to support builds and build systems where the same output directory may not be written by multiple build actions (e.g. the thin link and the ThinLTO backend compiles). The new format is: --thinlto-prefix-replace="origpath;outpath[;objpath]" This replaces the origpath directory tree of the thin link input files with outpath when writing the thin link index and imports outputs (number 1 above). If objpath is specified it replaces origpath of the input files with objpath when writing the response file (number 2 above), otherwise it falls back to the old behavior of using outpath for this as well. Reviewed By: tejohnson, MaskRay Differential Revision: https://reviews.llvm.org/D144596
2023-02-10[NFC][TargetParser] Replace uses of llvm/Support/Host.hArchibald Elliott1-1/+1
The forwarding header is left in place because of its use in `polly/lib/External/isl/interface/extract_interface.cc`, but I have added a GCC warning about the fact it is deprecated, because it is used in `isl` from where it is included by Polly.
2023-01-25[gold] Remove no-opaque-pointers optionNikita Popov1-7/+1
The opaque-pointers option is retained as a no-op, same as with new-pass-manager.
2023-01-23[NFC] Consolidate llvm::CodeGenOpt::Level handlingScott Linder1-15/+4
Add free functions llvm::CodeGenOpt::{getLevel,getID,parseLevel} to provide common implementations for functionality that has been duplicated in many places across the codebase. Differential Revision: https://reviews.llvm.org/D141968
2022-12-20[Support] Move TargetParsers to new componentArchibald Elliott1-0/+1
This is a fairly large changeset, but it can be broken into a few pieces: - `llvm/Support/*TargetParser*` are all moved from the LLVM Support component into a new LLVM Component called "TargetParser". This potentially enables using tablegen to maintain this information, as is shown in https://reviews.llvm.org/D137517. This cannot currently be done, as llvm-tblgen relies on LLVM's Support component. - This also moves two files from Support which use and depend on information in the TargetParser: - `llvm/Support/Host.{h,cpp}` which contains functions for inspecting the current Host machine for info about it, primarily to support getting the host triple, but also for `-mcpu=native` support in e.g. Clang. This is fairly tightly intertwined with the information in `X86TargetParser.h`, so keeping them in the same component makes sense. - `llvm/ADT/Triple.h` and `llvm/Support/Triple.cpp`, which contains the target triple parser and representation. This is very intertwined with the Arm target parser, because the arm architecture version appears in canonical triples on arm platforms. - I moved the relevant unittests to their own directory. And so, we end up with a single component that has all the information about the following, which to me seems like a unified component: - Triples that LLVM Knows about - Architecture names and CPUs that LLVM knows about - CPU detection logic for LLVM Given this, I have also moved `RISCVISAInfo.h` into this component, as it seems to me to be part of that same set of functionality. If you get link errors in your components after this patch, you likely need to add TargetParser into LLVM_LINK_COMPONENTS in CMake. Differential Revision: https://reviews.llvm.org/D137838
2022-12-10[gold] Fix buildFangrui Song1-1/+1
2022-12-04IR: HotnessThreshold llvm::Optional => std::optionalFangrui Song1-1/+1
2022-12-03CodeGen/CommandFlags: Convert Optional to std::optionalFangrui Song1-1/+1
2022-11-22Fix lto AddStream callsite in gold plugin.Zequan Wu1-1/+1
2022-11-22Fix lto AddStreamFn in gold plugin.Zequan Wu1-1/+3
2022-11-22Fix localCache in gold plugin.Zequan Wu1-1/+2
2022-08-14Use llvm::all_of (NFC)Kazu Hirata1-2/+2
2022-07-14[gold] Ignore bitcode from sections inside object filesTom Stellard1-0/+8
-fembed-bitcode will put bitcode into special sections within object files, but this is not meant to be used by LTO, so the gold plugin should ignore it. https://github.com/llvm/llvm-project/issues/47216 Reviewed By: tejohnson, MaskRay Differential Revision: https://reviews.llvm.org/D116995
2022-06-01Fix compilation in gold-plugin triggered by D125847Matthias Braun1-1/+1
2022-06-01LTO: Decide upfront whether to use opaque/non-opaque pointer typesMatthias Braun1-0/+8
LTO code may end up mixing bitcode files from various sources varying in their use of opaque pointer types. The current strategy to decide between opaque / typed pointers upon the first bitcode file loaded does not work here, since we could be loading a non-opaque bitcode file first and would then be unable to load any files with opaque pointer types later. So for LTO this: - Adds an `lto::Config::OpaquePointer` option and enforces an upfront decision between the two modes. - Adds `-opaque-pointers`/`-no-opaque-pointers` options to the gold plugin; disabled by default. - `--opaque-pointers`/`--no-opaque-pointers` options with `-plugin-opt=-opaque-pointers`/`-plugin-opt=-no-opaque-pointers` aliases to lld; disabled by default. - Adds an `-lto-opaque-pointers` option to the `llvm-lto2` tool. - Changes the clang driver to pass `-plugin-opt=-opaque-pointers` to the linker in LTO modes when clang was configured with opaque pointers enabled by default. This fixes https://github.com/llvm/llvm-project/issues/55377 Differential Revision: https://reviews.llvm.org/D125847
2022-04-08[gold] Remove support for legacy pass managerNikita Popov1-7/+1
This removes support for performing LTO using the legacy pass manager in LLVMgold.so. Explicitly enabling the new pass manager is retained as a no-op. Differential Revision: https://reviews.llvm.org/D123294
2022-04-06[cmake] Remove LLVM_ENABLE_NEW_PASS_MANAGER cmake optionNikita Popov1-1/+1
Or rather, error out if it is set to something other than ON. This removes the ability to enable the legacy pass manager by default, but does not remove the ability to explicitly enable it through various flags like -flegacy-pass-manager or -enable-new-pm=0. I checked, and our test suite definitely doesn't pass with LLVM_ENABLE_NEW_PASS_MANAGER=OFF anymore. Differential Revision: https://reviews.llvm.org/D123126
2022-01-31[BitcodeWriter] Fix cases of some functionsFangrui Song1-1/+1
`WriteIndexToFile` is used by external projects so I do not touch it.
2021-11-04[Support] Improve Caching conformance with Support library behaviorNoah Shutty1-3/+3
This diff makes several amendments to the local file caching mechanism which was migrated from ThinLTO to Support in rGe678c51177102845c93529d457b020f969125373 in response to follow-up discussion on that commit. Patch By: noajshu Differential Revision: https://reviews.llvm.org/D113080
2021-10-18[Support][ThinLTO] Move ThinLTO caching to LLVM Support libraryNoah Shutty1-5/+4
We would like to move ThinLTO’s battle-tested file caching mechanism to the LLVM Support library so that we can use it elsewhere in LLVM. Patch By: noajshu Differential Revision: https://reviews.llvm.org/D111371
2021-10-18Revert "[Support][ThinLTO] Move ThinLTO caching to LLVM Support library"Petr Hosek1-3/+4
This reverts commit 92b8cc52bbc8194f2cd6a5f742b874969421afca since it broke the gold plugin.
2021-10-18[Support][ThinLTO] Move ThinLTO caching to LLVM Support libraryNoah Shutty1-4/+3
We would like to move ThinLTO’s battle-tested file caching mechanism to the LLVM Support library so that we can use it elsewhere in LLVM. Patch By: noajshu Differential Revision: https://reviews.llvm.org/D111371
2021-07-20[LTO] Add SelectionKind to IRSymtab and use it in ld.lld/LLVMgoldFangrui Song1-2/+4
In PGO, a C++ external linkage function `foo` has a private counter `__profc_foo` and a private `__profd_foo` in a `comdat nodeduplicate`. A `__attribute__((weak))` function `foo` has a weak hidden counter `__profc_foo` and a private `__profd_foo` in a `comdat nodeduplicate`. In `ld.lld a.o b.o`, say a.o defines an external linkage `foo` and b.o defines a weak `foo`. Currently we treat `comdat nodeduplicate` as `comdat any`, ld.lld will incorrectly consider `b.o:__profc_foo` non-prevailing. In the worst case when `b.o:__profd_foo` is retained and `b.o:__profc_foo` isn't, there will be dangling reference causing an `undefined hidden symbol` error. Add SelectionKind to `Comdat` in IRSymtab and let linkers ignore nodeduplicate comdat. Differential Revision: https://reviews.llvm.org/D106228
2021-02-17[gold] Match lld WPD behavior for shared library symbols and add testTeresa Johnson1-1/+4
lld already marks shared library defs as ExportDynamic, which prevents potentially unsafe devirtualization of symbols defined in shared libraries. Match that behavior in the gold plugin, and add the same test. Depends on D96721. Differential Revision: https://reviews.llvm.org/D96722
2021-02-12[ThinLTO][gold] Fix filenaming scheme for tasks.Hongtao Yu1-1/+4
The gold LTO plugin uses a set of hooks to implements emit-llvm and capture intermediate file generated during LTO. The hooks are called by each lto backend thread with a taskID as argument to differentiate between threads and tasks. Currently, all threads are overwriting the same file which results into only the intermediate output of the last backend thread to be preserved. This diff encodes the taskID into the filename. Reviewed By: tejohnson, wenlei Differential Revision: https://reviews.llvm.org/D96173
2021-01-27[LTO] Prevent devirtualization for symbols dynamically exportedTeresa Johnson1-0/+3
Identify dynamically exported symbols (--export-dynamic[-symbol=], --dynamic-list=, or definitions needed to preempt shared objects) and prevent their LTO visibility from being upgraded. This helps avoid use of whole program devirtualization when there may be overrides in dynamic libraries. Differential Revision: https://reviews.llvm.org/D91583
2020-12-16Use basic_string::find(char) instead of basic_string::find(const char *s, ↵Fangrui Song1-2/+2
size_type pos=0) Many (StringRef) cannot be detected by clang-tidy performance-faster-string-find.
2020-12-09Rename -plugin-opt=no-new-pass-manager to -plugin-opt=legacy-pass-managerFangrui Song1-1/+1
2020-12-09[LLD][gold] Add -plugin-opt=no-new-pass-managerFangrui Song1-0/+2
-DENABLE_EXPERIMENTAL_NEW_PASS_MANAGER=on configured LLD and LLVMgold.so will use the new pass manager by default. Add an option to use the legacy pass manager. This will also be used by the Clang driver when -fno-new-pass-manager (D92915) / -fno-experimental-new-pass-manager is set. Reviewed By: aeubanks, tejohnson Differential Revision: https://reviews.llvm.org/D92916
2020-12-08[gold][NPM] Use NPM with ENABLE_EXPERIMENTAL_NEW_PASS_MANAGERArthur Eubanks1-1/+2
Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D92869
2020-11-30[Remarks][1/2] Expand remarks hotness threshold option support in more toolsWei Wang1-0/+9
This is the #1 of 2 changes that make remarks hotness threshold option available in more tools. The changes also allow the threshold to sync with hotness threshold from profile summary with special value 'auto'. This change modifies the interface of lto::setupLLVMOptimizationRemarks() to accept remarks hotness threshold. Update all the tools that use it with remarks hotness threshold options: * lld: '--opt-remarks-hotness-threshold=' * llvm-lto2: '--pass-remarks-hotness-threshold=' * llvm-lto: '--lto-pass-remarks-hotness-threshold=' * gold plugin: '-plugin-opt=opt-remarks-hotness-threshold=' Differential Revision: https://reviews.llvm.org/D85809
2020-10-14[AIX] Turn -fdata-sections on by default in Clangjasonliu1-1/+1
Summary: This patch does the following: 1. Make InitTargetOptionsFromCodeGenFlags() accepts Triple as a parameter, because some options' default value is triple dependant. 2. DataSections is turned on by default on AIX for llc. 3. Test cases change accordingly because of the default behaviour change. 4. Clang Driver passes in -fdata-sections by default on AIX. Reviewed By: MaskRay, DiggerLin Differential Revision: https://reviews.llvm.org/D88737
2020-07-20[LLVMgold.so] -plugin-opt=save-temps: save combined module to .lto.o instead ↵Fangrui Song1-1/+1
of .o This matches LLD and fixes https://sourceware.org/bugzilla/show_bug.cgi?id=26262#c1 .o is a bad choice for save-temps output because it is easy to override the bitcode file (*.o) ``` # Use bfd for the example, -fuse-ld=gold is similar. clang -flto -c a.c # generate bitcode file a.o clang -fuse-ld=bfd -flto a.o -o a -Wl,-plugin-opt=save-temps # override a.o # The user repeats the command but get surprised, because a.o is now a combined module. clang -fuse-ld=bfd -flto a.o -o a -Wl,-plugin-opt=save-temps ``` Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D84132
2020-05-20[gold-plugin] Unbreak the build after d9b9ce6c04764275a23cd0cf1856a35aae921af7Benjamin Kramer1-0/+1
2020-05-04[LTO] Suppress emission of empty combined module by defaultZakk Chen1-0/+1
Summary: That unless the user requested an output object (--lto-obj-path), the an unused empty combined module is not emitted. This changed is helpful for some target (ex. RISCV-V) which encoded the ABI info in IR module flags (target-abi). Empty unused module has no ABI info so the linker would get the linking error during merging incompatible ABIs. Reviewers: tejohnson, espindola, MaskRay Subscribers: emaste, inglorion, arichardson, hiraditya, simoncook, MaskRay, steven_wu, dexonsmith, PkmX, dang, lenary, s.egerton, luismarques, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D78988
2020-04-24[gold] Simplify with StringRef::consume_front. NFCFangrui Song1-45/+39
Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D78819
2020-03-27Fix build after 09158252f777c2e2f06a86b154c44abcbcf9bb74Alexandre Ganea1-1/+1
2020-03-27[ThinLTO] Allow usage of all hardware threads in the systemAlexandre Ganea1-8/+10
Before this patch, it wasn't possible to extend the ThinLTO threads to all SMT/CMT threads in the system. Only one thread per core was allowed, instructed by usage of llvm::heavyweight_hardware_concurrency() in the ThinLTO code. Any number passed to the LLD flag /opt:lldltojobs=..., or any other ThinLTO-specific flag, was previously interpreted in the context of llvm::heavyweight_hardware_concurrency(), which means SMT disabled. One can now say in LLD: /opt:lldltojobs=0 -- Use one std::thread / hardware core in the system (no SMT). Default value if flag not specified. /opt:lldltojobs=N -- Limit usage to N threads, regardless of usage of heavyweight_hardware_concurrency(). /opt:lldltojobs=all -- Use all hardware threads in the system. Equivalent to /opt:lldltojobs=$(nproc) on Linux and /opt:lldltojobs=%NUMBER_OF_PROCESSORS% on Windows. When an affinity mask is set for the process, threads will be created only for the cores selected by the mask. When N > number-of-hardware-threads-in-the-system, the threads in the thread pool will be dispatched equally on all CPU sockets (tested only on Windows). When N <= number-of-hardware-threads-on-a-CPU-socket, the threads will remain on the CPU socket where the process started (only on Windows). Differential Revision: https://reviews.llvm.org/D75153
2020-03-18Fix ac1d23ed7de01fb3 interaction with gold pluginserge-sans-paille1-1/+1
Correctly set RelocationModel, thanks @modocache for spotting this. Related to differential revision: https://reviews.llvm.org/D75579
2020-03-17Replace MCTargetOptionsCommandFlags.inc and CommandFlags.inc by runtime ↵serge-sans-paille1-7/+9
registration MCTargetOptionsCommandFlags.inc and CommandFlags.inc are headers which contain cl::opt with static storage. These headers are meant to be incuded by tools to make it easier to parametrize codegen/mc. However, these headers are also included in at least two libraries: lldCommon and handle-llvm. As a result, when creating DYLIB, clang-cpp holds a reference to the options, and lldCommon holds another reference. Linking the two in a single executable, as zig does[0], results in a double registration. This patch explores an other approach: the .inc files are moved to regular files, and the registration happens on-demand through static declaration of options in the constructor of a static object. [0] https://bugzilla.redhat.com/show_bug.cgi?id=1756977#c5 Differential Revision: https://reviews.llvm.org/D75579
2020-02-14[Support] On Windows, ensure hardware_concurrency() extends to all CPU ↵Alexandre Ganea1-2/+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-01-29Another stab at making the gold plugin compile againBenjamin Kramer1-3/+5