]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Bitcode/Reader/ValueList.h
Import mandoc snapshot 2017-06-08
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Bitcode / Reader / ValueList.h
1 //===-- Bitcode/Reader/ValueEnumerator.h - Number values --------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This class gives values and types Unique ID's.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/IR/LLVMContext.h"
15 #include "llvm/IR/ValueHandle.h"
16
17 #include <vector>
18
19 namespace llvm {
20 class Constant;
21
22 class BitcodeReaderValueList {
23   std::vector<WeakVH> ValuePtrs;
24
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.
29   ///
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;
34   LLVMContext &Context;
35
36 public:
37   BitcodeReaderValueList(LLVMContext &C) : Context(C) {}
38   ~BitcodeReaderValueList() {
39     assert(ResolveConstants.empty() && "Constants not resolved?");
40   }
41
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); }
46
47   void clear() {
48     assert(ResolveConstants.empty() && "Constants not resolved?");
49     ValuePtrs.clear();
50   }
51
52   Value *operator[](unsigned i) const {
53     assert(i < ValuePtrs.size());
54     return ValuePtrs[i];
55   }
56
57   Value *back() const { return ValuePtrs.back(); }
58   void pop_back() { ValuePtrs.pop_back(); }
59   bool empty() const { return ValuePtrs.empty(); }
60
61   void shrinkTo(unsigned N) {
62     assert(N <= size() && "Invalid shrinkTo request!");
63     ValuePtrs.resize(N);
64   }
65
66   Constant *getConstantFwdRef(unsigned Idx, Type *Ty);
67   Value *getValueFwdRef(unsigned Idx, Type *Ty);
68
69   void assignValue(Value *V, unsigned Idx);
70
71   /// Once all constants are read, this method bulk resolves any forward
72   /// references.
73   void resolveConstantForwardRefs();
74 };
75
76 } // namespace llvm