1 //===-- llvm/Function.h - Class to represent a single VM function -*- C++ -*-=//
3 // This file contains the declaration of the Function class, which represents a
4 // single function/procedure in the VM.
6 // Note that basic blocks in the method are value's, because they are referenced
7 // by instructions like calls and can go into virtual function tables and stuff.
9 //===----------------------------------------------------------------------===//
11 #ifndef LLVM_FUNCTION_H
12 #define LLVM_FUNCTION_H
14 #include "llvm/SymTabValue.h"
15 #include "llvm/GlobalValue.h"
16 #include "llvm/ValueHolder.h"
20 class Function : public GlobalValue, public SymTabValue {
22 typedef ValueHolder<FunctionArgument, Function, Function> ArgumentListType;
23 typedef ValueHolder<BasicBlock , Function, Function> BasicBlocksType;
25 // BasicBlock iterators...
26 typedef BasicBlocksType::iterator iterator;
27 typedef BasicBlocksType::const_iterator const_iterator;
28 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
29 typedef std::reverse_iterator<iterator> reverse_iterator;
33 // Important things that make up a method!
34 BasicBlocksType BasicBlocks; // The basic blocks
35 ArgumentListType ArgumentList; // The formal arguments
37 friend class ValueHolder<Function, Module, Module>;
38 void setParent(Module *parent);
41 Function(const FunctionType *Ty, bool isInternal, const std::string &N = "");
44 // Specialize setName to handle symbol table majik...
45 virtual void setName(const std::string &name, SymbolTable *ST = 0);
47 const Type *getReturnType() const; // Return the type of the ret val
48 const FunctionType *getFunctionType() const; // Return the FunctionType for me
50 // Is the body of this method unknown? (the basic block list is empty if so)
51 // this is true for external methods, defined as forward "declare"ations
52 bool isExternal() const { return BasicBlocks.empty(); }
54 // Get the underlying elements of the Function... both the argument list and
55 // basic block list are empty for external methods.
57 inline const ArgumentListType &getArgumentList() const{ return ArgumentList; }
58 inline ArgumentListType &getArgumentList() { return ArgumentList; }
60 inline const BasicBlocksType &getBasicBlocks() const { return BasicBlocks; }
61 inline BasicBlocksType &getBasicBlocks() { return BasicBlocks; }
63 inline const BasicBlock *getEntryNode() const { return front(); }
64 inline BasicBlock *getEntryNode() { return front(); }
66 //===--------------------------------------------------------------------===//
67 // BasicBlock iterator forwarding functions
69 inline iterator begin() { return BasicBlocks.begin(); }
70 inline const_iterator begin() const { return BasicBlocks.begin(); }
71 inline iterator end () { return BasicBlocks.end(); }
72 inline const_iterator end () const { return BasicBlocks.end(); }
74 inline reverse_iterator rbegin() { return BasicBlocks.rbegin(); }
75 inline const_reverse_iterator rbegin() const { return BasicBlocks.rbegin(); }
76 inline reverse_iterator rend () { return BasicBlocks.rend(); }
77 inline const_reverse_iterator rend () const { return BasicBlocks.rend(); }
79 inline unsigned size() const { return BasicBlocks.size(); }
80 inline bool empty() const { return BasicBlocks.empty(); }
81 inline const BasicBlock *front() const { return BasicBlocks.front(); }
82 inline BasicBlock *front() { return BasicBlocks.front(); }
83 inline const BasicBlock *back() const { return BasicBlocks.back(); }
84 inline BasicBlock *back() { return BasicBlocks.back(); }
86 virtual void print(std::ostream &OS) const;
88 // Methods for support type inquiry through isa, cast, and dyn_cast:
89 static inline bool classof(const Function *) { return true; }
90 static inline bool classof(const Value *V) {
91 return V->getValueType() == Value::FunctionVal;
94 // dropAllReferences() - This function causes all the subinstructions to "let
95 // go" of all references that they are maintaining. This allows one to
96 // 'delete' a whole class at a time, even though there may be circular
97 // references... first all references are dropped, and all use counts go to
98 // zero. Then everything is delete'd for real. Note that no operations are
99 // valid on an object that has "dropped all references", except operator
102 void dropAllReferences();