aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Module.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-02-14[NFC][IR] Make Module::getNamedMDList() privateVasileios Porpodas1-2/+2
This patch adds several missing NamedMDList modifier functions, like removeNamedMDNode(), eraseNamedMDNode() and insertNamedMDNode(). There is no longer need to access the list directly so it also makes getNamedMDList() private. Differential Revision: https://reviews.llvm.org/D143969
2023-02-08[TLS]: Clamp the alignment of TLS global variables if required by the targetWolfgang Pieb1-0/+7
Adding a module flag 'MaxTLSAlign' describing the maximum alignment a global TLS variable can have. Optimizers are prevented from increasing the alignment of such variables beyond this threshold. Reviewed By: probinson Differential Revision: https://reviews.llvm.org/D140123
2022-12-05[IR] llvm::Optional => std::optionalFangrui Song1-1/+0
Many llvm/IR/* files have been migrated by other contributors. This migrates most remaining files.
2022-12-03Convert Optional<CodeModel> to std::optional<CodeModel>Krzysztof Parzyszek1-1/+1
2022-12-02[IR] Use std::nullopt instead of None (NFC)Kazu Hirata1-2/+2
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-25[IR] Use std::optional in Module.cpp (NFC)Kazu Hirata1-1/+2
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-08-18[IR] Use Min behavior for module flag "PIC Level"Fangrui Song1-1/+3
Using Max for both "PIC Level" and "PIE Level" is inconsistent. PIC imposes less restriction while PIE imposes more restriction. The result generally picks the more restrictive behavior: Min for PIC. This choice matches `ld -r`: a non-pic object and a pic object merge into a result which should be treated as non-pic. To allow linking "PIC Level" using Error/Max from old bitcode files, upgrade Error/Max to Min. Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D130531
2022-07-12[X86] Support -mstack-protector-guard-symbolXiang1 Zhang1-0/+12
Reviewed By: nickdesaulniers Differential Revision: https://reviews.llvm.org/D129346
2022-07-12Revert "[X86] Support -mstack-protector-guard-symbol"Xiang1 Zhang1-12/+0
This reverts commit efbaad1c4a526e91b034e56386e98a9268cd87b2. due to miss adding review info.
2022-07-12[X86] Support -mstack-protector-guard-symbolXiang1 Zhang1-0/+12
2022-03-28Apply clang-tidy fixes for readability-redundant-member-init in Module.cpp (NFC)Kazu Hirata1-2/+1
2022-02-14Extend the `uwtable` attribute with unwind table kindMomchil Velikov1-4/+7
We have the `clang -cc1` command-line option `-funwind-tables=1|2` and the codegen option `VALUE_CODEGENOPT(UnwindTables, 2, 0) ///< Unwind tables (1) or asynchronous unwind tables (2)`. However, this is encoded in LLVM IR by the presence or the absence of the `uwtable` attribute, i.e. we lose the information whether to generate want just some unwind tables or asynchronous unwind tables. Asynchronous unwind tables take more space in the runtime image, I'd estimate something like 80-90% more, as the difference is adding roughly the same number of CFI directives as for prologues, only a bit simpler (e.g. `.cfi_offset reg, off` vs. `.cfi_restore reg`). Or even more, if you consider tail duplication of epilogue blocks. Asynchronous unwind tables could also restrict code generation to having only a finite number of frame pointer adjustments (an example of *not* having a finite number of `SP` adjustments is on AArch64 when untagging the stack (MTE) in some cases the compiler can modify `SP` in a loop). Having the CFI precise up to an instruction generally also means one cannot bundle together CFI instructions once the prologue is done, they need to be interspersed with ordinary instructions, which means extra `DW_CFA_advance_loc` commands, further increasing the unwind tables size. That is to say, async unwind tables impose a non-negligible overhead, yet for the most common use cases (like C++ exceptions), they are not even needed. This patch extends the `uwtable` attribute with an optional value: - `uwtable` (default to `async`) - `uwtable(sync)`, synchronous unwind tables - `uwtable(async)`, asynchronous (instruction precise) unwind tables Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D114543
2022-02-02[clang][macho] add clang frontend support for emitting macho files with two ↵Alex Lorenz1-3/+16
build version load commands This patch extends clang frontend to add metadata that can be used to emit macho files with two build version load commands. It utilizes "darwin.target_variant.triple" and "darwin.target_variant.SDK Version" metadata names for that. MachO uses two build version load commands to represent an object file / binary that is targeting both the macOS target, and the Mac Catalyst target. At runtime, a dynamic library that supports both targets can be loaded from either a native macOS or a Mac Catalyst app on a macOS system. We want to add support to this to upstream to LLVM to be able to build compiler-rt for both targets, to finish the complete support for the Mac Catalyst platform, which is right now targetable by upstream clang, but the compiler-rt bits aren't supported because of the lack of this multiple build version support. Differential Revision: https://reviews.llvm.org/D115415
2022-02-02Cleanup header dependencies in LLVMCoreserge-sans-paille1-2/+0
Based on the output of include-what-you-use. This is a big chunk of changes. It is very likely to break downstream code unless they took a lot of care in avoiding hidden ehader dependencies, something the LLVM codebase doesn't do that well :-/ I've tried to summarize the biggest change below: - llvm/include/llvm-c/Core.h: no longer includes llvm-c/ErrorHandling.h - llvm/IR/DIBuilder.h no longer includes llvm/IR/DebugInfo.h - llvm/IR/IRBuilder.h no longer includes llvm/IR/IntrinsicInst.h - llvm/IR/LLVMRemarkStreamer.h no longer includes llvm/Support/ToolOutputFile.h - llvm/IR/LegacyPassManager.h no longer include llvm/Pass.h - llvm/IR/Type.h no longer includes llvm/ADT/SmallPtrSet.h - llvm/IR/PassManager.h no longer includes llvm/Pass.h nor llvm/Support/Debug.h And the usual count of preprocessed lines: $ clang++ -E -Iinclude -I../llvm/include ../llvm/lib/IR/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l before: 6400831 after: 6189948 200k lines less to process is no that bad ;-) Discourse thread on the topic: https://llvm.discourse.group/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D118652
2022-01-03Revert "[llvm] Remove redundant member initialization (NFC)"Kazu Hirata1-1/+2
This reverts commit fd4808887ee47f3ec8a030e9211169ef4fb094c3. This patch causes gcc to issue a lot of warnings like: warning: base class ‘class llvm::MCParsedAsmOperand’ should be explicitly initialized in the copy constructor [-Wextra]
2022-01-01[llvm] Remove redundant member initialization (NFC)Kazu Hirata1-2/+1
Identified with readability-redundant-member-init.
2021-12-07[macho] add support for emitting macho files with two build version load ↵Alex Lorenz1-2/+16
commands This patch extends LLVM IR to add metadata that can be used to emit macho files with two build version load commands. It utilizes "darwin.target_variant.triple" and "darwin.target_variant.SDK Version" metadata names for that, which will be set by a future patch in clang. MachO uses two build version load commands to represent an object file / binary that is targeting both the macOS target, and the Mac Catalyst target. At runtime, a dynamic library that supports both targets can be loaded from either a native macOS or a Mac Catalyst app on a macOS system. We want to add support to this to upstream to LLVM to be able to build compiler-rt for both targets, to finish the complete support for the Mac Catalyst platform, which is right now targetable by upstream clang, but the compiler-rt bits aren't supported because of the lack of this multiple build version support. Differential Revision: https://reviews.llvm.org/D112189
2021-07-28[PredicateInfo] Use Intrinsic::getDeclaration now that it handles unnamed types.Jeroen Dobbelaere1-0/+4
This is a second attempt to fix the EXPENSIVE_CHECKS issue that was mentioned In D91661#2875179 by @jroelofs. (The first attempt was in D105983) D91661 more or less completely reverted D49126 and by doing so also removed the cleanup logic of the created declarations and calls. This patch is a replacement for D91661 (which must itself be reverted first). It replaces the custom declaration creation with the generic version and shows the test impact. It also tracks the number of NamedValues to detect if a new prototype was added instead of looking at the available users of a prototype. Reviewed By: jroelofs Differential Revision: https://reviews.llvm.org/D106147
2021-07-09[NFC][OpaquePtr] Use GlobalValue::getValueType() moreArthur Eubanks1-1/+1
Instead of getType()->getElementType().
2021-06-21[IR] convert warn-stack-size from module flag to fn attrNick Desaulniers1-11/+0
Otherwise, this causes issues when building with LTO for object files that use different values. Link: https://github.com/ClangBuiltLinux/linux/issues/1395 Reviewed By: dblaikie, MaskRay Differential Revision: https://reviews.llvm.org/D104342
2021-06-10[IR] make -warn-frame-size into a module attrNick Desaulniers1-0/+11
-Wframe-larger-than= is an interesting warning; we can't know the frame size until PrologueEpilogueInsertion (PEI); very late in the compilation pipeline. -Wframe-larger-than= was propagated through CC1 as an -mllvm flag, then was a cl::opt in LLVM's PEI pass; this meant it was dropped during LTO and needed to be re-specified via -plugin-opt. Instead, make it part of the IR proper as a module level attribute, similar to D103048. Introduce -fwarn-stack-size CC1 option. Reviewed By: rsmith, qcolombet Differential Revision: https://reviews.llvm.org/D103928
2021-06-08reland [IR] make -stack-alignment= into a module attrNick Desaulniers1-0/+11
Relands commit 433c8d950cb3a1fa0977355ce0367e8c763a3f13 with fixes for MIPS. Similar to D102742, specifying the stack alignment via CodegenOpts means that this flag gets dropped during LTO, unless the command line is re-specified as a plugin opt. Instead, encode this information as a module level attribute so that we don't have to expose this llvm internal flag when linking the Linux kernel with LTO. Looks like external dependencies might need a fix: * https://github.com/llvm-hs/llvm-hs/issues/345 * https://github.com/halide/Halide/issues/6079 Link: https://github.com/ClangBuiltLinux/linux/issues/1377 Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D103048
2021-06-08Revert "[IR] make -stack-alignment= into a module attr"Nick Desaulniers1-11/+0
This reverts commit 433c8d950cb3a1fa0977355ce0367e8c763a3f13. Breaks the MIPS build.
2021-06-08[IR] make -stack-alignment= into a module attrNick Desaulniers1-0/+11
Similar to D102742, specifying the stack alignment via CodegenOpts means that this flag gets dropped during LTO, unless the command line is re-specified as a plugin opt. Instead, encode this information as a module level attribute so that we don't have to expose this llvm internal flag when linking the Linux kernel with LTO. Looks like external dependencies might need a fix: * https://github.com/llvm-hs/llvm-hs/issues/345 * https://github.com/halide/Halide/issues/6079 Link: https://github.com/ClangBuiltLinux/linux/issues/1377 Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D103048
2021-05-27Fix non-global-value-max-name-size not considered by LLParserHasyimi Bahrudin1-1/+1
`non-global-value-max-name-size` is used by `Value` to cap the length of local value name. However, this flag is not considered by `LLParser`, which leads to unexpected `use of undefined value error`. The fix is to move the responsibility of capping the length to `ValueSymbolTable`. The test is the one provided by [[ https://bugs.llvm.org/show_bug.cgi?id=45899 | Mikael in the bug report ]]. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D102707
2021-05-21[IR] make stack-protector-guard-* flags into module attrsNick Desaulniers1-0/+35
D88631 added initial support for: - -mstack-protector-guard= - -mstack-protector-guard-reg= - -mstack-protector-guard-offset= flags, and D100919 extended these to AArch64. Unfortunately, these flags aren't retained for LTO. Make them module attributes rather than TargetOptions. Link: https://github.com/ClangBuiltLinux/linux/issues/1378 Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D102742
2021-04-22[IR][sanitizer] Add module flag "frame-pointer" and set it for cc1 ↵Fangrui Song1-0/+10
-mframe-pointer={non-leaf,all} The Linux kernel objtool diagnostic `call without frame pointer save/setup` arise in multiple instrumentation passes (asan/tsan/gcov). With the mechanism introduced in D100251, it's trivial to respect the command line -m[no-]omit-leaf-frame-pointer/-f[no-]omit-frame-pointer, so let's do it. Fix: https://github.com/ClangBuiltLinux/linux/issues/1236 (tsan) Fix: https://github.com/ClangBuiltLinux/linux/issues/1238 (asan) Also document the function attribute "frame-pointer" which is long overdue. Differential Revision: https://reviews.llvm.org/D101016
2021-04-21[IR][sanitizer] Set nounwind on module ctor/dtor, additionally set uwtable ↵Fangrui Song1-0/+7
if -fasynchronous-unwind-tables On ELF targets, if a function has uwtable or personality, or does not have nounwind (`needsUnwindTableEntry`), it marks that `.eh_frame` is needed in the module. Then, a function gets `.eh_frame` if `needsUnwindTableEntry` or `-g[123]` is specified. (i.e. If -g[123], every function gets `.eh_frame`. This behavior is strange but that is the status quo on GCC and Clang.) Let's take asan as an example. Other sanitizers are similar. `asan.module_[cd]tor` has no attribute. `needsUnwindTableEntry` returns true, so every function gets `.eh_frame` if `-g[123]` is specified. This is the root cause that `-fno-exceptions -fno-asynchronous-unwind-tables -g` produces .debug_frame while `-fno-exceptions -fno-asynchronous-unwind-tables -g -fsanitize=address` produces .eh_frame. This patch * sets the nounwind attribute on sanitizer module ctor/dtor. * let Clang emit a module flag metadata "uwtable" for -fasynchronous-unwind-tables. If "uwtable" is set, sanitizer module ctor/dtor additionally get the uwtable attribute. The "uwtable" mechanism is generic: synthesized functions not cloned/specialized from existing ones should consider `Function::createWithDefaultAttr` instead of `Function::create` if they want to get some default attributes which have more of module semantics. Other candidates: "frame-pointer" (https://github.com/ClangBuiltLinux/linux/issues/955 https://github.com/ClangBuiltLinux/linux/issues/1238), dso_local, etc. Differential Revision: https://reviews.llvm.org/D100251
2021-03-25[NFC] Module::getInstructionCount() is constMircea Trofin1-2/+2
2021-03-19Support intrinsic overloading on unnamed typesJeroen Dobbelaere1-0/+50
This patch adds support for intrinsic overloading on unnamed types. This fixes PR38117 and PR48340 and will also be needed for the Full Restrict Patches (D68484). The main problem is that the intrinsic overloading name mangling is using 's_s' for unnamed types. This can result in identical intrinsic mangled names for different function prototypes. This patch changes this by adding a '.XXXXX' to the intrinsic mangled name when at least one of the types is based on an unnamed type, ensuring that we get a unique name. Implementation details: - The mapping is created on demand and kept in Module. - It also checks for existing clashes and recycles potentially existing prototypes and declarations. - Because of extra data in Module, Intrinsic::getName needs an extra Module* argument and, for speed, an optional FunctionType* argument. - I still kept the original two-argument 'Intrinsic::getName' around which keeps the original behavior (providing the base name). -- Main reason is that I did not want to change the LLVMIntrinsicGetName version, as I don't know how acceptable such a change is -- The current situation already has a limitation. So that should not get worse with this patch. - Intrinsic::getDeclaration and the verifier are now using the new version. Other notes: - As far as I see, this should not suffer from stability issues. The count is only added for prototypes depending on at least one anonymous struct - The initial count starts from 0 for each intrinsic mangled name. - In case of name clashes, existing prototypes are remembered and reused when that makes sense. Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D91250
2021-02-23collectUsedGlobalVariables: migrate SmallPtrSetImpl overload to SmallVecImpl ↵Fangrui Song1-15/+0
overload after D97128 And delete the SmallPtrSetImpl overload. While here, decrease inline element counts from 8 to 4. See D97128 for the choice. Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D97257
2021-02-23[ThinLTO] Make cloneUsedGlobalVariables deterministicFangrui Song1-0/+15
Iterating on `SmallPtrSet<GlobalValue *, 8>` with more than 8 elements is not deterministic. Use a SmallVector instead because `Used` is guaranteed to contain unique elements. While here, decrease inline element counts from 8 to 4. The number of `llvm.used`/`llvm.compiler.used` elements is usually 0 or 1. For full LTO/hybrid LTO, the number may be large, so we need to be careful. According to tejohnson's analysis https://reviews.llvm.org/D97128#2582399 , 4 is good for a large project with WholeProgramDevirt, when available_externally vtables are placed in the llvm.compiler.used set. Differential Revision: https://reviews.llvm.org/D97128
2021-02-17[DebugInfo] Keep the DWARF64 flag in the module metadataIgor Kudrin1-0/+5
This allows the option to affect the LTO output. Module::Max helps to generate debug info for all modules in the same format. Differential Revision: https://reviews.llvm.org/D96597
2020-12-31Refactor how -fno-semantic-interposition sets dso_local on default ↵Fangrui Song1-7/+0
visibility external linkage definitions The idea is that the CC1 default for ELF should set dso_local on default visibility external linkage definitions in the default -mrelocation-model pic mode (-fpic/-fPIC) to match COFF/Mach-O and make output IR similar. The refactoring is made available by 2820a2ca3a0e69c3f301845420e0067ffff2251b. Currently only x86 supports local aliases. We move the decision to the driver. There are three CC1 states: * -fsemantic-interposition: make some linkages interposable and make default visibility external linkage definitions dso_preemptable. * (default): selected if the target supports .Lfoo$local: make default visibility external linkage definitions dso_local * -fhalf-no-semantic-interposition: if neither option is set or the target does not support .Lfoo$local: like -fno-semantic-interposition but local aliases are not used. So references can be interposed if not optimized out. Add -fhalf-no-semantic-interposition to a few tests using the half-based semantic interposition behavior.
2020-11-30[Remarks][2/2] Expand remarks hotness threshold option support in more toolsWei Wang1-1/+1
This is the #2 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 expands remarks hotness threshold option -fdiagnostics-hotness-threshold in clang and *-remarks-hotness-threshold in other tools to utilize hotness threshold from profile summary. Remarks hotness filtering relies on several driver options. Table below lists how different options are correlated and affect final remarks outputs: | profile | hotness | threshold | remarks printed | |---------|---------|-----------|-----------------| | No | No | No | All | | No | No | Yes | None | | No | Yes | No | All | | No | Yes | Yes | None | | Yes | No | No | All | | Yes | No | Yes | None | | Yes | Yes | No | All | | Yes | Yes | Yes | >=threshold | In the presence of profile summary, it is often more desirable to directly use the hotness threshold from profile summary. The new argument value 'auto' indicates threshold will be synced with hotness threshold from profile summary during compilation. The "auto" threshold relies on the availability of profile summary. In case of missing such information, no remarks will be generated. Differential Revision: https://reviews.llvm.org/D85808
2020-06-01[PGO] Improve the working set size heuristics under the partial sample PGO.Hiroshi Yamauchi1-0/+21
Summary: The working set size heuristics (ProfileSummaryInfo::hasHugeWorkingSetSize) under the partial sample PGO may not be accurate because the profile is partial and the number of hot profile counters in the ProfileSummary may not reflect the actual working set size of the program being compiled. To improve this, the (approximated) ratio of the the number of profile counters of the program being compiled to the number of profile counters in the partial sample profile is computed (which is called the partial profile ratio) and the working set size of the profile is scaled by this ratio to reflect the working set size of the program being compiled and used for the working set size heuristics. The partial profile ratio is approximated based on the number of the basic blocks in the program and the NumCounts field in the ProfileSummary and computed through the thin LTO indexing. This means that there is the limitation that the scaled working set size is available to the thin LTO post link passes only. Reviewers: davidxl Subscribers: mgorny, eraman, hiraditya, steven_wu, dexonsmith, arphaman, dang, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D79831
2020-05-25Make explicit -fno-semantic-interposition (in -fpic mode) infer dso_localFangrui Song1-0/+7
-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-05-21[IR] Make Module::setProfileSummary to replace an existing ProfileSummary flag.Hiroshi Yamauchi1-7/+36
Summary: Module::setProfileSummary currently calls addModuelFlag. This prevents from updating the ProfileSummary metadata in the module and results in a second ProfileSummary added instead of replacing an existing one. I don't think this is the expected behavior. It prevents updating the ProfileSummary and it does not make sense to have more than one. To address this, add Module::setModuleFlag and use it from setProfileSummary. Reviewers: davidxl Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D79902
2020-01-31RNG: Take pass name as argument instead of pass pointer.Dominic Chen1-3/+5
Summary: With the new pass manager, it is not possible to obtain a pointer to the pass. Reviewers: jfb, rinon, yln Subscribers: hiraditya, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D73390
2020-01-31Implement -fsemantic-interpositionserge-sans-paille1-0/+14
First attempt at implementing -fsemantic-interposition. Rely on GlobalValue::isInterposable that already captures most of the expected behavior. Rely on a ModuleFlag to state whether we should respect SemanticInterposition or not. The default remains no. So this should be a no-op if -fsemantic-interposition isn't used, and if it is, isInterposable being already used in most optimisation, they should honor it properly. Note that it only impacts architecture compiled with -fPIC and no pie. Differential Revision: https://reviews.llvm.org/D72829
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-1/+2
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-17[IR] Remove some unnecessary cleanup in Module's dtor, and use a unique_ptr ↵David Blaikie1-5/+2
to simplify some Follow on from D72812, based on Mehdi Amini's feedback.
2020-01-15[IR] Module's NamedMD table needn't be 'void *'Brian Gesiak1-6/+4
Summary: In July 21 2010 `llvm::NamedMDNode` was refactored such that it would no longer subclass `llvm::Value`: https://github.com/llvm/llvm-project/commit/2637cc1a38d7336ea30caf As part of this change, a map type from metadata names to their named metadata, `llvm::MDSymbolTable`, was deleted. In its place, the type of member `llvm::Module::NamedMDSymTab` was changed, from `llvm::MDSymbolTable` to `void *`. The underlying memory allocations for this pointer were changed to `new StringMap<NamedMDNode *>()`. However, as far as I can tell, there's no need for obscuring the underlying type being pointed to by the `void *`, and no need for static casts from `void *` to `StringMap`. In fact, I don't think there's a need for explicit calls to `new` and `delete` at all. This commit changes `NamedMDSymTab` from a pointer to a reference, which automatically couples its lifetime with the lifetime of its owning `llvm::Module` instance, thus removing the explicit calls to `new` and `delete` in the `llvm::Module` constructor and destructor. It also changes the type from `void *` to a newly defined `NamedMDSymTabType`, and removes the static casts. Test Plan: An ASAN-enabled build and run of `check-all` succeeds with this change (aside from some tests that always fail for me in ASAN for some reason, such as `check-clang` `SemaTemplate/stack-exhaustion.cpp`). Reviewers: aprantl, dblaikie, chandlerc, pcc, echristo Reviewed By: dblaikie Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D72812
2019-11-22[IR] Move global_objects and global_values out of line, NFCReid Kleckner1-0/+16
This saves 2.4% of CPU time compiling opt, according to ClangBuildAnalyzer. These helpers being inlined in the header was triggering the instantiation of concat_iterator in every TU using Module.h (~1118 TUs): https://reviews.llvm.org/P8171$35 **** Templates that took longest to instantiate: 76187 ms: llvm::AnalysisManager<llvm::Function>::getResult<llvm::TargetLibrary... (396 times, avg 192 ms) 73609 ms: llvm::AnalysisManager<llvm::Function>::getResultImpl (420 times, avg 175 ms) 49657 ms: llvm::detail::concat_range<llvm::GlobalValue, llvm::iterator_range<l... (1118 times, avg 44 ms) 49376 ms: llvm::detail::concat_range<const llvm::GlobalValue, llvm::iterator_r... (1118 times, avg 44 ms) 48167 ms: llvm::iterator_range<llvm::concat_iterator<llvm::GlobalValue, llvm::... (1118 times, avg 43 ms) 48125 ms: llvm::iterator_range<llvm::concat_iterator<const llvm::GlobalValue, ... (1118 times, avg 43 ms) 48061 ms: llvm::concat_iterator<llvm::GlobalValue, llvm::ilist_iterator<llvm::... (1118 times, avg 42 ms) 48014 ms: llvm::concat_iterator<const llvm::GlobalValue, llvm::ilist_iterator<... (1118 times, avg 42 ms) ... I haven't measured, but I don't think these helpers are performance critical. The iterator advance call can still be inlined, which is what matters for performance. Remove global_(objects|values)_(begin|end), since they were dead and would have to be out of line anyway.
2019-08-22IR. Change strip* family of functions to not look through aliases.Peter Collingbourne1-1/+1
I noticed another instance of the issue where references to aliases were being replaced with aliasees, this time in InstCombine. In the instance that I saw it turned out to be only a QoI issue (a symbol ended up being missing from the symbol table due to the last reference to the alias being removed, preventing HWASAN from symbolizing a global reference), but it could easily have manifested as incorrect behaviour. Since this is the third such issue encountered (previously: D65118, D65314) it seems to be time to address this common error/QoI issue once and for all and make the strip* family of functions not look through aliases. Includes a test for the specific issue that I saw, but no doubt there are other similar bugs fixed here. As with D65118 this has been tested to make sure that the optimization isn't load bearing. I built Clang, Chromium for Linux, Android and Windows as well as the test-suite and there were no size regressions. Differential Revision: https://reviews.llvm.org/D66606 llvm-svn: 369697
2019-02-28[PGO] Context sensitive PGO (part 2)Rong Xu1-4/+8
Part 2 of CSPGO changes (mostly related to ProfileSummary). Note that I use a default parameter in setProfileSummary() and getSummary(). This is to break the dependency in clang. I will make the parameter explicit after changing clang in a separated patch. Differential Revision: https://reviews.llvm.org/D54175 llvm-svn: 355131
2019-02-01[opaque pointer types] Add a FunctionCallee wrapper type, and use it.James Y Knight1-7/+6
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc doesn't choke on it, hopefully. Original Message: The FunctionCallee type is effectively a {FunctionType*,Value*} pair, and is a useful convenience to enable code to continue passing the result of getOrInsertFunction() through to EmitCall, even once pointer types lose their pointee-type. Then: - update the CallInst/InvokeInst instruction creation functions to take a Callee, - modify getOrInsertFunction to return FunctionCallee, and - update all callers appropriately. One area of particular note is the change to the sanitizer code. Previously, they had been casting the result of `getOrInsertFunction` to a `Function*` via `checkSanitizerInterfaceFunction`, and storing that. That would report an error if someone had already inserted a function declaraction with a mismatching signature. However, in general, LLVM allows for such mismatches, as `getOrInsertFunction` will automatically insert a bitcast if needed. As part of this cleanup, cause the sanitizer code to do the same. (It will call its functions using the expected signature, however they may have been declared.) Finally, in a small number of locations, callers of `getOrInsertFunction` actually were expecting/requiring that a brand new function was being created. In such cases, I've switched them to Function::Create instead. Differential Revision: https://reviews.llvm.org/D57315 llvm-svn: 352827
2019-01-31Revert "[opaque pointer types] Add a FunctionCallee wrapper type, and use it."James Y Knight1-6/+7
This reverts commit f47d6b38c7a61d50db4566b02719de05492dcef1 (r352791). Seems to run into compilation failures with GCC (but not clang, where I tested it). Reverting while I investigate. llvm-svn: 352800
2019-01-31[opaque pointer types] Add a FunctionCallee wrapper type, and use it.James Y Knight1-7/+6
The FunctionCallee type is effectively a {FunctionType*,Value*} pair, and is a useful convenience to enable code to continue passing the result of getOrInsertFunction() through to EmitCall, even once pointer types lose their pointee-type. Then: - update the CallInst/InvokeInst instruction creation functions to take a Callee, - modify getOrInsertFunction to return FunctionCallee, and - update all callers appropriately. One area of particular note is the change to the sanitizer code. Previously, they had been casting the result of `getOrInsertFunction` to a `Function*` via `checkSanitizerInterfaceFunction`, and storing that. That would report an error if someone had already inserted a function declaraction with a mismatching signature. However, in general, LLVM allows for such mismatches, as `getOrInsertFunction` will automatically insert a bitcast if needed. As part of this cleanup, cause the sanitizer code to do the same. (It will call its functions using the expected signature, however they may have been declared.) Finally, in a small number of locations, callers of `getOrInsertFunction` actually were expecting/requiring that a brand new function was being created. In such cases, I've switched them to Function::Create instead. Differential Revision: https://reviews.llvm.org/D57315 llvm-svn: 352791
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