summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/Core.cpp
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2017-03-17 17:16:39 +0000
committerReid Kleckner <rnk@google.com>2017-03-17 17:16:39 +0000
commit56d028d9744b045974fd2a52c296318018c30f9f (patch)
treeb45cf8b96299b4b23ec0ceaa24737fa2a9d99399 /llvm/lib/IR/Core.cpp
parentee2dd785f617101cc7f02e7fb192761154867327 (diff)
downloadbcm5719-llvm-56d028d9744b045974fd2a52c296318018c30f9f.tar.gz
bcm5719-llvm-56d028d9744b045974fd2a52c296318018c30f9f.zip
Store Arguments in a flat array instead of an iplist
This saves two pointers from Argument and eliminates some extra allocations. Arguments cannot be inserted or removed from a Function because that would require changing its Type, which LLVM does not allow. Instead, passes that change prototypes, like DeadArgElim, create a new Function and copy over argument names and attributes. The primary benefit of iplist is O(1) random insertion and removal. We just don't need that for arguments, so don't use it. Reviewed By: chandlerc Subscribers: dlj, inglorion, llvm-commits Differential Revision: https://reviews.llvm.org/D31058 llvm-svn: 298105
Diffstat (limited to 'llvm/lib/IR/Core.cpp')
-rw-r--r--llvm/lib/IR/Core.cpp17
1 files changed, 7 insertions, 10 deletions
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index 7236e4c454e..49f2e77ec40 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -1913,10 +1913,8 @@ void LLVMGetParams(LLVMValueRef FnRef, LLVMValueRef *ParamRefs) {
}
LLVMValueRef LLVMGetParam(LLVMValueRef FnRef, unsigned index) {
- Function::arg_iterator AI = unwrap<Function>(FnRef)->arg_begin();
- while (index --> 0)
- AI++;
- return wrap(&*AI);
+ Function *Fn = unwrap<Function>(FnRef);
+ return wrap(&Fn->arg_begin()[index]);
}
LLVMValueRef LLVMGetParamParent(LLVMValueRef V) {
@@ -1941,18 +1939,17 @@ LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn) {
LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg) {
Argument *A = unwrap<Argument>(Arg);
- Function::arg_iterator I(A);
- if (++I == A->getParent()->arg_end())
+ Function *Fn = A->getParent();
+ if (A->getArgNo() + 1 >= Fn->arg_size())
return nullptr;
- return wrap(&*I);
+ return wrap(&Fn->arg_begin()[A->getArgNo() + 1]);
}
LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg) {
Argument *A = unwrap<Argument>(Arg);
- Function::arg_iterator I(A);
- if (I == A->getParent()->arg_begin())
+ if (A->getArgNo() == 0)
return nullptr;
- return wrap(&*--I);
+ return wrap(&A->getParent()->arg_begin()[A->getArgNo() - 1]);
}
void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align) {
OpenPOWER on IntegriCloud