39#ifndef LLVM_SUPPORT_BALANCED_PARTITIONING_H
40#define LLVM_SUPPORT_BALANCED_PARTITIONING_H
46#include <condition_variable>
53class ThreadPoolInterface;
105 void run(std::vector<BPFunctionNode> &Nodes)
const;
108 struct UtilitySignature;
117 struct BPThreadPool {
120 std::condition_variable cv;
122 std::atomic<int> NumActiveThreads = 0;
124 bool IsFinishedSpawning =
false;
126 template <
typename Func>
void async(Func &&
F);
132 : TheThreadPool(TheThreadPool) {}
141 unsigned RootBucket,
unsigned Offset,
142 std::optional<BPThreadPool> &TP)
const;
146 unsigned RightBucket, std::mt19937 &RNG)
const;
152 std::mt19937 &RNG)
const;
158 std::mt19937 &RNG)
const;
166 float logCost(
unsigned X,
unsigned Y)
const;
168 float log2Cached(
unsigned i)
const;
173 static constexpr unsigned LOG_CACHE_SIZE = 16384;
174 float Log2Cache[LOG_CACHE_SIZE];
178 struct UtilitySignature {
180 unsigned LeftCount = 0;
182 unsigned RightCount = 0;
190 bool CachedGainIsValid =
false;
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
static const FuncProtoTy Signatures[]
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
A function with a set of utility nodes where it is beneficial to order two functions close together i...
IDT Id
The ID of this node.
friend class BPFunctionNodeTest_Basic_Test
BPFunctionNode(IDT Id, ArrayRef< UtilityNodeT > UtilityNodes)
friend class BalancedPartitioningTest_Large_Test
SmallVector< UtilityNodeT, 4 > UtilityNodes
The list of utility nodes associated with this node.
uint64_t InputOrderIndex
The index of the input order of the FunctionNodes.
friend class BalancedPartitioningTest_Basic_Test
std::optional< unsigned > Bucket
The bucket assigned by balanced partitioning.
void dump(raw_ostream &OS) const
static float moveGain(const BPFunctionNode &N, bool FromLeftToRight, const SignaturesT &Signatures)
Compute the move gain for uniform log-gap cost.
void run(std::vector< BPFunctionNode > &Nodes) const
Run recursive graph partitioning that optimizes a given objective.
friend class BalancedPartitioningTest_MoveGain_Test
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This defines the abstract base interface for a ThreadPool allowing asynchronous parallel execution on...
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
Algorithm parameters; default values are tuned on real-world binaries.
unsigned SplitDepth
The depth of the recursive bisection.
float SkipProbability
The probability for a vertex to skip a move from its current bucket to another bucket; it often helps...
unsigned TaskSplitDepth
Recursive subtasks up to the given depth are added to the queue and distributed among threads by Thre...
unsigned IterationsPerSplit
The maximum number of bp iterations per split.