2002-09-06 22:47:31 +02:00
|
|
|
//===-- llvm/Function.h - Class to represent a single function --*- C++ -*-===//
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-06 22:29:01 +02:00
|
|
|
//
|
2005-04-21 22:19:05 +02:00
|
|
|
// This file contains the declaration of the Function class, which represents a
|
2002-09-06 22:47:31 +02:00
|
|
|
// single function/procedure in LLVM.
|
2001-06-06 22:29:01 +02:00
|
|
|
//
|
2002-09-06 22:47:31 +02:00
|
|
|
// A function basically consists of a list of basic blocks, a list of arguments,
|
|
|
|
// and a symbol table.
|
2001-06-06 22:29:01 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-03-23 23:47:28 +01:00
|
|
|
#ifndef LLVM_FUNCTION_H
|
|
|
|
#define LLVM_FUNCTION_H
|
2001-06-06 22:29:01 +02:00
|
|
|
|
2001-10-03 16:53:21 +02:00
|
|
|
#include "llvm/GlobalValue.h"
|
2002-06-25 18:12:52 +02:00
|
|
|
#include "llvm/BasicBlock.h"
|
|
|
|
#include "llvm/Argument.h"
|
2004-09-02 00:55:40 +02:00
|
|
|
#include "llvm/Support/Annotation.h"
|
2008-09-24 01:03:40 +02:00
|
|
|
#include "llvm/Attributes.h"
|
2001-06-06 22:29:01 +02:00
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
namespace llvm {
|
|
|
|
|
2002-03-29 04:30:59 +01:00
|
|
|
class FunctionType;
|
2009-07-02 20:03:58 +02:00
|
|
|
class LLVMContext;
|
2001-06-06 22:29:01 +02:00
|
|
|
|
2009-03-01 10:45:52 +01:00
|
|
|
// Traits for intrusive list of basic blocks...
|
2002-06-25 18:12:52 +02:00
|
|
|
template<> struct ilist_traits<BasicBlock>
|
2007-04-17 05:26:42 +02:00
|
|
|
: public SymbolTableListTraits<BasicBlock, Function> {
|
2002-06-25 18:12:52 +02:00
|
|
|
|
2009-03-01 17:38:10 +01:00
|
|
|
// createSentinel is used to get hold of the node that marks the end of the
|
|
|
|
// list... (same trick used here as in ilist_traits<Instruction>)
|
|
|
|
BasicBlock *createSentinel() const {
|
2009-03-02 15:47:45 +01:00
|
|
|
return static_cast<BasicBlock*>(&Sentinel);
|
2009-03-01 17:38:10 +01:00
|
|
|
}
|
|
|
|
static void destroySentinel(BasicBlock*) {}
|
2009-03-04 21:36:44 +01:00
|
|
|
|
|
|
|
BasicBlock *provideInitialHead() const { return createSentinel(); }
|
|
|
|
BasicBlock *ensureHead(BasicBlock*) const { return createSentinel(); }
|
2009-03-04 22:54:31 +01:00
|
|
|
static void noteHead(BasicBlock*, BasicBlock*) {}
|
2009-03-04 21:36:44 +01:00
|
|
|
|
2007-04-17 05:26:42 +02:00
|
|
|
static ValueSymbolTable *getSymTab(Function *ItemParent);
|
2009-03-01 17:38:10 +01:00
|
|
|
private:
|
2009-03-27 19:37:13 +01:00
|
|
|
mutable ilist_node<BasicBlock> Sentinel;
|
2002-06-25 18:12:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct ilist_traits<Argument>
|
2007-04-17 05:26:42 +02:00
|
|
|
: public SymbolTableListTraits<Argument, Function> {
|
2002-06-25 18:12:52 +02:00
|
|
|
|
2009-03-01 18:13:15 +01:00
|
|
|
Argument *createSentinel() const {
|
2009-03-02 15:47:45 +01:00
|
|
|
return static_cast<Argument*>(&Sentinel);
|
2009-03-01 18:13:15 +01:00
|
|
|
}
|
|
|
|
static void destroySentinel(Argument*) {}
|
2009-03-04 21:36:44 +01:00
|
|
|
|
|
|
|
Argument *provideInitialHead() const { return createSentinel(); }
|
|
|
|
Argument *ensureHead(Argument*) const { return createSentinel(); }
|
2009-03-04 22:54:31 +01:00
|
|
|
static void noteHead(Argument*, Argument*) {}
|
2009-03-04 21:36:44 +01:00
|
|
|
|
2007-04-17 05:26:42 +02:00
|
|
|
static ValueSymbolTable *getSymTab(Function *ItemParent);
|
2009-03-01 18:13:15 +01:00
|
|
|
private:
|
2009-03-27 19:37:13 +01:00
|
|
|
mutable ilist_node<Argument> Sentinel;
|
2002-06-25 18:12:52 +02:00
|
|
|
};
|
|
|
|
|
2008-07-28 23:51:04 +02:00
|
|
|
class Function : public GlobalValue, public Annotable,
|
|
|
|
public ilist_node<Function> {
|
2001-06-06 22:29:01 +02:00
|
|
|
public:
|
2002-06-25 18:12:52 +02:00
|
|
|
typedef iplist<Argument> ArgumentListType;
|
|
|
|
typedef iplist<BasicBlock> BasicBlockListType;
|
2001-06-28 01:26:41 +02:00
|
|
|
|
|
|
|
// BasicBlock iterators...
|
2002-06-25 18:12:52 +02:00
|
|
|
typedef BasicBlockListType::iterator iterator;
|
|
|
|
typedef BasicBlockListType::const_iterator const_iterator;
|
2001-06-28 01:26:41 +02:00
|
|
|
|
2005-03-15 00:49:40 +01:00
|
|
|
typedef ArgumentListType::iterator arg_iterator;
|
|
|
|
typedef ArgumentListType::const_iterator const_arg_iterator;
|
2002-06-25 18:12:52 +02:00
|
|
|
|
2001-06-06 22:29:01 +02:00
|
|
|
private:
|
2002-04-28 06:44:40 +02:00
|
|
|
// Important things that make up a function!
|
2007-08-18 08:14:52 +02:00
|
|
|
BasicBlockListType BasicBlocks; ///< The basic blocks
|
|
|
|
mutable ArgumentListType ArgumentList; ///< The formal arguments
|
|
|
|
ValueSymbolTable *SymTab; ///< Symbol table of args/instructions
|
2008-10-04 20:08:00 +02:00
|
|
|
AttrListPtr AttributeList; ///< Parameter attributes
|
2008-09-02 20:33:55 +02:00
|
|
|
|
2007-04-17 06:31:29 +02:00
|
|
|
// The Calling Convention is stored in Value::SubclassData.
|
|
|
|
/*unsigned CallingConvention;*/
|
2005-04-21 22:19:05 +02:00
|
|
|
|
2007-04-17 05:26:42 +02:00
|
|
|
friend class SymbolTableListTraits<Function, Module>;
|
2002-06-25 18:12:52 +02:00
|
|
|
|
2001-06-06 22:29:01 +02:00
|
|
|
void setParent(Module *parent);
|
2007-04-28 15:45:00 +02:00
|
|
|
|
2007-08-18 08:14:52 +02:00
|
|
|
/// 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;
|
2008-01-03 01:09:47 +01:00
|
|
|
|
|
|
|
Function(const Function&); // DO NOT IMPLEMENT
|
|
|
|
void operator=(const Function&); // DO NOT IMPLEMENT
|
2008-04-06 22:25:17 +02:00
|
|
|
|
2002-09-06 22:47:31 +02:00
|
|
|
/// Function ctor - If the (optional) Module argument is specified, the
|
|
|
|
/// function is automatically inserted into the end of the function list for
|
|
|
|
/// the module.
|
|
|
|
///
|
2003-04-16 22:28:45 +02:00
|
|
|
Function(const FunctionType *Ty, LinkageTypes Linkage,
|
|
|
|
const std::string &N = "", Module *M = 0);
|
2008-04-06 22:25:17 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
static Function *Create(const FunctionType *Ty, LinkageTypes Linkage,
|
|
|
|
const std::string &N = "", Module *M = 0) {
|
|
|
|
return new(0) Function(Ty, Linkage, N, M);
|
|
|
|
}
|
|
|
|
|
2007-12-10 03:14:30 +01:00
|
|
|
~Function();
|
2001-06-06 22:29:01 +02:00
|
|
|
|
2002-03-29 04:30:59 +01:00
|
|
|
const Type *getReturnType() const; // Return the type of the ret val
|
|
|
|
const FunctionType *getFunctionType() const; // Return the FunctionType for me
|
2001-06-06 22:29:01 +02:00
|
|
|
|
2009-07-02 20:03:58 +02:00
|
|
|
/// getContext - Return a pointer to the LLVMContext associated with this
|
|
|
|
/// function, or NULL if this function is not bound to a context yet.
|
2009-07-07 01:00:19 +02:00
|
|
|
LLVMContext *getContext() const;
|
2009-07-02 20:03:58 +02:00
|
|
|
|
2005-01-07 08:40:32 +01:00
|
|
|
/// isVarArg - Return true if this function takes a variable number of
|
|
|
|
/// arguments.
|
|
|
|
bool isVarArg() const;
|
|
|
|
|
2007-01-30 21:08:39 +01:00
|
|
|
/// isDeclaration - Is the body of this function unknown? (The basic block
|
|
|
|
/// list is empty if so.) This is true for function declarations, but not
|
|
|
|
/// true for function definitions.
|
2002-08-26 00:54:55 +02:00
|
|
|
///
|
2007-01-30 21:08:39 +01:00
|
|
|
virtual bool isDeclaration() const { return BasicBlocks.empty(); }
|
2001-06-06 22:29:01 +02:00
|
|
|
|
2003-05-08 05:34:12 +02:00
|
|
|
/// getIntrinsicID - This method returns the ID number of the specified
|
2003-11-11 23:41:34 +01:00
|
|
|
/// function, or Intrinsic::not_intrinsic if the function is not an
|
2003-05-08 05:34:12 +02:00
|
|
|
/// instrinsic, or if the pointer is null. This value is always defined to be
|
|
|
|
/// zero to allow easy checking for whether a function is intrinsic or not.
|
|
|
|
/// The particular intrinsic functions which correspond to this value are
|
|
|
|
/// defined in llvm/Intrinsics.h.
|
|
|
|
///
|
2009-02-05 02:49:45 +01:00
|
|
|
unsigned getIntrinsicID() const;
|
2003-05-08 05:34:12 +02:00
|
|
|
bool isIntrinsic() const { return getIntrinsicID() != 0; }
|
|
|
|
|
2005-05-06 22:26:26 +02:00
|
|
|
/// 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.
|
2007-08-18 08:14:52 +02:00
|
|
|
unsigned getCallingConv() const { return SubclassData >> 1; }
|
|
|
|
void setCallingConv(unsigned CC) {
|
2007-08-20 23:31:08 +02:00
|
|
|
SubclassData = (SubclassData & 1) | (CC << 1);
|
2007-08-18 08:14:52 +02:00
|
|
|
}
|
|
|
|
|
2008-10-04 20:08:00 +02:00
|
|
|
/// getAttributes - Return the attribute list for this Function.
|
2008-03-13 05:33:03 +01:00
|
|
|
///
|
2008-09-25 23:00:45 +02:00
|
|
|
const AttrListPtr &getAttributes() const { return AttributeList; }
|
2008-03-12 18:45:29 +01:00
|
|
|
|
2008-10-04 20:08:00 +02:00
|
|
|
/// setAttributes - Set the attribute list for this Function.
|
2008-03-13 05:33:03 +01:00
|
|
|
///
|
2008-09-25 23:00:45 +02:00
|
|
|
void setAttributes(const AttrListPtr &attrs) { AttributeList = attrs; }
|
2007-11-27 14:23:08 +01:00
|
|
|
|
2008-09-29 20:16:38 +02:00
|
|
|
/// hasFnAttr - Return true if this function has the given attribute.
|
2008-09-27 01:51:19 +02:00
|
|
|
bool hasFnAttr(Attributes N) const {
|
|
|
|
// Function Attributes are stored at ~0 index
|
|
|
|
return AttributeList.paramHasAttr(~0U, N);
|
2008-09-23 00:32:29 +02:00
|
|
|
}
|
|
|
|
|
2008-10-04 20:08:00 +02:00
|
|
|
/// addFnAttr - Add function attributes to this function.
|
2008-09-02 20:33:55 +02:00
|
|
|
///
|
2008-10-04 20:08:00 +02:00
|
|
|
void addFnAttr(Attributes N) {
|
2008-09-27 01:51:19 +02:00
|
|
|
// Function Attributes are stored at ~0 index
|
2008-10-08 00:33:44 +02:00
|
|
|
addAttribute(~0U, N);
|
2008-09-24 00:35:17 +02:00
|
|
|
}
|
2008-09-02 20:33:55 +02:00
|
|
|
|
2009-01-04 19:21:35 +01:00
|
|
|
/// removeFnAttr - Remove function attributes from this function.
|
|
|
|
///
|
|
|
|
void removeFnAttr(Attributes N) {
|
|
|
|
// Function Attributes are stored at ~0 index
|
|
|
|
removeAttribute(~0U, N);
|
|
|
|
}
|
|
|
|
|
2008-08-17 20:44:35 +02:00
|
|
|
/// hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm
|
|
|
|
/// to use during code generation.
|
|
|
|
bool hasGC() const;
|
|
|
|
const char *getGC() const;
|
|
|
|
void setGC(const char *Str);
|
|
|
|
void clearGC();
|
2007-12-10 04:18:06 +01:00
|
|
|
|
2007-11-28 18:07:01 +01:00
|
|
|
/// @brief Determine whether the function has the given attribute.
|
2008-09-24 01:03:40 +02:00
|
|
|
bool paramHasAttr(unsigned i, Attributes attr) const {
|
2008-09-25 23:00:45 +02:00
|
|
|
return AttributeList.paramHasAttr(i, attr);
|
2008-03-13 06:00:21 +01:00
|
|
|
}
|
2008-05-16 22:39:43 +02:00
|
|
|
|
2008-09-25 23:00:45 +02:00
|
|
|
/// addAttribute - adds the attribute to the list of attributes.
|
|
|
|
void addAttribute(unsigned i, Attributes attr);
|
2008-01-03 00:42:30 +01:00
|
|
|
|
2008-09-25 23:00:45 +02:00
|
|
|
/// removeAttribute - removes the attribute from the list of attributes.
|
|
|
|
void removeAttribute(unsigned i, Attributes attr);
|
2008-07-08 11:41:30 +02:00
|
|
|
|
2008-02-22 18:49:45 +01:00
|
|
|
/// @brief Extract the alignment for a call or parameter (0=unknown).
|
2008-03-13 06:00:21 +01:00
|
|
|
unsigned getParamAlignment(unsigned i) const {
|
2008-09-25 23:00:45 +02:00
|
|
|
return AttributeList.getParamAlignment(i);
|
2008-03-13 06:00:21 +01:00
|
|
|
}
|
2008-02-22 18:49:45 +01:00
|
|
|
|
2007-12-03 21:06:50 +01:00
|
|
|
/// @brief Determine if the function does not access memory.
|
2008-03-13 06:00:21 +01:00
|
|
|
bool doesNotAccessMemory() const {
|
2009-01-04 19:21:35 +01:00
|
|
|
return hasFnAttr(Attribute::ReadNone);
|
2008-03-13 06:00:21 +01:00
|
|
|
}
|
2008-07-11 00:57:49 +02:00
|
|
|
void setDoesNotAccessMemory(bool DoesNotAccessMemory = true) {
|
2009-01-04 19:21:35 +01:00
|
|
|
if (DoesNotAccessMemory) addFnAttr(Attribute::ReadNone);
|
|
|
|
else removeFnAttr(Attribute::ReadNone);
|
2008-07-08 11:41:30 +02:00
|
|
|
}
|
2007-12-03 21:06:50 +01:00
|
|
|
|
|
|
|
/// @brief Determine if the function does not access or only reads memory.
|
2008-03-13 06:00:21 +01:00
|
|
|
bool onlyReadsMemory() const {
|
2009-01-04 19:21:35 +01:00
|
|
|
return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
|
2008-03-13 06:00:21 +01:00
|
|
|
}
|
2008-07-11 00:57:49 +02:00
|
|
|
void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
|
2009-01-04 19:21:35 +01:00
|
|
|
if (OnlyReadsMemory) addFnAttr(Attribute::ReadOnly);
|
|
|
|
else removeFnAttr(Attribute::ReadOnly | Attribute::ReadNone);
|
2008-07-08 11:41:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Determine if the function cannot return.
|
|
|
|
bool doesNotReturn() const {
|
2009-01-04 19:21:35 +01:00
|
|
|
return hasFnAttr(Attribute::NoReturn);
|
2008-07-08 11:41:30 +02:00
|
|
|
}
|
2008-07-11 00:57:49 +02:00
|
|
|
void setDoesNotReturn(bool DoesNotReturn = true) {
|
2009-01-04 19:21:35 +01:00
|
|
|
if (DoesNotReturn) addFnAttr(Attribute::NoReturn);
|
|
|
|
else removeFnAttr(Attribute::NoReturn);
|
2008-07-08 11:41:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Determine if the function cannot unwind.
|
|
|
|
bool doesNotThrow() const {
|
2009-01-04 19:21:35 +01:00
|
|
|
return hasFnAttr(Attribute::NoUnwind);
|
2008-07-08 11:41:30 +02:00
|
|
|
}
|
2008-07-11 00:57:49 +02:00
|
|
|
void setDoesNotThrow(bool DoesNotThrow = true) {
|
2009-01-04 19:21:35 +01:00
|
|
|
if (DoesNotThrow) addFnAttr(Attribute::NoUnwind);
|
|
|
|
else removeFnAttr(Attribute::NoUnwind);
|
2008-07-08 11:41:30 +02:00
|
|
|
}
|
2007-12-03 21:06:50 +01:00
|
|
|
|
2008-03-03 22:46:28 +01:00
|
|
|
/// @brief Determine if the function returns a structure through first
|
|
|
|
/// pointer argument.
|
2008-03-13 06:00:21 +01:00
|
|
|
bool hasStructRetAttr() const {
|
2008-09-25 23:00:45 +02:00
|
|
|
return paramHasAttr(1, Attribute::StructRet);
|
2008-03-13 06:00:21 +01:00
|
|
|
}
|
2007-04-09 17:01:12 +02:00
|
|
|
|
2009-01-04 19:21:35 +01:00
|
|
|
/// @brief Determine if the parameter does not alias other parameters.
|
|
|
|
/// @param n The parameter to check. 1 is the first parameter, 0 is the return
|
|
|
|
bool doesNotAlias(unsigned n) const {
|
|
|
|
return paramHasAttr(n, Attribute::NoAlias);
|
|
|
|
}
|
|
|
|
void setDoesNotAlias(unsigned n, bool DoesNotAlias = true) {
|
|
|
|
if (DoesNotAlias) addAttribute(n, Attribute::NoAlias);
|
|
|
|
else removeAttribute(n, Attribute::NoAlias);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Determine if the parameter can be captured.
|
|
|
|
/// @param n The parameter to check. 1 is the first parameter, 0 is the return
|
|
|
|
bool doesNotCapture(unsigned n) const {
|
|
|
|
return paramHasAttr(n, Attribute::NoCapture);
|
|
|
|
}
|
|
|
|
void setDoesNotCapture(unsigned n, bool DoesNotCapture = true) {
|
|
|
|
if (DoesNotCapture) addAttribute(n, Attribute::NoCapture);
|
|
|
|
else removeAttribute(n, Attribute::NoCapture);
|
|
|
|
}
|
|
|
|
|
2008-05-26 21:58:59 +02:00
|
|
|
/// copyAttributesFrom - copy all additional attributes (those not needed to
|
|
|
|
/// create a Function) from the Function Src to this one.
|
|
|
|
void copyAttributesFrom(const GlobalValue *Src);
|
|
|
|
|
2003-09-17 06:58:43 +02:00
|
|
|
/// deleteBody - This method deletes the body of the function, and converts
|
|
|
|
/// the linkage to external.
|
2004-03-01 19:31:19 +01:00
|
|
|
///
|
2003-09-17 06:58:43 +02:00
|
|
|
void deleteBody() {
|
|
|
|
dropAllReferences();
|
|
|
|
setLinkage(ExternalLinkage);
|
|
|
|
}
|
|
|
|
|
2004-10-12 00:21:13 +02:00
|
|
|
/// removeFromParent - This method unlinks 'this' from the containing module,
|
|
|
|
/// but does not delete it.
|
|
|
|
///
|
2008-08-29 09:30:15 +02:00
|
|
|
virtual void removeFromParent();
|
2004-10-12 00:21:13 +02:00
|
|
|
|
|
|
|
/// eraseFromParent - This method unlinks 'this' from the containing module
|
|
|
|
/// and deletes it.
|
|
|
|
///
|
2008-08-29 09:30:15 +02:00
|
|
|
virtual void eraseFromParent();
|
2004-10-12 00:21:13 +02:00
|
|
|
|
|
|
|
|
2003-05-10 00:16:18 +02:00
|
|
|
/// Get the underlying elements of the Function... the basic block list is
|
|
|
|
/// empty for external functions.
|
2002-08-26 00:54:55 +02:00
|
|
|
///
|
2007-08-18 08:14:52 +02:00
|
|
|
const ArgumentListType &getArgumentList() const {
|
|
|
|
CheckLazyArguments();
|
|
|
|
return ArgumentList;
|
|
|
|
}
|
|
|
|
ArgumentListType &getArgumentList() {
|
|
|
|
CheckLazyArguments();
|
|
|
|
return ArgumentList;
|
|
|
|
}
|
2009-03-07 11:00:35 +01:00
|
|
|
static iplist<Argument> Function::*getSublistAccess(Argument*) {
|
|
|
|
return &Function::ArgumentList;
|
|
|
|
}
|
2001-06-28 01:26:41 +02:00
|
|
|
|
2002-06-25 18:12:52 +02:00
|
|
|
const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
|
|
|
|
BasicBlockListType &getBasicBlockList() { return BasicBlocks; }
|
2009-03-07 11:00:35 +01:00
|
|
|
static iplist<BasicBlock> Function::*getSublistAccess(BasicBlock*) {
|
|
|
|
return &Function::BasicBlocks;
|
|
|
|
}
|
2001-06-06 22:29:01 +02:00
|
|
|
|
2003-09-20 16:36:49 +02:00
|
|
|
const BasicBlock &getEntryBlock() const { return front(); }
|
|
|
|
BasicBlock &getEntryBlock() { return front(); }
|
2002-04-28 06:44:40 +02:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Symbol Table Accessing functions...
|
|
|
|
|
2002-11-20 19:07:48 +01:00
|
|
|
/// getSymbolTable() - Return the symbol table...
|
2002-08-26 00:54:55 +02:00
|
|
|
///
|
2007-02-05 21:47:22 +01:00
|
|
|
inline ValueSymbolTable &getValueSymbolTable() { return *SymTab; }
|
|
|
|
inline const ValueSymbolTable &getValueSymbolTable() const { return *SymTab; }
|
2002-04-28 06:44:40 +02:00
|
|
|
|
2005-04-21 22:19:05 +02:00
|
|
|
|
2001-06-28 01:26:41 +02:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// BasicBlock iterator forwarding functions
|
|
|
|
//
|
2002-06-25 18:12:52 +02:00
|
|
|
iterator begin() { return BasicBlocks.begin(); }
|
|
|
|
const_iterator begin() const { return BasicBlocks.begin(); }
|
|
|
|
iterator end () { return BasicBlocks.end(); }
|
|
|
|
const_iterator end () const { return BasicBlocks.end(); }
|
|
|
|
|
2004-11-15 20:02:35 +01:00
|
|
|
size_t size() const { return BasicBlocks.size(); }
|
2002-06-25 18:12:52 +02:00
|
|
|
bool empty() const { return BasicBlocks.empty(); }
|
|
|
|
const BasicBlock &front() const { return BasicBlocks.front(); }
|
|
|
|
BasicBlock &front() { return BasicBlocks.front(); }
|
2004-10-19 07:50:34 +02:00
|
|
|
const BasicBlock &back() const { return BasicBlocks.back(); }
|
|
|
|
BasicBlock &back() { return BasicBlocks.back(); }
|
2002-06-25 18:12:52 +02:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Argument iterator forwarding functions
|
|
|
|
//
|
2007-08-18 08:14:52 +02:00
|
|
|
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();
|
|
|
|
}
|
2005-03-15 00:49:40 +01:00
|
|
|
|
2007-08-18 08:14:52 +02:00
|
|
|
size_t arg_size() const;
|
|
|
|
bool arg_empty() const;
|
2005-03-15 00:49:40 +01:00
|
|
|
|
2003-10-22 18:03:20 +02:00
|
|
|
/// viewCFG - This function is meant for use from the debugger. You can just
|
|
|
|
/// say 'call F->viewCFG()' and a ghostview window should pop up from the
|
|
|
|
/// program, displaying the CFG of the current function with the code for each
|
|
|
|
/// basic block inside. This depends on there being a 'dot' and 'gv' program
|
|
|
|
/// in your path.
|
|
|
|
///
|
|
|
|
void viewCFG() const;
|
2005-04-21 22:19:05 +02:00
|
|
|
|
2003-10-22 18:03:20 +02:00
|
|
|
/// viewCFGOnly - This function is meant for use from the debugger. It works
|
|
|
|
/// just like viewCFG, but it does not include the contents of basic blocks
|
2004-03-01 19:31:19 +01:00
|
|
|
/// into the nodes, just the label. If you are only interested in the CFG
|
|
|
|
/// this can make the graph smaller.
|
2003-10-22 18:03:20 +02:00
|
|
|
///
|
|
|
|
void viewCFGOnly() const;
|
|
|
|
|
2002-08-26 00:54:55 +02:00
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2002-03-23 23:47:28 +01:00
|
|
|
static inline bool classof(const Function *) { return true; }
|
2001-10-02 05:41:24 +02:00
|
|
|
static inline bool classof(const Value *V) {
|
2007-04-13 20:12:09 +02:00
|
|
|
return V->getValueID() == Value::FunctionVal;
|
2001-10-01 18:18:37 +02:00
|
|
|
}
|
2001-06-06 22:29:01 +02:00
|
|
|
|
2003-09-17 06:58:43 +02:00
|
|
|
/// dropAllReferences() - This method causes all the subinstructions to "let
|
2002-08-26 00:54:55 +02:00
|
|
|
/// go" of all references that they are maintaining. This allows one to
|
2003-09-17 06:58:43 +02:00
|
|
|
/// 'delete' a whole module at a time, even though there may be circular
|
2002-08-26 00:54:55 +02:00
|
|
|
/// references... first all references are dropped, and all use counts go to
|
2004-03-01 19:31:19 +01:00
|
|
|
/// zero. Then everything is deleted for real. Note that no operations are
|
2005-04-21 22:19:05 +02:00
|
|
|
/// valid on an object that has "dropped all references", except operator
|
2002-08-26 00:54:55 +02:00
|
|
|
/// delete.
|
|
|
|
///
|
2003-09-17 06:58:43 +02:00
|
|
|
/// Since no other object in the module can have references into the body of a
|
|
|
|
/// function, dropping all references deletes the entire body of the function,
|
|
|
|
/// including any contained basic blocks.
|
|
|
|
///
|
2001-06-06 22:29:01 +02:00
|
|
|
void dropAllReferences();
|
2009-06-10 10:41:11 +02:00
|
|
|
|
|
|
|
/// hasAddressTaken - returns true if there are any uses of this function
|
|
|
|
/// other than direct calls or invokes to it.
|
|
|
|
bool hasAddressTaken() const;
|
2001-09-29 00:56:31 +02:00
|
|
|
};
|
|
|
|
|
2007-04-17 05:26:42 +02:00
|
|
|
inline ValueSymbolTable *
|
|
|
|
ilist_traits<BasicBlock>::getSymTab(Function *F) {
|
|
|
|
return F ? &F->getValueSymbolTable() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline ValueSymbolTable *
|
|
|
|
ilist_traits<Argument>::getSymTab(Function *F) {
|
|
|
|
return F ? &F->getValueSymbolTable() : 0;
|
|
|
|
}
|
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-06-06 22:29:01 +02:00
|
|
|
#endif
|