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
|
|
|
|
2002-06-25 16:12:52 +00:00
|
|
|
#include "llvm/Argument.h"
|
2008-09-23 23:03:40 +00:00
|
|
|
#include "llvm/Attributes.h"
|
2012-12-03 17:02:12 +00:00
|
|
|
#include "llvm/BasicBlock.h"
|
|
|
|
#include "llvm/CallingConv.h"
|
|
|
|
#include "llvm/GlobalValue.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
|
2012-12-07 23:16:57 +00:00
|
|
|
AttributeSet 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;*/
|
2012-12-17 20:40:14 +00:00
|
|
|
|
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;
|
2012-09-17 07:16:40 +00:00
|
|
|
|
|
|
|
Function(const Function&) LLVM_DELETED_FUNCTION;
|
|
|
|
void operator=(const Function&) LLVM_DELETED_FUNCTION;
|
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.
|
|
|
|
///
|
2011-07-18 04:54:35 +00:00
|
|
|
Function(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:
|
2011-07-18 04:54:35 +00:00
|
|
|
static Function *Create(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
|
|
|
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134829 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-09 17:41:24 +00:00
|
|
|
Type *getReturnType() const; // Return the type of the ret val
|
|
|
|
FunctionType *getFunctionType() const; // Return the FunctionType for me
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2012-12-17 20:40:14 +00:00
|
|
|
/// getContext - Return a pointer to the LLVMContext associated with this
|
2009-07-02 18:03:58 +00:00
|
|
|
/// 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;
|
|
|
|
|
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.
|
|
|
|
///
|
2012-03-09 16:30:33 +00:00
|
|
|
unsigned getIntrinsicID() const LLVM_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
|
|
|
}
|
2012-12-17 20:40:14 +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
|
|
|
///
|
2012-12-07 23:16:57 +00:00
|
|
|
const AttributeSet &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
|
|
|
///
|
2012-12-07 23:16:57 +00:00
|
|
|
void setAttributes(const AttributeSet &attrs) { AttributeList = attrs; }
|
2007-11-27 13:23:08 +00:00
|
|
|
|
2012-09-26 21:48:26 +00:00
|
|
|
/// getFnAttributes - Return the function attributes for querying.
|
|
|
|
///
|
2012-12-19 07:18:57 +00:00
|
|
|
Attribute getFnAttributes() const {
|
2012-09-26 21:48:26 +00:00
|
|
|
return AttributeList.getFnAttributes();
|
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
|
|
|
///
|
2012-12-19 07:18:57 +00:00
|
|
|
void addFnAttr(Attribute::AttrVal N) {
|
|
|
|
// Function Attribute are stored at ~0 index
|
|
|
|
addAttribute(AttributeSet::FunctionIndex, Attribute::get(getContext(), 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.
|
|
|
|
///
|
2012-12-19 07:18:57 +00:00
|
|
|
void removeFnAttr(Attribute N) {
|
|
|
|
// Function Attribute are stored at ~0 index
|
2009-01-04 18:21:35 +00:00
|
|
|
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
|
|
|
|
2012-10-03 21:19:35 +00:00
|
|
|
|
|
|
|
/// getRetAttributes - Return the return attributes for querying.
|
2012-12-19 07:18:57 +00:00
|
|
|
Attribute getRetAttributes() const {
|
2012-10-03 21:19:35 +00:00
|
|
|
return AttributeList.getRetAttributes();
|
|
|
|
}
|
|
|
|
|
2012-09-26 21:48:26 +00:00
|
|
|
/// getParamAttributes - Return the parameter attributes for querying.
|
2012-12-19 07:18:57 +00:00
|
|
|
Attribute getParamAttributes(unsigned Idx) const {
|
2012-09-26 21:48:26 +00:00
|
|
|
return AttributeList.getParamAttributes(Idx);
|
|
|
|
}
|
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// addAttribute - adds the attribute to the list of attributes.
|
2012-12-19 07:18:57 +00:00
|
|
|
void addAttribute(unsigned i, Attribute attr);
|
2012-12-17 20:40:14 +00:00
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// removeAttribute - removes the attribute from the list of attributes.
|
2012-12-19 07:18:57 +00:00
|
|
|
void removeAttribute(unsigned i, Attribute 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 {
|
2012-12-19 07:18:57 +00:00
|
|
|
return getFnAttributes().hasAttribute(Attribute::ReadNone);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2012-10-10 03:12:49 +00:00
|
|
|
void setDoesNotAccessMemory() {
|
2012-12-19 07:18:57 +00:00
|
|
|
addFnAttr(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 {
|
2012-10-09 07:45:08 +00:00
|
|
|
return doesNotAccessMemory() ||
|
2012-12-19 07:18:57 +00:00
|
|
|
getFnAttributes().hasAttribute(Attribute::ReadOnly);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2012-10-10 03:12:49 +00:00
|
|
|
void setOnlyReadsMemory() {
|
2012-12-19 07:18:57 +00:00
|
|
|
addFnAttr(Attribute::ReadOnly);
|
2008-07-08 09:41:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Determine if the function cannot return.
|
|
|
|
bool doesNotReturn() const {
|
2012-12-19 07:18:57 +00:00
|
|
|
return getFnAttributes().hasAttribute(Attribute::NoReturn);
|
2008-07-08 09:41:30 +00:00
|
|
|
}
|
2012-10-10 03:12:49 +00:00
|
|
|
void setDoesNotReturn() {
|
2012-12-19 07:18:57 +00:00
|
|
|
addFnAttr(Attribute::NoReturn);
|
2008-07-08 09:41:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Determine if the function cannot unwind.
|
|
|
|
bool doesNotThrow() const {
|
2012-12-19 07:18:57 +00:00
|
|
|
return getFnAttributes().hasAttribute(Attribute::NoUnwind);
|
2008-07-08 09:41:30 +00:00
|
|
|
}
|
2012-10-10 03:12:49 +00:00
|
|
|
void setDoesNotThrow() {
|
2012-12-19 07:18:57 +00:00
|
|
|
addFnAttr(Attribute::NoUnwind);
|
2008-07-08 09:41:30 +00:00
|
|
|
}
|
2007-12-03 20:06:50 +00:00
|
|
|
|
2011-05-25 12:54:08 +00:00
|
|
|
/// @brief True if the ABI mandates (or the user requested) that this
|
|
|
|
/// function be in a unwind table.
|
2011-05-25 03:44:17 +00:00
|
|
|
bool hasUWTable() const {
|
2012-12-19 07:18:57 +00:00
|
|
|
return getFnAttributes().hasAttribute(Attribute::UWTable);
|
2011-05-25 03:44:17 +00:00
|
|
|
}
|
2012-10-10 03:12:49 +00:00
|
|
|
void setHasUWTable() {
|
2012-12-19 07:18:57 +00:00
|
|
|
addFnAttr(Attribute::UWTable);
|
2011-05-25 03:44:17 +00:00
|
|
|
}
|
|
|
|
|
2011-05-25 12:54:08 +00:00
|
|
|
/// @brief True if this function needs an unwind table.
|
2011-05-25 03:44:17 +00:00
|
|
|
bool needsUnwindTableEntry() const {
|
|
|
|
return hasUWTable() || !doesNotThrow();
|
|
|
|
}
|
|
|
|
|
2012-12-17 20:40:14 +00:00
|
|
|
/// @brief Determine if the function returns a structure through first
|
2008-03-03 21:46:28 +00:00
|
|
|
/// pointer argument.
|
2008-03-13 05:00:21 +00:00
|
|
|
bool hasStructRetAttr() const {
|
2012-12-19 07:18:57 +00:00
|
|
|
return getParamAttributes(1).hasAttribute(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 {
|
2012-12-19 07:18:57 +00:00
|
|
|
return getParamAttributes(n).hasAttribute(Attribute::NoAlias);
|
2009-01-04 18:21:35 +00:00
|
|
|
}
|
2012-10-10 06:13:42 +00:00
|
|
|
void setDoesNotAlias(unsigned n) {
|
2012-12-19 07:18:57 +00:00
|
|
|
addAttribute(n, Attribute::get(getContext(), Attribute::NoAlias));
|
2009-01-04 18:21:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @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 {
|
2012-12-19 07:18:57 +00:00
|
|
|
return getParamAttributes(n).hasAttribute(Attribute::NoCapture);
|
2009-01-04 18:21:35 +00:00
|
|
|
}
|
2012-10-10 06:13:42 +00:00
|
|
|
void setDoesNotCapture(unsigned n) {
|
2012-12-19 07:18:57 +00:00
|
|
|
addAttribute(n, Attribute::get(getContext(), Attribute::NoCapture));
|
2009-01-04 18:21:35 +00:00
|
|
|
}
|
|
|
|
|
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:
|
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
|
2012-05-12 08:30:16 +00:00
|
|
|
/// other than direct calls or invokes to it, or blockaddress expressions.
|
|
|
|
/// Optionally passes back an offending user for diagnostic purposes.
|
2010-03-24 13:21:49 +00:00
|
|
|
///
|
|
|
|
bool hasAddressTaken(const User** = 0) const;
|
|
|
|
|
2011-10-20 05:23:42 +00:00
|
|
|
/// isDefTriviallyDead - Return true if it is trivially safe to remove
|
|
|
|
/// this function definition from the module (because it isn't externally
|
|
|
|
/// visible, does not have its address taken, and has no callers). To make
|
|
|
|
/// this more accurate, call removeDeadConstantUsers first.
|
|
|
|
bool isDefTriviallyDead() const;
|
|
|
|
|
2011-10-17 18:43:40 +00:00
|
|
|
/// callsFunctionThatReturnsTwice - Return true if the function has a call to
|
|
|
|
/// setjmp or other function that gcc recognizes as "returning twice".
|
|
|
|
bool callsFunctionThatReturnsTwice() 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
|