Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:10

0001 //===- PredIteratorCache.h - pred_iterator Cache ----------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file defines the PredIteratorCache class.
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 /// PredIteratorCache - This class is an extremely trivial cache for
0025 /// predecessor iterator queries.  This is useful for code that repeatedly
0026 /// wants the predecessor list for the same blocks.
0027 class PredIteratorCache {
0028   /// Cached list of predecessors, allocated in Memory.
0029   DenseMap<BasicBlock *, ArrayRef<BasicBlock *>> BlockToPredsMap;
0030 
0031   /// Memory - This is the space that holds cached preds.
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   /// clear - Remove all information.
0049   void clear() {
0050     BlockToPredsMap.clear();
0051     Memory.Reset();
0052   }
0053 };
0054 
0055 } // end namespace llvm
0056 
0057 #endif