summaryrefslogtreecommitdiffstats
path: root/llvm/lib
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
commite2de908a2892cfe17422820071e3188085e36225 (patch)
tree37343edf63954da71b1fd352d7d9b278368a80aa /llvm/lib
parent45ffa21cb31d5f49c3bb994ba255c6bff08f7630 (diff)
downloadbcm5719-llvm-e2de908a2892cfe17422820071e3188085e36225.tar.gz
bcm5719-llvm-e2de908a2892cfe17422820071e3188085e36225.zip
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. llvm-svn: 41166
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/VMCore/Function.cpp31
1 files changed, 24 insertions, 7 deletions
diff --git a/llvm/lib/VMCore/Function.cpp b/llvm/lib/VMCore/Function.cpp
index 1374d55e7d9..04541dfbfdc 100644
--- a/llvm/lib/VMCore/Function.cpp
+++ b/llvm/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);
OpenPOWER on IntegriCloud