mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 03:02:36 +01:00
Reverting r243386 because it has serious post-commit concerns that have not been addressed. Also reverts r243389, which relied on this commit.
llvm-svn: 243527
This commit is contained in:
parent
b3c79b1eeb
commit
947bf10c75
@ -1314,8 +1314,7 @@ never use hash_set and unordered_set because they are generally very expensive
|
|||||||
std::multiset is useful if you're not interested in elimination of duplicates,
|
std::multiset is useful if you're not interested in elimination of duplicates,
|
||||||
but has all the drawbacks of :ref:`std::set <dss_set>`. A sorted vector
|
but has all the drawbacks of :ref:`std::set <dss_set>`. A sorted vector
|
||||||
(where you don't delete duplicate entries) or some other approach is almost
|
(where you don't delete duplicate entries) or some other approach is almost
|
||||||
always better. LLVM actually offers SortedVector which does the job of a sorted
|
always better.
|
||||||
std::vector.
|
|
||||||
|
|
||||||
.. _ds_map:
|
.. _ds_map:
|
||||||
|
|
||||||
|
@ -1,133 +0,0 @@
|
|||||||
//===-- llvm/ADT/SortedVector.h ---------------------------------*- C++ -*-===//
|
|
||||||
//
|
|
||||||
// The LLVM Compiler Infrastructure
|
|
||||||
//
|
|
||||||
// This file is distributed under the University of Illinois Open Source
|
|
||||||
// License. See LICENSE.TXT for details.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#ifndef LLVM_ADT_SORTEDVECTOR_H
|
|
||||||
#define LLVM_ADT_SORTEDVECTOR_H
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <cassert>
|
|
||||||
#include <functional>
|
|
||||||
#include "llvm/Support/raw_ostream.h"
|
|
||||||
|
|
||||||
namespace llvm {
|
|
||||||
|
|
||||||
/// \brief Lazily maintains a sorted and unique vector of elements of type T.
|
|
||||||
template<typename T, typename CMP = std::less<T>>
|
|
||||||
class SortedVector {
|
|
||||||
public:
|
|
||||||
typedef typename std::vector<T> VectorType;
|
|
||||||
typedef typename VectorType::iterator iterator;
|
|
||||||
typedef typename VectorType::const_iterator const_iterator;
|
|
||||||
|
|
||||||
private:
|
|
||||||
VectorType Vector;
|
|
||||||
bool IsSorted = true;
|
|
||||||
|
|
||||||
void doCheck() const {
|
|
||||||
assert(IsSorted && "Unsorted SortedVector access; call sortUnique prior.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// \brief Appends Entry to the sorted unique vector; sets the IsSorted flag
|
|
||||||
/// to false if appending Entry puts Vector into an unsorted state.
|
|
||||||
void insert(const T &Entry) {
|
|
||||||
if (!Vector.size())
|
|
||||||
Vector.push_back(Entry);
|
|
||||||
|
|
||||||
// Vector is sorted and Entry is a duplicate of the previous so skip.
|
|
||||||
if (IsSorted && Entry == Vector.back())
|
|
||||||
return;
|
|
||||||
|
|
||||||
IsSorted &= (CMP()(Vector.back(), Entry));
|
|
||||||
Vector.push_back(Entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
// \brief Sorts and uniques Vector.
|
|
||||||
void sortUnique() {
|
|
||||||
if (IsSorted)
|
|
||||||
return;
|
|
||||||
|
|
||||||
std::sort(Vector.begin(), Vector.end());
|
|
||||||
Vector.erase(std::unique(Vector.begin(), Vector.end()), Vector.end());
|
|
||||||
IsSorted = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Tells if Entry is in Vector without relying on sorted-uniqueness.
|
|
||||||
bool has(T Entry) const {
|
|
||||||
if (IsSorted)
|
|
||||||
return std::binary_search(Vector.begin(), Vector.end(), Entry);
|
|
||||||
|
|
||||||
return std::find(Vector.begin(), Vector.end(), Entry) != Vector.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Returns a reference to the entry with the specified index.
|
|
||||||
const T &operator[](unsigned index) const {
|
|
||||||
assert(index < size() && "SortedVector index is out of range!");
|
|
||||||
doCheck();
|
|
||||||
return Vector[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Return an iterator to the start of the vector.
|
|
||||||
iterator begin() {
|
|
||||||
doCheck();
|
|
||||||
return Vector.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Returns const iterator to the start of the vector.
|
|
||||||
const_iterator begin() const {
|
|
||||||
doCheck();
|
|
||||||
return Vector.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Returns iterator to the end of Vector.
|
|
||||||
iterator end() {
|
|
||||||
doCheck();
|
|
||||||
return Vector.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Returns const iterator to the end of Vector. Assert if unsorted.
|
|
||||||
const_iterator end() const {
|
|
||||||
doCheck();
|
|
||||||
return Vector.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Erases Vector at position. Asserts if Vector is unsorted.
|
|
||||||
iterator erase(iterator position) {
|
|
||||||
doCheck();
|
|
||||||
return Vector.erase(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Erases Vector entirely.
|
|
||||||
iterator erase() {
|
|
||||||
IsSorted = true;
|
|
||||||
return Vector.erase();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Returns number of entries in Vector; asserts if it is unsorted.
|
|
||||||
size_t size() const {
|
|
||||||
doCheck();
|
|
||||||
return Vector.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Returns true if Vector is empty.
|
|
||||||
bool empty() const {
|
|
||||||
return Vector.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Clears all the entries.
|
|
||||||
void reset() {
|
|
||||||
IsSorted = true;
|
|
||||||
Vector.resize(0, 0);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // End of namespace llvm
|
|
||||||
|
|
||||||
#endif // LLVM_ADT_SORTEDVECTOR_H
|
|
||||||
|
|
@ -14,7 +14,6 @@
|
|||||||
#ifndef LLVM_CODEGEN_MACHINEBASICBLOCK_H
|
#ifndef LLVM_CODEGEN_MACHINEBASICBLOCK_H
|
||||||
#define LLVM_CODEGEN_MACHINEBASICBLOCK_H
|
#define LLVM_CODEGEN_MACHINEBASICBLOCK_H
|
||||||
|
|
||||||
#include "llvm/ADT/SortedVector.h"
|
|
||||||
#include "llvm/ADT/GraphTraits.h"
|
#include "llvm/ADT/GraphTraits.h"
|
||||||
#include "llvm/CodeGen/MachineInstr.h"
|
#include "llvm/CodeGen/MachineInstr.h"
|
||||||
#include "llvm/Support/DataTypes.h"
|
#include "llvm/Support/DataTypes.h"
|
||||||
@ -81,7 +80,7 @@ class MachineBasicBlock : public ilist_node<MachineBasicBlock> {
|
|||||||
|
|
||||||
/// LiveIns - Keep track of the physical registers that are livein of
|
/// LiveIns - Keep track of the physical registers that are livein of
|
||||||
/// the basicblock.
|
/// the basicblock.
|
||||||
mutable SortedVector<unsigned> LiveIns;
|
std::vector<unsigned> LiveIns;
|
||||||
|
|
||||||
/// Alignment - Alignment of the basic block. Zero if the basic block does
|
/// Alignment - Alignment of the basic block. Zero if the basic block does
|
||||||
/// not need to be aligned.
|
/// not need to be aligned.
|
||||||
@ -319,12 +318,15 @@ public:
|
|||||||
/// Adds the specified register as a live in. Note that it is an error to add
|
/// 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
|
/// the same register to the same set more than once unless the intention is
|
||||||
/// to call sortUniqueLiveIns after all registers are added.
|
/// to call sortUniqueLiveIns after all registers are added.
|
||||||
void addLiveIn(unsigned Reg) { LiveIns.insert(Reg); }
|
void addLiveIn(unsigned Reg) { LiveIns.push_back(Reg); }
|
||||||
|
|
||||||
/// Sorts and uniques the LiveIns vector. It can be significantly faster to do
|
/// Sorts and uniques the LiveIns vector. It can be significantly faster to do
|
||||||
/// this than repeatedly calling isLiveIn before calling addLiveIn for every
|
/// this than repeatedly calling isLiveIn before calling addLiveIn for every
|
||||||
/// LiveIn insertion.
|
/// LiveIn insertion.
|
||||||
void sortUniqueLiveIns() { LiveIns.sortUnique(); }
|
void sortUniqueLiveIns() {
|
||||||
|
std::sort(LiveIns.begin(), LiveIns.end());
|
||||||
|
LiveIns.erase(std::unique(LiveIns.begin(), LiveIns.end()), LiveIns.end());
|
||||||
|
}
|
||||||
|
|
||||||
/// Add PhysReg as live in to this block, and ensure that there is a copy of
|
/// 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
|
/// PhysReg to a virtual register of class RC. Return the virtual register
|
||||||
@ -337,20 +339,14 @@ public:
|
|||||||
|
|
||||||
/// isLiveIn - Return true if the specified register is in the live in set.
|
/// isLiveIn - Return true if the specified register is in the live in set.
|
||||||
///
|
///
|
||||||
bool isLiveIn(unsigned Reg) const { return LiveIns.has(Reg); }
|
bool isLiveIn(unsigned Reg) const;
|
||||||
|
|
||||||
// Iteration support for live in sets. These sets are kept in sorted
|
// Iteration support for live in sets. These sets are kept in sorted
|
||||||
// order by their register number.
|
// order by their register number.
|
||||||
typedef std::vector<unsigned>::const_iterator livein_iterator;
|
typedef std::vector<unsigned>::const_iterator livein_iterator;
|
||||||
|
livein_iterator livein_begin() const { return LiveIns.begin(); }
|
||||||
|
livein_iterator livein_end() const { return LiveIns.end(); }
|
||||||
bool livein_empty() const { return LiveIns.empty(); }
|
bool livein_empty() const { return LiveIns.empty(); }
|
||||||
livein_iterator livein_begin() const {
|
|
||||||
LiveIns.sortUnique();
|
|
||||||
return LiveIns.begin();
|
|
||||||
}
|
|
||||||
livein_iterator livein_end() const {
|
|
||||||
LiveIns.sortUnique();
|
|
||||||
return LiveIns.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// getAlignment - Return alignment of the basic block.
|
/// getAlignment - Return alignment of the basic block.
|
||||||
/// The alignment is specified as log2(bytes).
|
/// The alignment is specified as log2(bytes).
|
||||||
|
@ -332,6 +332,11 @@ void MachineBasicBlock::removeLiveIn(unsigned Reg) {
|
|||||||
LiveIns.erase(I);
|
LiveIns.erase(I);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MachineBasicBlock::isLiveIn(unsigned Reg) const {
|
||||||
|
livein_iterator I = std::find(livein_begin(), livein_end(), Reg);
|
||||||
|
return I != livein_end();
|
||||||
|
}
|
||||||
|
|
||||||
unsigned
|
unsigned
|
||||||
MachineBasicBlock::addLiveIn(unsigned PhysReg, const TargetRegisterClass *RC) {
|
MachineBasicBlock::addLiveIn(unsigned PhysReg, const TargetRegisterClass *RC) {
|
||||||
assert(getParent() && "MBB must be inserted in function");
|
assert(getParent() && "MBB must be inserted in function");
|
||||||
|
Loading…
Reference in New Issue
Block a user