2002-10-28 01:21:55 +00:00
|
|
|
//===-- llvm/CodeGen/MachineBasicBlock.h ------------------------*- C++ -*-===//
|
2005-04-21 20:39:54 +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:39:54 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2005-04-21 20:39:54 +00:00
|
|
|
//
|
2002-10-27 20:49:47 +00:00
|
|
|
// Collect the sequence of machine instructions for a basic block.
|
|
|
|
//
|
2002-10-28 01:21:55 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-07-08 22:40:34 +00:00
|
|
|
|
2002-10-28 00:28:31 +00:00
|
|
|
#ifndef LLVM_CODEGEN_MACHINEBASICBLOCK_H
|
|
|
|
#define LLVM_CODEGEN_MACHINEBASICBLOCK_H
|
2002-07-08 22:40:34 +00:00
|
|
|
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/ADT/GraphTraits.h"
|
2012-12-03 17:02:12 +00:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2011-06-16 20:22:37 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2011-03-04 00:15:36 +00:00
|
|
|
#include <functional>
|
2003-11-11 22:41:34 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2008-07-28 21:51:04 +00:00
|
|
|
|
2010-06-22 17:25:57 +00:00
|
|
|
class Pass;
|
2008-07-28 21:51:04 +00:00
|
|
|
class BasicBlock;
|
|
|
|
class MachineFunction;
|
2010-02-10 01:04:16 +00:00
|
|
|
class MCSymbol;
|
2010-10-26 20:21:46 +00:00
|
|
|
class SlotIndexes;
|
2010-02-10 01:04:16 +00:00
|
|
|
class StringRef;
|
2009-07-24 10:36:58 +00:00
|
|
|
class raw_ostream;
|
2011-06-16 20:22:37 +00:00
|
|
|
class MachineBranchProbabilityInfo;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2004-02-12 19:12:03 +00:00
|
|
|
template <>
|
2008-09-20 18:02:18 +00:00
|
|
|
struct ilist_traits<MachineInstr> : public ilist_default_traits<MachineInstr> {
|
|
|
|
private:
|
2009-08-26 19:16:32 +00:00
|
|
|
mutable ilist_half_node<MachineInstr> Sentinel;
|
2008-07-28 21:51:04 +00:00
|
|
|
|
2008-07-07 23:14:23 +00:00
|
|
|
// this is only set by the MachineBasicBlock owning the LiveList
|
2004-02-12 19:12:03 +00:00
|
|
|
friend class MachineBasicBlock;
|
2008-07-07 23:14:23 +00:00
|
|
|
MachineBasicBlock* Parent;
|
2004-02-12 19:12:03 +00:00
|
|
|
|
2008-07-07 23:14:23 +00:00
|
|
|
public:
|
2009-03-04 06:57:48 +00:00
|
|
|
MachineInstr *createSentinel() const {
|
|
|
|
return static_cast<MachineInstr*>(&Sentinel);
|
|
|
|
}
|
2008-07-28 21:51:04 +00:00
|
|
|
void destroySentinel(MachineInstr *) const {}
|
2004-02-12 19:12:03 +00:00
|
|
|
|
2009-03-04 20:36:44 +00:00
|
|
|
MachineInstr *provideInitialHead() const { return createSentinel(); }
|
|
|
|
MachineInstr *ensureHead(MachineInstr*) const { return createSentinel(); }
|
2009-03-04 21:54:31 +00:00
|
|
|
static void noteHead(MachineInstr*, MachineInstr*) {}
|
2009-03-04 20:36:44 +00:00
|
|
|
|
2004-02-16 07:17:43 +00:00
|
|
|
void addNodeToList(MachineInstr* N);
|
|
|
|
void removeNodeFromList(MachineInstr* N);
|
2008-07-28 21:51:04 +00:00
|
|
|
void transferNodesFromList(ilist_traits &SrcTraits,
|
|
|
|
ilist_iterator<MachineInstr> first,
|
|
|
|
ilist_iterator<MachineInstr> last);
|
2008-07-07 23:14:23 +00:00
|
|
|
void deleteNode(MachineInstr *N);
|
2008-07-28 21:51:04 +00:00
|
|
|
private:
|
|
|
|
void createNode(const MachineInstr &);
|
2004-02-12 19:12:03 +00:00
|
|
|
};
|
|
|
|
|
2008-07-28 21:51:04 +00:00
|
|
|
class MachineBasicBlock : public ilist_node<MachineBasicBlock> {
|
|
|
|
typedef ilist<MachineInstr> Instructions;
|
2004-02-12 02:27:10 +00:00
|
|
|
Instructions Insts;
|
2003-07-26 23:30:37 +00:00
|
|
|
const BasicBlock *BB;
|
2004-05-12 21:35:20 +00:00
|
|
|
int Number;
|
2007-12-31 04:56:33 +00:00
|
|
|
MachineFunction *xParent;
|
2011-06-16 20:22:37 +00:00
|
|
|
|
2007-02-10 02:38:19 +00:00
|
|
|
/// Predecessors/Successors - Keep track of the predecessor / successor
|
|
|
|
/// basicblocks.
|
|
|
|
std::vector<MachineBasicBlock *> Predecessors;
|
|
|
|
std::vector<MachineBasicBlock *> Successors;
|
|
|
|
|
2011-06-16 20:22:37 +00:00
|
|
|
/// Weights - Keep track of the weights to the successors. This vector
|
|
|
|
/// has the same order as Successors, or it is empty if we don't use it
|
|
|
|
/// (disable optimization).
|
|
|
|
std::vector<uint32_t> Weights;
|
|
|
|
typedef std::vector<uint32_t>::iterator weight_iterator;
|
2011-12-20 20:03:10 +00:00
|
|
|
typedef std::vector<uint32_t>::const_iterator const_weight_iterator;
|
2011-06-16 20:22:37 +00:00
|
|
|
|
2007-02-10 02:38:19 +00:00
|
|
|
/// LiveIns - Keep track of the physical registers that are livein of
|
|
|
|
/// the basicblock.
|
|
|
|
std::vector<unsigned> LiveIns;
|
2008-02-28 00:43:03 +00:00
|
|
|
|
|
|
|
/// Alignment - Alignment of the basic block. Zero if the basic block does
|
|
|
|
/// not need to be aligned.
|
2011-12-06 01:26:19 +00:00
|
|
|
/// The alignment is specified as log2(bytes).
|
2008-02-28 00:43:03 +00:00
|
|
|
unsigned Alignment;
|
2011-12-06 01:26:19 +00:00
|
|
|
|
2007-02-21 22:39:52 +00:00
|
|
|
/// IsLandingPad - Indicate that this basic block is entered via an
|
|
|
|
/// exception handler.
|
|
|
|
bool IsLandingPad;
|
2007-02-10 02:38:19 +00:00
|
|
|
|
2009-10-30 01:27:03 +00:00
|
|
|
/// AddressTaken - Indicate that this basic block is potentially the
|
|
|
|
/// target of an indirect branch.
|
|
|
|
bool AddressTaken;
|
|
|
|
|
2013-04-22 21:21:08 +00:00
|
|
|
/// \brief since getSymbol is a relatively heavy-weight operation, the symbol
|
|
|
|
/// is only computed once and is cached.
|
|
|
|
mutable MCSymbol *CachedMCSymbol;
|
|
|
|
|
2008-07-28 21:51:04 +00:00
|
|
|
// Intrusive list support
|
|
|
|
MachineBasicBlock() {}
|
|
|
|
|
2008-07-07 23:14:23 +00:00
|
|
|
explicit MachineBasicBlock(MachineFunction &mf, const BasicBlock *bb);
|
|
|
|
|
2008-07-17 23:49:46 +00:00
|
|
|
~MachineBasicBlock();
|
2004-05-24 07:14:35 +00:00
|
|
|
|
2008-07-07 23:14:23 +00:00
|
|
|
// MachineBasicBlocks are allocated and owned by MachineFunction.
|
|
|
|
friend class MachineFunction;
|
2005-04-21 20:39:54 +00:00
|
|
|
|
2008-07-07 23:14:23 +00:00
|
|
|
public:
|
2002-10-28 05:30:46 +00:00
|
|
|
/// getBasicBlock - Return the LLVM basic block that this instance
|
2009-11-20 01:17:03 +00:00
|
|
|
/// corresponded to originally. Note that this may be NULL if this instance
|
|
|
|
/// does not correspond directly to an LLVM basic block.
|
2002-10-28 05:30:46 +00:00
|
|
|
///
|
2003-07-26 23:30:37 +00:00
|
|
|
const BasicBlock *getBasicBlock() const { return BB; }
|
2004-02-19 16:13:54 +00:00
|
|
|
|
2009-11-20 01:17:03 +00:00
|
|
|
/// getName - Return the name of the corresponding LLVM basic block, or
|
|
|
|
/// "(null)".
|
|
|
|
StringRef getName() const;
|
|
|
|
|
2012-03-07 00:18:18 +00:00
|
|
|
/// getFullName - Return a formatted string to identify this block and its
|
|
|
|
/// parent function.
|
|
|
|
std::string getFullName() const;
|
|
|
|
|
2009-10-30 01:27:03 +00:00
|
|
|
/// hasAddressTaken - Test whether this block is potentially the target
|
|
|
|
/// of an indirect branch.
|
|
|
|
bool hasAddressTaken() const { return AddressTaken; }
|
|
|
|
|
|
|
|
/// setHasAddressTaken - Set this block to reflect that it potentially
|
|
|
|
/// is the target of an indirect branch.
|
|
|
|
void setHasAddressTaken() { AddressTaken = true; }
|
|
|
|
|
2004-02-19 16:13:54 +00:00
|
|
|
/// getParent - Return the MachineFunction containing this basic block.
|
|
|
|
///
|
2007-12-31 04:56:33 +00:00
|
|
|
const MachineFunction *getParent() const { return xParent; }
|
|
|
|
MachineFunction *getParent() { return xParent; }
|
2004-02-19 16:13:54 +00:00
|
|
|
|
2011-12-06 22:12:01 +00:00
|
|
|
|
|
|
|
/// bundle_iterator - MachineBasicBlock iterator that automatically skips over
|
|
|
|
/// MIs that are inside bundles (i.e. walk top level MIs only).
|
|
|
|
template<typename Ty, typename IterTy>
|
|
|
|
class bundle_iterator
|
|
|
|
: public std::iterator<std::bidirectional_iterator_tag, Ty, ptrdiff_t> {
|
|
|
|
IterTy MII;
|
|
|
|
|
|
|
|
public:
|
2012-06-11 15:11:12 +00:00
|
|
|
bundle_iterator(IterTy mii) : MII(mii) {}
|
2011-12-06 22:12:01 +00:00
|
|
|
|
|
|
|
bundle_iterator(Ty &mi) : MII(mi) {
|
2012-12-18 23:21:49 +00:00
|
|
|
assert(!mi.isBundledWithPred() &&
|
2011-12-06 22:12:01 +00:00
|
|
|
"It's not legal to initialize bundle_iterator with a bundled MI");
|
|
|
|
}
|
|
|
|
bundle_iterator(Ty *mi) : MII(mi) {
|
2012-12-18 23:21:49 +00:00
|
|
|
assert((!mi || !mi->isBundledWithPred()) &&
|
2011-12-06 22:12:01 +00:00
|
|
|
"It's not legal to initialize bundle_iterator with a bundled MI");
|
|
|
|
}
|
2012-04-20 20:05:19 +00:00
|
|
|
// Template allows conversion from const to nonconst.
|
|
|
|
template<class OtherTy, class OtherIterTy>
|
|
|
|
bundle_iterator(const bundle_iterator<OtherTy, OtherIterTy> &I)
|
|
|
|
: MII(I.getInstrIterator()) {}
|
2014-04-14 00:51:57 +00:00
|
|
|
bundle_iterator() : MII(nullptr) {}
|
2011-12-06 22:12:01 +00:00
|
|
|
|
|
|
|
Ty &operator*() const { return *MII; }
|
|
|
|
Ty *operator->() const { return &operator*(); }
|
|
|
|
|
|
|
|
operator Ty*() const { return MII; }
|
|
|
|
|
|
|
|
bool operator==(const bundle_iterator &x) const {
|
|
|
|
return MII == x.MII;
|
|
|
|
}
|
|
|
|
bool operator!=(const bundle_iterator &x) const {
|
|
|
|
return !operator==(x);
|
|
|
|
}
|
2012-01-31 19:47:32 +00:00
|
|
|
|
2011-12-06 22:12:01 +00:00
|
|
|
// Increment and decrement operators...
|
|
|
|
bundle_iterator &operator--() { // predecrement - Back up
|
2012-06-11 15:11:12 +00:00
|
|
|
do --MII;
|
2012-12-18 23:21:49 +00:00
|
|
|
while (MII->isBundledWithPred());
|
2011-12-06 22:12:01 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
bundle_iterator &operator++() { // preincrement - Advance
|
2012-12-18 23:21:49 +00:00
|
|
|
while (MII->isBundledWithSucc())
|
|
|
|
++MII;
|
|
|
|
++MII;
|
2011-12-06 22:12:01 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
bundle_iterator operator--(int) { // postdecrement operators...
|
|
|
|
bundle_iterator tmp = *this;
|
2012-06-11 15:11:12 +00:00
|
|
|
--*this;
|
2011-12-06 22:12:01 +00:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
bundle_iterator operator++(int) { // postincrement operators...
|
|
|
|
bundle_iterator tmp = *this;
|
2012-06-11 15:11:12 +00:00
|
|
|
++*this;
|
2011-12-06 22:12:01 +00:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2011-12-14 02:11:42 +00:00
|
|
|
IterTy getInstrIterator() const {
|
2011-12-06 22:12:01 +00:00
|
|
|
return MII;
|
2012-01-31 19:47:32 +00:00
|
|
|
}
|
2011-12-06 22:12:01 +00:00
|
|
|
};
|
|
|
|
|
2011-12-14 02:11:42 +00:00
|
|
|
typedef Instructions::iterator instr_iterator;
|
|
|
|
typedef Instructions::const_iterator const_instr_iterator;
|
|
|
|
typedef std::reverse_iterator<instr_iterator> reverse_instr_iterator;
|
2011-12-06 22:12:01 +00:00
|
|
|
typedef
|
2011-12-14 02:11:42 +00:00
|
|
|
std::reverse_iterator<const_instr_iterator> const_reverse_instr_iterator;
|
2011-12-06 22:12:01 +00:00
|
|
|
|
|
|
|
typedef
|
2011-12-14 02:11:42 +00:00
|
|
|
bundle_iterator<MachineInstr,instr_iterator> iterator;
|
2011-12-06 22:12:01 +00:00
|
|
|
typedef
|
2011-12-14 02:11:42 +00:00
|
|
|
bundle_iterator<const MachineInstr,const_instr_iterator> const_iterator;
|
2011-12-06 22:12:01 +00:00
|
|
|
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
|
|
|
typedef std::reverse_iterator<iterator> reverse_iterator;
|
|
|
|
|
2002-07-08 22:40:34 +00:00
|
|
|
|
2008-05-05 18:30:58 +00:00
|
|
|
unsigned size() const { return (unsigned)Insts.size(); }
|
2002-07-08 22:40:34 +00:00
|
|
|
bool empty() const { return Insts.empty(); }
|
|
|
|
|
2004-02-12 02:27:10 +00:00
|
|
|
MachineInstr& front() { return Insts.front(); }
|
|
|
|
MachineInstr& back() { return Insts.back(); }
|
2008-10-16 01:49:15 +00:00
|
|
|
const MachineInstr& front() const { return Insts.front(); }
|
|
|
|
const MachineInstr& back() const { return Insts.back(); }
|
2002-07-08 22:40:34 +00:00
|
|
|
|
2011-12-14 02:11:42 +00:00
|
|
|
instr_iterator instr_begin() { return Insts.begin(); }
|
|
|
|
const_instr_iterator instr_begin() const { return Insts.begin(); }
|
|
|
|
instr_iterator instr_end() { return Insts.end(); }
|
|
|
|
const_instr_iterator instr_end() const { return Insts.end(); }
|
|
|
|
reverse_instr_iterator instr_rbegin() { return Insts.rbegin(); }
|
|
|
|
const_reverse_instr_iterator instr_rbegin() const { return Insts.rbegin(); }
|
|
|
|
reverse_instr_iterator instr_rend () { return Insts.rend(); }
|
|
|
|
const_reverse_instr_iterator instr_rend () const { return Insts.rend(); }
|
2011-12-06 22:12:01 +00:00
|
|
|
|
2012-06-11 15:11:12 +00:00
|
|
|
iterator begin() { return instr_begin(); }
|
|
|
|
const_iterator begin() const { return instr_begin(); }
|
|
|
|
iterator end () { return instr_end(); }
|
|
|
|
const_iterator end () const { return instr_end(); }
|
|
|
|
reverse_iterator rbegin() { return instr_rbegin(); }
|
|
|
|
const_reverse_iterator rbegin() const { return instr_rbegin(); }
|
|
|
|
reverse_iterator rend () { return instr_rend(); }
|
|
|
|
const_reverse_iterator rend () const { return instr_rend(); }
|
2002-07-08 22:40:34 +00:00
|
|
|
|
2014-04-16 22:37:58 +00:00
|
|
|
inline iterator_range<iterator> terminators() {
|
|
|
|
return iterator_range<iterator>(getFirstTerminator(), end());
|
|
|
|
}
|
|
|
|
inline iterator_range<const_iterator> terminators() const {
|
|
|
|
return iterator_range<const_iterator>(getFirstTerminator(), end());
|
|
|
|
}
|
2011-12-06 22:12:01 +00:00
|
|
|
|
2004-04-28 02:16:33 +00:00
|
|
|
// Machine-CFG iterators
|
|
|
|
typedef std::vector<MachineBasicBlock *>::iterator pred_iterator;
|
|
|
|
typedef std::vector<MachineBasicBlock *>::const_iterator const_pred_iterator;
|
|
|
|
typedef std::vector<MachineBasicBlock *>::iterator succ_iterator;
|
|
|
|
typedef std::vector<MachineBasicBlock *>::const_iterator const_succ_iterator;
|
2007-05-08 18:55:03 +00:00
|
|
|
typedef std::vector<MachineBasicBlock *>::reverse_iterator
|
|
|
|
pred_reverse_iterator;
|
|
|
|
typedef std::vector<MachineBasicBlock *>::const_reverse_iterator
|
|
|
|
const_pred_reverse_iterator;
|
|
|
|
typedef std::vector<MachineBasicBlock *>::reverse_iterator
|
|
|
|
succ_reverse_iterator;
|
|
|
|
typedef std::vector<MachineBasicBlock *>::const_reverse_iterator
|
|
|
|
const_succ_reverse_iterator;
|
2006-10-21 06:50:05 +00:00
|
|
|
pred_iterator pred_begin() { return Predecessors.begin(); }
|
|
|
|
const_pred_iterator pred_begin() const { return Predecessors.begin(); }
|
|
|
|
pred_iterator pred_end() { return Predecessors.end(); }
|
|
|
|
const_pred_iterator pred_end() const { return Predecessors.end(); }
|
2007-05-08 18:55:03 +00:00
|
|
|
pred_reverse_iterator pred_rbegin()
|
|
|
|
{ return Predecessors.rbegin();}
|
|
|
|
const_pred_reverse_iterator pred_rbegin() const
|
|
|
|
{ return Predecessors.rbegin();}
|
|
|
|
pred_reverse_iterator pred_rend()
|
|
|
|
{ return Predecessors.rend(); }
|
|
|
|
const_pred_reverse_iterator pred_rend() const
|
|
|
|
{ return Predecessors.rend(); }
|
2008-05-05 18:30:58 +00:00
|
|
|
unsigned pred_size() const {
|
|
|
|
return (unsigned)Predecessors.size();
|
|
|
|
}
|
2006-10-21 06:50:05 +00:00
|
|
|
bool pred_empty() const { return Predecessors.empty(); }
|
|
|
|
succ_iterator succ_begin() { return Successors.begin(); }
|
|
|
|
const_succ_iterator succ_begin() const { return Successors.begin(); }
|
|
|
|
succ_iterator succ_end() { return Successors.end(); }
|
|
|
|
const_succ_iterator succ_end() const { return Successors.end(); }
|
2007-05-08 18:55:03 +00:00
|
|
|
succ_reverse_iterator succ_rbegin()
|
|
|
|
{ return Successors.rbegin(); }
|
|
|
|
const_succ_reverse_iterator succ_rbegin() const
|
|
|
|
{ return Successors.rbegin(); }
|
|
|
|
succ_reverse_iterator succ_rend()
|
|
|
|
{ return Successors.rend(); }
|
|
|
|
const_succ_reverse_iterator succ_rend() const
|
|
|
|
{ return Successors.rend(); }
|
2008-05-05 18:30:58 +00:00
|
|
|
unsigned succ_size() const {
|
|
|
|
return (unsigned)Successors.size();
|
|
|
|
}
|
2006-10-21 06:50:05 +00:00
|
|
|
bool succ_empty() const { return Successors.empty(); }
|
2004-04-28 02:16:33 +00:00
|
|
|
|
2014-04-04 02:10:59 +00:00
|
|
|
inline iterator_range<pred_iterator> predecessors() {
|
|
|
|
return iterator_range<pred_iterator>(pred_begin(), pred_end());
|
|
|
|
}
|
2014-04-04 17:36:55 +00:00
|
|
|
inline iterator_range<const_pred_iterator> predecessors() const {
|
2014-04-04 02:10:59 +00:00
|
|
|
return iterator_range<const_pred_iterator>(pred_begin(), pred_end());
|
|
|
|
}
|
2014-04-04 02:14:38 +00:00
|
|
|
inline iterator_range<succ_iterator> successors() {
|
2014-04-04 02:10:59 +00:00
|
|
|
return iterator_range<succ_iterator>(succ_begin(), succ_end());
|
|
|
|
}
|
2014-04-04 17:36:55 +00:00
|
|
|
inline iterator_range<const_succ_iterator> successors() const {
|
2014-04-04 02:10:59 +00:00
|
|
|
return iterator_range<const_succ_iterator>(succ_begin(), succ_end());
|
|
|
|
}
|
|
|
|
|
2007-02-10 02:38:19 +00:00
|
|
|
// LiveIn management methods.
|
|
|
|
|
|
|
|
/// addLiveIn - Add the specified register as a live in. Note that it
|
|
|
|
/// is an error to add the same register to the same set more than once.
|
|
|
|
void addLiveIn(unsigned Reg) { LiveIns.push_back(Reg); }
|
|
|
|
|
2013-07-03 23:56:20 +00:00
|
|
|
/// Add PhysReg as live in to this block, and ensure that there is a copy of
|
|
|
|
/// PhysReg to a virtual register of class RC. Return the virtual register
|
|
|
|
/// that is a copy of the live in PhysReg.
|
|
|
|
unsigned addLiveIn(unsigned PhysReg, const TargetRegisterClass *RC);
|
|
|
|
|
2007-02-19 21:49:54 +00:00
|
|
|
/// removeLiveIn - Remove the specified register from the live in set.
|
|
|
|
///
|
|
|
|
void removeLiveIn(unsigned Reg);
|
|
|
|
|
2008-04-24 09:06:33 +00:00
|
|
|
/// isLiveIn - Return true if the specified register is in the live in set.
|
|
|
|
///
|
|
|
|
bool isLiveIn(unsigned Reg) const;
|
|
|
|
|
2007-02-10 02:38:19 +00:00
|
|
|
// Iteration support for live in sets. These sets are kept in sorted
|
|
|
|
// order by their register number.
|
2010-04-13 16:57:55 +00:00
|
|
|
typedef std::vector<unsigned>::const_iterator livein_iterator;
|
|
|
|
livein_iterator livein_begin() const { return LiveIns.begin(); }
|
|
|
|
livein_iterator livein_end() const { return LiveIns.end(); }
|
2007-02-10 02:38:19 +00:00
|
|
|
bool livein_empty() const { return LiveIns.empty(); }
|
|
|
|
|
2008-02-28 00:43:03 +00:00
|
|
|
/// getAlignment - Return alignment of the basic block.
|
2011-12-06 01:26:19 +00:00
|
|
|
/// The alignment is specified as log2(bytes).
|
2008-02-28 00:43:03 +00:00
|
|
|
///
|
|
|
|
unsigned getAlignment() const { return Alignment; }
|
|
|
|
|
|
|
|
/// setAlignment - Set alignment of the basic block.
|
2011-12-06 01:26:19 +00:00
|
|
|
/// The alignment is specified as log2(bytes).
|
2008-02-28 00:43:03 +00:00
|
|
|
///
|
|
|
|
void setAlignment(unsigned Align) { Alignment = Align; }
|
|
|
|
|
2007-02-21 22:39:52 +00:00
|
|
|
/// isLandingPad - Returns true if the block is a landing pad. That is
|
|
|
|
/// this basic block is entered via an exception handler.
|
|
|
|
bool isLandingPad() const { return IsLandingPad; }
|
|
|
|
|
|
|
|
/// setIsLandingPad - Indicates the block is a landing pad. That is
|
|
|
|
/// this basic block is entered via an exception handler.
|
2011-10-07 23:06:01 +00:00
|
|
|
void setIsLandingPad(bool V = true) { IsLandingPad = V; }
|
2007-02-21 22:39:52 +00:00
|
|
|
|
2011-02-04 19:33:11 +00:00
|
|
|
/// getLandingPadSuccessor - If this block has a successor that is a landing
|
|
|
|
/// pad, return it. Otherwise return NULL.
|
|
|
|
const MachineBasicBlock *getLandingPadSuccessor() const;
|
|
|
|
|
2006-10-23 23:35:35 +00:00
|
|
|
// Code Layout methods.
|
2012-01-31 19:47:32 +00:00
|
|
|
|
2006-10-23 23:35:35 +00:00
|
|
|
/// moveBefore/moveAfter - move 'this' block before or after the specified
|
|
|
|
/// block. This only moves the block, it does not modify the CFG or adjust
|
|
|
|
/// potential fall-throughs at the end of the block.
|
|
|
|
void moveBefore(MachineBasicBlock *NewAfter);
|
|
|
|
void moveAfter(MachineBasicBlock *NewBefore);
|
2009-11-12 03:55:33 +00:00
|
|
|
|
|
|
|
/// updateTerminator - Update the terminator instructions in block to account
|
|
|
|
/// for changes to the layout. If the block previously used a fallthrough,
|
|
|
|
/// it may now need a branch, and if it previously used branching it may now
|
|
|
|
/// be able to use a fallthrough.
|
|
|
|
void updateTerminator();
|
|
|
|
|
2004-04-28 02:16:33 +00:00
|
|
|
// Machine-CFG mutators
|
2011-06-16 20:22:37 +00:00
|
|
|
|
2004-04-28 02:16:33 +00:00
|
|
|
/// addSuccessor - Add succ as a successor of this MachineBasicBlock.
|
2011-06-16 20:22:37 +00:00
|
|
|
/// The Predecessors list of succ is automatically updated. WEIGHT
|
|
|
|
/// parameter is stored in Weights list and it may be used by
|
|
|
|
/// MachineBranchProbabilityInfo analysis to calculate branch probability.
|
2004-04-28 02:16:33 +00:00
|
|
|
///
|
2012-08-20 21:05:58 +00:00
|
|
|
/// Note that duplicate Machine CFG edges are not allowed.
|
|
|
|
///
|
2011-06-16 20:22:37 +00:00
|
|
|
void addSuccessor(MachineBasicBlock *succ, uint32_t weight = 0);
|
2004-04-28 02:16:33 +00:00
|
|
|
|
2014-01-29 23:18:47 +00:00
|
|
|
/// Set successor weight of a given iterator.
|
|
|
|
void setSuccWeight(succ_iterator I, uint32_t weight);
|
|
|
|
|
2004-07-31 01:59:11 +00:00
|
|
|
/// removeSuccessor - Remove successor from the successors list of this
|
2004-04-28 02:16:33 +00:00
|
|
|
/// MachineBasicBlock. The Predecessors list of succ is automatically updated.
|
|
|
|
///
|
2004-10-26 15:41:13 +00:00
|
|
|
void removeSuccessor(MachineBasicBlock *succ);
|
2004-07-31 01:59:11 +00:00
|
|
|
|
|
|
|
/// removeSuccessor - Remove specified successor from the successors list of
|
|
|
|
/// this MachineBasicBlock. The Predecessors list of succ is automatically
|
2007-06-29 02:45:24 +00:00
|
|
|
/// updated. Return the iterator to the element after the one removed.
|
2004-07-31 01:59:11 +00:00
|
|
|
///
|
2007-06-29 02:45:24 +00:00
|
|
|
succ_iterator removeSuccessor(succ_iterator I);
|
2011-06-16 20:22:37 +00:00
|
|
|
|
|
|
|
/// replaceSuccessor - Replace successor OLD with NEW and update weight info.
|
|
|
|
///
|
|
|
|
void replaceSuccessor(MachineBasicBlock *Old, MachineBasicBlock *New);
|
|
|
|
|
|
|
|
|
2008-05-05 19:05:59 +00:00
|
|
|
/// transferSuccessors - Transfers all the successors from MBB to this
|
|
|
|
/// machine basic block (i.e., copies all the successors fromMBB and
|
2009-11-09 17:06:51 +00:00
|
|
|
/// remove all the successors from fromMBB).
|
2008-05-05 19:05:59 +00:00
|
|
|
void transferSuccessors(MachineBasicBlock *fromMBB);
|
2010-07-06 20:24:04 +00:00
|
|
|
|
|
|
|
/// transferSuccessorsAndUpdatePHIs - Transfers all the successors, as
|
|
|
|
/// in transferSuccessors, and update PHI operands in the successor blocks
|
|
|
|
/// which refer to fromMBB to refer to this.
|
|
|
|
void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *fromMBB);
|
2012-01-31 19:47:32 +00:00
|
|
|
|
2012-07-30 17:36:47 +00:00
|
|
|
/// isPredecessor - Return true if the specified MBB is a predecessor of this
|
|
|
|
/// block.
|
|
|
|
bool isPredecessor(const MachineBasicBlock *MBB) const;
|
|
|
|
|
2006-10-21 06:50:05 +00:00
|
|
|
/// isSuccessor - Return true if the specified MBB is a successor of this
|
|
|
|
/// block.
|
2009-03-30 20:06:29 +00:00
|
|
|
bool isSuccessor(const MachineBasicBlock *MBB) const;
|
2004-04-28 02:16:33 +00:00
|
|
|
|
2008-10-02 22:09:09 +00:00
|
|
|
/// isLayoutSuccessor - Return true if the specified MBB will be emitted
|
|
|
|
/// immediately after this block, such that if this block exits by
|
|
|
|
/// falling through, control will transfer to the specified MBB. Note
|
|
|
|
/// that MBB need not be a successor at all, for example if this block
|
|
|
|
/// ends with an unconditional branch to some other block.
|
2009-03-30 20:06:29 +00:00
|
|
|
bool isLayoutSuccessor(const MachineBasicBlock *MBB) const;
|
2008-10-02 22:09:09 +00:00
|
|
|
|
2009-11-26 00:32:21 +00:00
|
|
|
/// canFallThrough - Return true if the block can implicitly transfer
|
|
|
|
/// control to the block after it by falling off the end of it. This should
|
|
|
|
/// return false if it can reach the block after it, but it uses an explicit
|
|
|
|
/// branch to do so (e.g., a table jump). True is a conservative answer.
|
|
|
|
bool canFallThrough();
|
|
|
|
|
2013-09-28 13:42:22 +00:00
|
|
|
/// Returns a pointer to the first instruction in this block that is not a
|
|
|
|
/// PHINode instruction. When adding instructions to the beginning of the
|
2010-07-07 14:33:51 +00:00
|
|
|
/// basic block, they should be added before the returned value, not before
|
|
|
|
/// the first instruction, which might be PHI.
|
|
|
|
/// Returns end() is there's no non-PHI instruction.
|
|
|
|
iterator getFirstNonPHI();
|
|
|
|
|
2010-10-30 01:26:14 +00:00
|
|
|
/// SkipPHIsAndLabels - Return the first instruction in MBB after I that is
|
|
|
|
/// not a PHI or a label. This is the correct point to insert copies at the
|
|
|
|
/// beginning of a basic block.
|
|
|
|
iterator SkipPHIsAndLabels(iterator I);
|
|
|
|
|
2004-02-23 18:14:48 +00:00
|
|
|
/// getFirstTerminator - returns an iterator to the first terminator
|
|
|
|
/// instruction of this basic block. If a terminator does not exist,
|
|
|
|
/// it returns end()
|
|
|
|
iterator getFirstTerminator();
|
2011-12-06 22:12:01 +00:00
|
|
|
const_iterator getFirstTerminator() const;
|
2004-02-23 18:14:48 +00:00
|
|
|
|
2011-12-14 02:11:42 +00:00
|
|
|
/// getFirstInstrTerminator - Same getFirstTerminator but it ignores bundles
|
|
|
|
/// and return an instr_iterator instead.
|
|
|
|
instr_iterator getFirstInstrTerminator();
|
2011-04-05 04:20:27 +00:00
|
|
|
|
2011-01-13 21:28:52 +00:00
|
|
|
/// getLastNonDebugInstr - returns an iterator to the last non-debug
|
|
|
|
/// instruction in the basic block, or end()
|
|
|
|
iterator getLastNonDebugInstr();
|
2011-12-06 22:12:01 +00:00
|
|
|
const_iterator getLastNonDebugInstr() const;
|
2011-03-26 02:19:36 +00:00
|
|
|
|
2010-06-22 17:25:57 +00:00
|
|
|
/// SplitCriticalEdge - Split the critical edge from this block to the
|
|
|
|
/// given successor block, and return the newly created block, or null
|
|
|
|
/// if splitting is not possible.
|
|
|
|
///
|
|
|
|
/// This function updates LiveVariables, MachineDominatorTree, and
|
|
|
|
/// MachineLoopInfo, as applicable.
|
|
|
|
MachineBasicBlock *SplitCriticalEdge(MachineBasicBlock *Succ, Pass *P);
|
|
|
|
|
2004-06-08 18:52:47 +00:00
|
|
|
void pop_front() { Insts.pop_front(); }
|
2004-07-31 09:59:04 +00:00
|
|
|
void pop_back() { Insts.pop_back(); }
|
2002-07-08 22:40:34 +00:00
|
|
|
void push_back(MachineInstr *MI) { Insts.push_back(MI); }
|
2011-12-06 22:12:01 +00:00
|
|
|
|
2012-12-18 17:54:53 +00:00
|
|
|
/// Insert MI into the instruction list before I, possibly inside a bundle.
|
|
|
|
///
|
|
|
|
/// If the insertion point is inside a bundle, MI will be added to the bundle,
|
|
|
|
/// otherwise MI will not be added to any bundle. That means this function
|
|
|
|
/// alone can't be used to prepend or append instructions to bundles. See
|
|
|
|
/// MIBundleBuilder::insert() for a more reliable way of doing that.
|
|
|
|
instr_iterator insert(instr_iterator I, MachineInstr *M);
|
2002-07-08 22:40:34 +00:00
|
|
|
|
2012-12-18 17:54:53 +00:00
|
|
|
/// Insert a range of instructions into the instruction list before I.
|
2011-12-06 22:12:01 +00:00
|
|
|
template<typename IT>
|
|
|
|
void insert(iterator I, IT S, IT E) {
|
2011-12-14 02:11:42 +00:00
|
|
|
Insts.insert(I.getInstrIterator(), S, E);
|
2011-12-06 22:12:01 +00:00
|
|
|
}
|
2012-12-18 17:54:53 +00:00
|
|
|
|
|
|
|
/// Insert MI into the instruction list before I.
|
|
|
|
iterator insert(iterator I, MachineInstr *MI) {
|
|
|
|
assert(!MI->isBundledWithPred() && !MI->isBundledWithSucc() &&
|
|
|
|
"Cannot insert instruction with bundle flags");
|
|
|
|
return Insts.insert(I.getInstrIterator(), MI);
|
2011-12-06 22:12:01 +00:00
|
|
|
}
|
2012-12-18 17:54:53 +00:00
|
|
|
|
|
|
|
/// Insert MI into the instruction list after I.
|
|
|
|
iterator insertAfter(iterator I, MachineInstr *MI) {
|
|
|
|
assert(!MI->isBundledWithPred() && !MI->isBundledWithSucc() &&
|
|
|
|
"Cannot insert instruction with bundle flags");
|
|
|
|
return Insts.insertAfter(I.getInstrIterator(), MI);
|
2011-12-06 22:12:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-17 23:55:38 +00:00
|
|
|
/// Remove an instruction from the instruction list and delete it.
|
2011-12-14 02:11:42 +00:00
|
|
|
///
|
2012-12-17 23:55:38 +00:00
|
|
|
/// If the instruction is part of a bundle, the other instructions in the
|
|
|
|
/// bundle will still be bundled after removing the single instruction.
|
|
|
|
instr_iterator erase(instr_iterator I);
|
|
|
|
|
|
|
|
/// Remove an instruction from the instruction list and delete it.
|
|
|
|
///
|
|
|
|
/// If the instruction is part of a bundle, the other instructions in the
|
|
|
|
/// bundle will still be bundled after removing the single instruction.
|
2011-12-14 02:11:42 +00:00
|
|
|
instr_iterator erase_instr(MachineInstr *I) {
|
2012-12-17 23:55:38 +00:00
|
|
|
return erase(instr_iterator(I));
|
2011-12-06 22:12:01 +00:00
|
|
|
}
|
2011-12-14 02:11:42 +00:00
|
|
|
|
2012-12-17 23:55:38 +00:00
|
|
|
/// Remove a range of instructions from the instruction list and delete them.
|
2011-12-06 22:12:01 +00:00
|
|
|
iterator erase(iterator I, iterator E) {
|
2011-12-14 02:11:42 +00:00
|
|
|
return Insts.erase(I.getInstrIterator(), E.getInstrIterator());
|
|
|
|
}
|
2012-12-17 23:55:38 +00:00
|
|
|
|
|
|
|
/// Remove an instruction or bundle from the instruction list and delete it.
|
|
|
|
///
|
|
|
|
/// If I points to a bundle of instructions, they are all erased.
|
|
|
|
iterator erase(iterator I) {
|
2014-03-02 12:27:27 +00:00
|
|
|
return erase(I, std::next(I));
|
2012-12-17 23:55:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Remove an instruction from the instruction list and delete it.
|
|
|
|
///
|
|
|
|
/// If I is the head of a bundle of instructions, the whole bundle will be
|
|
|
|
/// erased.
|
2011-12-14 02:11:42 +00:00
|
|
|
iterator erase(MachineInstr *I) {
|
2012-12-17 23:55:38 +00:00
|
|
|
return erase(iterator(I));
|
2011-12-06 22:12:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-17 23:55:38 +00:00
|
|
|
/// Remove the unbundled instruction from the instruction list without
|
|
|
|
/// deleting it.
|
|
|
|
///
|
|
|
|
/// This function can not be used to remove bundled instructions, use
|
|
|
|
/// remove_instr to remove individual instructions from a bundle.
|
|
|
|
MachineInstr *remove(MachineInstr *I) {
|
|
|
|
assert(!I->isBundled() && "Cannot remove bundled instructions");
|
|
|
|
return Insts.remove(I);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Remove the possibly bundled instruction from the instruction list
|
|
|
|
/// without deleting it.
|
|
|
|
///
|
|
|
|
/// If the instruction is part of a bundle, the other instructions in the
|
|
|
|
/// bundle will still be bundled after removing the single instruction.
|
|
|
|
MachineInstr *remove_instr(MachineInstr *I);
|
|
|
|
|
2011-12-14 02:11:42 +00:00
|
|
|
void clear() {
|
|
|
|
Insts.clear();
|
|
|
|
}
|
2005-04-21 20:39:54 +00:00
|
|
|
|
2012-12-18 20:59:41 +00:00
|
|
|
/// Take an instruction from MBB 'Other' at the position From, and insert it
|
|
|
|
/// into this MBB right before 'Where'.
|
|
|
|
///
|
|
|
|
/// If From points to a bundle of instructions, the whole bundle is moved.
|
|
|
|
void splice(iterator Where, MachineBasicBlock *Other, iterator From) {
|
|
|
|
// The range splice() doesn't allow noop moves, but this one does.
|
|
|
|
if (Where != From)
|
2014-03-02 12:27:27 +00:00
|
|
|
splice(Where, Other, From, std::next(From));
|
2009-01-15 22:01:38 +00:00
|
|
|
}
|
|
|
|
|
2012-12-18 20:59:41 +00:00
|
|
|
/// Take a block of instructions from MBB 'Other' in the range [From, To),
|
|
|
|
/// and insert them into this MBB right before 'Where'.
|
|
|
|
///
|
|
|
|
/// The instruction at 'Where' must not be included in the range of
|
|
|
|
/// instructions to move.
|
|
|
|
void splice(iterator Where, MachineBasicBlock *Other,
|
|
|
|
iterator From, iterator To) {
|
|
|
|
Insts.splice(Where.getInstrIterator(), Other->Insts,
|
2011-12-14 02:11:42 +00:00
|
|
|
From.getInstrIterator(), To.getInstrIterator());
|
2004-07-31 09:59:04 +00:00
|
|
|
}
|
2002-10-28 02:08:43 +00:00
|
|
|
|
2008-07-07 23:14:23 +00:00
|
|
|
/// removeFromParent - This method unlinks 'this' from the containing
|
|
|
|
/// function, and returns it, but does not delete it.
|
|
|
|
MachineBasicBlock *removeFromParent();
|
2012-01-31 19:47:32 +00:00
|
|
|
|
2008-07-07 23:14:23 +00:00
|
|
|
/// eraseFromParent - This method unlinks 'this' from the containing
|
|
|
|
/// function and deletes it.
|
|
|
|
void eraseFromParent();
|
|
|
|
|
2007-06-04 06:44:01 +00:00
|
|
|
/// ReplaceUsesOfBlockWith - Given a machine basic block that branched to
|
|
|
|
/// 'Old', change the code and CFG so that it branches to 'New' instead.
|
|
|
|
void ReplaceUsesOfBlockWith(MachineBasicBlock *Old, MachineBasicBlock *New);
|
|
|
|
|
2007-06-18 22:43:58 +00:00
|
|
|
/// CorrectExtraCFGEdges - Various pieces of code can cause excess edges in
|
|
|
|
/// the CFG to be inserted. If we have proven that MBB can only branch to
|
|
|
|
/// DestA and DestB, remove any other MBB successors from the CFG. DestA and
|
|
|
|
/// DestB can be null. Besides DestA and DestB, retain other edges leading
|
|
|
|
/// to LandingPads (currently there can be only one; we don't check or require
|
|
|
|
/// that here). Note it is possible that DestA and/or DestB are LandingPads.
|
|
|
|
bool CorrectExtraCFGEdges(MachineBasicBlock *DestA,
|
|
|
|
MachineBasicBlock *DestB,
|
|
|
|
bool isCond);
|
|
|
|
|
2010-01-20 21:36:02 +00:00
|
|
|
/// findDebugLoc - find the next valid DebugLoc starting at MBBI, skipping
|
2010-02-10 00:44:23 +00:00
|
|
|
/// any DBG_VALUE instructions. Return UnknownLoc if there is none.
|
2011-12-14 02:11:42 +00:00
|
|
|
DebugLoc findDebugLoc(instr_iterator MBBI);
|
2011-12-06 22:12:01 +00:00
|
|
|
DebugLoc findDebugLoc(iterator MBBI) {
|
2011-12-14 02:11:42 +00:00
|
|
|
return findDebugLoc(MBBI.getInstrIterator());
|
2011-12-06 22:12:01 +00:00
|
|
|
}
|
2010-01-20 21:36:02 +00:00
|
|
|
|
2012-09-12 10:18:23 +00:00
|
|
|
/// Possible outcome of a register liveness query to computeRegisterLiveness()
|
|
|
|
enum LivenessQueryResult {
|
|
|
|
LQR_Live, ///< Register is known to be live.
|
|
|
|
LQR_OverlappingLive, ///< Register itself is not live, but some overlapping
|
|
|
|
///< register is.
|
|
|
|
LQR_Dead, ///< Register is known to be dead.
|
|
|
|
LQR_Unknown ///< Register liveness not decidable from local
|
|
|
|
///< neighborhood.
|
|
|
|
};
|
|
|
|
|
|
|
|
/// computeRegisterLiveness - Return whether (physical) register \c Reg
|
|
|
|
/// has been <def>ined and not <kill>ed as of just before \c MI.
|
|
|
|
///
|
|
|
|
/// Search is localised to a neighborhood of
|
|
|
|
/// \c Neighborhood instructions before (searching for defs or kills) and
|
|
|
|
/// Neighborhood instructions after (searching just for defs) MI.
|
|
|
|
///
|
|
|
|
/// \c Reg must be a physical register.
|
|
|
|
LivenessQueryResult computeRegisterLiveness(const TargetRegisterInfo *TRI,
|
|
|
|
unsigned Reg, MachineInstr *MI,
|
|
|
|
unsigned Neighborhood=10);
|
|
|
|
|
2004-02-13 04:40:15 +00:00
|
|
|
// Debugging methods.
|
|
|
|
void dump() const;
|
2014-04-14 00:51:57 +00:00
|
|
|
void print(raw_ostream &OS, SlotIndexes* = nullptr) const;
|
2004-02-13 04:40:15 +00:00
|
|
|
|
2014-01-09 02:29:41 +00:00
|
|
|
// Printing method used by LoopInfo.
|
|
|
|
void printAsOperand(raw_ostream &OS, bool PrintType = true);
|
|
|
|
|
2004-05-12 21:57:23 +00:00
|
|
|
/// getNumber - MachineBasicBlocks are uniquely numbered at the function
|
|
|
|
/// level, unless they're not in a MachineFunction yet, in which case this
|
|
|
|
/// will return -1.
|
|
|
|
///
|
2004-05-12 21:35:20 +00:00
|
|
|
int getNumber() const { return Number; }
|
2006-10-03 20:16:45 +00:00
|
|
|
void setNumber(int N) { Number = N; }
|
2004-05-12 21:35:20 +00:00
|
|
|
|
2010-01-26 04:55:51 +00:00
|
|
|
/// getSymbol - Return the MCSymbol for this basic block.
|
|
|
|
///
|
2010-03-13 21:04:28 +00:00
|
|
|
MCSymbol *getSymbol() const;
|
2011-06-16 20:22:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// getWeightIterator - Return weight iterator corresponding to the I
|
|
|
|
/// successor iterator.
|
|
|
|
weight_iterator getWeightIterator(succ_iterator I);
|
2011-12-20 20:03:10 +00:00
|
|
|
const_weight_iterator getWeightIterator(const_succ_iterator I) const;
|
2011-06-16 20:22:37 +00:00
|
|
|
|
|
|
|
friend class MachineBranchProbabilityInfo;
|
|
|
|
|
|
|
|
/// getSuccWeight - Return weight of the edge from this block to MBB. This
|
|
|
|
/// method should NOT be called directly, but by using getEdgeWeight method
|
|
|
|
/// from MachineBranchProbabilityInfo class.
|
2012-08-20 22:01:38 +00:00
|
|
|
uint32_t getSuccWeight(const_succ_iterator Succ) const;
|
2011-06-16 20:22:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Methods used to maintain doubly linked list of blocks...
|
2008-07-28 21:51:04 +00:00
|
|
|
friend struct ilist_traits<MachineBasicBlock>;
|
2004-04-28 04:15:06 +00:00
|
|
|
|
|
|
|
// Machine-CFG mutators
|
|
|
|
|
|
|
|
/// addPredecessor - Remove pred as a predecessor of this MachineBasicBlock.
|
|
|
|
/// Don't do this unless you know what you're doing, because it doesn't
|
|
|
|
/// update pred's successors list. Use pred->addSuccessor instead.
|
|
|
|
///
|
2004-10-26 15:41:13 +00:00
|
|
|
void addPredecessor(MachineBasicBlock *pred);
|
2004-04-28 04:15:06 +00:00
|
|
|
|
|
|
|
/// removePredecessor - Remove pred as a predecessor of this
|
|
|
|
/// MachineBasicBlock. Don't do this unless you know what you're
|
|
|
|
/// doing, because it doesn't update pred's successors list. Use
|
|
|
|
/// pred->removeSuccessor instead.
|
|
|
|
///
|
2004-10-26 15:41:13 +00:00
|
|
|
void removePredecessor(MachineBasicBlock *pred);
|
2002-07-08 22:40:34 +00:00
|
|
|
};
|
|
|
|
|
2009-07-24 10:36:58 +00:00
|
|
|
raw_ostream& operator<<(raw_ostream &OS, const MachineBasicBlock &MBB);
|
2004-05-01 21:05:34 +00:00
|
|
|
|
2011-03-04 00:15:36 +00:00
|
|
|
// This is useful when building IndexedMaps keyed on basic block pointers.
|
|
|
|
struct MBB2NumberFunctor :
|
|
|
|
public std::unary_function<const MachineBasicBlock*, unsigned> {
|
|
|
|
unsigned operator()(const MachineBasicBlock *MBB) const {
|
|
|
|
return MBB->getNumber();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-05-01 21:05:34 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// GraphTraits specializations for machine basic block graphs (machine-CFGs)
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// Provide specializations of GraphTraits to be able to treat a
|
|
|
|
// MachineFunction as a graph of MachineBasicBlocks...
|
|
|
|
//
|
|
|
|
|
|
|
|
template <> struct GraphTraits<MachineBasicBlock *> {
|
|
|
|
typedef MachineBasicBlock NodeType;
|
|
|
|
typedef MachineBasicBlock::succ_iterator ChildIteratorType;
|
|
|
|
|
|
|
|
static NodeType *getEntryNode(MachineBasicBlock *BB) { return BB; }
|
2005-04-21 20:39:54 +00:00
|
|
|
static inline ChildIteratorType child_begin(NodeType *N) {
|
2004-05-01 21:05:34 +00:00
|
|
|
return N->succ_begin();
|
|
|
|
}
|
2005-04-21 20:39:54 +00:00
|
|
|
static inline ChildIteratorType child_end(NodeType *N) {
|
2004-05-01 21:05:34 +00:00
|
|
|
return N->succ_end();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct GraphTraits<const MachineBasicBlock *> {
|
|
|
|
typedef const MachineBasicBlock NodeType;
|
|
|
|
typedef MachineBasicBlock::const_succ_iterator ChildIteratorType;
|
|
|
|
|
|
|
|
static NodeType *getEntryNode(const MachineBasicBlock *BB) { return BB; }
|
2005-04-21 20:39:54 +00:00
|
|
|
static inline ChildIteratorType child_begin(NodeType *N) {
|
2004-05-01 21:05:34 +00:00
|
|
|
return N->succ_begin();
|
|
|
|
}
|
2005-04-21 20:39:54 +00:00
|
|
|
static inline ChildIteratorType child_end(NodeType *N) {
|
2004-05-01 21:05:34 +00:00
|
|
|
return N->succ_end();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Provide specializations of GraphTraits to be able to treat a
|
|
|
|
// MachineFunction as a graph of MachineBasicBlocks... and to walk it
|
|
|
|
// in inverse order. Inverse order for a function is considered
|
|
|
|
// to be when traversing the predecessor edges of a MBB
|
|
|
|
// instead of the successor edges.
|
|
|
|
//
|
|
|
|
template <> struct GraphTraits<Inverse<MachineBasicBlock*> > {
|
|
|
|
typedef MachineBasicBlock NodeType;
|
|
|
|
typedef MachineBasicBlock::pred_iterator ChildIteratorType;
|
|
|
|
static NodeType *getEntryNode(Inverse<MachineBasicBlock *> G) {
|
|
|
|
return G.Graph;
|
|
|
|
}
|
2005-04-21 20:39:54 +00:00
|
|
|
static inline ChildIteratorType child_begin(NodeType *N) {
|
2004-05-01 21:05:34 +00:00
|
|
|
return N->pred_begin();
|
|
|
|
}
|
2005-04-21 20:39:54 +00:00
|
|
|
static inline ChildIteratorType child_end(NodeType *N) {
|
2004-05-01 21:05:34 +00:00
|
|
|
return N->pred_end();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct GraphTraits<Inverse<const MachineBasicBlock*> > {
|
|
|
|
typedef const MachineBasicBlock NodeType;
|
|
|
|
typedef MachineBasicBlock::const_pred_iterator ChildIteratorType;
|
|
|
|
static NodeType *getEntryNode(Inverse<const MachineBasicBlock*> G) {
|
2005-04-21 20:39:54 +00:00
|
|
|
return G.Graph;
|
2004-05-01 21:05:34 +00:00
|
|
|
}
|
2005-04-21 20:39:54 +00:00
|
|
|
static inline ChildIteratorType child_begin(NodeType *N) {
|
2004-05-01 21:05:34 +00:00
|
|
|
return N->pred_begin();
|
|
|
|
}
|
2005-04-21 20:39:54 +00:00
|
|
|
static inline ChildIteratorType child_end(NodeType *N) {
|
2004-05-01 21:05:34 +00:00
|
|
|
return N->pred_end();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-08-14 23:50:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// MachineInstrSpan provides an interface to get an iteration range
|
|
|
|
/// containing the instruction it was initialized with, along with all
|
|
|
|
/// those instructions inserted prior to or following that instruction
|
|
|
|
/// at some point after the MachineInstrSpan is constructed.
|
|
|
|
class MachineInstrSpan {
|
|
|
|
MachineBasicBlock &MBB;
|
|
|
|
MachineBasicBlock::iterator I, B, E;
|
|
|
|
public:
|
|
|
|
MachineInstrSpan(MachineBasicBlock::iterator I)
|
|
|
|
: MBB(*I->getParent()),
|
|
|
|
I(I),
|
2014-03-02 12:27:27 +00:00
|
|
|
B(I == MBB.begin() ? MBB.end() : std::prev(I)),
|
|
|
|
E(std::next(I)) {}
|
2013-08-14 23:50:11 +00:00
|
|
|
|
|
|
|
MachineBasicBlock::iterator begin() {
|
2014-03-02 12:27:27 +00:00
|
|
|
return B == MBB.end() ? MBB.begin() : std::next(B);
|
2013-08-14 23:50:11 +00:00
|
|
|
}
|
|
|
|
MachineBasicBlock::iterator end() { return E; }
|
|
|
|
bool empty() { return begin() == end(); }
|
|
|
|
|
|
|
|
MachineBasicBlock::iterator getInitial() { return I; }
|
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
2002-07-08 22:40:34 +00:00
|
|
|
|
|
|
|
#endif
|