aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-08-18 06:14:52 +0000
committerChris Lattner <sabre@nondot.org>2007-08-18 06:14:52 +0000
commit06b898e0ea788281013deb23ae0e60fa1f53e5e3 (patch)
tree45953e45ead6bb1ef910631e975e817e4edda76b /lib/VMCore
parentc0e4f298d93f922c9916f7138a88788df951fb9a (diff)
downloadexternal_llvm-06b898e0ea788281013deb23ae0e60fa1f53e5e3.zip
external_llvm-06b898e0ea788281013deb23ae0e60fa1f53e5e3.tar.gz
external_llvm-06b898e0ea788281013deb23ae0e60fa1f53e5e3.tar.bz2
Compute the argument list as lazily as possible. This ensures that clients
that don't use it don't have to pay the memory cost for the arguments. This allows us to avoid creating Argument nodes for many prototypes and for clients who lazily deserialize code from a bytecode file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41166 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/Function.cpp31
1 files changed, 24 insertions, 7 deletions
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index 1374d55..04541df 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -152,13 +152,10 @@ Function::Function(const FunctionType *Ty, LinkageTypes Linkage,
assert((getReturnType()->isFirstClassType() ||getReturnType() == Type::VoidTy)
&& "LLVM functions cannot return aggregate values!");
- // Create the arguments vector, all arguments start out unnamed.
- for (unsigned i = 0, e = Ty->getNumParams(); i != e; ++i) {
- assert(Ty->getParamType(i) != Type::VoidTy &&
- "Cannot have void typed arguments!");
- ArgumentList.push_back(new Argument(Ty->getParamType(i)));
- }
-
+ // If the function has arguments, mark them as lazily built.
+ if (Ty->getNumParams())
+ SubclassData = 1; // Set the "has lazy arguments" bit.
+
// Make sure that we get added to a function
LeakDetector::addGarbageObject(this);
@@ -178,6 +175,26 @@ Function::~Function() {
ParamAttrs->dropRef();
}
+void Function::BuildLazyArguments() const {
+ // Create the arguments vector, all arguments start out unnamed.
+ const FunctionType *FT = getFunctionType();
+ for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
+ assert(FT->getParamType(i) != Type::VoidTy &&
+ "Cannot have void typed arguments!");
+ ArgumentList.push_back(new Argument(FT->getParamType(i)));
+ }
+
+ // Clear the lazy arguments bit.
+ const_cast<Function*>(this)->SubclassData &= ~1;
+}
+
+size_t Function::arg_size() const {
+ return getFunctionType()->getNumParams();
+}
+bool Function::arg_empty() const {
+ return getFunctionType()->getNumParams() == 0;
+}
+
void Function::setParent(Module *parent) {
if (getParent())
LeakDetector::addGarbageObject(this);