File indexing completed on 2026-05-10 08:43:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_EXECUTIONENGINE_ORC_SPECULATEANALYSES_H
0014 #define LLVM_EXECUTIONENGINE_ORC_SPECULATEANALYSES_H
0015
0016 #include "llvm/Analysis/BranchProbabilityInfo.h"
0017 #include "llvm/ExecutionEngine/Orc/Core.h"
0018 #include "llvm/ExecutionEngine/Orc/Speculation.h"
0019
0020 namespace llvm {
0021
0022 namespace orc {
0023
0024
0025 class SpeculateQuery {
0026 protected:
0027 void findCalles(const BasicBlock *, DenseSet<StringRef> &);
0028 bool isStraightLine(const Function &F);
0029
0030 public:
0031 using ResultTy = std::optional<DenseMap<StringRef, DenseSet<StringRef>>>;
0032 };
0033
0034
0035 class BlockFreqQuery : public SpeculateQuery {
0036 size_t numBBToGet(size_t);
0037
0038 public:
0039
0040 ResultTy operator()(Function &F);
0041 };
0042
0043
0044
0045
0046
0047 class SequenceBBQuery : public SpeculateQuery {
0048 struct WalkDirection {
0049 bool Upward = true, Downward = true;
0050
0051 bool CallerBlock = false;
0052 };
0053
0054 public:
0055 using VisitedBlocksInfoTy = DenseMap<const BasicBlock *, WalkDirection>;
0056 using BlockListTy = SmallVector<const BasicBlock *, 8>;
0057 using BackEdgesInfoTy =
0058 SmallVector<std::pair<const BasicBlock *, const BasicBlock *>, 8>;
0059 using BlockFreqInfoTy =
0060 SmallVector<std::pair<const BasicBlock *, uint64_t>, 8>;
0061
0062 private:
0063 std::size_t getHottestBlocks(std::size_t TotalBlocks);
0064 BlockListTy rearrangeBB(const Function &, const BlockListTy &);
0065 BlockListTy queryCFG(Function &, const BlockListTy &);
0066 void traverseToEntryBlock(const BasicBlock *, const BlockListTy &,
0067 const BackEdgesInfoTy &,
0068 const BranchProbabilityInfo *,
0069 VisitedBlocksInfoTy &);
0070 void traverseToExitBlock(const BasicBlock *, const BlockListTy &,
0071 const BackEdgesInfoTy &,
0072 const BranchProbabilityInfo *,
0073 VisitedBlocksInfoTy &);
0074
0075 public:
0076 ResultTy operator()(Function &F);
0077 };
0078
0079 }
0080 }
0081
0082 #endif