aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2013-07-06 00:29:58 +0000
committerNick Lewycky <nicholas@mxc.ca>2013-07-06 00:29:58 +0000
commitc2ec0725cedceb851858c3991fbdd36ee9ac85dd (patch)
tree841ddf4ab15a0d446543803d7124a7716619cb04 /llvm/lib/IR
parente8545dde7be8fe78e64bf4d9578c25368243c274 (diff)
downloadllvm-c2ec0725cedceb851858c3991fbdd36ee9ac85dd.zip
llvm-c2ec0725cedceb851858c3991fbdd36ee9ac85dd.tar.gz
llvm-c2ec0725cedceb851858c3991fbdd36ee9ac85dd.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. llvm-svn: 185735
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r--llvm/lib/IR/Attributes.cpp2
-rw-r--r--llvm/lib/IR/Function.cpp10
-rw-r--r--llvm/lib/IR/Verifier.cpp21
3 files changed, 24 insertions, 9 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 2160ea2..59da815 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -1157,6 +1157,8 @@ AttributeSet AttributeFuncs::typeIncompatible(Type *Ty, uint64_t Index) {
.addAttribute(Attribute::Nest)
.addAttribute(Attribute::NoAlias)
.addAttribute(Attribute::NoCapture)
+ .addAttribute(Attribute::ReadNone)
+ .addAttribute(Attribute::ReadOnly)
.addAttribute(Attribute::StructRet);
return AttributeSet::get(Ty->getContext(), Index, Incompatible);
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp
index 7f7efabf..bf9d949b 100644
--- a/llvm/lib/IR/Function.cpp
+++ b/llvm/lib/IR/Function.cpp
@@ -131,6 +131,15 @@ bool Argument::hasReturnedAttr() const {
hasAttribute(getArgNo()+1, Attribute::Returned);
}
+/// Return true if this argument has the readonly or readnone attribute on it
+/// in its containing function.
+bool Argument::onlyReadsMemory() const {
+ return getParent()->getAttributes().
+ hasAttribute(getArgNo()+1, Attribute::ReadOnly) ||
+ getParent()->getAttributes().
+ hasAttribute(getArgNo()+1, Attribute::ReadNone);
+}
+
/// addAttr - Add attributes to an argument.
void Argument::addAttr(AttributeSet AS) {
assert(AS.getNumSlots() <= 1 &&
@@ -711,4 +720,3 @@ bool Function::callsFunctionThatReturnsTwice() const {
return false;
}
-
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 8b4c165..420bc15 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -654,7 +654,7 @@ void Verifier::visitModuleFlag(MDNode *Op, DenseMap<MDString*, MDNode*>&SeenIDs,
}
void Verifier::VerifyAttributeTypes(AttributeSet Attrs, unsigned Idx,
- bool isFunction, const Value* V) {
+ bool isFunction, const Value *V) {
unsigned Slot = ~0U;
for (unsigned I = 0, E = Attrs.getNumSlots(); I != E; ++I)
if (Attrs.getSlotIndex(I) == Idx) {
@@ -671,8 +671,6 @@ void Verifier::VerifyAttributeTypes(AttributeSet Attrs, unsigned Idx,
if (I->getKindAsEnum() == Attribute::NoReturn ||
I->getKindAsEnum() == Attribute::NoUnwind ||
- I->getKindAsEnum() == Attribute::ReadNone ||
- I->getKindAsEnum() == Attribute::ReadOnly ||
I->getKindAsEnum() == Attribute::NoInline ||
I->getKindAsEnum() == Attribute::AlwaysInline ||
I->getKindAsEnum() == Attribute::OptimizeForSize ||
@@ -696,14 +694,21 @@ void Verifier::VerifyAttributeTypes(AttributeSet Attrs, unsigned Idx,
I->getKindAsEnum() == Attribute::NoBuiltin ||
I->getKindAsEnum() == Attribute::Cold) {
if (!isFunction) {
- CheckFailed("Attribute '" + I->getAsString() +
- "' only applies to functions!", V);
- return;
+ CheckFailed("Attribute '" + I->getAsString() +
+ "' only applies to functions!", V);
+ return;
}
- } else if (isFunction) {
+ } else if (I->getKindAsEnum() == Attribute::ReadOnly ||
+ I->getKindAsEnum() == Attribute::ReadNone) {
+ if (Idx == 0) {
CheckFailed("Attribute '" + I->getAsString() +
- "' does not apply to functions!", V);
+ "' does not apply to function returns");
return;
+ }
+ } else if (isFunction) {
+ CheckFailed("Attribute '" + I->getAsString() +
+ "' does not apply to functions!", V);
+ return;
}
}
}