LLVM 22.0.0git
PredIteratorCache.h
Go to the documentation of this file.
1//===- PredIteratorCache.h - pred_iterator Cache ----------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the PredIteratorCache class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_IR_PREDITERATORCACHE_H
14#define LLVM_IR_PREDITERATORCACHE_H
15
16#include "llvm/ADT/ArrayRef.h"
17#include "llvm/ADT/DenseMap.h"
19#include "llvm/IR/CFG.h"
21
22namespace llvm {
23
24/// PredIteratorCache - This class is an extremely trivial cache for
25/// predecessor iterator queries. This is useful for code that repeatedly
26/// wants the predecessor list for the same blocks.
28 /// Cached list of predecessors, allocated in Memory.
30
31 /// Memory - This is the space that holds cached preds.
32 BumpPtrAllocator Memory;
33
34public:
35 size_t size(BasicBlock *BB) { return get(BB).size(); }
37 ArrayRef<BasicBlock *> &Entry = BlockToPredsMap[BB];
38 if (Entry.data())
39 return Entry;
40
42 BasicBlock **Data = Memory.Allocate<BasicBlock *>(PredCache.size());
43 std::copy(PredCache.begin(), PredCache.end(), Data);
44 Entry = ArrayRef(Data, PredCache.size());
45 return Entry;
46 }
47
48 /// clear - Remove all information.
49 void clear() {
50 BlockToPredsMap.clear();
51 Memory.Reset();
52 }
53};
54
55} // end namespace llvm
56
57#endif
This file defines the BumpPtrAllocator interface.
This file defines the DenseMap class.
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
LLVM Basic Block Representation.
Definition BasicBlock.h:62
PredIteratorCache - This class is an extremely trivial cache for predecessor iterator queries.
size_t size(BasicBlock *BB)
void clear()
clear - Remove all information.
ArrayRef< BasicBlock * > get(BasicBlock *BB)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This is an optimization pass for GlobalISel generic memory operations.
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:383
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:189
ArrayRef(const T &OneElt) -> ArrayRef< T >
auto predecessors(const MachineBasicBlock *BB)