LLVM  4.0.0
ValueList.h
Go to the documentation of this file.
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 
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:
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.
74 };
75 
76 } // namespace llvm
size_t i
BitcodeReaderValueList(LLVMContext &C)
Definition: ValueList.h:37
void shrinkTo(unsigned N)
Definition: ValueList.h:61
Value * getValueFwdRef(unsigned Idx, Type *Ty)
Definition: ValueList.cpp:96
void push_back(Value *V)
Definition: ValueList.h:45
Value * back() const
Definition: ValueList.h:57
void assignValue(Value *V, unsigned Idx)
Definition: ValueList.cpp:52
unsigned size() const
Definition: ValueList.h:43
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:48
This is an important base class in LLVM.
Definition: Constant.h:42
Value * operator[](unsigned i) const
Definition: ValueList.h:52
void resolveConstantForwardRefs()
Once all constants are read, this method bulk resolves any forward references.
Definition: ValueList.cpp:127
Constant * getConstantFwdRef(unsigned Idx, Type *Ty)
Definition: ValueList.cpp:80
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
void resize(unsigned N)
Definition: ValueList.h:44
#define N
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:71