aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Attributes.cpp
AgeCommit message (Collapse)AuthorFilesLines
2020-07-16Use findEnumAttribute helper for preallocatedMatt Arsenault1-5/+4
2020-07-08[LLVM] Accept `noundef` attribute in function definitions/callsGui Andrade1-0/+2
The `noundef` attribute indicates an argument or return value which may never have an undef value representation. This patch allows LLVM to parse the attribute. Differential Revision: https://reviews.llvm.org/D83412
2020-07-03[IR] Short-circuit comparison with itself for AttributesDanila Malyutin1-0/+2
Differential Revision: https://reviews.llvm.org/D82295
2020-07-01AttrBuilder::merge/remove - use const& for iterator values in for-range loops.Simon Pilgrim1-2/+2
Noticed by clang-tidy performance-for-range-copy warning.
2020-06-27[IR] Store attributes that are available "somewhere" (NFC)Nikita Popov1-14/+27
I noticed that for some benchmarks we spend quite a bit of time inside AttributeList::hasAttrSomewhere(), mainly when checking for the "returned" attribute. Most of the time the attribute will not be present, in which case this function has to walk through the whole attribute list and check for the attribute at each index. This patch adds a cache of all "available somewhere" attributes inside AttributeListImpl. This makes the structure 12 bytes larger, but I don't think that's problematic, as attribute lists are uniqued. Compile-time in terms of instructions retired improves by 0.4% on average, but >1% for sqlite. Differential Revision: https://reviews.llvm.org/D81867
2020-06-25Attributes.cpp - fix include sorting order. NFC.Simon Pilgrim1-1/+1
2020-06-23[IR] Remove MSVC warning workaround (NFC)Nikita Popov1-4/+2
While LLVM does fold this to x+1, GCC does not. As this is hot code, let's try to avoid that. According to https://developercommunity.visualstudio.com/content/problem/211134/unsigned-integer-overflows-in-constexpr-functionsa.html this spurious warning in MSVC has been fixed in Visual Studio 2019 Version 16.4. Let's see if there are any build bots running old MSVC versions with warnings treated as errors...
2020-06-15[IR] Add AttributeBitSet wrapper (NFC)Nikita Popov1-16/+5
This wraps the uint8_t[12] type used in two places, because I plan to introduce a third use of the same pattern.
2020-05-27Enable `align <n>` to be used in the intrinsic definition.Michael Liao1-0/+11
- This allow us to specify the (minimal) alignment on an intrinsic's arguments and, more importantly, the return value. Differential Revision: https://reviews.llvm.org/D80422
2020-05-20Reland [X86] Codegen for preallocatedArthur Eubanks1-0/+4
See https://reviews.llvm.org/D74651 for the preallocated IR constructs and LangRef changes. In X86TargetLowering::LowerCall(), if a call is preallocated, record each argument's offset from the stack pointer and the total stack adjustment. Associate the call Value with an integer index. Store the info in X86MachineFunctionInfo with the integer index as the key. This adds two new target independent ISDOpcodes and two new target dependent Opcodes corresponding to @llvm.call.preallocated.{setup,arg}. The setup ISelDAG node takes in a chain and outputs a chain and a SrcValue of the preallocated call Value. It is lowered to a target dependent node with the SrcValue replaced with the integer index key by looking in X86MachineFunctionInfo. In X86TargetLowering::EmitInstrWithCustomInserter() this is lowered to an %esp adjustment, the exact amount determined by looking in X86MachineFunctionInfo with the integer index key. The arg ISelDAG node takes in a chain, a SrcValue of the preallocated call Value, and the arg index int constant. It produces a chain and the pointer fo the arg. It is lowered to a target dependent node with the SrcValue replaced with the integer index key by looking in X86MachineFunctionInfo. In X86TargetLowering::EmitInstrWithCustomInserter() this is lowered to a lea of the stack pointer plus an offset determined by looking in X86MachineFunctionInfo with the integer index key. Force any function containing a preallocated call to use the frame pointer. Does not yet handle a setup without a call, or a conditional call. Does not yet handle musttail. That requires a LangRef change first. Tried to look at all references to inalloca and see if they apply to preallocated. I've made preallocated versions of tests testing inalloca whenever possible and when they make sense (e.g. not alloca related, inalloca edge cases). Aside from the tests added here, I checked that this codegen produces correct code for something like ``` struct A { A(); A(A&&); ~A(); }; void bar() { foo(foo(foo(foo(foo(A(), 4), 5), 6), 7), 8); } ``` by replacing the inalloca version of the .ll file with the appropriate preallocated code. Running the executable produces the same results as using the current inalloca implementation. Reverted due to unexpectedly passing tests, added REQUIRES: asserts for reland. Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77689
2020-05-20Revert "[X86] Codegen for preallocated"Arthur Eubanks1-4/+0
This reverts commit 810567dc691a57c8c13fef06368d7549f7d9c064. Some tests are unexpectedly passing
2020-05-20[X86] Codegen for preallocatedArthur Eubanks1-0/+4
See https://reviews.llvm.org/D74651 for the preallocated IR constructs and LangRef changes. In X86TargetLowering::LowerCall(), if a call is preallocated, record each argument's offset from the stack pointer and the total stack adjustment. Associate the call Value with an integer index. Store the info in X86MachineFunctionInfo with the integer index as the key. This adds two new target independent ISDOpcodes and two new target dependent Opcodes corresponding to @llvm.call.preallocated.{setup,arg}. The setup ISelDAG node takes in a chain and outputs a chain and a SrcValue of the preallocated call Value. It is lowered to a target dependent node with the SrcValue replaced with the integer index key by looking in X86MachineFunctionInfo. In X86TargetLowering::EmitInstrWithCustomInserter() this is lowered to an %esp adjustment, the exact amount determined by looking in X86MachineFunctionInfo with the integer index key. The arg ISelDAG node takes in a chain, a SrcValue of the preallocated call Value, and the arg index int constant. It produces a chain and the pointer fo the arg. It is lowered to a target dependent node with the SrcValue replaced with the integer index key by looking in X86MachineFunctionInfo. In X86TargetLowering::EmitInstrWithCustomInserter() this is lowered to a lea of the stack pointer plus an offset determined by looking in X86MachineFunctionInfo with the integer index key. Force any function containing a preallocated call to use the frame pointer. Does not yet handle a setup without a call, or a conditional call. Does not yet handle musttail. That requires a LangRef change first. Tried to look at all references to inalloca and see if they apply to preallocated. I've made preallocated versions of tests testing inalloca whenever possible and when they make sense (e.g. not alloca related, inalloca edge cases). Aside from the tests added here, I checked that this codegen produces correct code for something like ``` struct A { A(); A(A&&); ~A(); }; void bar() { foo(foo(foo(foo(foo(A(), 4), 5), 6), 7), 8); } ``` by replacing the inalloca version of the .ll file with the appropriate preallocated code. Running the executable produces the same results as using the current inalloca implementation. Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77689
2020-05-15[IR] Convert null-pointer-is-valid into an enum attributeNikita Popov1-2/+4
The "null-pointer-is-valid" attribute needs to be checked by many pointer-related combines. To make the check more efficient, convert it from a string into an enum attribute. In the future, this attribute may be replaced with data layout properties. Differential Revision: https://reviews.llvm.org/D78862
2020-05-12Add nomerge function attribute to supress tail merge optimization in simplifyCFGZequan Wu1-0/+2
We want to add a way to avoid merging identical calls so as to keep the separate debug-information for those calls. There is also an asan usecase where having this attribute would be beneficial to avoid alternative work-arounds. Here is the link to the feature request: https://bugs.llvm.org/show_bug.cgi?id=42783. `nomerge` is different from `noline`. `noinline` prevents function from inlining at callsites, but `nomerge` prevents multiple identical calls from being merged into one. This patch adds `nomerge` to disable the optimization in IR level. A followup patch will be needed to let backend understands `nomerge` and avoid tail merge at backend. Reviewed By: asbirlea, rnk Differential Revision: https://reviews.llvm.org/D78659
2020-05-01[IR] AttributeList::getContext has a single user, remove it.Benjamin Kramer1-6/+3
2020-05-01[IR] Make Attributes and AttributeLists trivially destructible and ↵Benjamin Kramer1-17/+10
BumpPtrAllocate them
2020-04-27Add IR constructs for preallocated (inalloca replacement)Arthur Eubanks1-12/+60
Add llvm.call.preallocated.{setup,arg} instrinsics. Add "preallocated" operand bundle which takes a token produced by llvm.call.preallocated.setup. Add "preallocated" parameter attribute, which is like byval but without the copy. Verifier changes for these IR constructs. See https://github.com/rnk/llvm-project/blob/call-setup-docs/llvm/docs/CallSetup.md Subscribers: hiraditya, jdoerfert, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D74651
2020-04-26[IR] Since AttributeSets are sorted, binary search them.Benjamin Kramer1-23/+31
Not likely to make a big difference, but there's a fair bit of pointer chasing in large sets.
2020-04-26Sort EnumAttr so it matches Attribute::operator<Benjamin Kramer1-6/+11
This means AttrBuilder will always create a sorted set of attributes and we can skip the sorting step. Sorting attributes is surprisingly expensive, and I recently made it worse by making it use array_pod_sort.
2020-04-26[IR] Simplify code to print string attributes a bit. NFC.Benjamin Kramer1-11/+11
2020-04-26[IR] Use map for string attributes (NFC)Nikita Popov1-9/+5
Attributes are currently stored as a simple list. Enum attributes additionally use a bitset to allow quickly determining whether an attribute is set. String attributes on the other hand require a full scan of the list. As functions tend to have a lot of string attributes (at least when clang is used), this is a noticeable performance issue. This patch adds an additional name => attribute map to the AttributeSetNode, which allows querying string attributes quickly. This results in a 3% reduction in instructions retired on CTMark. Changes to memory usage seem to be in the noise (attribute sets are uniqued, and we don't tend to have more than a few dozen or hundred unique attribute sets, so adding an extra map does not have a noticeable cost.) Differential Revision: https://reviews.llvm.org/D78859
2020-04-14[ADT/STLExtras.h] - Add llvm::is_sorted wrapper and update callers.Georgii Rymar1-11/+12
It can be used to avoid passing the begin and end of a range. This makes the code shorter and it is consistent with another wrappers we already have. Differential revision: https://reviews.llvm.org/D78016
2020-03-11[AssumeBundles] Enforce constraints on the operand bundle of llvm.assumeTyker1-0/+8
Summary: Add verification that operand bundles on an llvm.assume are well formed to the verify pass. Reviewers: jdoerfert Reviewed By: jdoerfert Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75269
2020-02-29Avoid including FileSystem.h from MemoryBuffer.hReid Kleckner1-0/+1
Lots of headers pass around MemoryBuffer objects, but very few open them. Let those that do include FileSystem.h. Saves ~250 includes of Chrono.h & FileSystem.h: $ diff -u thedeps-before.txt thedeps-after.txt | grep '^[-+] ' | sort | uniq -c | sort -nr 254 - ../llvm/include/llvm/Support/FileSystem.h 253 - ../llvm/include/llvm/Support/Chrono.h 237 - ../llvm/include/llvm/Support/NativeFormatting.h 237 - ../llvm/include/llvm/Support/FormatProviders.h 192 - ../llvm/include/llvm/ADT/StringSwitch.h 190 - ../llvm/include/llvm/Support/FormatVariadicDetails.h ... This requires duplicating the file_t typedef, which is unfortunate. I sunk the choice of mapping mode down into the cpp file using variable template specializations instead of class members in headers.
2020-02-03[NFC] Factor out function to detect if an attribute has an argument.Tyker1-2/+9
2020-02-02Build assume from callTyker1-0/+23
Fix attempt this is part of the implementation of http://lists.llvm.org/pipermail/llvm-dev/2019-December/137632.html this patch gives the basis of building an assume to preserve all information from an instruction and add support for building an assume that preserve the information from a call.
2020-02-02Revert "[WIP] Build assume from call"Tyker1-23/+0
casued buildbot failure This reverts commit 8ebe001553d0c204cc41f3dbc595031828b1f140.
2020-02-02[WIP] Build assume from callTyker1-0/+23
Summary: this is part of the implementation of http://lists.llvm.org/pipermail/llvm-dev/2019-December/137632.html this patch gives the basis of building an assume to preserve all information from an instruction and add support for building an assume that preserve the information from a call. Reviewers: jdoerfert Reviewed By: jdoerfert Subscribers: mgrang, fhahn, mgorny, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D72475
2020-02-02Revert "[WIP] Build assume from call"Tyker1-23/+0
caused build bot failure This reverts commit 780d2c532fe5ca4a368c5e631197a839e03a3cc4.
2020-02-02[WIP] Build assume from callTyker1-0/+23
Summary: this is part of the implementation of http://lists.llvm.org/pipermail/llvm-dev/2019-December/137632.html this patch gives the basis of building an assume to preserve all information from an instruction and add support for building an assume that preserve the information from a call. Reviewers: jdoerfert Reviewed By: jdoerfert Subscribers: mgrang, fhahn, mgorny, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D72475
2020-02-02Revert "[WIP] Build assume from call"Tyker1-23/+0
This reverts commit 355e4bfd7890e50b492b2dc29f70fc41ad8f867f.
2020-02-02[WIP] Build assume from callTyker1-0/+23
Summary: this is part of the implementation of http://lists.llvm.org/pipermail/llvm-dev/2019-December/137632.html this patch gives the basis of building an assume to preserve all information from an instruction and add support for building an assume that preserve the information from a call. Reviewers: jdoerfert Reviewed By: jdoerfert Subscribers: mgrang, fhahn, mgorny, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D72475
2020-02-02[NFC] Refactor TableGen for attributesTyker1-1/+42
Summary: this patch makes tablegen generate llvm attributes in a more generic and simpler (at least to me). changes: make tablegen generate ... ATTRIBUTE_ENUM(Alignment,align) ATTRIBUTE_ENUM(AllocSize,allocsize) ... which can be used to generate most of what was previously used and more. Tablegen was also generating attributes from 2 identical files leading to identical output. so I removed one of them and made user use the other. Reviewers: jdoerfert, thakis, aaron.ballman Reviewed By: aaron.ballman Subscribers: mgorny, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D72455
2020-02-02Revert "[NFC] Refactor TableGen for attributes"Tyker1-42/+1
This reverts commit 4dba14cf37abda16ab33cb748a5c762dae2e95e9.
2020-02-02Revert "[WIP] Build assume from call"Tyker1-23/+0
This reverts commit 2ff5602cb52969d3273062f36340fe95ac4e82da.
2020-02-02Revert "[NFC] Factor out function to detect if an attribute has an argument."Tyker1-9/+2
This reverts commit ff1b9add2ffd47abc649895e33b3e5c30d6f2079.
2020-02-02[NFC] Factor out function to detect if an attribute has an argument.Tyker1-2/+9
Reviewers: jdoerfert Reviewed By: jdoerfert Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D72884
2020-02-02[WIP] Build assume from callTyker1-0/+23
Summary: this is part of the implementation of http://lists.llvm.org/pipermail/llvm-dev/2019-December/137632.html this patch gives the basis of building an assume to preserve all information from an instruction and add support for building an assume that preserve the information from a call. Reviewers: jdoerfert Reviewed By: jdoerfert Subscribers: mgrang, fhahn, mgorny, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D72475
2020-02-02[NFC] Refactor TableGen for attributesTyker1-1/+42
Summary: this patch makes tablegen generate llvm attributes in a more generic and simpler (at least to me). changes: make tablegen generate ... ATTRIBUTE_ENUM(Alignment,align) ATTRIBUTE_ENUM(AllocSize,allocsize) ... which can be used to generate most of what was previously used and more. Tablegen was also generating attributes from 2 identical files leading to identical output. so I removed one of them and made user use the other. Reviewers: jdoerfert, thakis, aaron.ballman Reviewed By: aaron.ballman Subscribers: mgorny, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D72455
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-2/+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-23[IR] Attribute/AttrBuilder: use Value::MaximumAlignment magic constantRoman Lebedev1-2/+2
Summary: I initially encountered those assertions when trying to create this IR `alignment` attribute from clang's `__attribute__((assume_aligned(imm)))`, because until D72994 there is no sanity checking for the value of `imm`. But even then, we have `llvm::Value::MaximumAlignment` constant (which is `536870912`), which is enforced for clang attributes, and then there are some other magical constant (`0x40000000` i.e. `1073741824` i.e. `2 * 536870912`) in `Attribute::getWithAlignment()`/`AttrBuilder::addAlignmentAttr()`. I strongly suspect that `0x40000000` is incorrect, and that also should be `llvm::Value::MaximumAlignment`. Reviewers: erichkeane, hfinkel, jdoerfert, gchatelet, courbet Reviewed By: erichkeane Subscribers: hiraditya, cfe-commits, llvm-commits Tags: #llvm, #clang Differential Revision: https://reviews.llvm.org/D72998
2020-01-17Remove unneeded FoldingSet.h include from Attributes.hReid Kleckner1-0/+4
Avoids 637 extra FoldingSet.h and Allocator.h includes. FoldingSet.h needs Allocator.h, which is relatively expensive.
2019-12-17[IR] Use a reference in a range-based forMark de Wever1-18/+18
This avoids unneeded copies when using a range-based for loops. This avoids new warnings due to D68912 adds -Wrange-loop-analysis to -Wall. Differential Revision: https://reviews.llvm.org/D70870
2019-10-22[Alignment][NFC] Use MaybeAlign in AttrBuilderGuillaume Chatelet1-5/+7
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69300 llvm-svn: 375496
2019-10-22[Alignment][NFC] Attributes use Align/MaybeAlignGuillaume Chatelet1-21/+18
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Subscribers: jholewinski, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69278 llvm-svn: 375495
2019-10-15[Alignment] Migrate Attribute::getWith(Stack)AlignmentGuillaume Chatelet1-11/+8
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet, jdoerfert Reviewed By: courbet Subscribers: arsenm, jvesely, nhaehnle, hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D68792 llvm-svn: 374884
2019-08-06[LLVM][Alignment] Introduce Alignment In AttributesGuillaume Chatelet1-15/+19
Summary: This is patch is part of a serie to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: jfb Subscribers: hiraditya, dexonsmith, llvm-commits, courbet Tags: #llvm Differential Revision: https://reviews.llvm.org/D65742 llvm-svn: 368002
2019-07-15ARM MTE stack sanitizer.Evgeniy Stepanov1-0/+2
Add "memtag" sanitizer that detects and mitigates stack memory issues using armv8.5 Memory Tagging Extension. It is similar in principle to HWASan, which is a software implementation of the same idea, but there are enough differencies to warrant a new sanitizer type IMHO. It is also expected to have very different performance properties. The new sanitizer does not have a runtime library (it may grow one later, along with a "debugging" mode). Similar to SafeStack and StackProtector, the instrumentation pass (in a follow up change) will be inserted in all cases, but will only affect functions marked with the new sanitize_memtag attribute. Reviewers: pcc, hctim, vitalybuka, ostannard Subscribers: srhines, mehdi_amini, javed.absar, kristof.beyls, hiraditya, cryptoad, steven_wu, dexonsmith, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D64169 llvm-svn: 366123
2019-07-13Extend function attributes bitset size from 64 to 96.Evgeniy Stepanov1-5/+12
Summary: We are going to add a function attribute number 64. Reviewers: pcc, jdoerfert, lebedev.ri Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64663 llvm-svn: 365980
2019-07-11[Attributor] Deduce "nosync" function attribute.Stefan Stipanovic1-0/+2
Introduce and deduce "nosync" function attribute to indicate that a function does not synchronize with another thread in a way that other thread might free memory. Reviewers: jdoerfert, jfb, nhaehnle, arsenm Subscribers: wdng, hfinkel, nhaenhle, mehdi_amini, steven_wu, dexonsmith, arsenm, uenoku, hiraditya, jfb, llvm-commits Differential Revision: https://reviews.llvm.org/D62766 llvm-svn: 365830