summaryrefslogtreecommitdiff
path: root/include/llvm/CodeGen/MachineBasicBlock.h
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-01-02 19:17:04 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-01-02 19:17:04 +0000
commitb915e9e0fc85ba6f398b3fab0db6a81a8913af94 (patch)
tree98b8f811c7aff2547cab8642daf372d6c59502fb /include/llvm/CodeGen/MachineBasicBlock.h
parent6421cca32f69ac849537a3cff78c352195e99f1b (diff)
Notes
Diffstat (limited to 'include/llvm/CodeGen/MachineBasicBlock.h')
-rw-r--r--include/llvm/CodeGen/MachineBasicBlock.h152
1 files changed, 78 insertions, 74 deletions
diff --git a/include/llvm/CodeGen/MachineBasicBlock.h b/include/llvm/CodeGen/MachineBasicBlock.h
index 2923371c1005..be811c6fe437 100644
--- a/include/llvm/CodeGen/MachineBasicBlock.h
+++ b/include/llvm/CodeGen/MachineBasicBlock.h
@@ -19,6 +19,7 @@
#include "llvm/CodeGen/MachineInstrBundleIterator.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/Support/BranchProbability.h"
+#include "llvm/MC/LaneBitmask.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/Support/DataTypes.h"
#include <functional>
@@ -35,36 +36,21 @@ class StringRef;
class raw_ostream;
class MachineBranchProbabilityInfo;
-// Forward declaration to avoid circular include problem with TargetRegisterInfo
-typedef unsigned LaneBitmask;
-
-template <>
-struct ilist_traits<MachineInstr> : public ilist_default_traits<MachineInstr> {
+template <> struct ilist_traits<MachineInstr> {
private:
- mutable ilist_half_node<MachineInstr> Sentinel;
+ friend class MachineBasicBlock; // Set by the owning MachineBasicBlock.
+ MachineBasicBlock *Parent;
- // this is only set by the MachineBasicBlock owning the LiveList
- friend class MachineBasicBlock;
- MachineBasicBlock* Parent;
+ typedef simple_ilist<MachineInstr, ilist_sentinel_tracking<true>>::iterator
+ instr_iterator;
public:
- MachineInstr *createSentinel() const {
- return static_cast<MachineInstr*>(&Sentinel);
- }
- void destroySentinel(MachineInstr *) const {}
-
- MachineInstr *provideInitialHead() const { return createSentinel(); }
- MachineInstr *ensureHead(MachineInstr*) const { return createSentinel(); }
- static void noteHead(MachineInstr*, MachineInstr*) {}
+ void addNodeToList(MachineInstr *N);
+ void removeNodeFromList(MachineInstr *N);
+ void transferNodesFromList(ilist_traits &OldList, instr_iterator First,
+ instr_iterator Last);
- void addNodeToList(MachineInstr* N);
- void removeNodeFromList(MachineInstr* N);
- void transferNodesFromList(ilist_traits &SrcTraits,
- ilist_iterator<MachineInstr> First,
- ilist_iterator<MachineInstr> Last);
- void deleteNode(MachineInstr *N);
-private:
- void createNode(const MachineInstr &);
+ void deleteNode(MachineInstr *MI);
};
class MachineBasicBlock
@@ -83,7 +69,7 @@ public:
};
private:
- typedef ilist<MachineInstr> Instructions;
+ typedef ilist<MachineInstr, ilist_sentinel_tracking<true>> Instructions;
Instructions Insts;
const BasicBlock *BB;
int Number;
@@ -161,15 +147,14 @@ public:
typedef Instructions::iterator instr_iterator;
typedef Instructions::const_iterator const_instr_iterator;
- typedef std::reverse_iterator<instr_iterator> reverse_instr_iterator;
- typedef
- std::reverse_iterator<const_instr_iterator> const_reverse_instr_iterator;
+ typedef Instructions::reverse_iterator reverse_instr_iterator;
+ typedef Instructions::const_reverse_iterator const_reverse_instr_iterator;
typedef MachineInstrBundleIterator<MachineInstr> iterator;
typedef MachineInstrBundleIterator<const MachineInstr> const_iterator;
- typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
- typedef std::reverse_iterator<iterator> reverse_iterator;
-
+ typedef MachineInstrBundleIterator<MachineInstr, true> reverse_iterator;
+ typedef MachineInstrBundleIterator<const MachineInstr, true>
+ const_reverse_iterator;
unsigned size() const { return (unsigned)Insts.size(); }
bool empty() const { return Insts.empty(); }
@@ -204,10 +189,16 @@ public:
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(); }
+ reverse_iterator rbegin() {
+ return reverse_iterator::getAtBundleBegin(instr_rbegin());
+ }
+ const_reverse_iterator rbegin() const {
+ return const_reverse_iterator::getAtBundleBegin(instr_rbegin());
+ }
+ reverse_iterator rend() { return reverse_iterator(instr_rend()); }
+ const_reverse_iterator rend() const {
+ return const_reverse_iterator(instr_rend());
+ }
/// Support for MachineInstr::getNextNode().
static Instructions MachineBasicBlock::*getSublistAccess(MachineInstr *) {
@@ -285,7 +276,8 @@ public:
/// Adds 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 unless the intention is
/// to call sortUniqueLiveIns after all registers are added.
- void addLiveIn(MCPhysReg PhysReg, LaneBitmask LaneMask = ~0u) {
+ void addLiveIn(MCPhysReg PhysReg,
+ LaneBitmask LaneMask = LaneBitmask::getAll()) {
LiveIns.push_back(RegisterMaskPair(PhysReg, LaneMask));
}
void addLiveIn(const RegisterMaskPair &RegMaskPair) {
@@ -297,16 +289,21 @@ public:
/// LiveIn insertion.
void sortUniqueLiveIns();
+ /// Clear live in list.
+ void clearLiveIns();
+
/// 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(MCPhysReg PhysReg, const TargetRegisterClass *RC);
/// Remove the specified register from the live in set.
- void removeLiveIn(MCPhysReg Reg, LaneBitmask LaneMask = ~0u);
+ void removeLiveIn(MCPhysReg Reg,
+ LaneBitmask LaneMask = LaneBitmask::getAll());
/// Return true if the specified register is in the live in set.
- bool isLiveIn(MCPhysReg Reg, LaneBitmask LaneMask = ~0u) const;
+ bool isLiveIn(MCPhysReg Reg,
+ LaneBitmask LaneMask = LaneBitmask::getAll()) const;
// Iteration support for live in sets. These sets are kept in sorted
// order by their register number.
@@ -462,10 +459,15 @@ public:
iterator getFirstNonPHI();
/// 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.
+ /// This is the correct point to insert lowered copies at the beginning of a
+ /// basic block that must be before any debugging information.
iterator SkipPHIsAndLabels(iterator I);
+ /// Return the first instruction in MBB after I that is not a PHI, label or
+ /// debug. This is the correct point to insert copies at the beginning of a
+ /// basic block.
+ iterator SkipPHIsLabelsAndDebug(iterator I);
+
/// Returns an iterator to the first terminator instruction of this basic
/// block. If a terminator does not exist, it returns end().
iterator getFirstTerminator();
@@ -705,7 +707,7 @@ private:
BranchProbability getSuccProbability(const_succ_iterator Succ) const;
// Methods used to maintain doubly linked list of blocks...
- friend struct ilist_traits<MachineBasicBlock>;
+ friend struct ilist_callback_traits<MachineBasicBlock>;
// Machine-CFG mutators
@@ -739,31 +741,21 @@ struct MBB2NumberFunctor :
//
template <> struct GraphTraits<MachineBasicBlock *> {
- typedef MachineBasicBlock NodeType;
typedef MachineBasicBlock *NodeRef;
typedef MachineBasicBlock::succ_iterator ChildIteratorType;
- static NodeType *getEntryNode(MachineBasicBlock *BB) { return BB; }
- static inline ChildIteratorType child_begin(NodeType *N) {
- return N->succ_begin();
- }
- static inline ChildIteratorType child_end(NodeType *N) {
- return N->succ_end();
- }
+ static NodeRef getEntryNode(MachineBasicBlock *BB) { return BB; }
+ static ChildIteratorType child_begin(NodeRef N) { return N->succ_begin(); }
+ static ChildIteratorType child_end(NodeRef N) { return N->succ_end(); }
};
template <> struct GraphTraits<const MachineBasicBlock *> {
- typedef const MachineBasicBlock NodeType;
typedef const MachineBasicBlock *NodeRef;
typedef MachineBasicBlock::const_succ_iterator ChildIteratorType;
- static NodeType *getEntryNode(const MachineBasicBlock *BB) { return BB; }
- static inline ChildIteratorType child_begin(NodeType *N) {
- return N->succ_begin();
- }
- static inline ChildIteratorType child_end(NodeType *N) {
- return N->succ_end();
- }
+ static NodeRef getEntryNode(const MachineBasicBlock *BB) { return BB; }
+ static ChildIteratorType child_begin(NodeRef N) { return N->succ_begin(); }
+ static ChildIteratorType child_end(NodeRef N) { return N->succ_end(); }
};
// Provide specializations of GraphTraits to be able to treat a
@@ -773,33 +765,23 @@ template <> struct GraphTraits<const MachineBasicBlock *> {
// instead of the successor edges.
//
template <> struct GraphTraits<Inverse<MachineBasicBlock*> > {
- typedef MachineBasicBlock NodeType;
typedef MachineBasicBlock *NodeRef;
typedef MachineBasicBlock::pred_iterator ChildIteratorType;
- static NodeType *getEntryNode(Inverse<MachineBasicBlock *> G) {
+ static NodeRef getEntryNode(Inverse<MachineBasicBlock *> G) {
return G.Graph;
}
- static inline ChildIteratorType child_begin(NodeType *N) {
- return N->pred_begin();
- }
- static inline ChildIteratorType child_end(NodeType *N) {
- return N->pred_end();
- }
+ static ChildIteratorType child_begin(NodeRef N) { return N->pred_begin(); }
+ static ChildIteratorType child_end(NodeRef N) { return N->pred_end(); }
};
template <> struct GraphTraits<Inverse<const MachineBasicBlock*> > {
- typedef const MachineBasicBlock NodeType;
typedef const MachineBasicBlock *NodeRef;
typedef MachineBasicBlock::const_pred_iterator ChildIteratorType;
- static NodeType *getEntryNode(Inverse<const MachineBasicBlock*> G) {
+ static NodeRef getEntryNode(Inverse<const MachineBasicBlock *> G) {
return G.Graph;
}
- static inline ChildIteratorType child_begin(NodeType *N) {
- return N->pred_begin();
- }
- static inline ChildIteratorType child_end(NodeType *N) {
- return N->pred_end();
- }
+ static ChildIteratorType child_begin(NodeRef N) { return N->pred_begin(); }
+ static ChildIteratorType child_end(NodeRef N) { return N->pred_end(); }
};
@@ -827,6 +809,28 @@ public:
MachineBasicBlock::iterator getInitial() { return I; }
};
+/// Increment \p It until it points to a non-debug instruction or to \p End
+/// and return the resulting iterator. This function should only be used
+/// MachineBasicBlock::{iterator, const_iterator, instr_iterator,
+/// const_instr_iterator} and the respective reverse iterators.
+template<typename IterT>
+inline IterT skipDebugInstructionsForward(IterT It, IterT End) {
+ while (It != End && It->isDebugValue())
+ It++;
+ return It;
+}
+
+/// Decrement \p It until it points to a non-debug instruction or to \p Begin
+/// and return the resulting iterator. This function should only be used
+/// MachineBasicBlock::{iterator, const_iterator, instr_iterator,
+/// const_instr_iterator} and the respective reverse iterators.
+template<class IterT>
+inline IterT skipDebugInstructionsBackward(IterT It, IterT Begin) {
+ while (It != Begin && It->isDebugValue())
+ It--;
+ return It;
+}
+
} // End llvm namespace
#endif