2002-09-06 20:47:31 +00:00
|
|
|
//===-- llvm/Function.h - Class to represent a single function --*- C++ -*-===//
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
2005-04-21 20:19:05 +00:00
|
|
|
// This file contains the declaration of the Function class, which represents a
|
2002-09-06 20:47:31 +00:00
|
|
|
// single function/procedure in LLVM.
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
2002-09-06 20:47:31 +00:00
|
|
|
// A function basically consists of a list of basic blocks, a list of arguments,
|
|
|
|
// and a symbol table.
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-03-23 22:47:28 +00:00
|
|
|
#ifndef LLVM_FUNCTION_H
|
|
|
|
#define LLVM_FUNCTION_H
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-10-03 14:53:21 +00:00
|
|
|
#include "llvm/GlobalValue.h"
|
2009-09-02 08:44:58 +00:00
|
|
|
#include "llvm/CallingConv.h"
|
2002-06-25 16:12:52 +00:00
|
|
|
#include "llvm/BasicBlock.h"
|
|
|
|
#include "llvm/Argument.h"
|
2008-09-23 23:03:40 +00:00
|
|
|
#include "llvm/Attributes.h"
|
2009-11-15 19:56:28 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2002-03-29 03:30:59 +00:00
|
|
|
class FunctionType;
|
2009-08-11 17:45:13 +00:00
|
|
|
class LLVMContext;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2009-03-01 09:45:52 +00:00
|
|
|
// Traits for intrusive list of basic blocks...
|
2002-06-25 16:12:52 +00:00
|
|
|
template<> struct ilist_traits<BasicBlock>
|
2007-04-17 03:26:42 +00:00
|
|
|
: public SymbolTableListTraits<BasicBlock, Function> {
|
2002-06-25 16:12:52 +00:00
|
|
|
|
2009-03-01 16:38:10 +00: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 14:47:45 +00:00
|
|
|
return static_cast<BasicBlock*>(&Sentinel);
|
2009-03-01 16:38:10 +00:00
|
|
|
}
|
|
|
|
static void destroySentinel(BasicBlock*) {}
|
2009-03-04 20:36:44 +00:00
|
|
|
|
|
|
|
BasicBlock *provideInitialHead() const { return createSentinel(); }
|
|
|
|
BasicBlock *ensureHead(BasicBlock*) const { return createSentinel(); }
|
2009-03-04 21:54:31 +00:00
|
|
|
static void noteHead(BasicBlock*, BasicBlock*) {}
|
2009-03-04 20:36:44 +00:00
|
|
|
|
2007-04-17 03:26:42 +00:00
|
|
|
static ValueSymbolTable *getSymTab(Function *ItemParent);
|
2009-03-01 16:38:10 +00:00
|
|
|
private:
|
2009-08-26 19:16:32 +00:00
|
|
|
mutable ilist_half_node<BasicBlock> Sentinel;
|
2002-06-25 16:12:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct ilist_traits<Argument>
|
2007-04-17 03:26:42 +00:00
|
|
|
: public SymbolTableListTraits<Argument, Function> {
|
2002-06-25 16:12:52 +00:00
|
|
|
|
2009-03-01 17:13:15 +00:00
|
|
|
Argument *createSentinel() const {
|
2009-03-02 14:47:45 +00:00
|
|
|
return static_cast<Argument*>(&Sentinel);
|
2009-03-01 17:13:15 +00:00
|
|
|
}
|
|
|
|
static void destroySentinel(Argument*) {}
|
2009-03-04 20:36:44 +00:00
|
|
|
|
|
|
|
Argument *provideInitialHead() const { return createSentinel(); }
|
|
|
|
Argument *ensureHead(Argument*) const { return createSentinel(); }
|
2009-03-04 21:54:31 +00:00
|
|
|
static void noteHead(Argument*, Argument*) {}
|
2009-03-04 20:36:44 +00:00
|
|
|
|
2007-04-17 03:26:42 +00:00
|
|
|
static ValueSymbolTable *getSymTab(Function *ItemParent);
|
2009-03-01 17:13:15 +00:00
|
|
|
private:
|
2009-08-26 19:16:32 +00:00
|
|
|
mutable ilist_half_node<Argument> Sentinel;
|
2002-06-25 16:12:52 +00:00
|
|
|
};
|
|
|
|
|
2009-07-31 18:16:33 +00:00
|
|
|
class Function : public GlobalValue,
|
2008-07-28 21:51:04 +00:00
|
|
|
public ilist_node<Function> {
|
2001-06-06 20:29:01 +00:00
|
|
|
public:
|
2002-06-25 16:12:52 +00:00
|
|
|
typedef iplist<Argument> ArgumentListType;
|
|
|
|
typedef iplist<BasicBlock> BasicBlockListType;
|
2001-06-27 23:26:41 +00:00
|
|
|
|
|
|
|
// BasicBlock iterators...
|
2002-06-25 16:12:52 +00:00
|
|
|
typedef BasicBlockListType::iterator iterator;
|
|
|
|
typedef BasicBlockListType::const_iterator const_iterator;
|
2001-06-27 23:26:41 +00:00
|
|
|
|
2005-03-14 23:49:40 +00:00
|
|
|
typedef ArgumentListType::iterator arg_iterator;
|
|
|
|
typedef ArgumentListType::const_iterator const_arg_iterator;
|
2002-06-25 16:12:52 +00:00
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
private:
|
2002-04-28 04:44:40 +00:00
|
|
|
// Important things that make up a function!
|
2007-08-18 06:14:52 +00:00
|
|
|
BasicBlockListType BasicBlocks; ///< The basic blocks
|
|
|
|
mutable ArgumentListType ArgumentList; ///< The formal arguments
|
|
|
|
ValueSymbolTable *SymTab; ///< Symbol table of args/instructions
|
2008-10-04 18:08:00 +00:00
|
|
|
AttrListPtr AttributeList; ///< Parameter attributes
|
2008-09-02 18:33:55 +00:00
|
|
|
|
2009-12-29 02:14:09 +00:00
|
|
|
// HasLazyArguments is stored in Value::SubclassData.
|
|
|
|
/*bool HasLazyArguments;*/
|
|
|
|
|
2007-04-17 04:31:29 +00:00
|
|
|
// The Calling Convention is stored in Value::SubclassData.
|
2009-09-02 08:44:58 +00:00
|
|
|
/*CallingConv::ID CallingConvention;*/
|
2005-04-21 20:19:05 +00:00
|
|
|
|
2007-04-17 03:26:42 +00:00
|
|
|
friend class SymbolTableListTraits<Function, Module>;
|
2002-06-25 16:12:52 +00:00
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
void setParent(Module *parent);
|
2007-04-28 13:45:00 +00:00
|
|
|
|
2007-08-18 06:14:52 +00: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 {
|
2009-12-29 02:14:09 +00:00
|
|
|
return getSubclassDataFromValue() & 1;
|
2007-08-18 06:14:52 +00:00
|
|
|
}
|
|
|
|
void CheckLazyArguments() const {
|
|
|
|
if (hasLazyArguments())
|
|
|
|
BuildLazyArguments();
|
|
|
|
}
|
|
|
|
void BuildLazyArguments() const;
|
2008-01-03 00:09:47 +00:00
|
|
|
|
|
|
|
Function(const Function&); // DO NOT IMPLEMENT
|
|
|
|
void operator=(const Function&); // DO NOT IMPLEMENT
|
2008-04-06 20:25:17 +00:00
|
|
|
|
2002-09-06 20:47:31 +00: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 20:28:45 +00:00
|
|
|
Function(const FunctionType *Ty, LinkageTypes Linkage,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &N = "", Module *M = 0);
|
2008-04-06 20:25:17 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
static Function *Create(const FunctionType *Ty, LinkageTypes Linkage,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &N = "", Module *M = 0) {
|
2008-04-06 20:25:17 +00:00
|
|
|
return new(0) Function(Ty, Linkage, N, M);
|
|
|
|
}
|
|
|
|
|
2007-12-10 02:14:30 +00:00
|
|
|
~Function();
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2002-03-29 03:30:59 +00:00
|
|
|
const Type *getReturnType() const; // Return the type of the ret val
|
|
|
|
const FunctionType *getFunctionType() const; // Return the FunctionType for me
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2009-07-02 18:03:58 +00: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-22 00:24:57 +00:00
|
|
|
LLVMContext &getContext() const;
|
2009-07-02 18:03:58 +00:00
|
|
|
|
2005-01-07 07:40:32 +00:00
|
|
|
/// isVarArg - Return true if this function takes a variable number of
|
|
|
|
/// arguments.
|
|
|
|
bool isVarArg() const;
|
|
|
|
|
2007-01-30 20:08:39 +00: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-25 22:54:55 +00:00
|
|
|
///
|
2007-01-30 20:08:39 +00:00
|
|
|
virtual bool isDeclaration() const { return BasicBlocks.empty(); }
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2003-05-08 03:34:12 +00:00
|
|
|
/// getIntrinsicID - This method returns the ID number of the specified
|
2003-11-11 22:41:34 +00:00
|
|
|
/// function, or Intrinsic::not_intrinsic if the function is not an
|
2003-05-08 03:34:12 +00: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.
|
|
|
|
///
|
2010-10-23 08:10:43 +00:00
|
|
|
unsigned getIntrinsicID() const LLVM_ATTRIBUTE_READONLY;
|
2003-05-08 03:34:12 +00:00
|
|
|
bool isIntrinsic() const { return getIntrinsicID() != 0; }
|
|
|
|
|
2009-09-02 08:44:58 +00:00
|
|
|
/// getCallingConv()/setCallingConv(CC) - These method get and set the
|
2005-05-06 20:26:26 +00:00
|
|
|
/// calling convention of this function. The enum values for the known
|
|
|
|
/// calling conventions are defined in CallingConv.h.
|
2009-09-02 08:44:58 +00:00
|
|
|
CallingConv::ID getCallingConv() const {
|
2009-12-29 02:14:09 +00:00
|
|
|
return static_cast<CallingConv::ID>(getSubclassDataFromValue() >> 1);
|
2009-09-02 08:44:58 +00:00
|
|
|
}
|
|
|
|
void setCallingConv(CallingConv::ID CC) {
|
2009-12-29 02:14:09 +00:00
|
|
|
setValueSubclassData((getSubclassDataFromValue() & 1) |
|
|
|
|
(static_cast<unsigned>(CC) << 1));
|
2007-08-18 06:14:52 +00:00
|
|
|
}
|
2010-01-21 20:10:22 +00:00
|
|
|
|
2008-10-04 18:08:00 +00:00
|
|
|
/// getAttributes - Return the attribute list for this Function.
|
2008-03-13 04:33:03 +00:00
|
|
|
///
|
2008-09-25 21:00:45 +00:00
|
|
|
const AttrListPtr &getAttributes() const { return AttributeList; }
|
2008-03-12 17:45:29 +00:00
|
|
|
|
2008-10-04 18:08:00 +00:00
|
|
|
/// setAttributes - Set the attribute list for this Function.
|
2008-03-13 04:33:03 +00:00
|
|
|
///
|
2008-09-25 21:00:45 +00:00
|
|
|
void setAttributes(const AttrListPtr &attrs) { AttributeList = attrs; }
|
2007-11-27 13:23:08 +00:00
|
|
|
|
2008-09-29 18:16:38 +00:00
|
|
|
/// hasFnAttr - Return true if this function has the given attribute.
|
2008-09-26 23:51:19 +00:00
|
|
|
bool hasFnAttr(Attributes N) const {
|
|
|
|
// Function Attributes are stored at ~0 index
|
|
|
|
return AttributeList.paramHasAttr(~0U, N);
|
2008-09-22 22:32:29 +00:00
|
|
|
}
|
|
|
|
|
2008-10-04 18:08:00 +00:00
|
|
|
/// addFnAttr - Add function attributes to this function.
|
2008-09-02 18:33:55 +00:00
|
|
|
///
|
2008-10-04 18:08:00 +00:00
|
|
|
void addFnAttr(Attributes N) {
|
2008-09-26 23:51:19 +00:00
|
|
|
// Function Attributes are stored at ~0 index
|
2008-10-07 22:33:44 +00:00
|
|
|
addAttribute(~0U, N);
|
2008-09-23 22:35:17 +00:00
|
|
|
}
|
2008-09-02 18:33:55 +00:00
|
|
|
|
2009-01-04 18:21:35 +00: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 18:44:35 +00: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 03:18:06 +00:00
|
|
|
|
2007-11-28 17:07:01 +00:00
|
|
|
/// @brief Determine whether the function has the given attribute.
|
2008-09-23 23:03:40 +00:00
|
|
|
bool paramHasAttr(unsigned i, Attributes attr) const {
|
2008-09-25 21:00:45 +00:00
|
|
|
return AttributeList.paramHasAttr(i, attr);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2008-05-16 20:39:43 +00:00
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// addAttribute - adds the attribute to the list of attributes.
|
|
|
|
void addAttribute(unsigned i, Attributes attr);
|
2008-01-02 23:42:30 +00:00
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// removeAttribute - removes the attribute from the list of attributes.
|
|
|
|
void removeAttribute(unsigned i, Attributes attr);
|
2008-07-08 09:41:30 +00:00
|
|
|
|
2008-02-22 17:49:45 +00:00
|
|
|
/// @brief Extract the alignment for a call or parameter (0=unknown).
|
2008-03-13 05:00:21 +00:00
|
|
|
unsigned getParamAlignment(unsigned i) const {
|
2008-09-25 21:00:45 +00:00
|
|
|
return AttributeList.getParamAlignment(i);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2008-02-22 17:49:45 +00:00
|
|
|
|
2007-12-03 20:06:50 +00:00
|
|
|
/// @brief Determine if the function does not access memory.
|
2008-03-13 05:00:21 +00:00
|
|
|
bool doesNotAccessMemory() const {
|
2009-01-04 18:21:35 +00:00
|
|
|
return hasFnAttr(Attribute::ReadNone);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2008-07-10 22:57:49 +00:00
|
|
|
void setDoesNotAccessMemory(bool DoesNotAccessMemory = true) {
|
2009-01-04 18:21:35 +00:00
|
|
|
if (DoesNotAccessMemory) addFnAttr(Attribute::ReadNone);
|
|
|
|
else removeFnAttr(Attribute::ReadNone);
|
2008-07-08 09:41:30 +00:00
|
|
|
}
|
2007-12-03 20:06:50 +00:00
|
|
|
|
|
|
|
/// @brief Determine if the function does not access or only reads memory.
|
2008-03-13 05:00:21 +00:00
|
|
|
bool onlyReadsMemory() const {
|
2009-01-04 18:21:35 +00:00
|
|
|
return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2008-07-10 22:57:49 +00:00
|
|
|
void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
|
2009-01-04 18:21:35 +00:00
|
|
|
if (OnlyReadsMemory) addFnAttr(Attribute::ReadOnly);
|
|
|
|
else removeFnAttr(Attribute::ReadOnly | Attribute::ReadNone);
|
2008-07-08 09:41:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Determine if the function cannot return.
|
|
|
|
bool doesNotReturn() const {
|
2009-01-04 18:21:35 +00:00
|
|
|
return hasFnAttr(Attribute::NoReturn);
|
2008-07-08 09:41:30 +00:00
|
|
|
}
|
2008-07-10 22:57:49 +00:00
|
|
|
void setDoesNotReturn(bool DoesNotReturn = true) {
|
2009-01-04 18:21:35 +00:00
|
|
|
if (DoesNotReturn) addFnAttr(Attribute::NoReturn);
|
|
|
|
else removeFnAttr(Attribute::NoReturn);
|
2008-07-08 09:41:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Determine if the function cannot unwind.
|
|
|
|
bool doesNotThrow() const {
|
2009-01-04 18:21:35 +00:00
|
|
|
return hasFnAttr(Attribute::NoUnwind);
|
2008-07-08 09:41:30 +00:00
|
|
|
}
|
2008-07-10 22:57:49 +00:00
|
|
|
void setDoesNotThrow(bool DoesNotThrow = true) {
|
2009-01-04 18:21:35 +00:00
|
|
|
if (DoesNotThrow) addFnAttr(Attribute::NoUnwind);
|
|
|
|
else removeFnAttr(Attribute::NoUnwind);
|
2008-07-08 09:41:30 +00:00
|
|
|
}
|
2007-12-03 20:06:50 +00:00
|
|
|
|
2008-03-03 21:46:28 +00:00
|
|
|
/// @brief Determine if the function returns a structure through first
|
|
|
|
/// pointer argument.
|
2008-03-13 05:00:21 +00:00
|
|
|
bool hasStructRetAttr() const {
|
2008-09-25 21:00:45 +00:00
|
|
|
return paramHasAttr(1, Attribute::StructRet);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2007-04-09 15:01:12 +00:00
|
|
|
|
2009-01-04 18:21:35 +00: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 19:58:59 +00: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 04:58:43 +00:00
|
|
|
/// deleteBody - This method deletes the body of the function, and converts
|
|
|
|
/// the linkage to external.
|
2004-03-01 18:31:19 +00:00
|
|
|
///
|
2003-09-17 04:58:43 +00:00
|
|
|
void deleteBody() {
|
|
|
|
dropAllReferences();
|
|
|
|
setLinkage(ExternalLinkage);
|
|
|
|
}
|
|
|
|
|
2004-10-11 22:21:13 +00:00
|
|
|
/// removeFromParent - This method unlinks 'this' from the containing module,
|
|
|
|
/// but does not delete it.
|
|
|
|
///
|
2008-08-29 07:30:15 +00:00
|
|
|
virtual void removeFromParent();
|
2004-10-11 22:21:13 +00:00
|
|
|
|
|
|
|
/// eraseFromParent - This method unlinks 'this' from the containing module
|
|
|
|
/// and deletes it.
|
|
|
|
///
|
2008-08-29 07:30:15 +00:00
|
|
|
virtual void eraseFromParent();
|
2004-10-11 22:21:13 +00:00
|
|
|
|
|
|
|
|
2003-05-09 22:16:18 +00:00
|
|
|
/// Get the underlying elements of the Function... the basic block list is
|
|
|
|
/// empty for external functions.
|
2002-08-25 22:54:55 +00:00
|
|
|
///
|
2007-08-18 06:14:52 +00:00
|
|
|
const ArgumentListType &getArgumentList() const {
|
|
|
|
CheckLazyArguments();
|
|
|
|
return ArgumentList;
|
|
|
|
}
|
|
|
|
ArgumentListType &getArgumentList() {
|
|
|
|
CheckLazyArguments();
|
|
|
|
return ArgumentList;
|
|
|
|
}
|
2009-03-07 10:00:35 +00:00
|
|
|
static iplist<Argument> Function::*getSublistAccess(Argument*) {
|
|
|
|
return &Function::ArgumentList;
|
|
|
|
}
|
2001-06-27 23:26:41 +00:00
|
|
|
|
2002-06-25 16:12:52 +00:00
|
|
|
const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
|
|
|
|
BasicBlockListType &getBasicBlockList() { return BasicBlocks; }
|
2009-03-07 10:00:35 +00:00
|
|
|
static iplist<BasicBlock> Function::*getSublistAccess(BasicBlock*) {
|
|
|
|
return &Function::BasicBlocks;
|
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2003-09-20 14:36:49 +00:00
|
|
|
const BasicBlock &getEntryBlock() const { return front(); }
|
|
|
|
BasicBlock &getEntryBlock() { return front(); }
|
2002-04-28 04:44:40 +00:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Symbol Table Accessing functions...
|
|
|
|
|
2002-11-20 18:07:48 +00:00
|
|
|
/// getSymbolTable() - Return the symbol table...
|
2002-08-25 22:54:55 +00:00
|
|
|
///
|
2007-02-05 20:47:22 +00:00
|
|
|
inline ValueSymbolTable &getValueSymbolTable() { return *SymTab; }
|
|
|
|
inline const ValueSymbolTable &getValueSymbolTable() const { return *SymTab; }
|
2002-04-28 04:44:40 +00:00
|
|
|
|
2005-04-21 20:19:05 +00:00
|
|
|
|
2001-06-27 23:26:41 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// BasicBlock iterator forwarding functions
|
|
|
|
//
|
2002-06-25 16:12:52 +00: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 19:02:35 +00:00
|
|
|
size_t size() const { return BasicBlocks.size(); }
|
2002-06-25 16:12:52 +00:00
|
|
|
bool empty() const { return BasicBlocks.empty(); }
|
|
|
|
const BasicBlock &front() const { return BasicBlocks.front(); }
|
|
|
|
BasicBlock &front() { return BasicBlocks.front(); }
|
2004-10-19 05:50:34 +00:00
|
|
|
const BasicBlock &back() const { return BasicBlocks.back(); }
|
|
|
|
BasicBlock &back() { return BasicBlocks.back(); }
|
2002-06-25 16:12:52 +00:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Argument iterator forwarding functions
|
|
|
|
//
|
2007-08-18 06:14:52 +00: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-14 23:49:40 +00:00
|
|
|
|
2007-08-18 06:14:52 +00:00
|
|
|
size_t arg_size() const;
|
|
|
|
bool arg_empty() const;
|
2005-03-14 23:49:40 +00:00
|
|
|
|
2003-10-22 16:03:20 +00: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 20:19:05 +00:00
|
|
|
|
2003-10-22 16:03:20 +00: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 18:31:19 +00:00
|
|
|
/// into the nodes, just the label. If you are only interested in the CFG
|
|
|
|
/// this can make the graph smaller.
|
2003-10-22 16:03:20 +00:00
|
|
|
///
|
|
|
|
void viewCFGOnly() const;
|
|
|
|
|
2002-08-25 22:54:55 +00:00
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2002-03-23 22:47:28 +00:00
|
|
|
static inline bool classof(const Function *) { return true; }
|
2001-10-02 03:41:24 +00:00
|
|
|
static inline bool classof(const Value *V) {
|
2007-04-13 18:12:09 +00:00
|
|
|
return V->getValueID() == Value::FunctionVal;
|
2001-10-01 16:18:37 +00:00
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2003-09-17 04:58:43 +00:00
|
|
|
/// dropAllReferences() - This method causes all the subinstructions to "let
|
2002-08-25 22:54:55 +00:00
|
|
|
/// go" of all references that they are maintaining. This allows one to
|
2003-09-17 04:58:43 +00:00
|
|
|
/// 'delete' a whole module at a time, even though there may be circular
|
2002-08-25 22:54:55 +00:00
|
|
|
/// references... first all references are dropped, and all use counts go to
|
2004-03-01 18:31:19 +00:00
|
|
|
/// zero. Then everything is deleted for real. Note that no operations are
|
2005-04-21 20:19:05 +00:00
|
|
|
/// valid on an object that has "dropped all references", except operator
|
2002-08-25 22:54:55 +00:00
|
|
|
/// delete.
|
|
|
|
///
|
2003-09-17 04:58:43 +00: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 20:29:01 +00:00
|
|
|
void dropAllReferences();
|
2009-06-10 08:41:11 +00:00
|
|
|
|
|
|
|
/// hasAddressTaken - returns true if there are any uses of this function
|
2010-03-24 13:21:49 +00:00
|
|
|
/// other than direct calls or invokes to it. Optionally passes back the
|
|
|
|
/// offending user for diagnostic purposes.
|
|
|
|
///
|
|
|
|
bool hasAddressTaken(const User** = 0) const;
|
|
|
|
|
2009-12-29 02:14:09 +00:00
|
|
|
private:
|
|
|
|
// Shadow Value::setValueSubclassData with a private forwarding method so that
|
|
|
|
// subclasses cannot accidentally use it.
|
|
|
|
void setValueSubclassData(unsigned short D) {
|
|
|
|
Value::setValueSubclassData(D);
|
|
|
|
}
|
2001-09-28 22:56:31 +00:00
|
|
|
};
|
|
|
|
|
2007-04-17 03:26:42 +00: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 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
#endif
|