mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-30 02:25:19 +00:00
IR: Optimize size of use-list order shuffle vectors
Since we're storing lots of these, save two-pointers per vector with a custom type rather than using the relatively heavy `SmallVector`. Part of PR5680. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214135 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -25,11 +25,58 @@ class Module;
|
|||||||
class Function;
|
class Function;
|
||||||
class Value;
|
class Value;
|
||||||
|
|
||||||
|
/// \brief Structure to hold a use-list shuffle vector.
|
||||||
|
///
|
||||||
|
/// Stores most use-lists locally, but large use-lists use an extra heap entry.
|
||||||
|
/// Costs two fewer pointers than the equivalent \a SmallVector.
|
||||||
|
class UseListShuffleVector {
|
||||||
|
unsigned Size;
|
||||||
|
union {
|
||||||
|
unsigned *Ptr;
|
||||||
|
unsigned Array[6];
|
||||||
|
} Storage;
|
||||||
|
|
||||||
|
bool isSmall() const { return Size <= 6; }
|
||||||
|
unsigned *data() { return isSmall() ? Storage.Array : Storage.Ptr; }
|
||||||
|
const unsigned *data() const {
|
||||||
|
return isSmall() ? Storage.Array : Storage.Ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
UseListShuffleVector() : Size(0) {}
|
||||||
|
UseListShuffleVector(UseListShuffleVector &&X) {
|
||||||
|
std::memcpy(this, &X, sizeof(UseListShuffleVector));
|
||||||
|
X.Size = 0;
|
||||||
|
}
|
||||||
|
explicit UseListShuffleVector(size_t Size) : Size(Size) {
|
||||||
|
if (!isSmall())
|
||||||
|
Storage.Ptr = new unsigned[Size];
|
||||||
|
}
|
||||||
|
~UseListShuffleVector() {
|
||||||
|
if (!isSmall())
|
||||||
|
delete Storage.Ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef unsigned *iterator;
|
||||||
|
typedef const unsigned *const_iterator;
|
||||||
|
|
||||||
|
size_t size() const { return Size; }
|
||||||
|
iterator begin() { return data(); }
|
||||||
|
iterator end() { return begin() + size(); }
|
||||||
|
const_iterator begin() const { return data(); }
|
||||||
|
const_iterator end() const { return begin() + size(); }
|
||||||
|
unsigned &operator[](size_t I) { return data()[I]; }
|
||||||
|
unsigned operator[](size_t I) const { return data()[I]; }
|
||||||
|
};
|
||||||
|
|
||||||
/// \brief Structure to hold a use-list order.
|
/// \brief Structure to hold a use-list order.
|
||||||
struct UseListOrder {
|
struct UseListOrder {
|
||||||
const Function *F;
|
|
||||||
const Value *V;
|
const Value *V;
|
||||||
SmallVector<unsigned, 8> Shuffle;
|
const Function *F;
|
||||||
|
UseListShuffleVector Shuffle;
|
||||||
|
|
||||||
|
UseListOrder(const Value *V, const Function *F, size_t ShuffleSize)
|
||||||
|
: V(V), F(F), Shuffle(ShuffleSize) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<UseListOrder> UseListOrderStack;
|
typedef std::vector<UseListOrder> UseListOrderStack;
|
||||||
|
@@ -133,12 +133,11 @@ static void predictValueUseListOrderImpl(const Value *V, const Function *F,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Store the shuffle.
|
// Store the shuffle.
|
||||||
UseListOrder O;
|
UseListOrder O(V, F, List.size());
|
||||||
O.V = V;
|
assert(List.size() == O.Shuffle.size() && "Wrong size");
|
||||||
O.F = F;
|
for (size_t I = 0, E = List.size(); I != E; ++I)
|
||||||
for (auto &I : List)
|
O.Shuffle[I] = List[I].second;
|
||||||
O.Shuffle.push_back(I.second);
|
Stack.emplace_back(std::move(O));
|
||||||
Stack.push_back(O);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void predictValueUseListOrder(const Value *V, const Function *F,
|
static void predictValueUseListOrder(const Value *V, const Function *F,
|
||||||
|
Reference in New Issue
Block a user