aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/TargetMachine.cpp
AgeCommit message (Collapse)AuthorFilesLines
2021-04-17Normalize interaction with boolean attributesSerge Guelton1-1/+1
Such attributes can either be unset, or set to "true" or "false" (as string). throughout the codebase, this led to inelegant checks ranging from if (Fn->getFnAttribute("no-jump-tables").getValueAsString() == "true") to if (Fn->hasAttribute("no-jump-tables") && Fn->getFnAttribute("no-jump-tables").getValueAsString() == "true") Introduce a getValueAsBool that normalize the check, with the following behavior: no attributes or attribute set to "false" => return false attribute set to "true" => return true Differential Revision: https://reviews.llvm.org/D99299
2021-01-26Add -fbinutils-version= to gate ELF features on the specified binutils versionFangrui Song1-0/+9
There are two use cases. Assembler We have accrued some code gated on MCAsmInfo::useIntegratedAssembler(). Some features are supported by latest GNU as, but we have to use MCAsmInfo::useIntegratedAs() because the newer versions have not been widely adopted (e.g. SHF_LINK_ORDER 'o' and 'unique' linkage in 2.35, --compress-debug-sections= in 2.26). Linker We want to use features supported only by LLD or very new GNU ld, or don't want to work around older GNU ld. We currently can't represent that "we don't care about old GNU ld". You can find such workarounds in a few other places, e.g. Mips/MipsAsmprinter.cpp PowerPC/PPCTOCRegDeps.cpp X86/X86MCInstrLower.cpp AArch64 TLS workaround for R_AARCH64_TLSLD_MOVW_DTPREL_* (PR ld/18276), R_AARCH64_TLSLE_LDST8_TPREL_LO12 (https://bugs.llvm.org/show_bug.cgi?id=36727 https://sourceware.org/bugzilla/show_bug.cgi?id=22969) Mixed SHF_LINK_ORDER and non-SHF_LINK_ORDER components (supported by LLD in D84001; GNU ld feature request https://sourceware.org/bugzilla/show_bug.cgi?id=16833 may take a while before available). This feature allows to garbage collect some unused sections (e.g. fragmented .gcc_except_table). This patch adds `-fbinutils-version=` to clang and `-binutils-version` to llc. It changes one codegen place in SHF_MERGE to demonstrate its usage. `-fbinutils-version=2.35` means the produced object file does not care about GNU ld<2.35 compatibility. When `-fno-integrated-as` is specified, the produced assembly can be consumed by GNU as>=2.35, but older versions may not work. `-fbinutils-version=none` means that we can use all ELF features, regardless of GNU as/ld support. Both clang and llc need `parseBinutilsVersion`. Such command line parsing is usually implemented in `llvm/lib/CodeGen/CommandFlags.cpp` (LLVMCodeGen), however, ClangCodeGen does not depend on LLVMCodeGen. So I add `parseBinutilsVersion` to `llvm/lib/Target/TargetMachine.cpp` (LLVMTarget). Differential Revision: https://reviews.llvm.org/D85474
2020-12-30[TargetMachine] Drop implied dso_local for definitions in ELF static ↵Fangrui Song1-10/+0
relocation model/PIE TargetMachine::shouldAssumeDSOLocal currently implies dso_local for such definitions. Since clang -fno-pic add the dso_local specifier, we don't need to special case.
2020-12-29Move -fno-semantic-interposition dso_local logic from TargetMachine to Clang ↵Fangrui Song1-8/+0
CodeGenModule This simplifies TargetMachine::shouldAssumeDSOLocal and and gives frontend the decision to use dso_local. For LLVM synthesized functions/globals, they may lose inferred dso_local but such optimizations are probably not very useful. Note: the hasComdat() condition in canBenefitFromLocalAlias (D77429) may be dead now. (llvm/CodeGen/X86/semantic-interposition-comdat.ll) (Investigate whether we need test coverage when Fuchsia C++ ABI is clearer)
2020-12-06[TargetMachine] Delete asan workaroundFangrui Song1-5/+0
687b83ceabafe81970cd4639e7f0c89036402081 has fixed the X86FastISel bug. We can revert the workaround now. Actually, the commit introduced a bug that ppc64 should be excluded.
2020-12-05[TargetMachine] Don't imply dso_local for memprof in static relocation modelFangrui Song1-2/+1
The workaround is no longer needed with my previous commit to MemProfiler.cpp
2020-12-05[TargetMachine] Set dso_local for memprofVitaly Buka1-3/+4
Similar to 5582a7987662a92eda5d883b88fc4586e755acf5
2020-12-05[TargetMachine] Set dso_local if asan is detectedFangrui Song1-0/+5
AddressSanitizer instrumentation does not set dso_local on non-thread-local global variables in -fno-pic and it seems to rely on implied dso_local to work. Add a hack until we have fixed AddressSanitizer to call setDSOLocal() as appropriate. Thanks to Vitaly Buka for reporting the issue and suggesting the way to detect asan.
2020-12-05[TargetMachine] Drop implied dso_local for an edge case (extern_weak + ↵Fangrui Song1-10/+0
non-pic + hidden) This does not deserve special handling. The code should be added to Clang instead if deemed useful. With this simplification, we can additionally delete the PIC extern_weak special case.
2020-12-05[TargetMachine] Clean up TargetMachine::shouldAssumeDSOLocal after x86-32 ↵Fangrui Song1-21/+0
specific hack is moved to X86Subtarget With my previous commit, X86Subtarget::classifyGlobalReference has learned to use MO_NO_FLAG for 32-bit ELF -fno-pic code, the x86-32 special case in TargetMachine::shouldAssumeDSOLocal can be removed. Since we no longer imply dso_local for function declarations, we can drop the ppc64 special case as well. This is NFC in terms of Clang emitted assembly.
2020-12-05[TargetMachine] Don't imply dso_local on function declarations in ↵Fangrui Song1-9/+4
Reloc::Static model for ELF/wasm clang/lib/CodeGen/CodeGenModule sets dso_local on applicable function declarations, we don't need to duplicate the work in TargetMachine:shouldAssumeDSOLocal. (Actually the long-term goal (started by r324535) is to drop TargetMachine::shouldAssumeDSOLocal.) By not implying dso_local, we will respect dso_local/dso_preemptable specifiers set by the frontend. This allows the proposed -fno-direct-access-external-data option to work with -fno-pic and prevent a canonical PLT entry (SHN_UNDEF with non-zero st_value) when taking the address of a function symbol. This patch should be NFC in terms of the Clang emitted assembly because the case we don't set dso_local is a case Clang sets dso_local. However, some tests don't set dso_local on some function declarations and expose some differences. Most tests have been fixed to be more robust in the previous commit.
2020-12-05[TargetMachine] Move X86 specific shouldAssumeDSOLocal logic to ↵Fangrui Song1-11/+2
X86Subtarget::classifyGlobalFunctionReference
2020-12-05[TargetMachine] Simplify shouldAssumeDSOLocal by processing ↵Fangrui Song1-21/+27
ExternalSymbolSDNode early The function accrues many `GV` nullness checks. Process `!GV` (ExternalSymbolSDNode) early to simplify code. Also improve a comment added in r327198 (intrinsics is a subset of ExternalSymbolSDNode). Intended to be NFC.
2020-12-05[TargetMachine][CodeGenModule] Delete unneeded ppc32 special case from ↵Fangrui Song1-2/+2
shouldAssumeDSOLocal PPCMCInstLower does not actually call shouldAssumeDSOLocal for ppc32 so this is dead. Actually Clang ppc32 does produce a pair of absolute relocations which match GCC. This also fixes a comment (R_PPC_COPY and R_PPC64_COPY do exist).
2020-12-04[TargetMachine] Delete wasm special case from shouldAssumeDSOLocalFangrui Song1-2/+2
2020-12-04[TargetMachine] Don't imply dso_local on global variable declarations in ↵Fangrui Song1-3/+12
Reloc::Static model clang/lib/CodeGen/CodeGenModule sets dso_local on applicable global variables, we don't need to duplicate the work in TargetMachine:shouldAssumeDSOLocal. (Actually the long-term goal (started by r324535) is to remove as much additional implied dso_local in TargetMachine:shouldAssumeDSOLocal as possible.) By not implying dso_local, we will respect dso_local/dso_preemptable specifiers set by the frontend. This allows the proposed -fno-direct-access-external-data option to work with -fno-pic and prevent copy relocations. This patch should be NFC in terms of the Clang behavior because the case we don't set dso_local is a case Clang sets dso_local. However, some tests don't set dso_local on some `external global` and expose some differences. Most tests have been fixed to be more robust in previous commits.
2020-07-24Revert rG5dd566b7c7b78bd- "PassManager.h - remove unnecessary ↵Simon Pilgrim1-2/+0
Function.h/Module.h includes. NFCI." This reverts commit 5dd566b7c7b78bd385418c72d63c79895be9ae97. Causing some buildbot failures that I'm not seeing on MSVC builds.
2020-07-24PassManager.h - remove unnecessary Function.h/Module.h includes. NFCI.Simon Pilgrim1-0/+2
PassManager.h is one of the top headers in the ClangBuildAnalyzer frontend worst offenders list. This exposes a large number of implicit dependencies on various forward declarations/includes in other headers that need addressing.
2020-05-25Make explicit -fno-semantic-interposition (in -fpic mode) infer dso_localFangrui Song1-0/+8
-fno-semantic-interposition is currently the CC1 default. (The opposite disables some interprocedural optimizations.) However, it does not infer dso_local: on most targets accesses to ExternalLinkage functions/variables defined in the current module still need PLT/GOT. This patch makes explicit -fno-semantic-interposition infer dso_local, so that PLT/GOT can be eliminated if targets implement local aliases for AsmPrinter::getSymbolPreferLocal (currently only x86). Currently we check whether the module flag "SemanticInterposition" is 0. If yes, infer dso_local. In the future, we can infer dso_local unless "SemanticInterposition" is 1: frontends other than clang will also benefit from the optimization if they don't bother setting the flag. (There will be risks if they do want ELF interposition: they need to set "SemanticInterposition" to 1.)
2020-04-17[XCOFF][AIX] Fix getSymbol to return the correct qualname when necessaryjasonliu1-0/+4
Summary: AIX symbol have qualname and unqualified name. The stock getSymbol could only return unqualified name, which leads us to patch many caller side(lowerConstant, getMCSymbolForTOCPseudoMO). So we should try to address this problem in the callee side(getSymbol) and clean up the caller side instead. Note: this is a "mostly" NFC patch, with a fix for the original lowerConstant behavior. Differential Revision: https://reviews.llvm.org/D78045
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-4/+4
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-15Set some fast math attributes in setFunctionAttributesMatt Arsenault1-6/+6
This will provide a more consistent view to codegen for these attributes. The current system is somewhat awkward, and the fields in TargetOptions are reset based on the command line flag if the attribute isn't set. By forcing these attributes with the flag, there can never be an inconsistency in the behavior if code directly inspects the attribute on the function without considering the command line flags.
2020-01-10[MIR] Fix cyclic dependency of MIR formatterPeng Guo1-4/+1
Summary: Move MIR formatter pointer from TargetMachine to TargetInstrInfo to avoid cyclic dependency between target & codegen. Reviewers: dsanders, bkramer, arsenm Subscribers: wdng, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D72485
2020-01-08Revert "Revert "[MIR] Target specific MIR formating and parsing""Daniel Sanders1-1/+4
There was an unguarded dereference of MF in a function that permitted nullptr. Fixed This reverts commit 71d64f72f934631aa2f12b9542c23f74f256f494.
2020-01-08Revert "[MIR] Target specific MIR formating and parsing"Nico Weber1-4/+1
This reverts commit 3ef05d85be8c3666ebfa3ad986eb334da5195a47. It broke check-llvm on many bots, see comments on D69836.
2020-01-08[MIR] Target specific MIR formating and parsingPeng Guo1-1/+4
Summary: Added MIRFormatter for target specific MIR formating and parsing with immediate and custom pseudo source values. Target machine can subclass MIRFormatter and implement custom logic for printing and parsing immediate and custom pseudo source values for better readability. * Target specific immediate mnemonic need to start with "." follows by identifier string. When MIR parser sees immediate it will call target specific parsing function. * Custom pseudo source value need to start with custom follows by double-quoted string. MIR parser will pass the quoted string to target specific PSV parsing function. * MIRFormatter have 2 helper functions to facilitate LLVM value printing and parsing for custom PSV if they refers LLVM values. Patch by Peng Guo Reviewers: dsanders, arsenm Reviewed By: dsanders Subscribers: wdng, jvesely, nhaehnle, hiraditya, jfb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69836
2020-01-08Revert "[MIR] Target specific MIR formating and parsing"Daniel Sanders1-4/+1
Forgot to credit Peng in the commit message. This reverts commit be841f89d0014b1e0246a4feae941b2f74abd908.
2020-01-08[MIR] Target specific MIR formating and parsingPeng Guo1-1/+4
Summary: Added MIRFormatter for target specific MIR formating and parsing with immediate and custom pseudo source values. Target machine can subclass MIRFormatter and implement custom logic for printing and parsing immediate and custom pseudo source values for better readability. * Target specific immediate mnemonic need to start with "." follows by identifier string. When MIR parser sees immediate it will call target specific parsing function. * Custom pseudo source value need to start with custom follows by double-quoted string. MIR parser will pass the quoted string to target specific PSV parsing function. * MIRFormatter have 2 helper functions to facilitate LLVM value printing and parsing for custom PSV if they refers LLVM values. Reviewers: dsanders, arsenm Reviewed By: dsanders Subscribers: wdng, jvesely, nhaehnle, hiraditya, jfb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69836
2020-01-01[MC][TargetMachine] Delete MCTargetOptions::MCPIECopyRelocationsFangrui Song1-8/+7
clang/lib/CodeGen/CodeGenModule performs the -mpie-copy-relocations check and sets dso_local on applicable global variables. We don't need to duplicate the work in TargetMachine shouldAssumeDSOLocal. Verified that -mpie-copy-relocations can still emit PC relative relocations for external variable accesses. clang -target x86_64 -fpie -mpie-copy-relocations -c => R_X86_64_PC32 clang -target aarch64 -fpie -mpie-copy-relocations -c => R_AARCH64_ADR_PREL_PG_HI21+R_AARCH64_LDST64_ABS_LO12_NC
2019-11-02TargetMachine - fix uninitialized variable warning. NFCI.Simon Pilgrim1-2/+2
TargetPassConfig::addCoreISelPasses() always initializes O0WantsFastISel but it appeases static analyzers that complain that O0WantsFastISel isn't initialized in the constructor.
2019-08-20[TargetMachine] Don't try to create COFFSTUB references on windows on non-COFFMartin Storsjo1-3/+5
This avoids spurious relocation types for windows/elf targets. Differential Revision: https://reviews.llvm.org/D66401 llvm-svn: 369426
2019-07-19Don't update NoTrappingFPMath and FPDenormalMode in resetTargetOptionsOliver Stannard1-12/+0
We'd like to remove this whole function, because these are properties of functions, not the target as a whole. These two are easy to remove because they are only used for emitting ARM build attributes, which expects them to represent the defaults for the whole module, not just the last function generated. This is needed to get correct build attributes when using IPRA on ARM, because IPRA causes resetTargetOptions to get called before ARMAsmPrinter::emitAttributes. Differential revision: https://reviews.llvm.org/D64929 llvm-svn: 366562
2019-05-24Implement call lowering without parameters on AIXJason Liu1-0/+5
Summary:dd This patch implements call lowering for calls without parameters on AIX as initial support. Reviewers: sfertile, hubert.reinterpretcast, aheejin, efriedma Differential Revision: https://reviews.llvm.org/D61948 llvm-svn: 361669
2019-05-10[WebAssembly] Don't assume that strongly defined symbols are DSO-localSam Clegg1-3/+3
The current PIC model for WebAssembly is more like ELF in that it allows symbol interposition. This means that more functions end up being addressed via the GOT and fewer directly added to the wasm table. One effect is a reduction in the number of wasm table entries similar to the previous attempt in https://reviews.llvm.org/D61539 which was reverted. Differential Revision: https://reviews.llvm.org/D61772 llvm-svn: 360402
2019-05-07[COFF] Use COFF stubs for extern_weak functionsReid Kleckner1-0/+6
Summary: A COFF stub indirects the reference to a symbol through memory. A .refptr.$sym global variable pointer is created to refer to $sym. Typically mingw uses these for external global variable declarations, but we can use them for weak function declarations as well. Updates the dso_local classification to add a special case for extern_weak symbols on COFF in both clang and LLVM. Fixes PR37598 Reviewers: smeenai, mstorsjo Subscribers: hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D61615 llvm-svn: 360207
2019-03-18[WebAssembly] Don't override default implementation of isOffsetFoldingLegal. ↵Sam Clegg1-1/+1
NFC. The default implementation does we want and is going to more compatible with dynamic linking (-fPIC) support that is planned. This is NFC because currently we only build wasm with `-relocation-model=static` which in turn means that the default `isOffsetFoldingLegal` always returns true today. Differential Revision: https://reviews.llvm.org/D54661 llvm-svn: 356410
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-09-25Use unique_ptr to hold AsmInfo,MRI,MII,STIFangrui Song1-6/+1
Reviewers: pcc, dblaikie Reviewed By: dblaikie Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D52389 llvm-svn: 342945
2018-09-04[MinGW] Move code for indicating "potentially not DSO local" into ↵Martin Storsjo1-0/+9
shouldAssumeDSOLocal. NFC. On Windows, if shouldAssumeDSOLocal returns false, it's either a dllimport reference, or a reference that we should treat as non-local and create a stub for. Clean up AArch64Subtarget::ClassifyGlobalReference a little while touching the flag handling relating to dllimport. Differential Revision: https://reviews.llvm.org/D51590 llvm-svn: 341402
2018-05-01Remove \brief commands from doxygen comments.Adrian Prantl1-1/+1
We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46290 llvm-svn: 331272
2018-03-26Remove unneeded (& mislayered) include from TargetMachine.cpp on a CodeGen ↵David Blaikie1-1/+0
header llvm-svn: 328548
2018-03-23Move TargetLoweringObjectFile from CodeGen to Target to fix layeringDavid Blaikie1-1/+1
It's implemented in Target & include from other Target headers, so the header should be in Target. llvm-svn: 328392
2018-03-10Go back to sometimes assuming intristics are local.Rafael Espindola1-20/+25
This fixes pr36674. While it is valid for shouldAssumeDSOLocal to return false anytime, always returning false for intrinsics is not optimal on i386 and also hits a bug in the backend. To use a plt, the caller must first setup ebx to handle the case of that file being linked into a PIE executable or shared library. In those cases the generated PLT uses ebx. Currently we can produce "calll expf@plt" without setting ebx. We could fix that by correctly setting ebx, but this would produce worse code for the case where the runtime library is statically linked. It would also required other tools to handle R_386_PLT32. llvm-svn: 327198
2018-02-28[TLS] use emulated TLS if the target supports only this modeChih-Hung Hsieh1-0/+8
Emulated TLS is enabled by llc flag -emulated-tls, which is passed by clang driver. When llc is called explicitly or from other drivers like LTO, missing -emulated-tls flag would generate wrong TLS code for targets that supports only this mode. Now use useEmulatedTLS() instead of Options.EmulatedTLS to decide whether emulated TLS code should be generated. Unit tests are modified to run with and without the -emulated-tls flag. Differential Revision: https://reviews.llvm.org/D42999 llvm-svn: 326341
2018-02-22Fix grammar. NFC.Rafael Espindola1-1/+1
Thank to Eric Christopher for noticing. llvm-svn: 325842
2018-02-19Bring back r323297.Rafael Espindola1-7/+14
It was reverted because it broke the grub build. The reason the grub build broke is because grub does its own relocation processing and was not handing R_386_PLT32. Since grub has no dynamic linker, the fix is trivial: handle R_386_PLT32 exactly like R_386_PC32. On the report it was noted that they are using -fno-integrated-assembler. The upstream GAS (starting with 451875b4f976a527395e9303224c7881b65e12ed) will already be producing a R_386_PLT32 anyway, so they have to update their code one way or the other Original message: Don't assume a null GV is local for ELF and MachO. This is already a simplification, and should help with avoiding a plt reference when calling an intrinsic with -fno-plt. With this change we return false for null GVs, so the caller only needs to check the new metadata to decide if it should use foo@plt or *foo@got. llvm-svn: 325514
2018-02-06Revert "Don't assume a null GV is local for ELF and MachO."Reid Kleckner1-14/+7
This reverts r323297. It breaks building grub. llvm-svn: 324301
2018-01-24Don't assume a null GV is local for ELF and MachO.Rafael Espindola1-7/+14
This is already a simplification, and should help with avoiding a plt reference when calling an intrinsic with -fno-plt. With this change we return false for null GVs, so the caller only needs to check the new metadata to decide if it should use foo@plt or *foo@got. llvm-svn: 323297
2018-01-17Use a got to access a hidden weak undefined on MachO.Rafael Espindola1-3/+1
Trying to link __attribute__((weak, visibility("hidden"))) extern int foo; int *main(void) { return &foo; } on OS X fails with ld: 32-bit RIP relative reference out of range (-4294971318 max is +/-2GB): from _main (0x100000FAB) to _foo@0x00001000 (0x00000000) in '_main' from test.o for architecture x86_64 The problem being that 0 cannot be computed as a fixed difference from %rip. Exactly the same issue exists on ELF and we can use the same solution. llvm-svn: 322739
2018-01-11Make internal/private GVs implicitly dso_local.Rafael Espindola1-1/+1
While updating clang tests for having clang set dso_local I noticed that: - There are *a lot* of tests to update. - Many of the updates are redundant. They are redundant because a GV is "obviously dso_local". This patch starts formalizing that a bit by requiring that internal and private GVs be dso_local too. Since they all are, we don't have to print dso_local to the textual representation, making it a bit more compact and easier to read. llvm-svn: 322317