1 //===-- Bitcode/Reader/ValueEnumerator.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 #include "llvm/IR/LLVMContext.h"
15 #include "llvm/IR/ValueHandle.h"
22 class BitcodeReaderValueList {
23 std::vector<WeakVH> ValuePtrs;
25 /// As we resolve forward-referenced constants, we add information about them
26 /// to this vector. This allows us to resolve them in bulk instead of
27 /// resolving each reference at a time. See the code in
28 /// ResolveConstantForwardRefs for more information about this.
30 /// The key of this vector is the placeholder constant, the value is the slot
31 /// number that holds the resolved value.
32 typedef std::vector<std::pair<Constant *, unsigned>> ResolveConstantsTy;
33 ResolveConstantsTy ResolveConstants;
37 BitcodeReaderValueList(LLVMContext &C) : Context(C) {}
38 ~BitcodeReaderValueList() {
39 assert(ResolveConstants.empty() && "Constants not resolved?");
42 // vector compatibility methods
43 unsigned size() const { return ValuePtrs.size(); }
44 void resize(unsigned N) { ValuePtrs.resize(N); }
45 void push_back(Value *V) { ValuePtrs.emplace_back(V); }
48 assert(ResolveConstants.empty() && "Constants not resolved?");
52 Value *operator[](unsigned i) const {
53 assert(i < ValuePtrs.size());
57 Value *back() const { return ValuePtrs.back(); }
58 void pop_back() { ValuePtrs.pop_back(); }
59 bool empty() const { return ValuePtrs.empty(); }
61 void shrinkTo(unsigned N) {
62 assert(N <= size() && "Invalid shrinkTo request!");
66 Constant *getConstantFwdRef(unsigned Idx, Type *Ty);
67 Value *getValueFwdRef(unsigned Idx, Type *Ty);
69 void assignValue(Value *V, unsigned Idx);
71 /// Once all constants are read, this method bulk resolves any forward
73 void resolveConstantForwardRefs();