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 /// 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.
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
;
43 BitcodeReaderValueList(LLVMContext
&C
) : Context(C
) {}
45 ~BitcodeReaderValueList() {
46 assert(ResolveConstants
.empty() && "Constants not resolved?");
49 // vector compatibility methods
50 unsigned size() const { return ValuePtrs
.size(); }
51 void resize(unsigned N
) { ValuePtrs
.resize(N
); }
52 void push_back(Value
*V
) { ValuePtrs
.emplace_back(V
); }
55 assert(ResolveConstants
.empty() && "Constants not resolved?");
59 Value
*operator[](unsigned i
) const {
60 assert(i
< ValuePtrs
.size());
64 Value
*back() const { return ValuePtrs
.back(); }
65 void pop_back() { ValuePtrs
.pop_back(); }
66 bool empty() const { return ValuePtrs
.empty(); }
68 void shrinkTo(unsigned N
) {
69 assert(N
<= size() && "Invalid shrinkTo request!");
73 Constant
*getConstantFwdRef(unsigned Idx
, Type
*Ty
);
74 Value
*getValueFwdRef(unsigned Idx
, Type
*Ty
);
76 void assignValue(Value
*V
, unsigned Idx
);
78 /// Once all constants are read, this method bulk resolves any forward
80 void resolveConstantForwardRefs();
83 } // end namespace llvm
85 #endif // LLVM_LIB_BITCODE_READER_VALUELIST_H