LLVM  14.0.0git
ValueList.h
Go to the documentation of this file.
1 //===-- Bitcode/Reader/ValueList.h - Number values --------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This class gives values and types Unique ID's.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_BITCODE_READER_VALUELIST_H
14 #define LLVM_LIB_BITCODE_READER_VALUELIST_H
15 
16 #include "llvm/IR/ValueHandle.h"
17 #include <cassert>
18 #include <utility>
19 #include <vector>
20 
21 namespace llvm {
22 
23 class Constant;
24 class LLVMContext;
25 class Type;
26 class Value;
27 
29  std::vector<WeakTrackingVH> ValuePtrs;
30 
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.
35  ///
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;
40  LLVMContext &Context;
41 
42  /// Maximum number of valid references. Forward references exceeding the
43  /// maximum must be invalid.
44  unsigned RefsUpperBound;
45 
46 public:
47  BitcodeReaderValueList(LLVMContext &C, size_t RefsUpperBound)
48  : Context(C),
49  RefsUpperBound(std::min((size_t)std::numeric_limits<unsigned>::max(),
50  RefsUpperBound)) {}
51 
53  assert(ResolveConstants.empty() && "Constants not resolved?");
54  }
55 
56  // vector compatibility methods
57  unsigned size() const { return ValuePtrs.size(); }
58  void resize(unsigned N) {
59  ValuePtrs.resize(N);
60  }
61  void push_back(Value *V) { ValuePtrs.emplace_back(V); }
62 
63  void clear() {
64  assert(ResolveConstants.empty() && "Constants not resolved?");
65  ValuePtrs.clear();
66  }
67 
68  Value *operator[](unsigned i) const {
69  assert(i < ValuePtrs.size());
70  return ValuePtrs[i];
71  }
72 
73  Value *back() const { return ValuePtrs.back(); }
74  void pop_back() {
75  ValuePtrs.pop_back();
76  }
77  bool empty() const { return ValuePtrs.empty(); }
78 
79  void shrinkTo(unsigned N) {
80  assert(N <= size() && "Invalid shrinkTo request!");
81  ValuePtrs.resize(N);
82  }
83 
84  Constant *getConstantFwdRef(unsigned Idx, Type *Ty);
85  Value *getValueFwdRef(unsigned Idx, Type *Ty);
86 
87  void assignValue(Value *V, unsigned Idx);
88 
89  /// Once all constants are read, this method bulk resolves any forward
90  /// references.
92 };
93 
94 } // end namespace llvm
95 
96 #endif // LLVM_LIB_BITCODE_READER_VALUELIST_H
i
i
Definition: README.txt:29
llvm::BitcodeReaderValueList::operator[]
Value * operator[](unsigned i) const
Definition: ValueList.h:68
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
size_t
llvm::BitcodeReaderValueList::getConstantFwdRef
Constant * getConstantFwdRef(unsigned Idx, Type *Ty)
Definition: ValueList.cpp:93
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::BitcodeReaderValueList::clear
void clear()
Definition: ValueList.h:63
llvm::BitcodeReaderValueList::push_back
void push_back(Value *V)
Definition: ValueList.h:61
llvm::ISD::Constant
@ Constant
Definition: ISDOpcodes.h:76
llvm::BitcodeReaderValueList::getValueFwdRef
Value * getValueFwdRef(unsigned Idx, Type *Ty)
Definition: ValueList.cpp:113
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::BitcodeReaderValueList
Definition: ValueList.h:28
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::BitcodeReaderValueList::assignValue
void assignValue(Value *V, unsigned Idx)
Definition: ValueList.cpp:65
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
llvm::BitcodeReaderValueList::back
Value * back() const
Definition: ValueList.h:73
TemplateParamKind::Type
@ Type
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::BitcodeReaderValueList::empty
bool empty() const
Definition: ValueList.h:77
llvm::BitcodeReaderValueList::resize
void resize(unsigned N)
Definition: ValueList.h:58
llvm::BitcodeReaderValueList::resolveConstantForwardRefs
void resolveConstantForwardRefs()
Once all constants are read, this method bulk resolves any forward references.
Definition: ValueList.cpp:144
llvm::BitcodeReaderValueList::pop_back
void pop_back()
Definition: ValueList.h:74
llvm::BitcodeReaderValueList::size
unsigned size() const
Definition: ValueList.h:57
llvm::min
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:357
ValueHandle.h
llvm::BitcodeReaderValueList::BitcodeReaderValueList
BitcodeReaderValueList(LLVMContext &C, size_t RefsUpperBound)
Definition: ValueList.h:47
std
Definition: BitVector.h:838
llvm::BitcodeReaderValueList::shrinkTo
void shrinkTo(unsigned N)
Definition: ValueList.h:79
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
N
#define N
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
llvm::BitcodeReaderValueList::~BitcodeReaderValueList
~BitcodeReaderValueList()
Definition: ValueList.h:52
llvm::Value
LLVM Value Representation.
Definition: Value.h:75