summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/Instructions.cpp
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2017-05-03 18:17:31 +0000
committerReid Kleckner <rnk@google.com>2017-05-03 18:17:31 +0000
commita0b45f4bfccb3ab197ca504032c28160ce82eac2 (patch)
tree91fbb62cc8ff2350e9319c9d020f148632427bc7 /llvm/lib/IR/Instructions.cpp
parent2e23ce4cadeace53fd7de8c89d786f59108f378a (diff)
downloadbcm5719-llvm-a0b45f4bfccb3ab197ca504032c28160ce82eac2.tar.gz
bcm5719-llvm-a0b45f4bfccb3ab197ca504032c28160ce82eac2.zip
[IR] Abstract away ArgNo+1 attribute indexing as much as possible
Summary: Do three things to help with that: - Add AttributeList::FirstArgIndex, which is an enumerator currently set to 1. It allows us to change the indexing scheme with fewer changes. - Add addParamAttr/removeParamAttr. This just shortens addAttribute call sites that would otherwise need to spell out FirstArgIndex. - Remove some attribute-specific getters and setters from Function that take attribute list indices. Most of these were only used from BuildLibCalls, and doesNotAlias was only used to test or set if the return value is malloc-like. I'm happy to split the patch, but I think they are probably easier to review when taken together. This patch should be NFC, but it sets the stage to change the indexing scheme to this, which is more convenient when indexing into an array: 0: func attrs 1: retattrs 2...: arg attrs Reviewers: chandlerc, pete, javed.absar Subscribers: david2050, llvm-commits Differential Revision: https://reviews.llvm.org/D32811 llvm-svn: 302060
Diffstat (limited to 'llvm/lib/IR/Instructions.cpp')
-rw-r--r--llvm/lib/IR/Instructions.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index 59500992abb..a60cc375d56 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -335,12 +335,12 @@ Value *CallInst::getReturnedArgOperand() const {
unsigned Index;
if (Attrs.hasAttrSomewhere(Attribute::Returned, &Index) && Index)
- return getArgOperand(Index-1);
+ return getArgOperand(Index - AttributeList::FirstArgIndex);
if (const Function *F = getCalledFunction())
if (F->getAttributes().hasAttrSomewhere(Attribute::Returned, &Index) &&
Index)
- return getArgOperand(Index-1);
-
+ return getArgOperand(Index - AttributeList::FirstArgIndex);
+
return nullptr;
}
@@ -356,6 +356,10 @@ void CallInst::addAttribute(unsigned i, Attribute Attr) {
setAttributes(PAL);
}
+void CallInst::addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
+ addAttribute(ArgNo + AttributeList::FirstArgIndex, Kind);
+}
+
void CallInst::removeAttribute(unsigned i, Attribute::AttrKind Kind) {
AttributeList PAL = getAttributes();
PAL = PAL.removeAttribute(getContext(), i, Kind);
@@ -368,6 +372,10 @@ void CallInst::removeAttribute(unsigned i, StringRef Kind) {
setAttributes(PAL);
}
+void CallInst::removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
+ removeAttribute(ArgNo + AttributeList::FirstArgIndex, Kind);
+}
+
void CallInst::addDereferenceableAttr(unsigned i, uint64_t Bytes) {
AttributeList PAL = getAttributes();
PAL = PAL.addDereferenceableAttr(getContext(), i, Bytes);
@@ -501,8 +509,8 @@ static Instruction *createMalloc(Instruction *InsertBefore,
MCall->setTailCall();
if (Function *F = dyn_cast<Function>(MallocFunc)) {
MCall->setCallingConv(F->getCallingConv());
- if (!F->doesNotAlias(AttributeList::ReturnIndex))
- F->setDoesNotAlias(AttributeList::ReturnIndex);
+ if (!F->returnDoesNotAlias())
+ F->setReturnDoesNotAlias();
}
assert(!MCall->getType()->isVoidTy() && "Malloc has void return type");
@@ -695,12 +703,12 @@ Value *InvokeInst::getReturnedArgOperand() const {
unsigned Index;
if (Attrs.hasAttrSomewhere(Attribute::Returned, &Index) && Index)
- return getArgOperand(Index-1);
+ return getArgOperand(Index - AttributeList::FirstArgIndex);
if (const Function *F = getCalledFunction())
if (F->getAttributes().hasAttrSomewhere(Attribute::Returned, &Index) &&
Index)
- return getArgOperand(Index-1);
-
+ return getArgOperand(Index - AttributeList::FirstArgIndex);
+
return nullptr;
}
@@ -756,6 +764,10 @@ void InvokeInst::addAttribute(unsigned i, Attribute Attr) {
setAttributes(PAL);
}
+void InvokeInst::addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
+ addAttribute(ArgNo + AttributeList::FirstArgIndex, Kind);
+}
+
void InvokeInst::removeAttribute(unsigned i, Attribute::AttrKind Kind) {
AttributeList PAL = getAttributes();
PAL = PAL.removeAttribute(getContext(), i, Kind);
@@ -768,6 +780,10 @@ void InvokeInst::removeAttribute(unsigned i, StringRef Kind) {
setAttributes(PAL);
}
+void InvokeInst::removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
+ removeAttribute(ArgNo + AttributeList::FirstArgIndex, Kind);
+}
+
void InvokeInst::addDereferenceableAttr(unsigned i, uint64_t Bytes) {
AttributeList PAL = getAttributes();
PAL = PAL.addDereferenceableAttr(getContext(), i, Bytes);
OpenPOWER on IntegriCloud