1 //===-- Bitcode/Reader/ValueList.h - Number values --------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This class gives values and types Unique ID's.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_BITCODE_READER_VALUELIST_H
15 #define LLVM_LIB_BITCODE_READER_VALUELIST_H
17 #include "llvm/IR/ValueHandle.h"
29 class BitcodeReaderValueList
{
30 std::vector
<WeakTrackingVH
> ValuePtrs
;
32 /// As we resolve forward-referenced constants, we add information about them
33 /// to this vector. This allows us to resolve them in bulk instead of
34 /// resolving each reference at a time. See the code in
35 /// ResolveConstantForwardRefs for more information about this.
37 /// The key of this vector is the placeholder constant, the value is the slot
38 /// number that holds the resolved value.
39 using ResolveConstantsTy
= std::vector
<std::pair
<Constant
*, unsigned>>;
40 ResolveConstantsTy ResolveConstants
;
44 BitcodeReaderValueList(LLVMContext
&C
) : Context(C
) {}
46 ~BitcodeReaderValueList() {
47 assert(ResolveConstants
.empty() && "Constants not resolved?");
50 // vector compatibility methods
51 unsigned size() const { return ValuePtrs
.size(); }
52 void resize(unsigned N
) { ValuePtrs
.resize(N
); }
53 void push_back(Value
*V
) { ValuePtrs
.emplace_back(V
); }
56 assert(ResolveConstants
.empty() && "Constants not resolved?");
60 Value
*operator[](unsigned i
) const {
61 assert(i
< ValuePtrs
.size());
65 Value
*back() const { return ValuePtrs
.back(); }
66 void pop_back() { ValuePtrs
.pop_back(); }
67 bool empty() const { return ValuePtrs
.empty(); }
69 void shrinkTo(unsigned N
) {
70 assert(N
<= size() && "Invalid shrinkTo request!");
74 Constant
*getConstantFwdRef(unsigned Idx
, Type
*Ty
);
75 Value
*getValueFwdRef(unsigned Idx
, Type
*Ty
);
77 void assignValue(Value
*V
, unsigned Idx
);
79 /// Once all constants are read, this method bulk resolves any forward
81 void resolveConstantForwardRefs();
84 } // end namespace llvm
86 #endif // LLVM_LIB_BITCODE_READER_VALUELIST_H