aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Attributes.cpp
AgeCommit message (Collapse)AuthorFilesLines
2022-10-21[IR] Add support for memory attributeNikita Popov1-0/+67
This implements IR and bitcode support for the memory attribute, as specified in https://reviews.llvm.org/D135597. The new attribute is not used for anything yet (and as such, the old memory attributes are unaffected). Differential Revision: https://reviews.llvm.org/D135592
2022-10-11[Attributes] Return Optional from getAllocSizeArgs() (NFC)Nikita Popov1-7/+13
As suggested on D135572, return Optional<> from getAllocSizeArgs() rather than the peculiar pair(0, 0) sentinel. The method on Attribute itself does not return Optional, because the attribute must exist in that case.
2022-10-11[Attributes] Support int attributes with zero valueNikita Popov1-9/+13
This regularly comes up as a stumbling stone when adding int attributes: They currently need to be encoded in a way to avoids the zero value. This adds support for zero-value int attributes by a) making the ctor determine int/enum attribute based on attribute kind, not whether the value is non-zero and b) switching getRawIntAttr() to return an Optional, so that it's possible to distinguish a zero value from non-existence. Differential Revision: https://reviews.llvm.org/D135572
2022-10-11[AttrBuilder] Remove unused vscale accessors (NFC)Nikita Popov1-8/+0
These accessors are not used. Generally, nowadays it is preferable to perform queries on AttributeSets/Lists, rather than the AttrBuilder, which is optimized towards attribute construction now.
2022-10-11[Attributes] Remove AttrBuilder::hasAlignmentAttr() method (NFC)Nikita Popov1-4/+0
This was the odd one out, with similar methods not existing for any other attributes. In the places where it is used, it is best replaced by AttrBuilder::getAttribute(), which allows us to both test for presence of the attribute and retrieve its value at the same time. (To just check for presence, contains() could be used.)
2022-06-20Don't use Optional::hasValue (NFC)Kazu Hirata1-2/+1
2022-06-18[llvm] Use value_or instead of getValueOr (NFC)Kazu Hirata1-3/+3
2022-06-04Use llvm::less_first (NFC)Kazu Hirata1-10/+2
2022-05-31attributes: introduce allockind attr for describing allocator fn behaviorAugie Fackler1-0/+44
I chose to encode the allockind information in a string constant because otherwise we would get a bit of an explosion of keywords to deal with the possible permutations of allocation function types. I'm not sure that CodeGen.h is the correct place for this enum, but it seemed to kind of match the UWTableKind enum so I put it in the same place. Constructive suggestions on a better location most certainly encouraged. Differential Revision: https://reviews.llvm.org/D123088
2022-05-27Revert "[llvm][clang][bolt][NFC] Use llvm::less_first() when applicable"Balazs Benics1-2/+10
This reverts commit 3988bd13988aad72ec979beb2361e8738584926b. Did not build on this bot: https://lab.llvm.org/buildbot#builders/215/builds/6372 /usr/include/c++/9/bits/predefined_ops.h:177:11: error: no match for call to ‘(llvm::less_first) (std::pair<long unsigned int, llvm::bolt::BinaryBasicBlock*>&, const std::pair<long unsigned int, std::nullptr_t>&)’ 177 | { return bool(_M_comp(*__it, __val)); }
2022-05-27[llvm][clang][bolt][NFC] Use llvm::less_first() when applicableBalazs Benics1-10/+2
One could reuse this functor instead of rolling out your own version. There were a couple other cases where the code was similar, but not quite the same, such as it might have an assertion in the lambda or other constructs. Thus, I've not touched any of those, as it might change the behavior in some way. As per https://discourse.llvm.org/t/submitting-simple-nfc-patches/62640/3?u=steakhal Chris Lattner > LLVM intentionally has a “yes, you can apply common sense judgement to > things” policy when it comes to code review. If you are doing mechanical > patches (e.g. adopting less_first) that apply to the entire monorepo, > then you don’t need everyone in the monorepo to sign off on it. Having > some +1 validation from someone is useful, but you don’t need everyone > whose code you touch to weigh in. Differential Revision: https://reviews.llvm.org/D126068
2022-05-02[ArgPromotion][Attributor] Update min-legal-vector-width when do promotionPhoebe Wang1-0/+11
X86 codegen uses function attribute `min-legal-vector-width` to select the proper ABI. The intention of the attribute is to reflect user's requirement when they passing or returning vector arguments. So Clang front-end will iterate the vector arguments and set `min-legal-vector-width` to the width of the maximum for both caller and callee. It is assumed any middle end optimizations won't care of the attribute expect inlining and argument promotion. - For inlining, we will propagate the attribute of inlined functions because the inlining functions become the newer caller. - For argument promotion, we check the `min-legal-vector-width` of the caller and callee and refuse to promote when they don't match. The problem comes from the optimizations' combination, as shown by https://godbolt.org/z/zo3hba8xW. The caller `foo` has two callees `bar` and `baz`. When doing argument promotion, both `foo` and `bar` has the same `min-legal-vector-width`. So the argument was promoted to vector. Then the inlining inlines `baz` to `foo` and updates `min-legal-vector-width`, which results in ABI mismatch between `foo` and `bar`. This patch fixes the problem by expanding the concept of `min-legal-vector-width` to indicator of functions arguments. That says, any passes touch functions arguments have to set `min-legal-vector-width` to the value reflects the width of vector arguments. It makes sense to me because any arguments modifications are ABI related and should response for the ABI compatibility. Differential Revision: https://reviews.llvm.org/D123284
2022-04-26Attributes: add a new `allocptr` attributeAugie Fackler1-1/+2
This continues the push away from hard-coded knowledge about functions towards attributes. We'll use this to annotate free(), realloc() and cousins and obviate the hard-coded list of free functions. Differential Revision: https://reviews.llvm.org/D123083
2022-03-28[InstCombineCalls] Optimize call of bitcast even w/ parameter attributesJohannes Doerfert1-26/+36
Before we gave up if a call through bitcast had parameter attributes. Interestingly, we allowed attributes for the return value already. We now handle both the same way, namely, we drop the ones that are incompatible with the new type and keep the rest. This cannot cause "more UB" than initially present. Differential Revision: https://reviews.llvm.org/D119967
2022-03-12Cleanup includes: DebugInfo & CodeGenserge-sans-paille1-1/+0
Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D121332
2022-03-04Attributes: add a new allocalign attributeAugie Fackler1-1/+2
This will let us start moving away from hard-coded attributes in MemoryBuiltins.cpp and put the knowledge about various attribute functions in the compilers that emit those calls where it probably belongs. Differential Revision: https://reviews.llvm.org/D117921
2022-02-17Remove duplicated code for printing the `uwtable` attribute (NFC)Momchil Velikov1-8/+0
Committed as obvious. Reviewed By: chill Differential Revision: https://reviews.llvm.org/D120030
2022-02-14Extend the `uwtable` attribute with unwind table kindMomchil Velikov1-0/+50
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-02Cleanup header dependencies in LLVMCoreserge-sans-paille1-3/+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-31Save some `std::string` allocations/deallocations when formatting attributes ↵Momchil Velikov1-33/+14
(NFC) Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D118451
2022-01-19[AttrBuilder] Change storage to sorted vector (NFC)Nikita Popov1-131/+77
This follows up on the work in D116599, which changed AttrBuilder to store string attributes as SmallVector<Attribute>. This patch changes the implementation to store *all* attributes as a sorted vector. This both makes the implementation simpler and improves compile-time. We get a -0.5% geomean compile-time improvement on CTMark at O0. Differential Revision: https://reviews.llvm.org/D117558
2022-01-19[Attributes] Make attribute addition behavior consistentNikita Popov1-17/+5
Currently, the behavior when adding an attribute with the same key as an existing attribute is inconsistent, depending on the type of the attribute and the method used to add it. When going through AttrBuilder::addAttribute(), the new attribute always overwrites the old one. When going through AttrBuilder::merge() the new attribute overwrites the existing one if it is a string attribute, but keeps the existing one for int and type attributes. One particular API also asserts that you can't overwrite an align attribute, but does not handle any of the other int, type or string attributes. This patch makes the behavior consistent by always overwriting with the new attribute, which is the behavior I would intuitively expect. Two tests are affected, which now make a different (but equally valid) choice. Those tests could be improved by taking the maximum deref bytes, but I haven't bothered with that, since this is testing a degenerate case -- the important bit is that it doesn't crash. Differential Revision: https://reviews.llvm.org/D117552
2022-01-18[AttrBuilder] Add string attribute getter (NFC)Nikita Popov1-2/+8
This avoids the need to scan through td_attrs() in AutoUpgrade, decoupling it from AttrBuilder implementation details.
2022-01-16[AttrBuilder] Remove unused removeAttributes() overloadNikita Popov1-5/+0
The idiomatic way would be to call remove() with an AttributeMask constructed from an AttributeSet.
2022-01-16[AttrBuilder] Remove unused hasAttributes() overloadNikita Popov1-16/+0
This is unused, and doesn't make a lot of sense as an API. The usual pattern would be to combine the AttrBuilder(AttributeSet) constructor with the overlaps() method.
2022-01-15[AttrBuilder] Remove ctor accepting AttributeList and IndexNikita Popov1-8/+0
Use the AttributeSet constructor instead. There's no good reason why AttrBuilder itself should exact the AttributeSet from the AttributeList. Moving this out of the AttrBuilder generally results in cleaner code.
2022-01-13Don't override __attribute__((no_stack_protector)) by inlining (PR52886)Hans Wennborg1-0/+6
Since 26c6a3e736d3, LLVM's inliner will "upgrade" the caller's stack protector attribute based on the callee. This lead to surprising results with Clang's no_stack_protector attribute added in 4fbf84c1732f (D46300). Consider the following code compiled with clang -fstack-protector-strong -Os (https://godbolt.org/z/7s3rW7a1q). extern void h(int* p); inline __attribute__((always_inline)) int g() { return 0; } int __attribute__((__no_stack_protector__)) f() { int a[1]; h(a); return g(); } LLVM will inline g() into f(), and f() would get a stack protector, against the users explicit wishes, potentially breaking the program e.g. if h() changes the value of the stack cookie. That's a miscompile. More recently, bc044a88ee3c (D91816) addressed this problem by preventing inlining when the stack protector is disabled in the caller and enabled in the callee or vice versa. However, the problem remained if the callee is marked always_inline as in the example above. This affected users, see e.g. http://crbug.com/1274129 and http://llvm.org/pr52886. One way to fix this would be to prevent inlining also in the always_inline case. Despite the name, always_inline does not guarantee inlining, so this would be legal but potentially surprising to users. However, I think the better fix is to not enable the stack protector in a caller based on the callee. The motivation for the old behaviour is unclear, it seems counter-intuitive, and causes real problems as we've seen. This commit implements that fix, which means in the example above, g() gets inlined into f() (also without always_inline), and f() is emitted without stack protector. I think that matches most developers' expectations, and that's also what GCC does. Another effect of this change is that a no_stack_protector function can now be inlined into a stack protected function, e.g. (https://godbolt.org/z/hafP6W856): extern void h(int* p); inline int __attribute__((__no_stack_protector__)) __attribute__((always_inline)) g() { return 0; } int f() { int a[1]; h(a); return g(); } I think that's fine. Such code would be unusual since no_stack_protector is normally applied to a program entry point which sets up the stack canary. And even if such code exists, inlining doesn't change the semantics: there is still no stack cookie setup/check around entry/exit of the g() code region, but there may be in the surrounding context, as there was before inlining. This also matches GCC. See also the discussion at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94722 Differential revision: https://reviews.llvm.org/D116589
2022-01-10Use a sorted array instead of a map to store AttrBuilder string attributesSerge Guelton1-37/+47
Using and std::map<SmallString, SmallString> for target dependent attributes is inefficient: it makes its constructor slightly heavier, and involves extra allocation for each new string attribute. Storing the attribute key/value as strings implies extra allocation/copy step. Use a sorted vector instead. Given the low number of attributes generally involved, this is cheaper, as showcased by https://llvm-compile-time-tracker.com/compare.php?from=5de322295f4ade692dc4f1823ae4450ad3c48af2&to=05bc480bf641a9e3b466619af43a2d123ee3f71d&stat=instructions Differential Revision: https://reviews.llvm.org/D116599
2022-01-04Introduce the AttributeMask classserge-sans-paille1-37/+35
This class is solely used as a lightweight and clean way to build a set of attributes to be removed from an AttrBuilder. Previously AttrBuilder was used both for building and removing, which introduced odd situation like creation of Attribute with dummy value because the only relevant part was the attribute kind. Differential Revision: https://reviews.llvm.org/D116110
2022-01-03[IR] Allow the 'align' param attr on vectors of pointersFraser Cormack1-3/+6
This patch extends the available uses of the 'align' parameter attribute to include vectors of pointers. The attribute specifies pointer alignment element-wise. This change was previously requested and discussed in D87304. The vector predication (VP) intrinsics intend to use this for scatter and gather operations, as they lack the explicit alignment parameter that the masked versions use. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D115161
2021-12-20[Attributes] Add AttributeList ctor from AttributeSet (NFC)Nikita Popov1-3/+8
It was already possible to create an AttributeList from an Index and an AttributeSet. However, this would actually end up using the implicit constructor on AttrBuilder, thus doing an unnecessary conversion from AttributeSet to AttrBuilder to AttributeSet. Instead we can accept the AttributeSet directly, as that is what we need anyway.
2021-12-07[IR] Split vscale_range interfaceCullen Rhodes1-18/+40
Interface is split from: std::pair<unsigned, unsigned> getVScaleRangeArgs() into separate functions for min/max: unsigned getVScaleRangeMin(); Optional<unsigned> getVScaleRangeMax(); Reviewed By: sdesmalen, paulwalker-arm Differential Revision: https://reviews.llvm.org/D114075
2021-12-07[IR] Remove unbounded as possible value for vscale_range minimumCullen Rhodes1-2/+2
The default for min is changed to 1. The behaviour of -mvscale-{min,max} in Clang is also changed such that 16 is the max vscale when targeting SVE and no max is specified. Reviewed By: sdesmalen, paulwalker-arm Differential Revision: https://reviews.llvm.org/D113294
2021-10-24[llvm] Call *(Set|Map)::erase directly (NFC)Kazu Hirata1-3/+1
We can erase an item in a set or map without checking its membership first.
2021-10-03[AttrBuilder] Make handling of int attribtues more generifc (NFC)Nikita Popov1-130/+51
This is basically the same change as 42cc7f3c524a0ede6b903486c588003fe12d9293 but for integer attributes. Rather than treating each attribute individually, handle them all the same way. The only thing that needs to be done per attribute is specify how get/add convert from/to the raw representation.
2021-10-01[NFC][AttributeList] Replace index_begin/end with an iteratorArthur Eubanks1-1/+1
We expose the fact that we rely on unsigned wrapping to iterate through all indexes. This can be confusing. Rather, keeping it as an implementation detail through an iterator is less confusing and is less code. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D110885
2021-09-01[NFC] Rename attribute methods that work with indexesArthur Eubanks1-35/+45
This is part one of a couple of patches to fully rename these methods. I've made the mistake of assuming that these indexes are for parameters multiple times, but actually they're based off of a weird indexing scheme AttributeList::AttrIndex where 0 is the return value and ~0 is the function. Hopefully renaming these methods will make this clearer. Ideally users should use more specific methods like AttributeList::getFnAttr(). This patch simply adds the name that we want in the end. This is so the removal of the methods with the original names happens in a separate change to make it easier for downstream users. This touches all relevant methods in AttributeList, CallBase, and Function. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D108788
2021-08-20[NFC] Cleanup/remove some AttributeList setter methodsArthur Eubanks1-15/+7
2021-08-19[NFC] Cleanup AttributeList::getStackAlignment()Arthur Eubanks1-2/+6
So that we don't use a confusing index.
2021-08-19[NFC] Replace some attribute methods that use confusing indexesArthur Eubanks1-8/+24
2021-08-18[NFC] Remove some unnecessary AttributeList methodsArthur Eubanks1-10/+0
These rely on methods I'm trying to cleanup.
2021-08-17[NFC] Migrate some callers away from Function/AttributeLists methods that ↵Arthur Eubanks1-2/+2
take an index These methods can be confusing.
2021-08-13[NFC] Rename AttributeList::getParam/Ret/FnAttributes() -> get*Attributes()Arthur Eubanks1-3/+3
This is more consistent with similar methods.
2021-08-13[NFC] Rename AttributeList::hasFnAttribute() -> hasFnAttr()Arthur Eubanks1-2/+2
This is more consistent with similar methods.
2021-08-13[NFC] Remove AttributeList::hasParamAttribute()Arthur Eubanks1-5/+0
It's the same as AttributeList::hasParamAttr().
2021-07-25[Attributes] Clean up handling of UB implying attributes (NFC)Nikita Popov1-10/+8
Rather than adding methods for dropping these attributes in various places, add a function that returns an AttrBuilder with these attributes, which can then be used with existing methods for dropping attributes. This is with an eye on D104641, which also needs to drop them from returns, not just parameters. Also be more explicit about the semantics of the method in the documentation. Refer to UB rather than Undef, which is what this is actually about.
2021-07-25[Attributes] Remove nonnull from UB-implying attributesNikita Popov1-1/+0
From LangRef: > if the parameter or return pointer is null, poison value is > returned or passed instead. The nonnull attribute should be > combined with the noundef attribute to ensure a pointer is not > null or otherwise the behavior is undefined. Dropping noundef is sufficient to prevent UB. Including nonnull in this method just muddies the semantics.
2021-07-17[BPF] Use elementtype attribute for preserve.array/struct.index intrinsicsNikita Popov1-0/+4
Use the elementtype attribute introduced in D105407 for the llvm.preserve.array/struct.index intrinsics. It carries the element type of the GEP these intrinsics effectively encode. This patch: * Adds a verifier check that the attribute is required. * Adds it in the IRBuilder methods for these intrinsics. * Autoupgrades old bitcode without the attribute. * Updates the lowering code to use the attribute rather than the pointer element type. * Updates lots of tests to specify the attribute. * Adds -force-opaque-pointers to the intrinsic-array.ll test to demonstrate they work now. https://reviews.llvm.org/D106184
2021-07-15[IR] Add elementtype attributeNikita Popov1-1/+6
This implements the elementtype attribute specified in D105407. It just adds the attribute and the specified verifier rules, but doesn't yet make use of it anywhere. Differential Revision: https://reviews.llvm.org/D106008
2021-07-14[Attributes] Use single method to fetch type from AttributeSet (NFC)Nikita Popov1-31/+7
While it is nice to have separate methods in the public AttributeSet API, we can fetch the type from the internal AttributeSetNode using a generic API for all type attribute kinds.