File indexing completed on 2026-05-10 08:44:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_IR_PREDITERATORCACHE_H
0014 #define LLVM_IR_PREDITERATORCACHE_H
0015
0016 #include "llvm/ADT/ArrayRef.h"
0017 #include "llvm/ADT/DenseMap.h"
0018 #include "llvm/ADT/SmallVector.h"
0019 #include "llvm/IR/CFG.h"
0020 #include "llvm/Support/Allocator.h"
0021
0022 namespace llvm {
0023
0024
0025
0026
0027 class PredIteratorCache {
0028
0029 DenseMap<BasicBlock *, ArrayRef<BasicBlock *>> BlockToPredsMap;
0030
0031
0032 BumpPtrAllocator Memory;
0033
0034 public:
0035 size_t size(BasicBlock *BB) { return get(BB).size(); }
0036 ArrayRef<BasicBlock *> get(BasicBlock *BB) {
0037 ArrayRef<BasicBlock *> &Entry = BlockToPredsMap[BB];
0038 if (Entry.data())
0039 return Entry;
0040
0041 SmallVector<BasicBlock *, 32> PredCache(predecessors(BB));
0042 BasicBlock **Data = Memory.Allocate<BasicBlock *>(PredCache.size());
0043 std::copy(PredCache.begin(), PredCache.end(), Data);
0044 Entry = ArrayRef(Data, PredCache.size());
0045 return Entry;
0046 }
0047
0048
0049 void clear() {
0050 BlockToPredsMap.clear();
0051 Memory.Reset();
0052 }
0053 };
0054
0055 }
0056
0057 #endif