diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2013-07-06 00:29:58 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2013-07-06 00:29:58 +0000 |
commit | dc89737bcdbb8f69d8ae7578bdfa904cabcfc5ed (patch) | |
tree | 1838b5d8368383a083fad1cdca2fe777528e5a69 /include | |
parent | 202eb7b18e220205ec86a03ddf18f2066c70ab15 (diff) | |
download | external_llvm-dc89737bcdbb8f69d8ae7578bdfa904cabcfc5ed.zip external_llvm-dc89737bcdbb8f69d8ae7578bdfa904cabcfc5ed.tar.gz external_llvm-dc89737bcdbb8f69d8ae7578bdfa904cabcfc5ed.tar.bz2 |
Extend 'readonly' and 'readnone' to work on function arguments as well as
functions. Make the function attributes pass add it to known library functions
and when it can deduce it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185735 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/IR/Argument.h | 5 | ||||
-rw-r--r-- | include/llvm/IR/Function.h | 8 | ||||
-rw-r--r-- | include/llvm/IR/Intrinsics.td | 18 | ||||
-rw-r--r-- | include/llvm/Support/CallSite.h | 9 |
4 files changed, 38 insertions, 2 deletions
diff --git a/include/llvm/IR/Argument.h b/include/llvm/IR/Argument.h index 40d61ff..eb6ed46 100644 --- a/include/llvm/IR/Argument.h +++ b/include/llvm/IR/Argument.h @@ -82,6 +82,11 @@ public: /// its containing function. bool hasReturnedAttr() const; + /// \brief Return true if this argument has the readonly or readnone attribute + /// on it in its containing function. + bool onlyReadsMemory() const; + + /// \brief Add a Attribute to an argument. void addAttr(AttributeSet AS); diff --git a/include/llvm/IR/Function.h b/include/llvm/IR/Function.h index 0645539..cfb862d 100644 --- a/include/llvm/IR/Function.h +++ b/include/llvm/IR/Function.h @@ -310,6 +310,14 @@ public: addAttribute(n, Attribute::NoCapture); } + bool onlyReadsMemory(unsigned n) const { + return AttributeSets.hasAttribute(n, Attribute::ReadOnly) || + AttributeSets.hasAttribute(n, Attribute::ReadNone); + } + void setOnlyReadsMemory(unsigned n) { + addAttribute(n, Attribute::ReadOnly); + } + /// copyAttributesFrom - copy all additional attributes (those not needed to /// create a Function) from the Function Src to this one. void copyAttributesFrom(const GlobalValue *Src); diff --git a/include/llvm/IR/Intrinsics.td b/include/llvm/IR/Intrinsics.td index 6530187..e102382 100644 --- a/include/llvm/IR/Intrinsics.td +++ b/include/llvm/IR/Intrinsics.td @@ -55,6 +55,18 @@ class NoCapture<int argNo> : IntrinsicProperty { int ArgNo = argNo; } +// ReadOnly - The specified argument pointer is not written to through the +// pointer by the intrinsic. +class ReadOnly<int argNo> : IntrinsicProperty { + int ArgNo = argNo; +} + +// ReadNone - The specified argument pointer is not dereferenced by the +// intrinsic. +class ReadNone<int argNo> : IntrinsicProperty { + int ArgNo = argNo; +} + def IntrNoReturn : IntrinsicProperty; //===----------------------------------------------------------------------===// @@ -253,11 +265,13 @@ def int_stackprotector : Intrinsic<[], [llvm_ptr_ty, llvm_ptrptr_ty], []>; def int_memcpy : Intrinsic<[], [llvm_anyptr_ty, llvm_anyptr_ty, llvm_anyint_ty, llvm_i32_ty, llvm_i1_ty], - [IntrReadWriteArgMem, NoCapture<0>, NoCapture<1>]>; + [IntrReadWriteArgMem, NoCapture<0>, NoCapture<1>, + ReadOnly<1>]>; def int_memmove : Intrinsic<[], [llvm_anyptr_ty, llvm_anyptr_ty, llvm_anyint_ty, llvm_i32_ty, llvm_i1_ty], - [IntrReadWriteArgMem, NoCapture<0>, NoCapture<1>]>; + [IntrReadWriteArgMem, NoCapture<0>, NoCapture<1>, + ReadOnly<1>]>; def int_memset : Intrinsic<[], [llvm_anyptr_ty, llvm_i8_ty, llvm_anyint_ty, llvm_i32_ty, llvm_i1_ty], diff --git a/include/llvm/Support/CallSite.h b/include/llvm/Support/CallSite.h index 961c38e..2a1c5ca 100644 --- a/include/llvm/Support/CallSite.h +++ b/include/llvm/Support/CallSite.h @@ -257,6 +257,15 @@ public: return paramHasAttr(ArgNo + 1, Attribute::ByVal); } + bool doesNotAccessMemory(unsigned ArgNo) const { + return paramHasAttr(ArgNo + 1, Attribute::ReadNone); + } + + bool onlyReadsMemory(unsigned ArgNo) const { + return paramHasAttr(ArgNo + 1, Attribute::ReadOnly) || + paramHasAttr(ArgNo + 1, Attribute::ReadNone); + } + /// hasArgument - Returns true if this CallSite passes the given Value* as an /// argument to the called function. bool hasArgument(const Value *Arg) const { |