2002-10-28 02:21:55 +01:00
|
|
|
//===-- llvm/CodeGen/MachineBasicBlock.h ------------------------*- C++ -*-===//
|
2005-04-21 22:39:54 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:39:54 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2005-04-21 22:39:54 +02:00
|
|
|
//
|
2002-10-27 21:49:47 +01:00
|
|
|
// Collect the sequence of machine instructions for a basic block.
|
|
|
|
//
|
2002-10-28 02:21:55 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-07-09 00:40:34 +02:00
|
|
|
|
2002-10-28 01:28:31 +01:00
|
|
|
#ifndef LLVM_CODEGEN_MACHINEBASICBLOCK_H
|
|
|
|
#define LLVM_CODEGEN_MACHINEBASICBLOCK_H
|
2002-07-09 00:40:34 +02:00
|
|
|
|
2004-02-12 03:27:10 +01:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2004-09-02 00:55:40 +02:00
|
|
|
#include "llvm/ADT/GraphTraits.h"
|
2003-11-11 23:41:34 +01:00
|
|
|
|
|
|
|
namespace llvm {
|
2008-07-28 23:51:04 +02:00
|
|
|
|
|
|
|
class BasicBlock;
|
|
|
|
class MachineFunction;
|
2010-02-10 02:04:16 +01:00
|
|
|
class MCSymbol;
|
|
|
|
class StringRef;
|
2009-07-24 12:36:58 +02:00
|
|
|
class raw_ostream;
|
2003-11-11 23:41:34 +01:00
|
|
|
|
2004-02-12 20:12:03 +01:00
|
|
|
template <>
|
2008-09-20 20:02:18 +02:00
|
|
|
struct ilist_traits<MachineInstr> : public ilist_default_traits<MachineInstr> {
|
|
|
|
private:
|
2009-08-26 21:16:32 +02:00
|
|
|
mutable ilist_half_node<MachineInstr> Sentinel;
|
2008-07-28 23:51:04 +02:00
|
|
|
|
2008-07-08 01:14:23 +02:00
|
|
|
// this is only set by the MachineBasicBlock owning the LiveList
|
2004-02-12 20:12:03 +01:00
|
|
|
friend class MachineBasicBlock;
|
2008-07-08 01:14:23 +02:00
|
|
|
MachineBasicBlock* Parent;
|
2004-02-12 20:12:03 +01:00
|
|
|
|
2008-07-08 01:14:23 +02:00
|
|
|
public:
|
2009-03-04 07:57:48 +01:00
|
|
|
MachineInstr *createSentinel() const {
|
|
|
|
return static_cast<MachineInstr*>(&Sentinel);
|
|
|
|
}
|
2008-07-28 23:51:04 +02:00
|
|
|
void destroySentinel(MachineInstr *) const {}
|
2004-02-12 20:12:03 +01:00
|
|
|
|
2009-03-04 21:36:44 +01:00
|
|
|
MachineInstr *provideInitialHead() const { return createSentinel(); }
|
|
|
|
MachineInstr *ensureHead(MachineInstr*) const { return createSentinel(); }
|
2009-03-04 22:54:31 +01:00
|
|
|
static void noteHead(MachineInstr*, MachineInstr*) {}
|
2009-03-04 21:36:44 +01:00
|
|
|
|
2004-02-16 08:17:43 +01:00
|
|
|
void addNodeToList(MachineInstr* N);
|
|
|
|
void removeNodeFromList(MachineInstr* N);
|
2008-07-28 23:51:04 +02:00
|
|
|
void transferNodesFromList(ilist_traits &SrcTraits,
|
|
|
|
ilist_iterator<MachineInstr> first,
|
|
|
|
ilist_iterator<MachineInstr> last);
|
2008-07-08 01:14:23 +02:00
|
|
|
void deleteNode(MachineInstr *N);
|
2008-07-28 23:51:04 +02:00
|
|
|
private:
|
|
|
|
void createNode(const MachineInstr &);
|
2004-02-12 20:12:03 +01:00
|
|
|
};
|
|
|
|
|
2008-07-28 23:51:04 +02:00
|
|
|
class MachineBasicBlock : public ilist_node<MachineBasicBlock> {
|
|
|
|
typedef ilist<MachineInstr> Instructions;
|
2004-02-12 03:27:10 +01:00
|
|
|
Instructions Insts;
|
2003-07-27 01:30:37 +02:00
|
|
|
const BasicBlock *BB;
|
2004-05-12 23:35:20 +02:00
|
|
|
int Number;
|
2007-12-31 05:56:33 +01:00
|
|
|
MachineFunction *xParent;
|
|
|
|
|
2007-02-10 03:38:19 +01: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 01:43:03 +01:00
|
|
|
|
|
|
|
/// Alignment - Alignment of the basic block. Zero if the basic block does
|
|
|
|
/// not need to be aligned.
|
|
|
|
unsigned Alignment;
|
2007-02-21 23:39:52 +01:00
|
|
|
|
|
|
|
/// IsLandingPad - Indicate that this basic block is entered via an
|
|
|
|
/// exception handler.
|
|
|
|
bool IsLandingPad;
|
2007-02-10 03:38:19 +01:00
|
|
|
|
2009-10-30 02:27:03 +01:00
|
|
|
/// AddressTaken - Indicate that this basic block is potentially the
|
|
|
|
/// target of an indirect branch.
|
|
|
|
bool AddressTaken;
|
|
|
|
|
2008-07-28 23:51:04 +02:00
|
|
|
// Intrusive list support
|
|
|
|
MachineBasicBlock() {}
|
|
|
|
|
2008-07-08 01:14:23 +02:00
|
|
|
explicit MachineBasicBlock(MachineFunction &mf, const BasicBlock *bb);
|
|
|
|
|
2008-07-18 01:49:46 +02:00
|
|
|
~MachineBasicBlock();
|
2004-05-24 09:14:35 +02:00
|
|
|
|
2008-07-08 01:14:23 +02:00
|
|
|
// MachineBasicBlocks are allocated and owned by MachineFunction.
|
|
|
|
friend class MachineFunction;
|
2005-04-21 22:39:54 +02:00
|
|
|
|
2008-07-08 01:14:23 +02:00
|
|
|
public:
|
2002-10-28 06:30:46 +01:00
|
|
|
/// getBasicBlock - Return the LLVM basic block that this instance
|
2009-11-20 02:17:03 +01: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 06:30:46 +01:00
|
|
|
///
|
2003-07-27 01:30:37 +02:00
|
|
|
const BasicBlock *getBasicBlock() const { return BB; }
|
2004-02-19 17:13:54 +01:00
|
|
|
|
2009-11-20 02:17:03 +01:00
|
|
|
/// getName - Return the name of the corresponding LLVM basic block, or
|
|
|
|
/// "(null)".
|
|
|
|
StringRef getName() const;
|
|
|
|
|
2009-10-30 02:27:03 +01: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 17:13:54 +01:00
|
|
|
/// getParent - Return the MachineFunction containing this basic block.
|
|
|
|
///
|
2007-12-31 05:56:33 +01:00
|
|
|
const MachineFunction *getParent() const { return xParent; }
|
|
|
|
MachineFunction *getParent() { return xParent; }
|
2004-02-19 17:13:54 +01:00
|
|
|
|
2008-07-08 01:14:23 +02:00
|
|
|
typedef Instructions::iterator iterator;
|
|
|
|
typedef Instructions::const_iterator const_iterator;
|
2002-07-09 00:40:34 +02:00
|
|
|
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
|
|
|
typedef std::reverse_iterator<iterator> reverse_iterator;
|
|
|
|
|
2008-05-05 20:30:58 +02:00
|
|
|
unsigned size() const { return (unsigned)Insts.size(); }
|
2002-07-09 00:40:34 +02:00
|
|
|
bool empty() const { return Insts.empty(); }
|
|
|
|
|
2004-02-12 03:27:10 +01:00
|
|
|
MachineInstr& front() { return Insts.front(); }
|
|
|
|
MachineInstr& back() { return Insts.back(); }
|
2008-10-16 03:49:15 +02:00
|
|
|
const MachineInstr& front() const { return Insts.front(); }
|
|
|
|
const MachineInstr& back() const { return Insts.back(); }
|
2002-07-09 00:40:34 +02: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 04:16:33 +02: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 20:55:03 +02: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 22:39:54 +02:00
|
|
|
|
2006-10-21 08:50:05 +02: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 20:55:03 +02: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 20:30:58 +02:00
|
|
|
unsigned pred_size() const {
|
|
|
|
return (unsigned)Predecessors.size();
|
|
|
|
}
|
2006-10-21 08:50:05 +02: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 20:55:03 +02: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 20:30:58 +02:00
|
|
|
unsigned succ_size() const {
|
|
|
|
return (unsigned)Successors.size();
|
|
|
|
}
|
2006-10-21 08:50:05 +02:00
|
|
|
bool succ_empty() const { return Successors.empty(); }
|
2004-04-28 04:16:33 +02:00
|
|
|
|
2007-02-10 03:38:19 +01: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 22:49:54 +01:00
|
|
|
/// removeLiveIn - Remove the specified register from the live in set.
|
|
|
|
///
|
|
|
|
void removeLiveIn(unsigned Reg);
|
|
|
|
|
2008-04-24 11:06:33 +02:00
|
|
|
/// isLiveIn - Return true if the specified register is in the live in set.
|
|
|
|
///
|
|
|
|
bool isLiveIn(unsigned Reg) const;
|
|
|
|
|
2007-02-10 03:38:19 +01:00
|
|
|
// Iteration support for live in sets. These sets are kept in sorted
|
|
|
|
// order by their register number.
|
2010-04-13 18:57:55 +02: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 03:38:19 +01:00
|
|
|
bool livein_empty() const { return LiveIns.empty(); }
|
|
|
|
|
2008-02-28 01:43:03 +01: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 23:39:52 +01: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-24 01:35:35 +02: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 04:55:33 +01: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 04:16:33 +02:00
|
|
|
// Machine-CFG mutators
|
2006-10-24 01:35:35 +02:00
|
|
|
|
2004-04-28 04:16:33 +02:00
|
|
|
/// addSuccessor - Add succ as a successor of this MachineBasicBlock.
|
|
|
|
/// The Predecessors list of succ is automatically updated.
|
|
|
|
///
|
2004-10-26 17:41:13 +02:00
|
|
|
void addSuccessor(MachineBasicBlock *succ);
|
2004-04-28 04:16:33 +02:00
|
|
|
|
2004-07-31 03:59:11 +02:00
|
|
|
/// removeSuccessor - Remove successor from the successors list of this
|
2004-04-28 04:16:33 +02:00
|
|
|
/// MachineBasicBlock. The Predecessors list of succ is automatically updated.
|
|
|
|
///
|
2004-10-26 17:41:13 +02:00
|
|
|
void removeSuccessor(MachineBasicBlock *succ);
|
2004-07-31 03:59:11 +02:00
|
|
|
|
|
|
|
/// removeSuccessor - Remove specified successor from the successors list of
|
|
|
|
/// this MachineBasicBlock. The Predecessors list of succ is automatically
|
2007-06-29 04:45:24 +02:00
|
|
|
/// updated. Return the iterator to the element after the one removed.
|
2004-07-31 03:59:11 +02:00
|
|
|
///
|
2007-06-29 04:45:24 +02:00
|
|
|
succ_iterator removeSuccessor(succ_iterator I);
|
2006-10-21 08:50:05 +02:00
|
|
|
|
2008-05-05 21:05:59 +02:00
|
|
|
/// transferSuccessors - Transfers all the successors from MBB to this
|
|
|
|
/// machine basic block (i.e., copies all the successors fromMBB and
|
2009-11-09 18:06:51 +01:00
|
|
|
/// remove all the successors from fromMBB).
|
2008-05-05 21:05:59 +02:00
|
|
|
void transferSuccessors(MachineBasicBlock *fromMBB);
|
|
|
|
|
2006-10-21 08:50:05 +02:00
|
|
|
/// isSuccessor - Return true if the specified MBB is a successor of this
|
|
|
|
/// block.
|
2009-03-30 22:06:29 +02:00
|
|
|
bool isSuccessor(const MachineBasicBlock *MBB) const;
|
2004-04-28 04:16:33 +02:00
|
|
|
|
2008-10-03 00:09:09 +02: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 22:06:29 +02:00
|
|
|
bool isLayoutSuccessor(const MachineBasicBlock *MBB) const;
|
2008-10-03 00:09:09 +02:00
|
|
|
|
2009-11-26 01:32:21 +01: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 19:14:48 +01: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();
|
|
|
|
|
2004-06-08 20:52:47 +02:00
|
|
|
void pop_front() { Insts.pop_front(); }
|
2004-07-31 11:59:04 +02:00
|
|
|
void pop_back() { Insts.pop_back(); }
|
2002-07-09 00:40:34 +02: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 02:55:57 +02:00
|
|
|
// erase - Remove the specified element or range from the instruction list.
|
2004-02-12 03:27:10 +01:00
|
|
|
// These functions delete any instructions removed.
|
2002-07-09 00:40:34 +02:00
|
|
|
//
|
2002-09-20 02:55:57 +02:00
|
|
|
iterator erase(iterator I) { return Insts.erase(I); }
|
2002-07-09 00:40:34 +02:00
|
|
|
iterator erase(iterator I, iterator E) { return Insts.erase(I, E); }
|
2004-03-31 23:58:50 +02:00
|
|
|
MachineInstr *remove(MachineInstr *I) { return Insts.remove(I); }
|
2004-04-01 00:43:12 +02:00
|
|
|
void clear() { Insts.clear(); }
|
2005-04-21 22:39:54 +02:00
|
|
|
|
2009-01-15 23:01:38 +01: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 11:59:04 +02: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 03:08:43 +01:00
|
|
|
|
2008-07-08 01:14:23 +02: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 08:44:01 +02: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-19 00:43:58 +02: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 22:36:02 +01:00
|
|
|
/// findDebugLoc - find the next valid DebugLoc starting at MBBI, skipping
|
2010-02-10 01:44:23 +01:00
|
|
|
/// any DBG_VALUE instructions. Return UnknownLoc if there is none.
|
2010-01-20 22:36:02 +01:00
|
|
|
DebugLoc findDebugLoc(MachineBasicBlock::iterator &MBBI);
|
|
|
|
|
2004-02-13 05:40:15 +01:00
|
|
|
// Debugging methods.
|
|
|
|
void dump() const;
|
2009-08-23 02:47:04 +02:00
|
|
|
void print(raw_ostream &OS) const;
|
2004-02-13 05:40:15 +01:00
|
|
|
|
2004-05-12 23:57:23 +02: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 23:35:20 +02:00
|
|
|
int getNumber() const { return Number; }
|
2006-10-03 22:16:45 +02:00
|
|
|
void setNumber(int N) { Number = N; }
|
2004-05-12 23:35:20 +02:00
|
|
|
|
2010-01-26 05:55:51 +01:00
|
|
|
/// getSymbol - Return the MCSymbol for this basic block.
|
|
|
|
///
|
2010-03-13 22:04:28 +01:00
|
|
|
MCSymbol *getSymbol() const;
|
2010-01-26 05:55:51 +01:00
|
|
|
|
2002-10-28 03:08:43 +01:00
|
|
|
private: // Methods used to maintain doubly linked list of blocks...
|
2008-07-28 23:51:04 +02:00
|
|
|
friend struct ilist_traits<MachineBasicBlock>;
|
2004-04-28 06:15:06 +02: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 17:41:13 +02:00
|
|
|
void addPredecessor(MachineBasicBlock *pred);
|
2004-04-28 06:15:06 +02: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 17:41:13 +02:00
|
|
|
void removePredecessor(MachineBasicBlock *pred);
|
2002-07-09 00:40:34 +02:00
|
|
|
};
|
|
|
|
|
2009-07-24 12:36:58 +02:00
|
|
|
raw_ostream& operator<<(raw_ostream &OS, const MachineBasicBlock &MBB);
|
2004-05-01 23:05:34 +02:00
|
|
|
|
2009-11-17 20:19:59 +01:00
|
|
|
void WriteAsOperand(raw_ostream &, const MachineBasicBlock*, bool t);
|
|
|
|
|
2004-05-01 23:05:34 +02: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 22:39:54 +02:00
|
|
|
static inline ChildIteratorType child_begin(NodeType *N) {
|
2004-05-01 23:05:34 +02:00
|
|
|
return N->succ_begin();
|
|
|
|
}
|
2005-04-21 22:39:54 +02:00
|
|
|
static inline ChildIteratorType child_end(NodeType *N) {
|
2004-05-01 23:05:34 +02: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 22:39:54 +02:00
|
|
|
static inline ChildIteratorType child_begin(NodeType *N) {
|
2004-05-01 23:05:34 +02:00
|
|
|
return N->succ_begin();
|
|
|
|
}
|
2005-04-21 22:39:54 +02:00
|
|
|
static inline ChildIteratorType child_end(NodeType *N) {
|
2004-05-01 23:05:34 +02: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 22:39:54 +02:00
|
|
|
static inline ChildIteratorType child_begin(NodeType *N) {
|
2004-05-01 23:05:34 +02:00
|
|
|
return N->pred_begin();
|
|
|
|
}
|
2005-04-21 22:39:54 +02:00
|
|
|
static inline ChildIteratorType child_end(NodeType *N) {
|
2004-05-01 23:05:34 +02: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 22:39:54 +02:00
|
|
|
return G.Graph;
|
2004-05-01 23:05:34 +02:00
|
|
|
}
|
2005-04-21 22:39:54 +02:00
|
|
|
static inline ChildIteratorType child_begin(NodeType *N) {
|
2004-05-01 23:05:34 +02:00
|
|
|
return N->pred_begin();
|
|
|
|
}
|
2005-04-21 22:39:54 +02:00
|
|
|
static inline ChildIteratorType child_end(NodeType *N) {
|
2004-05-01 23:05:34 +02:00
|
|
|
return N->pred_end();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
} // End llvm namespace
|
2002-07-09 00:40:34 +02:00
|
|
|
|
|
|
|
#endif
|