mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-04 17:56:53 +00:00
Add extra forwarding accessor methods so that getMethodList(), getBasicBlocks()
and getInstList() are obsolete... except for when modifying those lists. This makes code much more succinct and to the point. llvm-svn: 79
This commit is contained in:
parent
a58203d9fd
commit
b2d6da7f1e
@ -43,6 +43,12 @@ private :
|
||||
void setParent(Method *parent);
|
||||
|
||||
public:
|
||||
// Instruction iterators...
|
||||
typedef InstListType::iterator iterator;
|
||||
typedef InstListType::const_iterator const_iterator;
|
||||
typedef reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
typedef reverse_iterator<iterator> reverse_iterator;
|
||||
|
||||
typedef cfg::succ_iterator succ_iterator; // Include CFG.h to use these
|
||||
typedef cfg::pred_iterator pred_iterator;
|
||||
typedef cfg::succ_const_iterator succ_const_iterator;
|
||||
@ -57,9 +63,6 @@ public:
|
||||
const Method *getParent() const { return (const Method*)InstList.getParent();}
|
||||
Method *getParent() { return (Method*)InstList.getParent(); }
|
||||
|
||||
const InstListType &getInstList() const { return InstList; }
|
||||
InstListType &getInstList() { return InstList; }
|
||||
|
||||
// getTerminator() - If this is a well formed basic block, then this returns
|
||||
// a pointer to the terminator instruction. If it is not, then you get a null
|
||||
// pointer back.
|
||||
@ -67,6 +70,31 @@ public:
|
||||
TerminatorInst *getTerminator();
|
||||
const TerminatorInst *const getTerminator() const;
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Instruction iterator methods
|
||||
inline iterator begin() { return InstList.begin(); }
|
||||
inline const_iterator begin() const { return InstList.begin(); }
|
||||
inline iterator end () { return InstList.end(); }
|
||||
inline const_iterator end () const { return InstList.end(); }
|
||||
|
||||
inline reverse_iterator rbegin() { return InstList.rbegin(); }
|
||||
inline const_reverse_iterator rbegin() const { return InstList.rbegin(); }
|
||||
inline reverse_iterator rend () { return InstList.rend(); }
|
||||
inline const_reverse_iterator rend () const { return InstList.rend(); }
|
||||
|
||||
inline unsigned size() const { return InstList.size(); }
|
||||
inline bool empty() const { return InstList.empty(); }
|
||||
inline const Instruction *front() const { return InstList.front(); }
|
||||
inline Instruction *front() { return InstList.front(); }
|
||||
inline const Instruction *back() const { return InstList.back(); }
|
||||
inline Instruction *back() { return InstList.back(); }
|
||||
|
||||
// getInstList() - Return the underlying instruction list container. You need
|
||||
// to access it directly if you want to modify it currently.
|
||||
//
|
||||
const InstListType &getInstList() const { return InstList; }
|
||||
InstListType &getInstList() { return InstList; }
|
||||
|
||||
// hasConstantPoolReferences() - This predicate is true if there is a
|
||||
// reference to this basic block in the constant pool for this method. For
|
||||
// example, if a block is reached through a switch table, that table resides
|
||||
@ -96,7 +124,7 @@ public:
|
||||
// cause a degenerate basic block to be formed, having a terminator inside of
|
||||
// the basic block).
|
||||
//
|
||||
BasicBlock *splitBasicBlock(InstListType::iterator I);
|
||||
BasicBlock *splitBasicBlock(iterator I);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -28,7 +28,13 @@ class Method : public SymTabValue {
|
||||
public:
|
||||
typedef ValueHolder<MethodArgument, Method> ArgumentListType;
|
||||
typedef ValueHolder<BasicBlock , Method> BasicBlocksType;
|
||||
|
||||
// BasicBlock iterators...
|
||||
typedef BasicBlocksType::iterator iterator;
|
||||
typedef BasicBlocksType::const_iterator const_iterator;
|
||||
typedef reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
typedef reverse_iterator<iterator> reverse_iterator;
|
||||
|
||||
private:
|
||||
|
||||
// Important things that make up a method!
|
||||
@ -59,11 +65,34 @@ public:
|
||||
inline Module *getParent() { return Parent; }
|
||||
inline const Module *getParent() const { return Parent; }
|
||||
|
||||
// Get the underlying elements of the Method...
|
||||
inline const ArgumentListType &getArgumentList() const{ return ArgumentList; }
|
||||
inline ArgumentListType &getArgumentList() { return ArgumentList; }
|
||||
|
||||
inline const BasicBlocksType &getBasicBlocks() const { return BasicBlocks; }
|
||||
inline BasicBlocksType &getBasicBlocks() { return BasicBlocks; }
|
||||
|
||||
inline const ArgumentListType &getArgumentList() const{ return ArgumentList; }
|
||||
inline ArgumentListType &getArgumentList() { return ArgumentList; }
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// BasicBlock iterator forwarding functions
|
||||
//
|
||||
inline iterator begin() { return BasicBlocks.begin(); }
|
||||
inline const_iterator begin() const { return BasicBlocks.begin(); }
|
||||
inline iterator end () { return BasicBlocks.end(); }
|
||||
inline const_iterator end () const { return BasicBlocks.end(); }
|
||||
|
||||
inline reverse_iterator rbegin() { return BasicBlocks.rbegin(); }
|
||||
inline const_reverse_iterator rbegin() const { return BasicBlocks.rbegin(); }
|
||||
inline reverse_iterator rend () { return BasicBlocks.rend(); }
|
||||
inline const_reverse_iterator rend () const { return BasicBlocks.rend(); }
|
||||
|
||||
inline unsigned size() const { return BasicBlocks.size(); }
|
||||
inline bool empty() const { return BasicBlocks.empty(); }
|
||||
inline const BasicBlock *front() const { return BasicBlocks.front(); }
|
||||
inline BasicBlock *front() { return BasicBlocks.front(); }
|
||||
inline const BasicBlock *back() const { return BasicBlocks.back(); }
|
||||
inline BasicBlock *back() { return BasicBlocks.back(); }
|
||||
|
||||
|
||||
|
||||
// dropAllReferences() - This function causes all the subinstructions to "let
|
||||
@ -82,11 +111,10 @@ public:
|
||||
//
|
||||
template <class _BB_t, class _BB_i_t, class _BI_t, class _II_t>
|
||||
class InstIterator;
|
||||
typedef InstIterator<BasicBlocksType, BasicBlocksType::iterator,
|
||||
BasicBlock::InstListType::iterator,
|
||||
Instruction*> inst_iterator;
|
||||
typedef InstIterator<const BasicBlocksType, BasicBlocksType::const_iterator,
|
||||
BasicBlock::InstListType::const_iterator,
|
||||
typedef InstIterator<BasicBlocksType, iterator,
|
||||
BasicBlock::iterator, Instruction*> inst_iterator;
|
||||
typedef InstIterator<const BasicBlocksType, const_iterator,
|
||||
BasicBlock::const_iterator,
|
||||
const Instruction*> inst_const_iterator;
|
||||
|
||||
// This inner class is used to implement inst_begin() & inst_end() for
|
||||
@ -100,14 +128,14 @@ public:
|
||||
typedef _II_t IIty;
|
||||
_BB_t &BBs; // BasicBlocksType
|
||||
_BB_i_t BB; // BasicBlocksType::iterator
|
||||
_BI_t BI; // BasicBlock::InstListType::iterator
|
||||
_BI_t BI; // BasicBlock::iterator
|
||||
public:
|
||||
typedef bidirectional_iterator_tag iterator_category;
|
||||
|
||||
template<class M> InstIterator(M &m)
|
||||
: BBs(m.getBasicBlocks()), BB(BBs.begin()) { // begin ctor
|
||||
if (BB != BBs.end()) {
|
||||
BI = (*BB)->getInstList().begin();
|
||||
BI = (*BB)->begin();
|
||||
resyncInstructionIterator();
|
||||
}
|
||||
}
|
||||
@ -137,10 +165,10 @@ public:
|
||||
inline void resyncInstructionIterator() {
|
||||
// The only way that the II could be broken is if it is now pointing to
|
||||
// the end() of the current BasicBlock and there are successor BBs.
|
||||
while (BI == (*BB)->getInstList().end()) {
|
||||
while (BI == (*BB)->end()) {
|
||||
++BB;
|
||||
if (BB == BBs.end()) break;
|
||||
BI = (*BB)->getInstList().begin();
|
||||
BI = (*BB)->begin();
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,9 +182,9 @@ public:
|
||||
}
|
||||
|
||||
InstIterator& operator--() {
|
||||
while (BB == BBs.end() || BI == (*BB)->getInstList().begin()) {
|
||||
while (BB == BBs.end() || BI == (*BB)->begin()) {
|
||||
--BB;
|
||||
BI = (*BB)->getInstList().end();
|
||||
BI = (*BB)->end();
|
||||
}
|
||||
--BI;
|
||||
return *this;
|
||||
|
@ -14,6 +14,12 @@ class Method;
|
||||
class Module : public SymTabValue {
|
||||
public:
|
||||
typedef ValueHolder<Method, Module> MethodListType;
|
||||
|
||||
// Method iterators...
|
||||
typedef MethodListType::iterator iterator;
|
||||
typedef MethodListType::const_iterator const_iterator;
|
||||
typedef reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
typedef reverse_iterator<iterator> reverse_iterator;
|
||||
private:
|
||||
MethodListType MethodList; // The Methods
|
||||
|
||||
@ -21,9 +27,31 @@ public:
|
||||
Module();
|
||||
~Module();
|
||||
|
||||
// Get the underlying elements of the Module...
|
||||
inline const MethodListType &getMethodList() const { return MethodList; }
|
||||
inline MethodListType &getMethodList() { return MethodList; }
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Module iterator forwarding functions
|
||||
//
|
||||
inline iterator begin() { return MethodList.begin(); }
|
||||
inline const_iterator begin() const { return MethodList.begin(); }
|
||||
inline iterator end () { return MethodList.end(); }
|
||||
inline const_iterator end () const { return MethodList.end(); }
|
||||
|
||||
inline reverse_iterator rbegin() { return MethodList.rbegin(); }
|
||||
inline const_reverse_iterator rbegin() const { return MethodList.rbegin(); }
|
||||
inline reverse_iterator rend () { return MethodList.rend(); }
|
||||
inline const_reverse_iterator rend () const { return MethodList.rend(); }
|
||||
|
||||
inline unsigned size() const { return MethodList.size(); }
|
||||
inline bool empty() const { return MethodList.empty(); }
|
||||
inline const Method *front() const { return MethodList.front(); }
|
||||
inline Method *front() { return MethodList.front(); }
|
||||
inline const Method *back() const { return MethodList.back(); }
|
||||
inline Method *back() { return MethodList.back(); }
|
||||
|
||||
|
||||
// dropAllReferences() - This function causes all the subinstructions to "let
|
||||
// go" of all references that they are maintaining. This allows one to
|
||||
// 'delete' a whole class at a time, even though there may be circular
|
||||
|
Loading…
Reference in New Issue
Block a user