1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-23 04:52:54 +02:00

CodeGen: Split bundle_iterator into a separate file, NFC

Split MachineBasicBlock::bundle_iterator into a separate file, and
rename the class to MachineBundleIterator.

This is a precursor to adding a `MachineInstr::getBundleIterator()`
accessor, which will eventually let us delete the final call to
getNodePtrUnchecked(), and then remove the UB from ilist_iterator.

As a drive-by, I removed an unnecessary second template parameter.

llvm-svn: 261502
This commit is contained in:
Duncan P. N. Exon Smith 2016-02-21 22:05:50 +00:00
parent 9902368eff
commit 9cd515c2c0
2 changed files with 95 additions and 68 deletions

View File

@ -15,6 +15,7 @@
#define LLVM_CODEGEN_MACHINEBASICBLOCK_H
#include "llvm/ADT/GraphTraits.h"
#include "llvm/CodeGen/MachineInstrBundleIterator.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/Support/BranchProbability.h"
#include "llvm/MC/MCRegisterInfo.h"
@ -157,80 +158,14 @@ public:
const MachineFunction *getParent() const { return xParent; }
MachineFunction *getParent() { return xParent; }
/// 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:
bundle_iterator(IterTy MI) : MII(MI) {}
bundle_iterator(Ty &MI) : MII(MI) {
assert(!MI.isBundledWithPred() &&
"It's not legal to initialize bundle_iterator with a bundled MI");
}
bundle_iterator(Ty *MI) : MII(MI) {
assert((!MI || !MI->isBundledWithPred()) &&
"It's not legal to initialize bundle_iterator with a bundled MI");
}
// Template allows conversion from const to nonconst.
template<class OtherTy, class OtherIterTy>
bundle_iterator(const bundle_iterator<OtherTy, OtherIterTy> &I)
: MII(I.getInstrIterator()) {}
bundle_iterator() : MII(nullptr) {}
Ty &operator*() const { return *MII; }
Ty *operator->() const { return &operator*(); }
operator Ty *() const { return MII.getNodePtrUnchecked(); }
bool operator==(const bundle_iterator &X) const {
return MII == X.MII;
}
bool operator!=(const bundle_iterator &X) const {
return !operator==(X);
}
// Increment and decrement operators...
bundle_iterator &operator--() { // predecrement - Back up
do --MII;
while (MII->isBundledWithPred());
return *this;
}
bundle_iterator &operator++() { // preincrement - Advance
while (MII->isBundledWithSucc())
++MII;
++MII;
return *this;
}
bundle_iterator operator--(int) { // postdecrement operators...
bundle_iterator tmp = *this;
--*this;
return tmp;
}
bundle_iterator operator++(int) { // postincrement operators...
bundle_iterator tmp = *this;
++*this;
return tmp;
}
IterTy getInstrIterator() const {
return MII;
}
};
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
bundle_iterator<MachineInstr,instr_iterator> iterator;
typedef
bundle_iterator<const MachineInstr,const_instr_iterator> const_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;

View File

@ -0,0 +1,92 @@
//===- llvm/CodeGen/MachineInstrBundleIterator.h ----------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Defines an iterator class that bundles MachineInstr.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CODEGEN_MACHINEINSTRBUNDLEITERATOR_H
#define LLVM_CODEGEN_MACHINEINSTRBUNDLEITERATOR_H
#include "llvm/ADT/ilist.h"
#include <iterator>
namespace llvm {
/// MachineBasicBlock iterator that automatically skips over MIs that are
/// inside bundles (i.e. walk top level MIs only).
template <typename Ty>
class MachineInstrBundleIterator
: public std::iterator<std::bidirectional_iterator_tag, Ty, ptrdiff_t> {
typedef ilist_iterator<Ty> instr_iterator;
instr_iterator MII;
public:
MachineInstrBundleIterator(instr_iterator MI) : MII(MI) {}
MachineInstrBundleIterator(Ty &MI) : MII(MI) {
assert(!MI.isBundledWithPred() && "It's not legal to initialize "
"MachineInstrBundleIterator with a "
"bundled MI");
}
MachineInstrBundleIterator(Ty *MI) : MII(MI) {
// FIXME: This conversion should be explicit.
assert((!MI || !MI->isBundledWithPred()) && "It's not legal to initialize "
"MachineInstrBundleIterator "
"with a bundled MI");
}
// Template allows conversion from const to nonconst.
template <class OtherTy>
MachineInstrBundleIterator(const MachineInstrBundleIterator<OtherTy> &I)
: MII(I.getInstrIterator()) {}
MachineInstrBundleIterator() : MII(nullptr) {}
Ty &operator*() const { return *MII; }
Ty *operator->() const { return &operator*(); }
// FIXME: This conversion should be explicit.
operator Ty *() const { return MII.getNodePtrUnchecked(); }
bool operator==(const MachineInstrBundleIterator &X) const {
return MII == X.MII;
}
bool operator!=(const MachineInstrBundleIterator &X) const {
return !operator==(X);
}
// Increment and decrement operators...
MachineInstrBundleIterator &operator--() {
do
--MII;
while (MII->isBundledWithPred());
return *this;
}
MachineInstrBundleIterator &operator++() {
while (MII->isBundledWithSucc())
++MII;
++MII;
return *this;
}
MachineInstrBundleIterator operator--(int) {
MachineInstrBundleIterator Temp = *this;
--*this;
return Temp;
}
MachineInstrBundleIterator operator++(int) {
MachineInstrBundleIterator Temp = *this;
++*this;
return Temp;
}
instr_iterator getInstrIterator() const { return MII; }
};
} // end namespace llvm
#endif