aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Attributes.cpp
AgeCommit message (Collapse)AuthorFilesLines
2016-09-09Rationalise the attribute getter/setter methods on Function and CallSite.Amaury Sechet1-0/+4
Summary: While woring on mapping attributes in the C API, it clearly appeared that the recent changes in the API on the C++ side left Function and Call/Invoke with an attribute API that grew in an ad hoc manner. This makes it difficult to work with it, because one doesn't know which overloads exists and which do not. Make sure that getter/setter function exists for both enum and string version. Remove inconsistent getter/setter, unless they have many callsites. This should make it easier to work with attributes in the future. This doesn't change how attribute works. Reviewers: bkramer, whitequark, mehdi_amini, void Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D21514 llvm-svn: 281019
2016-09-01[IR] Properly handle escape characters in Attribute::getAsString()Honggyu Kim1-4/+12
If an attribute name has special characters such as '\01', it is not properly printed in LLVM assembly language format. Since the format expects the special characters are printed as it is, it has to contain escape characters to make it printable. Before: attributes #0 = { ... "counting-function"="^A__gnu_mcount_nc" ... After: attributes #0 = { ... "counting-function"="\01__gnu_mcount_nc" ... Reviewers: hfinkel, rengolin, rjmccall, compnerd Subscribers: nemanjai, mcrosier, hans, shenhan, majnemer, llvm-commits Differential Revision: https://reviews.llvm.org/D23792 llvm-svn: 280357
2016-08-25Make some LLVM_CONSTEXPR variables const. NFC.George Burgess IV1-1/+1
This patch changes LLVM_CONSTEXPR variable declarations to const variable declarations, since LLVM_CONSTEXPR expands to nothing if the current compiler doesn't support constexpr. In all of the changed cases, it looks like the code intended the variable to be const instead of sometimes-constexpr sometimes-not. llvm-svn: 279696
2016-08-11Use range algorithms instead of unpacking begin/endDavid Majnemer1-11/+10
No functionality change is intended. llvm-svn: 278417
2016-07-18Fix -Wreturn-type with gcc 4.8 and libc++Matt Arsenault1-1/+1
llvm-svn: 275922
2016-07-10Add getReturnedArgOperand to Call/InvokeInst, CallSiteHal Finkel1-2/+5
In order to make the optimizer smarter about using the 'returned' argument attribute (generally, but motivated by my llvm.noalias intrinsic work), add a utility function to Call/InvokeInst, and CallSite, to make it easy to get the returned call argument (when one exists). P.S. There is already an unfortunate amount of code duplication between CallInst and InvokeInst, and this adds to it. We should probably clean that up separately. Differential Revision: http://reviews.llvm.org/D22204 llvm-svn: 275031
2016-07-04Add writeonly IR attributeNicolai Haehnle1-0/+3
Summary: This complements the earlier addition of IntrWriteMem and IntrWriteArgMem LLVM intrinsic properties, see D18291. Also start using the attribute for memset, memcpy, and memmove intrinsics, and remove their special-casing in BasicAliasAnalysis. Reviewers: reames, joker.eph Subscribers: joker.eph, llvm-commits Differential Revision: http://reviews.llvm.org/D18714 llvm-svn: 274485
2016-06-26Apply clang-tidy's modernize-loop-convert to most of lib/IR.Benjamin Kramer1-23/+23
Only minor manual fixes. No functionality change intended. llvm-svn: 273813
2016-06-15Add support for string attributes in the C API.Amaury Sechet1-0/+14
Summary: As per title. This completes the C API Attribute support. Reviewers: Wallbraker, whitequark, echristo, rafael, jyknight Subscribers: mehdi_amini Differential Revision: http://reviews.llvm.org/D21365 llvm-svn: 272811
2016-06-14Rename AttributeSetImpl::NumAttrs and AttributeSetImpl::getNumAttributes to ↵Amaury Sechet1-15/+15
reflect that they work on slots rather than attributes. NFC Summary: The current naming not only doesn't convey the meaning of what this does, but worse, it convey the wrong meaning. This was a major source of confusion understanding the code, so I'm applying the boy scout rule here and making it better after I leave. Reviewers: void, bkramer, whitequark Differential Revision: http://reviews.llvm.org/D21264 llvm-svn: 272725
2016-06-14Make sure attribute kind and attributes are named respectively Kind and Attr ↵Amaury Sechet1-15/+8
consistently. Historically they used to be the same the terminology is very confused in the codebase. NFC. llvm-svn: 272704
2016-06-12Use 'auto' to avoid implicit copies.Benjamin Kramer1-1/+1
td_type is std::pair<std::string, std::string>, but the map returns elements of std::pair<const std::string, std::string>. In well-designed languages like C++ that yields an implicit copy perfectly hidden by constref's lifetime extension. Just use auto, the typedef obscured the real type anyways. Found with a little help from clang-tidy's performance-implicit-cast-in-loop. llvm-svn: 272519
2016-04-12Attempt to make buildbot happier with r266032.George Burgess IV1-2/+1
Apparently std::numeric_limits<unsigned>::max() isn't constexpr everywhere yet. llvm-svn: 266034
2016-04-12Add the allocsize attribute to LLVM.George Burgess IV1-5/+128
`allocsize` is a function attribute that allows users to request that LLVM treat arbitrary functions as allocation functions. This patch makes LLVM accept the `allocsize` attribute, and makes `@llvm.objectsize` recognize said attribute. The review for this was split into two patches for ease of reviewing: D18974 and D14933. As promised on the revisions, I'm landing both patches as a single commit. Differential Revision: http://reviews.llvm.org/D14933 llvm-svn: 266032
2016-04-11[safestack] Add canary to unsafe stack framesEvgeniy Stepanov1-7/+1
Add StackProtector to SafeStack. This adds limited protection against data corruption in the caller frame. Current implementation treats all stack protector levels as -fstack-protector-all. llvm-svn: 266004
2016-04-04Fix non-determinism in order of LLVM attributesReid Kleckner1-2/+6
We were using array_pod_sort on an array of type 'Attribute', which wraps a pointer to AttributeImpl. For the most part this didn't matter because the printing code prints enum attributes in a defined order, but integer attributes such as 'align' and 'dereferenceable' were not ordered. Furthermore, AttributeImpl::operator< was broken for integer attributes. An integer attribute is a kind and an integer value, and both pieces need to be compared. By fixing the comparison operator, we can go back to std::sort, and things look good now. This should fix clang arm-swiftcall.c test failures on Windows. llvm-svn: 265361
2016-04-01Swift Calling Convention: add swifterror attribute.Manman Ren1-0/+3
A ``swifterror`` attribute can be applied to a function parameter or an AllocaInst. This commit does not include any target-specific change. The target-specific optimization will come as a follow-up patch. Differential Revision: http://reviews.llvm.org/D18092 llvm-svn: 265189
2016-03-29Swift Calling Convention: add swiftself attribute.Manman Ren1-0/+3
Differential Revision: http://reviews.llvm.org/D17866 llvm-svn: 264754
2016-01-29AttributeSetImpl: Summarize existing function attributes in a bitset.Matthias Braun1-0/+4
The majority of attribute queries checks for the existence of an enum attribute in the FunctionIndex slot. We only have 48 of those and can therefore summarize them in an uint64_t bitset which measurably improves compile time. Differential Revision: http://reviews.llvm.org/D16618 llvm-svn: 259252
2016-01-29AttributeSetNode: Summarize existing attributes in a bitset.Matthias Braun1-10/+5
The majority of queries just checks for the existince of an enum attribute. We only have 48 of those and can summaryiz them in an uint64_t bitfield so we can avoid searching the list. This improves "opt" compile time by 1-4% in my measurements. Differential Revision: http://reviews.llvm.org/D16617 llvm-svn: 259251
2016-01-29Annotate dump() methods with LLVM_DUMP_METHOD, addressing Richard Smith ↵Yaron Keren1-2/+2
r259192 post commit comment. clang part in r259232, this is the LLVM part of the patch. llvm-svn: 259240
2016-01-23Remove duplicate documentation in Attributes.cpp. NFC.Manuel Jacob1-10/+0
The documentation for these methods is already present in the header. llvm-svn: 258648
2016-01-03Use std::is_sorted and std::none_of instead of manual loops. NFCCraig Topper1-8/+9
llvm-svn: 256719
2015-12-22Provide a way to specify inliner's attribute compatibility and merging.Akira Hatanaka1-0/+78
This reapplies r256277 with two changes: - In emitFnAttrCompatCheck, change FuncName's type to std::string to fix a use-after-free bug. - Remove an unnecessary install-local target in lib/IR/Makefile. Original commit message for r252949: Provide a way to specify inliner's attribute compatibility and merging rules using table-gen. NFC. This commit adds new classes CompatRule and MergeRule to Attributes.td, which are used to generate code to check attribute compatibility and merge attributes of the caller and callee. rdar://problem/19836465 llvm-svn: 256304
2015-12-22Revert r256277 and r256279.Akira Hatanaka1-78/+0
Some of the bots failed again. llvm-svn: 256280
2015-12-22Provide a way to specify inliner's attribute compatibility and merging.Akira Hatanaka1-0/+78
This reapplies r252990 and r252949. I've added member function getKind to the Attr classes which returns the enum or string of the attribute. Original commit message for r252949: Provide a way to specify inliner's attribute compatibility and merging rules using table-gen. NFC. This commit adds new classes CompatRule and MergeRule to Attributes.td, which are used to generate code to check attribute compatibility and merge attributes of the caller and callee. rdar://problem/19836465 llvm-svn: 256277
2015-12-16Add InaccessibleMemOnly and inaccessibleMemOrArgMemOnly attributesVaivaswatha Nagaraj1-0/+6
Summary: This patch introduces two new function attributes InaccessibleMemOnly: This attribute indicates that the function may only access memory that is not accessible by the program/IR being compiled. This is a weaker form of ReadNone. inaccessibleMemOrArgMemOnly: This attribute indicates that the function may only access memory that is either not accessible by the program/IR being compiled, or is pointed to by its pointer arguments. This is a weaker form of ArgMemOnly Test cases have been updated. This revision uses this (https://github.com/llvm-mirror/llvm/commit/d001932f3a8aa1ebd1555162fdce365f011bc292) as reference. Reviewers: jmolloy, hfinkel Subscribers: reames, joker.eph, llvm-commits Differential Revision: http://reviews.llvm.org/D15499 llvm-svn: 255778
2015-12-16Minor cleanup of Attribute code. NFC.George Burgess IV1-46/+34
llvm-svn: 255751
2015-12-02[AttributeSet] Overload AttributeSet::addAttribute to reduce compileAkira Hatanaka1-0/+30
time. The new overloaded function is used when an attribute is added to a large number of slots of an AttributeSet (for example, to function parameters). This is much faster than calling AttributeSet::addAttribute once per slot, because AttributeSet::getImpl (which calls FoldingSet::FIndNodeOrInsertPos) is called only once per function instead of once per slot. With this commit, clang compiles a file which used to take over 22 minutes in just 13 seconds. rdar://problem/23581000 Differential Revision: http://reviews.llvm.org/D15085 llvm-svn: 254491
2015-11-19Revert "Change memcpy/memset/memmove to have dest and source alignments."Pete Cooper1-0/+5
This reverts commit r253511. This likely broke the bots in http://lab.llvm.org:8011/builders/clang-ppc64-elf-linux2/builds/20202 http://bb.pgr.jp/builders/clang-3stage-i686-linux/builds/3787 llvm-svn: 253543
2015-11-18Change memcpy/memset/memmove to have dest and source alignments.Pete Cooper1-5/+0
Note, this was reviewed (and more details are in) http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20151109/312083.html These intrinsics currently have an explicit alignment argument which is required to be a constant integer. It represents the alignment of the source and dest, and so must be the minimum of those. This change allows source and dest to each have their own alignments by using the alignment attribute on their arguments. The alignment argument itself is removed. There are a few places in the code for which the code needs to be checked by an expert as to whether using only src/dest alignment is safe. For those places, they currently take the minimum of src/dest alignments which matches the current behaviour. For example, code which used to read: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 500, i32 8, i1 false) will now read: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 8 %dest, i8* align 8 %src, i32 500, i1 false) For out of tree owners, I was able to strip alignment from calls using sed by replacing: (call.*llvm\.memset.*)i32\ [0-9]*\,\ i1 false\) with: $1i1 false) and similarly for memmove and memcpy. I then added back in alignment to test cases which needed it. A similar commit will be made to clang which actually has many differences in alignment as now IRBuilder can generate different source/dest alignments on calls. In IRBuilder itself, a new argument was added. Instead of calling: CreateMemCpy(Dst, Src, getInt64(Size), DstAlign, /* isVolatile */ false) you now call CreateMemCpy(Dst, Src, getInt64(Size), DstAlign, SrcAlign, /* isVolatile */ false) There is a temporary class (IntegerAlignment) which takes the source alignment and rejects implicit conversion from bool. This is to prevent isVolatile here from passing its default parameter to the source alignment. Note, changes in future can now be made to codegen. I didn't change anything here, but this change should enable better memcpy code sequences. Reviewed by Hal Finkel. llvm-svn: 253511
2015-11-13Revert r252990.Akira Hatanaka1-78/+0
Some of the buildbots are still failing. llvm-svn: 252999
2015-11-13Provide a way to specify inliner's attribute compatibility and merging.Akira Hatanaka1-0/+78
This reapplies r252949. I've changed the type of FuncName to be std::string instead of StringRef in emitFnAttrCompatCheck. Original commit message for r252949: Provide a way to specify inliner's attribute compatibility and merging rules using table-gen. NFC. This commit adds new classes CompatRule and MergeRule to Attributes.td, which are used to generate code to check attribute compatibility and merge attributes of the caller and callee. rdar://problem/19836465 llvm-svn: 252990
2015-11-12Revert r252949.Akira Hatanaka1-78/+0
It broke some of the bots including clang-x64-ninja-win7. llvm-svn: 252951
2015-11-12Provide a way to specify inliner's attribute compatibility and mergingAkira Hatanaka1-0/+78
rules using table-gen. NFC. This commit adds new classes CompatRule and MergeRule to Attributes.td, which are used to generate code to check attribute compatibility and merge attributes of the caller and callee. rdar://problem/19836465 llvm-svn: 252949
2015-11-06Add a new attribute: norecurseJames Molloy1-0/+3
This attribute allows the compiler to assume that the function never recurses into itself, either directly or indirectly (transitively). This can be used among other things to demote global variables to locals. llvm-svn: 252282
2015-09-03[IR] Have AttrBuilder::clear clear `TargetDepAttrs`.Sanjoy Das1-0/+1
Test case attached -- currently the parser smears the "foo bar" to all of the formal arguments. llvm-svn: 246812
2015-08-05Add a TrailingObjects template class.James Y Knight1-8/+5
This is intended to help support the idiom of a class that has some other objects (or multiple arrays of different types of objects) appended on the end, which is used quite heavily in clang. Differential Revision: http://reviews.llvm.org/D11272 llvm-svn: 244164
2015-08-01De-constify pointers to Type since they can't be modified. NFCCraig Topper1-1/+1
This was already done in most places a while ago. This just fixes the ones that crept in over time. llvm-svn: 243842
2015-07-11Add argmemonly attribute.Igor Laevsky1-1/+7
This change adds new attribute called "argmemonly". Function marked with this attribute can only access memory through it's argument pointers. This attribute directly corresponds to the "OnlyAccessesArgumentPointees" ModRef behaviour in alias analysis. Differential Revision: http://reviews.llvm.org/D10398 llvm-svn: 241979
2015-06-15Protection against stack-based memory corruption errors using SafeStackPeter Collingbourne1-0/+3
This patch adds the safe stack instrumentation pass to LLVM, which separates the program stack into a safe stack, which stores return addresses, register spills, and local variables that are statically verified to be accessed in a safe way, and the unsafe stack, which stores everything else. Such separation makes it much harder for an attacker to corrupt objects on the safe stack, including function pointers stored in spilled registers and return addresses. You can find more information about the safe stack, as well as other parts of or control-flow hijack protection technique in our OSDI paper on code-pointer integrity (http://dslab.epfl.ch/pubs/cpi.pdf) and our project website (http://levee.epfl.ch). The overhead of our implementation of the safe stack is very close to zero (0.01% on the Phoronix benchmarks). This is lower than the overhead of stack cookies, which are supported by LLVM and are commonly used today, yet the security guarantees of the safe stack are strictly stronger than stack cookies. In some cases, the safe stack improves performance due to better cache locality. Our current implementation of the safe stack is stable and robust, we used it to recompile multiple projects on Linux including Chromium, and we also recompiled the entire FreeBSD user-space system and more than 100 packages. We ran unit tests on the FreeBSD system and many of the packages and observed no errors caused by the safe stack. The safe stack is also fully binary compatible with non-instrumented code and can be applied to parts of a program selectively. This patch is our implementation of the safe stack on top of LLVM. The patches make the following changes: - Add the safestack function attribute, similar to the ssp, sspstrong and sspreq attributes. - Add the SafeStack instrumentation pass that applies the safe stack to all functions that have the safestack attribute. This pass moves all unsafe local variables to the unsafe stack with a separate stack pointer, whereas all safe variables remain on the regular stack that is managed by LLVM as usual. - Invoke the pass as the last stage before code generation (at the same time the existing cookie-based stack protector pass is invoked). - Add unit tests for the safe stack. Original patch by Volodymyr Kuznetsov and others at the Dependable Systems Lab at EPFL; updates and upstreaming by myself. Differential Revision: http://reviews.llvm.org/D6094 llvm-svn: 239761
2015-05-26Add initial support for the convergent attribute.Owen Anderson1-0/+3
llvm-svn: 238264
2015-05-06Change typeIncompatible to return an AttrBuilder instead of new-ing an ↵Pete Cooper1-2/+2
AttributeSet. This makes use of the new API which can remove attributes from a set given a builder. This is much faster than creating a temporary set and reduces llc time by about 0.3% which was all spent creating temporary attributes sets on the context. llvm-svn: 236668
2015-05-06Add remove method to operate on AttrBuilder instead of AttributeSet.Pete Cooper1-3/+76
Prior to this change we would have to construct a temporary AttributeSet (which isn't temporary at all given that its allocated on the context), just to contain the attributes in the builder, then call remove on that. Now we can just remove any attributes from the (lightweight and really temporary) builder itself. Will be used in a future commit to remove some temporary attributes sets. llvm-svn: 236666
2015-05-06Remove unnecessary #ifndef NDEBUG guard around assert. NFC.Pete Cooper1-2/+0
Found by Hal Finkel in the review of AttributeSets. http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20150504/275058.html llvm-svn: 236662
2015-05-06Add missing dereferenceable_or_null gettersSanjoy Das1-0/+12
Summary: Add missing dereferenceable_or_null getters required for http://reviews.llvm.org/D9253 change. Separated from the D9253 review. Patch by Artur Pilipenko! Reviewers: sanjoy Reviewed By: sanjoy Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D9499 llvm-svn: 236615
2015-04-16[IR] Introduce a dereferenceable_or_null(N) attribute.Sanjoy Das1-19/+62
Summary: If a pointer is marked as dereferenceable_or_null(N), LLVM assumes it is either `null` or `dereferenceable(N)` or both. This change only introduces the attribute and adds a token test case for the `llvm-as` / `llvm-dis`. It does not hook up other parts of the optimizer to actually exploit the attribute -- those changes will come later. For pointers in address space 0, `dereferenceable(N)` is now exactly equivalent to `dereferenceable_or_null(N)` && `nonnull`. For other address spaces, `dereferenceable(N)` is potentially weaker than `dereferenceable_or_null(N)` && `nonnull` (since we could have a null `dereferenceable(N)` pointer). The motivating case for this change is Java (and other managed languages), where pointers are either `null` or dereferenceable up to some usually known-at-compile-time constant offset. Reviewers: rafael, hfinkel Reviewed By: hfinkel Subscribers: nicholas, llvm-commits Differential Revision: http://reviews.llvm.org/D8650 llvm-svn: 235132
2015-03-30Remove more superfluous .str() and replace std::string concatenation with Twine.Yaron Keren1-2/+2
Following r233392, http://llvm.org/viewvc/llvm-project?rev=233392&view=rev. llvm-svn: 233555
2015-02-14InstCombine: propagate deref via new addDereferenceableAttrRamkumar Ramachandra1-0/+7
The "dereferenceable" attribute cannot be added via .addAttribute(), since it also expects a size in bytes. AttrBuilder#addAttribute or AttributeSet#addAttribute is wrapped by classes Function, InvokeInst, and CallInst. Add corresponding wrappers to AttrBuilder#addDereferenceableAttr. Having done this, propagate the dereferenceable attribute via gc.relocate, adding a test to exercise it. Note that -datalayout is required during execution over and above -instcombine, because InstCombine only optionally requires DataLayoutPass. Differential Revision: http://reviews.llvm.org/D7510 llvm-svn: 229265
2014-09-03Revert accidentally committed r217107Matt Arsenault1-21/+5
"Don't treat 0 as a special value for int attributes." llvm-svn: 217110