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-02-12 02:27:10 +00:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/ADT/GraphTraits.h"
|
2003-11-11 22:41:34 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2008-07-28 21:51:04 +00:00
|
|
|
|
|
|
|
class BasicBlock;
|
|
|
|
class MachineFunction;
|
2009-07-24 10:36:58 +00:00
|
|
|
class raw_ostream;
|
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;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/// 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.
|
|
|
|
unsigned Alignment;
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
2008-07-07 23:14:23 +00:00
|
|
|
typedef Instructions::iterator iterator;
|
|
|
|
typedef Instructions::const_iterator const_iterator;
|
2002-07-08 22:40:34 +00:00
|
|
|
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
|
|
|
typedef std::reverse_iterator<iterator> reverse_iterator;
|
|
|
|
|
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
|
|
|
|
|
|
|
iterator begin() { return Insts.begin(); }
|
|
|
|
const_iterator begin() const { return Insts.begin(); }
|
|
|
|
iterator end() { return Insts.end(); }
|
|
|
|
const_iterator end() const { return Insts.end(); }
|
|
|
|
reverse_iterator rbegin() { return Insts.rbegin(); }
|
|
|
|
const_reverse_iterator rbegin() const { return Insts.rbegin(); }
|
|
|
|
reverse_iterator rend () { return Insts.rend(); }
|
|
|
|
const_reverse_iterator rend () const { return Insts.rend(); }
|
|
|
|
|
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;
|
2005-04-21 20:39:54 +00:00
|
|
|
|
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
|
|
|
|
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); }
|
|
|
|
|
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.
|
2007-02-19 21:49:54 +00:00
|
|
|
typedef std::vector<unsigned>::iterator livein_iterator;
|
|
|
|
typedef std::vector<unsigned>::const_iterator const_livein_iterator;
|
|
|
|
livein_iterator livein_begin() { return LiveIns.begin(); }
|
|
|
|
const_livein_iterator livein_begin() const { return LiveIns.begin(); }
|
|
|
|
livein_iterator livein_end() { return LiveIns.end(); }
|
|
|
|
const_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.
|
|
|
|
///
|
|
|
|
unsigned getAlignment() const { return Alignment; }
|
|
|
|
|
|
|
|
/// setAlignment - Set alignment of the basic block.
|
|
|
|
///
|
|
|
|
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.
|
|
|
|
void setIsLandingPad() { IsLandingPad = true; }
|
|
|
|
|
2006-10-23 23:35:35 +00:00
|
|
|
// Code Layout methods.
|
|
|
|
|
|
|
|
/// 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
|
2006-10-23 23:35:35 +00:00
|
|
|
|
2004-04-28 02:16:33 +00:00
|
|
|
/// addSuccessor - Add succ as a successor of this MachineBasicBlock.
|
|
|
|
/// The Predecessors list of succ is automatically updated.
|
|
|
|
///
|
2004-10-26 15:41:13 +00:00
|
|
|
void addSuccessor(MachineBasicBlock *succ);
|
2004-04-28 02:16:33 +00:00
|
|
|
|
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);
|
2006-10-21 06:50:05 +00:00
|
|
|
|
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);
|
|
|
|
|
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();
|
|
|
|
|
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();
|
|
|
|
|
2009-03-31 18:39:13 +00:00
|
|
|
/// isOnlyReachableViaFallthough - Return true if this basic block has
|
|
|
|
/// exactly one predecessor and the control transfer mechanism between
|
|
|
|
/// the predecessor and this block is a fall-through.
|
|
|
|
bool isOnlyReachableByFallthrough() const;
|
|
|
|
|
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); }
|
|
|
|
template<typename IT>
|
|
|
|
void insert(iterator I, IT S, IT E) { Insts.insert(I, S, E); }
|
|
|
|
iterator insert(iterator I, MachineInstr *M) { return Insts.insert(I, M); }
|
|
|
|
|
2002-09-20 00:55:57 +00:00
|
|
|
// erase - Remove the specified element or range from the instruction list.
|
2004-02-12 02:27:10 +00:00
|
|
|
// These functions delete any instructions removed.
|
2002-07-08 22:40:34 +00:00
|
|
|
//
|
2002-09-20 00:55:57 +00:00
|
|
|
iterator erase(iterator I) { return Insts.erase(I); }
|
2002-07-08 22:40:34 +00:00
|
|
|
iterator erase(iterator I, iterator E) { return Insts.erase(I, E); }
|
2004-03-31 21:58:50 +00:00
|
|
|
MachineInstr *remove(MachineInstr *I) { return Insts.remove(I); }
|
2004-03-31 22:43:12 +00:00
|
|
|
void clear() { Insts.clear(); }
|
2005-04-21 20:39:54 +00:00
|
|
|
|
2009-01-15 22:01:38 +00:00
|
|
|
/// splice - Take an instruction from MBB 'Other' at the position From,
|
|
|
|
/// and insert it into this MBB right before 'where'.
|
|
|
|
void splice(iterator where, MachineBasicBlock *Other, iterator From) {
|
|
|
|
Insts.splice(where, Other->Insts, From);
|
|
|
|
}
|
|
|
|
|
2004-07-31 09:59:04 +00:00
|
|
|
/// splice - Take a block of instructions from MBB 'Other' in the range [From,
|
|
|
|
/// To), and insert them into this MBB right before 'where'.
|
|
|
|
void splice(iterator where, MachineBasicBlock *Other, iterator From,
|
|
|
|
iterator To) {
|
|
|
|
Insts.splice(where, Other->Insts, From, To);
|
|
|
|
}
|
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();
|
|
|
|
|
|
|
|
/// 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.
|
2010-01-20 21:36:02 +00:00
|
|
|
DebugLoc findDebugLoc(MachineBasicBlock::iterator &MBBI);
|
|
|
|
|
2004-02-13 04:40:15 +00:00
|
|
|
// Debugging methods.
|
|
|
|
void dump() const;
|
2009-08-23 00:47:04 +00:00
|
|
|
void print(raw_ostream &OS) const;
|
2004-02-13 04:40:15 +00:00
|
|
|
|
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.
|
|
|
|
///
|
|
|
|
MCSymbol *getSymbol(MCContext &Ctx) const;
|
|
|
|
|
2002-10-28 02:08:43 +00:00
|
|
|
private: // 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
|
|
|
|
2009-11-17 19:19:59 +00:00
|
|
|
void WriteAsOperand(raw_ostream &, const MachineBasicBlock*, bool t);
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
2002-07-08 22:40:34 +00:00
|
|
|
|
|
|
|
#endif
|