[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / lib / Bitcode / Reader / ValueList.h
bloba39617018f4232b8f6d5afa01131d7969ce73024
1 //===-- Bitcode/Reader/ValueList.h - Number values --------------*- 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 class gives values and types Unique ID's.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_BITCODE_READER_VALUELIST_H
14 #define LLVM_LIB_BITCODE_READER_VALUELIST_H
16 #include "llvm/IR/ValueHandle.h"
17 #include <cassert>
18 #include <utility>
19 #include <vector>
21 namespace llvm {
23 class Constant;
24 class LLVMContext;
25 class Type;
26 class Value;
28 class BitcodeReaderValueList {
29 std::vector<WeakTrackingVH> ValuePtrs;
31 /// As we resolve forward-referenced constants, we add information about them
32 /// to this vector. This allows us to resolve them in bulk instead of
33 /// resolving each reference at a time. See the code in
34 /// ResolveConstantForwardRefs for more information about this.
35 ///
36 /// The key of this vector is the placeholder constant, the value is the slot
37 /// number that holds the resolved value.
38 using ResolveConstantsTy = std::vector<std::pair<Constant *, unsigned>>;
39 ResolveConstantsTy ResolveConstants;
40 LLVMContext &Context;
42 /// Maximum number of valid references. Forward references exceeding the
43 /// maximum must be invalid.
44 unsigned RefsUpperBound;
46 public:
47 BitcodeReaderValueList(LLVMContext &C, size_t RefsUpperBound)
48 : Context(C),
49 RefsUpperBound(std::min((size_t)std::numeric_limits<unsigned>::max(),
50 RefsUpperBound)) {}
52 ~BitcodeReaderValueList() {
53 assert(ResolveConstants.empty() && "Constants not resolved?");
56 // vector compatibility methods
57 unsigned size() const { return ValuePtrs.size(); }
58 void resize(unsigned N) {
59 ValuePtrs.resize(N);
61 void push_back(Value *V) { ValuePtrs.emplace_back(V); }
63 void clear() {
64 assert(ResolveConstants.empty() && "Constants not resolved?");
65 ValuePtrs.clear();
68 Value *operator[](unsigned i) const {
69 assert(i < ValuePtrs.size());
70 return ValuePtrs[i];
73 Value *back() const { return ValuePtrs.back(); }
74 void pop_back() {
75 ValuePtrs.pop_back();
77 bool empty() const { return ValuePtrs.empty(); }
79 void shrinkTo(unsigned N) {
80 assert(N <= size() && "Invalid shrinkTo request!");
81 ValuePtrs.resize(N);
84 Constant *getConstantFwdRef(unsigned Idx, Type *Ty);
85 Value *getValueFwdRef(unsigned Idx, Type *Ty);
87 void assignValue(Value *V, unsigned Idx);
89 /// Once all constants are read, this method bulk resolves any forward
90 /// references.
91 void resolveConstantForwardRefs();
94 } // end namespace llvm
96 #endif // LLVM_LIB_BITCODE_READER_VALUELIST_H