mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-15 15:48:38 +00:00
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
This commit is contained in:
parent
6e6a77d83b
commit
d5f075ed16
@ -65,11 +65,10 @@ public:
|
||||
|
||||
private:
|
||||
// Important things that make up a function!
|
||||
BasicBlockListType BasicBlocks; ///< The basic blocks
|
||||
ArgumentListType ArgumentList; ///< The formal arguments
|
||||
ValueSymbolTable *SymTab; ///< Symbol table of args/instructions
|
||||
ParamAttrsList *ParamAttrs; ///< Parameter attributes
|
||||
|
||||
BasicBlockListType BasicBlocks; ///< The basic blocks
|
||||
mutable ArgumentListType ArgumentList; ///< The formal arguments
|
||||
ValueSymbolTable *SymTab; ///< Symbol table of args/instructions
|
||||
ParamAttrsList *ParamAttrs; ///< Parameter attributes
|
||||
|
||||
// The Calling Convention is stored in Value::SubclassData.
|
||||
/*unsigned CallingConvention;*/
|
||||
@ -90,6 +89,18 @@ private:
|
||||
Function *getPrev() { return Prev; }
|
||||
const Function *getPrev() const { return Prev; }
|
||||
|
||||
/// hasLazyArguments/CheckLazyArguments - The argument list of a function is
|
||||
/// built on demand, so that the list isn't allocated until the first client
|
||||
/// needs it. The hasLazyArguments predicate returns true if the arg list
|
||||
/// hasn't been set up yet.
|
||||
bool hasLazyArguments() const {
|
||||
return SubclassData & 1;
|
||||
}
|
||||
void CheckLazyArguments() const {
|
||||
if (hasLazyArguments())
|
||||
BuildLazyArguments();
|
||||
}
|
||||
void BuildLazyArguments() const;
|
||||
public:
|
||||
/// Function ctor - If the (optional) Module argument is specified, the
|
||||
/// function is automatically inserted into the end of the function list for
|
||||
@ -125,9 +136,11 @@ public:
|
||||
/// getCallingConv()/setCallingConv(uint) - These method get and set the
|
||||
/// calling convention of this function. The enum values for the known
|
||||
/// calling conventions are defined in CallingConv.h.
|
||||
unsigned getCallingConv() const { return SubclassData; }
|
||||
void setCallingConv(unsigned CC) { SubclassData = CC; }
|
||||
|
||||
unsigned getCallingConv() const { return SubclassData >> 1; }
|
||||
void setCallingConv(unsigned CC) {
|
||||
SubclassData = (SubclassData & 1) | CC << 1;
|
||||
}
|
||||
|
||||
/// Obtains a constant pointer to the ParamAttrsList object which holds the
|
||||
/// parameter attributes information, if any.
|
||||
/// @returns 0 if no parameter attributes have been set.
|
||||
@ -161,8 +174,14 @@ public:
|
||||
/// Get the underlying elements of the Function... the basic block list is
|
||||
/// empty for external functions.
|
||||
///
|
||||
const ArgumentListType &getArgumentList() const { return ArgumentList; }
|
||||
ArgumentListType &getArgumentList() { return ArgumentList; }
|
||||
const ArgumentListType &getArgumentList() const {
|
||||
CheckLazyArguments();
|
||||
return ArgumentList;
|
||||
}
|
||||
ArgumentListType &getArgumentList() {
|
||||
CheckLazyArguments();
|
||||
return ArgumentList;
|
||||
}
|
||||
|
||||
const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
|
||||
BasicBlockListType &getBasicBlockList() { return BasicBlocks; }
|
||||
@ -197,13 +216,25 @@ public:
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Argument iterator forwarding functions
|
||||
//
|
||||
arg_iterator arg_begin() { return ArgumentList.begin(); }
|
||||
const_arg_iterator arg_begin() const { return ArgumentList.begin(); }
|
||||
arg_iterator arg_end () { return ArgumentList.end(); }
|
||||
const_arg_iterator arg_end () const { return ArgumentList.end(); }
|
||||
arg_iterator arg_begin() {
|
||||
CheckLazyArguments();
|
||||
return ArgumentList.begin();
|
||||
}
|
||||
const_arg_iterator arg_begin() const {
|
||||
CheckLazyArguments();
|
||||
return ArgumentList.begin();
|
||||
}
|
||||
arg_iterator arg_end() {
|
||||
CheckLazyArguments();
|
||||
return ArgumentList.end();
|
||||
}
|
||||
const_arg_iterator arg_end() const {
|
||||
CheckLazyArguments();
|
||||
return ArgumentList.end();
|
||||
}
|
||||
|
||||
size_t arg_size () const { return ArgumentList.size(); }
|
||||
bool arg_empty() const { return ArgumentList.empty(); }
|
||||
size_t arg_size() const;
|
||||
bool arg_empty() const;
|
||||
|
||||
virtual void print(std::ostream &OS) const { print(OS, 0); }
|
||||
void print(std::ostream *OS) const { if (OS) print(*OS); }
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user