1 //===- llvm/IR/UseListOrder.h - LLVM Use List Order functions ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file has functions to modify the use-list order and to verify that it
11 // doesn't change after serialization.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_IR_USELISTORDER_H
16 #define LLVM_IR_USELISTORDER_H
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/SmallVector.h"
28 /// \brief Structure to hold a use-list shuffle vector.
30 /// Stores most use-lists locally, but large use-lists use an extra heap entry.
31 /// Costs two fewer pointers than the equivalent \a SmallVector.
32 class UseListShuffleVector {
39 bool isSmall() const { return Size <= 6; }
40 unsigned *data() { return isSmall() ? Storage.Array : Storage.Ptr; }
41 const unsigned *data() const {
42 return isSmall() ? Storage.Array : Storage.Ptr;
49 void moveUnchecked(UseListShuffleVector &X) {
50 std::memcpy(this, &X, sizeof(UseListShuffleVector));
54 UseListShuffleVector(const UseListShuffleVector &X) LLVM_DELETED_FUNCTION;
55 UseListShuffleVector &
56 operator=(const UseListShuffleVector &X) LLVM_DELETED_FUNCTION;
59 UseListShuffleVector() : Size(0) {}
60 UseListShuffleVector(UseListShuffleVector &&X) { moveUnchecked(X); }
61 UseListShuffleVector &operator=(UseListShuffleVector &&X) {
66 explicit UseListShuffleVector(size_t Size) : Size(Size) {
68 Storage.Ptr = new unsigned[Size];
70 ~UseListShuffleVector() { destroy(); }
72 typedef unsigned *iterator;
73 typedef const unsigned *const_iterator;
75 size_t size() const { return Size; }
76 iterator begin() { return data(); }
77 iterator end() { return begin() + size(); }
78 const_iterator begin() const { return data(); }
79 const_iterator end() const { return begin() + size(); }
80 unsigned &operator[](size_t I) { return data()[I]; }
81 unsigned operator[](size_t I) const { return data()[I]; }
84 /// \brief Structure to hold a use-list order.
88 UseListShuffleVector Shuffle;
90 UseListOrder(const Value *V, const Function *F, size_t ShuffleSize)
91 : V(V), F(F), Shuffle(ShuffleSize) {}
94 typedef std::vector<UseListOrder> UseListOrderStack;
96 /// \brief Whether to preserve use-list ordering.
97 bool shouldPreserveBitcodeUseListOrder();
98 bool shouldPreserveAssemblyUseListOrder();
100 /// \brief Shuffle all use-lists in a module.
102 /// Adds \c SeedOffset to the default seed for the random number generator.
103 void shuffleUseLists(Module &M, unsigned SeedOffset = 0);
105 } // end namespace llvm