1 //===-- Bitcode/Reader/ValueList.h - Number values --------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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"
28 class BitcodeReaderValueList
{
29 std::vector
<WeakTrackingVH
> ValuePtrs
;
31 /// Struct containing fully-specified copies of the type of each
32 /// value. When pointers are opaque, this will be contain non-opaque
33 /// variants so that restructuring instructions can determine their
34 /// type correctly even if being loaded from old bitcode where some
35 /// types are implicit.
36 std::vector
<Type
*> FullTypes
;
38 /// As we resolve forward-referenced constants, we add information about them
39 /// to this vector. This allows us to resolve them in bulk instead of
40 /// resolving each reference at a time. See the code in
41 /// ResolveConstantForwardRefs for more information about this.
43 /// The key of this vector is the placeholder constant, the value is the slot
44 /// number that holds the resolved value.
45 using ResolveConstantsTy
= std::vector
<std::pair
<Constant
*, unsigned>>;
46 ResolveConstantsTy ResolveConstants
;
49 /// Maximum number of valid references. Forward references exceeding the
50 /// maximum must be invalid.
51 unsigned RefsUpperBound
;
54 BitcodeReaderValueList(LLVMContext
&C
, size_t RefsUpperBound
)
56 RefsUpperBound(std::min((size_t)std::numeric_limits
<unsigned>::max(),
59 ~BitcodeReaderValueList() {
60 assert(ResolveConstants
.empty() && "Constants not resolved?");
63 // vector compatibility methods
64 unsigned size() const { return ValuePtrs
.size(); }
65 void resize(unsigned N
) {
69 void push_back(Value
*V
, Type
*Ty
) {
70 ValuePtrs
.emplace_back(V
);
71 FullTypes
.emplace_back(Ty
);
75 assert(ResolveConstants
.empty() && "Constants not resolved?");
80 Value
*operator[](unsigned i
) const {
81 assert(i
< ValuePtrs
.size());
85 Value
*back() const { return ValuePtrs
.back(); }
90 bool empty() const { return ValuePtrs
.empty(); }
92 void shrinkTo(unsigned N
) {
93 assert(N
<= size() && "Invalid shrinkTo request!");
98 Constant
*getConstantFwdRef(unsigned Idx
, Type
*Ty
);
99 Value
*getValueFwdRef(unsigned Idx
, Type
*Ty
, Type
**FullTy
= nullptr);
101 void assignValue(Value
*V
, unsigned Idx
, Type
*FullTy
);
103 /// Once all constants are read, this method bulk resolves any forward
105 void resolveConstantForwardRefs();
108 } // end namespace llvm
110 #endif // LLVM_LIB_BITCODE_READER_VALUELIST_H