This is an archive of the discontinued LLVM Phabricator instance.

Add InaccessibleMemOnly and inaccessibleMemOrArgMemOnly attributes
ClosedPublic

Authored by vaivaswatha on Dec 14 2015, 8:33 AM.

Details

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.

Diff Detail

Repository
rL LLVM

Event Timeline

vaivaswatha retitled this revision from to Add AlmostReadNone and AlmostArgMemOnly attributes and set it for a few libc functions. Enhance GlobalsAA.
vaivaswatha updated this object.
vaivaswatha added reviewers: hfinkel, jmolloy.
vaivaswatha set the repository for this revision to rL LLVM.
vaivaswatha added a subscriber: llvm-commits.
jmolloy requested changes to this revision.Dec 14 2015, 10:18 AM
jmolloy edited edge metadata.

Hi Vaivaswatha,

Thanks for pushing this forward. Firstly, this patch should be split into at about four separate patches:

  1. Introduce new function attributes
  2. Modify GlobalsAA
  3. Add these new attributes to libc functions
  4. Add __mulsc3

The LLVM community prefer small, targetted patches, and each should come with at least one test case.

There will be a lot of bikeshedding on the names for these attributes. I'll just throw my penniworth in the ring and say I don't like the current names. "almostreadnone" only tells me that it isn't readnone - I'm going to have to look at the LangRef (which needs updating as part of patch (1) by the way) to see what it means.

A well-named attribute should imply its semantics at least vaguely. "readnone" for example is self explanatory. It'd be good to replace "almost" with something that describes how it differs from "readnone".

I'd suggest having a look the commits that introduced other attributes (like "norecurse" that I added recently) - they will show you what tests need touching/adding. Adding an attribute requires more tests than a normal commit, because you change the bitcode format and we need to ensure we don't regress this.

Did you run the LLVM regression tests? I think this line:

ATTR_KIND_ALMOST_ARGMEM_ONLY = 50,

should have broken at least one test - there is an invalid bitcode test that uses "50" as a known-invalid attribute kind.

/// @brief Determine if the function may read only non IR visible globals,

What about heap allocations or any other allocation that is considered an object, like an alloca whose address has been taken? Are we restricting this completely to globals, or do we need to expand this to cover all addressable objects?

Cheers,

James

This revision now requires changes to proceed.Dec 14 2015, 10:18 AM

I don't see changes to the LangRef?

include/llvm/IR/Attributes.td
23 ↗(On Diff #42726)

Can you clarify in the description that ReadNone is stricter that AlmostReadNone (i.e. one contains the other)? (if I understood correctly)

29 ↗(On Diff #42726)

Again if we could make very clear and explicit the relationship between AlmostArgMemOnly and ArgMemOnly in the description.

include/llvm/IR/Function.h
296 ↗(On Diff #42726)

@brief unneeded here.

reames added a subscriber: reames.Dec 14 2015, 1:32 PM

Hi Vaivaswatha,

Thanks for pushing this forward. Firstly, this patch should be split into at about four separate patches:

  1. Introduce new function attributes
  2. Modify GlobalsAA
  3. Add these new attributes to libc functions
  4. Add __mulsc3

The LLVM community prefer small, targetted patches, and each should come with at least one test case.

I can do that. So the first patch can be part of this review and I'll create new ones as I go along?

There will be a lot of bikeshedding on the names for these attributes. I'll just throw my penniworth in the ring and say I don't like the current names. "almostreadnone" only tells me that it isn't readnone - I'm going to have to look at the LangRef (which needs updating as part of patch (1) by the way) to see what it means.

A well-named attribute should imply its semantics at least vaguely. "readnone" for example is self explanatory. It'd be good to replace "almost" with something that describes how it differs from "readnone".

I'd suggest having a look the commits that introduced other attributes (like "norecurse" that I added recently) - they will show you what tests need touching/adding. Adding an attribute requires more tests than a normal commit, because you change the bitcode format and we need to ensure we don't regress this.

Did you run the LLVM regression tests? I think this line:

ATTR_KIND_ALMOST_ARGMEM_ONLY = 50,

should have broken at least one test - there is an invalid bitcode test that uses "50" as a known-invalid attribute kind.

I did run the regression tests and as expected saw some failures. I am currently working on them. I'll update this patch with the corrected tests, and only covering work-item (1). Will submit more patches as it progresses.

/// @brief Determine if the function may read only non IR visible globals,

What about heap allocations or any other allocation that is considered an object, like an alloca whose address has been taken? Are we restricting this completely to globals, or do we need to expand this to cover all addressable objects?

Does "read only non-IR visible memory" sound more appropriate ?

Cheers,

James

I'll also update the langref when I submit the new patch.

vaivaswatha edited edge metadata.
vaivaswatha updated this object.

Changes as per reviews: This change now just adds the two attributes and relevant tests.

vaivaswatha retitled this revision from Add AlmostReadNone and AlmostArgMemOnly attributes and set it for a few libc functions. Enhance GlobalsAA to Add AlmostReadNone and AlmostArgMemOnly attributes.Dec 16 2015, 2:49 AM
vaivaswatha updated this object.
vaivaswatha edited edge metadata.
vaivaswatha set the repository for this revision to rL LLVM.
vaivaswatha retitled this revision from Add AlmostReadNone and AlmostArgMemOnly attributes to Add InaccessibleMemOnly and inaccessibleMemOrArgMemOnly attributes.
hfinkel accepted this revision.Dec 16 2015, 4:55 AM
hfinkel edited edge metadata.

We should say module instead of program/IR, but otherwise LGTM.

docs/LangRef.rst
1248 ↗(On Diff #42976)

program/IR -> module

1252 ↗(On Diff #42976)

program/IR -> module

This revision was automatically updated to reflect the committed changes.

What is the intended use case of that attribute ? Also, what is the intended effect when module are merged ?