aboutsummaryrefslogtreecommitdiff
path: root/lib/VMCore/Function.cpp
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
commit0162c1815e5a1b33750d313c49f707bc446ea946 (patch)
tree45953e45ead6bb1ef910631e975e817e4edda76b /lib/VMCore/Function.cpp
parent453eed147ad009f4608197928a3ed8ea7e67a78d (diff)
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/Function.cpp')
-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 1374d55e7d..04541dfbfd 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);