aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/TargetMachine.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-08-29[IR][CodeGen] Remove "approx-func-fp-math" attribute (#155740)paperchalice1-1/+0
Remove "approx-func-fp-math" attribute and related command line option, users should always use afn flag in IR. Resolve FIXME in `TargetMachine::resetTargetOptions` partially.
2025-04-29Target: Stop assigning RELRO sections to .ldata.rel.ro.Peter Collingbourne1-0/+13
Linkers do not currently support PT_GNU_RELRO for SHF_X86_64_LARGE sections; that would require the linker to emit more than one PT_GNU_RELRO because large sections are discontiguous by design, and most ELF dynamic loaders do not support that (bionic appears to support it but glibc/musl/FreeBSD/NetBSD/OpenBSD appear not to). With current linkers these sections will end up in .ldata which results in silently disabling RELRO. Therefore, disable SHF_X86_64_LARGE for RELRO sections. If this ever gets supported by downstream components in the future we could add an opt-in flag for moving these sections to .ldata.rel.ro which would trigger the creation of a second PT_GNU_RELRO. Reviewers: MaskRay, aeubanks Reviewed By: aeubanks Pull Request: https://github.com/llvm/llvm-project/pull/137742
2025-04-14[CodeGen] Prune headers and move code out of line for build efficiency, NFC ↵Reid Kleckner1-0/+8
(#135622) I noticed these destructors taking time with -ftime-trace and moved some of them for minor build efficiency improvements. The main impact of moving destructors out of line is that it avoids requiring container fields containing other types from being complete, i.e. one can have uptr<T> or vector<T> as a field with an incomplete type T, and that means we can reduce transitive includes, as with LegalizerInfo.h. Move expensive getDebugOperandsForReg template out-of-line. The std::function instantiation shows up in time trace even if you don't use the function.
2025-01-29[KernelInfo] Implement new LLVM IR pass for GPU code analysis (#102944)Joel E. Denny1-0/+5
This patch implements an LLVM IR pass, named kernel-info, that reports various statistics for codes compiled for GPUs. The ultimate goal of these statistics to help identify bad code patterns and ways to mitigate them. The pass operates at the LLVM IR level so that it can, in theory, support any LLVM-based compiler for programming languages supporting GPUs. It has been tested so far with LLVM IR generated by Clang for OpenMP offload codes targeting NVIDIA GPUs and AMD GPUs. By default, the pass runs at the end of LTO, and options like ``-Rpass=kernel-info`` enable its remarks. Example `opt` and `clang` command lines appear in `llvm/docs/KernelInfo.rst`. Remarks include summary statistics (e.g., total size of static allocas) and individual occurrences (e.g., source location of each alloca). Examples of its output appear in tests in `llvm/test/Analysis/KernelInfo`.
2025-01-03[Cygwin] Fix global variable dll import (#121439)王宇逸1-1/+1
This PR is necessary for cygwin target of Rust. References: * https://github.com/rust-lang/llvm-project/commit/86657cc39f8e42ae73be810fb0703ddac0eeef94 * https://github.com/Berrysoft/llvm-project/commit/a807e9f077351d3c6a68f4abe74c94a039759a2e
2024-08-12TargetMachine: Move trivial setter/getter to headerMatt Arsenault1-5/+0
The others are already inline here.
2024-06-28[IR] Don't include Module.h in Analysis.h (NFC) (#97023)Nikita Popov1-0/+1
Replace it with a forward declaration instead. Analysis.h is pulled in by all passes, but not all passes need to access the module.
2024-06-28[IR] Add getDataLayout() helpers to Function and GlobalValue (#96919)Nikita Popov1-2/+2
Similar to https://github.com/llvm/llvm-project/pull/96902, this adds `getDataLayout()` helpers to Function and GlobalValue, replacing the current `getParent()->getDataLayout()` pattern.
2024-04-16[X86] Change how we treat functions with explicit sections as small/large ↵Arthur Eubanks1-6/+20
(#88172) Following #78348, we should treat functions with an explicit section as small, unless the section name is (or has the prefix) ".ltext". Clang emits global initializers into a ".text.startup" section on Linux. If we mix small/medium code model object files with large code model object files, we'll end up mixing sections with and without the large section flag. Reland of #87838 with a check for non-ELF platforms in TargetMachine::isLargeGlobalValue(), otherwise MCJIT on Windows tests fail.
2024-04-08Revert "[X86] Change how we treat functions with explicit sections as ↵Arthur Eubanks1-14/+6
small/large (#87838)" This reverts commit e27c3736f975ca463476223c465e4777186f603f. Breaks ExecutionEngine/MCJIT/test-global-ctors.ll on windows, e.g. https://lab.llvm.org/buildbot/#/builders/117/builds/18749.
2024-04-08[X86] Change how we treat functions with explicit sections as small/large ↵Arthur Eubanks1-6/+14
(#87838) Following #78348, we should treat functions with an explicit section as small, unless the section name is (or has the prefix) ".ltext". Clang emits global initializers into a ".text.startup" section on Linux. If we mix small/medium code model object files with large code model object files, we'll end up mixing sections with and without the large section flag.
2024-03-12[X86] Fix determining if globals with size <8 bits are large (#84975)Arthur Eubanks1-1/+1
Previously any global under 8 bits would accidentally be considered 0 sized, which is considered a large global.
2024-03-11[NFC] Remove unused parameter from shouldAssumeDSOLocal()Arthur Eubanks1-3/+2
2024-01-29[X86] Treat __start_*/__stop_* symbols as large (#79909)Arthur Eubanks1-1/+5
Followup to #79884. The linker adds __start_foo/__stop_foo symbols pointing to the beginning/end of the foo section. These can be far away from text, so treat them as large symbols under the medium/large code models. Performance to access these is almost certainly not important.
2024-01-29[X86] Treat __ehdr_start as large (#79884)Arthur Eubanks1-0/+2
The __ehdr_start symbol is added by the linker and points to the ELF file headers, which can be very far away from text. Treat it as a large symbol under the medium/large code models. Performance to access __ehdr_start is almost certainly not important. There are a couple of other symbols that the linker adds [1], but this is the most relevant one that may be far away from text. [1] https://github.com/llvm/llvm-project/blob/547c395b279a93357082ac06cf3e8fe37ebfc3fe/lld/ELF/Writer.cpp#L226
2024-01-23[RISCV] Support TLSDESC in the RISC-V backend (#66915)Paul Kirth1-0/+1
This patch adds basic TLSDESC support in the RISC-V backend. Specifically, we add new relocation types for TLSDESC, as prescribed in https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/373, and add a new pseudo instruction to simplify code generation. This patch does not try to optimize the local dynamic case, which can be improved in separate patches. Linker side changes will also be handled separately. The current implementation is only enabled when passing the new `-enable-tlsdesc` codegen flag.
2024-01-17[X86] Don't respect large data threshold for globals with an explicit ↵Arthur Eubanks1-16/+14
section (#78348) If multiple globals are placed in an explicit section, there's a chance that the large data threshold will cause the different globals to be inconsistent in whether they're large or small. Mixing sections with mismatched large section flags can cause undesirable issues like increased relocation pressure because there may be 32-bit references to the section in some TUs, but the section is considered large since input section flags are unioned and other TUs added the large section flag. An explicit code model on the global still overrides the decision. We can do this for globals without any references to them, like what we did with asan_globals in #74514. If we have some precompiled small code model files where asan_globals is not considered large mixed with medium/large code model files, that's ok because the section is considered large and placed farther. However, overriding the code model for globals in some TUs but not others and having references to them from code will still result in the above undesired behavior. This mitigates a whole class of mismatched large section flag issues like what #77986 was trying to fix. This ends up not adding the SHF_X86_64_LARGE section flag on explicit sections in the medium/large code model. This is ok for the large code model since all references from large text must use 64-bit relocations anyway.
2023-12-21Reapply "[X86] Set SHF_X86_64_LARGE for globals with explicit well-known ↵Arthur Eubanks1-2/+2
large section name (#74381)" This reverts commit 19fff858931bf575b63a0078cc553f8f93cced20. Now that explicit large globals are handled properly in the small code model.
2023-12-14Re-Reland [X86] Respect code models more when determining if a global ↵Arthur Eubanks1-1/+7
reference can fit in 32 bits (#75386) For non-GlobalValue references, the small and medium code models can use 32 bit constants. For GlobalValue references, use TargetMachine::isLargeGlobalObject(). Look through aliases for determining if a GlobalValue is small or large. Even the large code model can reference small objects with 32 bit constants as long as we're in no-pic mode, or if the reference is offset from the GOT. Original commit broke the build... First reland broke large PIC builds referencing small data since it was using GOTOFF as a 32-bit constant.
2023-12-14Revert "Reland [X86] Respect code models more when determining if a global ↵Arthur Eubanks1-7/+1
reference can fit in 32 bits (#75386)" This reverts commit ec92d74a0ef89b9dd46aee6ec8aca6bfd3c66a54. Breaks some compiler-rt tests, e.g. https://lab.llvm.org/buildbot/#/builders/37/builds/28834
2023-12-14Reland [X86] Respect code models more when determining if a global reference ↵Arthur Eubanks1-1/+7
can fit in 32 bits (#75386) For non-GlobalValue references, the small and medium code models can use 32 bit constants. For GlobalValue references, use TargetMachine::isLargeGlobalObject(). Look through aliases for determining if a GlobalValue is small or large. Even the large code model can reference small objects with 32 bit constants as long as we're in no-pic mode, or if the reference is offset from the GOT. Original commit broke the build...
2023-12-14Revert "[X86] Respect code models more when determining if a global ↵Arthur Eubanks1-7/+1
reference can fit in 32 bits" (#75500) Reverts llvm/llvm-project#75386 Breaks build.
2023-12-14[X86] Respect code models more when determining if a global reference can ↵Arthur Eubanks1-1/+7
fit in 32 bits (#75386) For non-GlobalValue references, the small and medium code models can use 32 bit constants. For GlobalValue references, use TargetMachine::isLargeGlobalObject(). Look through aliases for determining if a GlobalValue is small or large. Even the large code model can reference small objects with 32 bit constants as long as we're in no-pic mode, or if the reference is offset from the GOT.
2023-12-12Revert "[X86] Set SHF_X86_64_LARGE for globals with explicit well-known ↵Arthur Eubanks1-2/+2
large section name (#74381)" This reverts commit 323451ab88866c42c87971cbc670771bd0d48692. Code with these section names in the wild doesn't compile because support for large globals in the small code model is not complete yet.
2023-12-11[X86] Handle unsized types in TargetMachine::isLargeGlobalObject() (#74952)Arthur Eubanks1-0/+2
isLargeGlobalObject() didn't handle opaque types, resulting in crashes.
2023-12-11[X86] Handle ifuncs in TargetMachine::isLargeGlobalObject() (#74911)Arthur Eubanks1-3/+4
isLargeGlobalObject() didn't handle GlobalIFuncs, resulting in crashes. Treat ifuncs the same as normal Functions.
2023-12-05[X86] Respect code_model when determining if a global is small/large (#74498)Arthur Eubanks1-0/+10
Using the GlobalVariable code_model property added in #72077. code_model = "small" means the global should be treated as small regardless of the TargetMachine code model. code_model = "large" means the global should be treated as large regardless of the TargetMachine code model. Inferring small/large based on a known section name still takes precedence for correctness. The intention is to use this for globals that are accessed very infrequently but also take up a lot of space in the binary to mitigate relocation overflows. Prime examples are globals that go in "__llvm_prf_names" for coverage/PGO instrumented builds and "asan_globals" for ASan builds.
2023-12-05[X86] Set SHF_X86_64_LARGE for globals with explicit well-known large ↵Arthur Eubanks1-17/+21
section name (#74381) Globals marked with the .lbss/.ldata/.lrodata should automatically be treated as large. Do this regardless of the code model for consistency when mixing object files compiled with different code models. Basically the other half of #70748. Example in the wild: https://codebrowser.dev/qt5/qtbase/src/testlib/qtestcase.cpp.html#1664
2023-12-01Reland [X86] With large code model, put functions into .ltext with large ↵Arthur Eubanks1-2/+10
section flag (#73037) So that when mixing small and large text, large text stays out of the way of the rest of the binary. This is useful for mixing precompiled small code model object files and built-from-source large code model binaries so that the the text sections don't get merged. The reland fixes an issue where a function in the large code model would reference small data without GOTOFF. This was incorrectly reverted in 76f78ecc789d58baa3a88b2fe2a57428f07e5362.
2023-12-01Revert "Reland [X86] With large code model, put functions into .ltext with ↵Dmitri Gribenko1-10/+2
large section flag (#73037)" This reverts commit 4bf8a688956a759b7b6b8d94f42d25c13c7af130. This commit seems to be breaking the semantics of the ObjectFile::isSectionText method, which breaks numba/llvmlite bindings.
2023-11-30Reland [X86] With large code model, put functions into .ltext with large ↵Arthur Eubanks1-2/+10
section flag (#73037) So that when mixing small and large text, large text stays out of the way of the rest of the binary. This is useful for mixing precompiled small code model object files and built-from-source large code model binaries so that the the text sections don't get merged. The reland fixes an issue where a function in the large code model would reference small data without GOTOFF.
2023-11-28Revert "[X86] With large code model, put functions into .ltext with large ↵Arthur Eubanks1-10/+2
section flag (#73037)" This reverts commit 38e435895779c6f0e6c47a171f3b300ad99828b3. May be culprit for https://lab.llvm.org/buildbot/#/builders/37/builds/28079/steps/9/logs/stdio.
2023-11-28[X86] With large code model, put functions into .ltext with large section ↵Arthur Eubanks1-2/+10
flag (#73037) So that when mixing small and large text, large text stays out of the way of the rest of the binary. This is useful for mixing precompiled small code model object files and built-from-source large code model binaries so that the the text sections don't get merged.
2023-11-17[X86] Place data in large sections for large code model (#70265)Arthur Eubanks1-3/+2
This allows better interoperability mixing small/medium/large code model code since large code model data can be put into separate large sections. And respect large data threshold under large code model. gcc also does this: https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html. See https://groups.google.com/g/x86-64-abi/c/jnQdJeabxiU.
2023-10-30[X86] Don't set SHF_X86_64_LARGE for variables with explicit section name of ↵Fangrui Song1-0/+14
a well-known small data section prefix (#70748) Commit f3ea73133f91c1c23596d45680c8f2269c1dd289 allows SHF_X86_64_LARGE for all global variables with an explicit section. For the following variables, their data sections will be annotated as SHF_X86_64_LARGE. ``` const char relro[512] __attribute__((section(".rodata"))) = "a"; const char *const relro __attribute__((section(".data.rel.ro"))) = "a"; char data[512] __attribute__((section(".data"))) = "a"; ``` The typical linker requirement is that we do not create more than one output section with the same name, and the only output section should have the bitwise OR value of all input section flags. Therefore, the output .data section will have the SHF_X86_64_LARGE flag and be moved away from the regular sections. This is undesired but benign. However, .data.rel.ro having the SHF_X86_64_LARGE flag is problematic because dynamic loaders do not support more than one PT_GNU_RELRO program header, and LLD produces the error `error: section: .jcr is not contiguous with other relro sections`. I believe the most appropriate solution is to disallow SHF_X86_64_LARGE on variables with an explicit section of certain prefixes ( .bss/.data/.bss) and allow others (e.g. metadata sections for various instrumentation). Fortunately, global variables with an explicit .bss/.data/.bss section are rare, so they should not cause excessive relocation overflow pressure.
2023-09-29[CodeGen] Don't treat thread local globals as large data (#67764)Arthur Eubanks1-1/+1
Otherwise they may mistakenly get the large section flag.
2023-09-18[TargetMachine] Remove DefaultOptions (#66673)Arthur Eubanks1-1/+1
7d81813d says that this was used because functions missing certain attributes (e.g. fast math) would inherit behavior from previous functions with those attributes. However, later c378e52c explicitly set those attributes if they were missing and removed the use of DefaultOptions.
2023-09-14[X86] Introduce a large data threshold for the medium code modelArthur Eubanks1-2/+4
Currently clang's medium code model treats all data as large, putting them in a large data section and using more expensive instruction sequences to access them. Following gcc's -mlarge-data-threshold, which allows putting data under a certain size in a normal data section as opposed to a large data section. This allows using cheaper code sequences to access some portion of data in the binary (which will be implemented in LLVM in a future patch). And under the medium codel mode, only put data above the large data threshold into large data sections, not all data. Reviewed By: MaskRay, rnk Differential Revision: https://reviews.llvm.org/D149288
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-08-16Fix MSVC "not all control paths return a value" warning. NFC.Simon Pilgrim1-0/+1
2023-08-16[AArch64] Relax cross-section branchesDaniel Hoekwater1-0/+13
Because the code layout is not known during compilation, the distance of cross-section jumps is not knowable at compile-time. Because of this, we should assume that any cross-sectional jumps are out of range. This assumption is necessary for machine function splitting on AArch64, which introduces cross-section branches in the middle of functions. The linker relaxes out-of-range unconditional branches, but it clobbers X16 to do so; it doesn't relax conditional branches, which must be manually relaxed by the compiler. Differential Revision: https://reviews.llvm.org/D145211
2023-05-31[X86] Use "l" prefix for data sections under medium/large code modelArthur Eubanks1-0/+11
And also set the SHF_X86_64_LARGE section flag. gcc only uses the "l" prefix and SHF_X86_64_LARGE in the medium code model for data larger than -mlarge-data-threshold. But it seems more consistent to use it in the large code model as well in case separate parts of the binary aren't compiled with the large code model and also have a .data/.bss/.rodata section. Reviewed By: MaskRay, tkoeppe Differential Revision: https://reviews.llvm.org/D148836
2023-04-23Remove ExplicitEmulatedTLS and simplify -femulated-tls handlingFangrui Song1-7/+1
Currently clangDriver passes -femulated-tls and -fno-emulated-tls to cc1. cc1 forwards the option to LLVMCodeGen and ExplicitEmulatedTLS is used to decide the value. Simplify this by moving the Clang decision to clangDriver and moving the LLVM decision to InitTargetOptionsFromCodeGenFlags.
2022-06-29Pass code-model through Module IR to [llc].esmeyi1-4/+0
Currently, the code-model specified in IR can't be captured by [llc]. This patch fixes that. Reviewed By: shchenz, MaskRay Differential Revision: https://reviews.llvm.org/D128623
2022-03-10Cleanup includes: LLVMTargetserge-sans-paille1-5/+0
Most notably, Pass.h is no longer included by TargetMachine.h before: 1063570306 after: 1063332844 Differential Revision: https://reviews.llvm.org/D121168
2022-02-25mark getTargetTransformInfo and getTargetIRAnalysis as constJameson Nash1-2/+3
Seems like this can be const, since Passes shouldn't modify it. Reviewed By: wsmoses Differential Revision: https://reviews.llvm.org/D120518
2022-02-09Cleanup LLVMMC headersserge-sans-paille1-0/+2
There's a few relevant forward declarations in there that may require downstream adding explicit includes: llvm/MC/MCContext.h no longer includes llvm/BinaryFormat/ELF.h, llvm/MC/MCSubtargetInfo.h, llvm/MC/MCTargetOptions.h llvm/MC/MCObjectStreamer.h no longer include llvm/MC/MCAssembler.h llvm/MC/MCAssembler.h no longer includes llvm/MC/MCFixup.h, llvm/MC/MCFragment.h Counting preprocessed lines required to rebuild llvm-project on my setup: before: 1052436830 after: 1049293745 Which is significant and backs up the change in addition to the usual benefits of decreasing coupling between headers and compilation units. Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D119244
2022-02-02[PowerPC] Scalar IBM MASS library conversion passMasoud Ataei1-0/+1
This patch introduces the conversions from math function calls to MASS library calls. To resolves calls generated with these conversions, one need to link libxlopt.a library. This patch is tested on PowerPC Linux and AIX. Differential: https://reviews.llvm.org/D101759 Reviewer: bmahjour
2021-10-21[SystemZ][z/OS] Initial implementation for lowerCall on z/OSAnirudh Prasad1-0/+3
- This patch provides the initial implementation for lowering a call on z/OS according to the XPLINK64 calling convention - A series of changes have been made to SystemZCallingConv.td to account for these additional XPLINK64 changes including adding a new helper function to shadow the stack along with allocation of a register wherever appropriate - For the cases of copying a f64 to a gr64 and a f128 / 128-bit vector type to a gr64, a `CCBitConvertToType` has been added and has been bitcasted appropriately in the lowering phase - Support for the ADA register (R5) will be provided in a later patch. Reviewed By: uweigand Differential Revision: https://reviews.llvm.org/D111662
2021-08-23[TargetMachine] Move COFF special case for ExternalSymbolSDNode from ↵Fangrui Song1-5/+1
shouldAssumeDSOLocal to X86Subtarget Intended to be NFC. ARM/AArch64 don't appear to need adjustment. TargetMachine::shouldAssumeDSOLocal is expected to be very simple, ideally matching isDSOLocal(). The IR producers are expected to set dso_local correctly. (While some may think this function can make producers' work easier, the function is really not in a good position to set dso_local. See the various special cases we duplicate from clang CodeGenModule.cpp.) Reviewed By: mstorsjo Differential Revision: https://reviews.llvm.org/D108514