LLVM  16.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 "llvm/Support/Error.h"
18 #include <cassert>
19 #include <utility>
20 #include <vector>
21 
22 namespace llvm {
23 
24 class Error;
25 class Type;
26 class Value;
27 
29  /// Maps Value ID to pair of Value* and Type ID.
30  std::vector<std::pair<WeakTrackingVH, unsigned>> ValuePtrs;
31 
32  /// Maximum number of valid references. Forward references exceeding the
33  /// maximum must be invalid.
34  unsigned RefsUpperBound;
35 
36  using MaterializeValueFnTy =
37  std::function<Expected<Value *>(unsigned, BasicBlock *)>;
38  MaterializeValueFnTy MaterializeValueFn;
39 
40 public:
41  BitcodeReaderValueList(size_t RefsUpperBound,
42  MaterializeValueFnTy MaterializeValueFn)
43  : RefsUpperBound(std::min((size_t)std::numeric_limits<unsigned>::max(),
44  RefsUpperBound)),
45  MaterializeValueFn(MaterializeValueFn) {}
46 
47  // vector compatibility methods
48  unsigned size() const { return ValuePtrs.size(); }
49  void resize(unsigned N) {
50  ValuePtrs.resize(N);
51  }
52  void push_back(Value *V, unsigned TypeID) {
53  ValuePtrs.emplace_back(V, TypeID);
54  }
55 
56  void clear() {
57  ValuePtrs.clear();
58  }
59 
60  Value *operator[](unsigned i) const {
61  assert(i < ValuePtrs.size());
62  return ValuePtrs[i].first;
63  }
64 
65  unsigned getTypeID(unsigned ValNo) const {
66  assert(ValNo < ValuePtrs.size());
67  return ValuePtrs[ValNo].second;
68  }
69 
70  Value *back() const { return ValuePtrs.back().first; }
71  void pop_back() {
72  ValuePtrs.pop_back();
73  }
74  bool empty() const { return ValuePtrs.empty(); }
75 
76  void shrinkTo(unsigned N) {
77  assert(N <= size() && "Invalid shrinkTo request!");
78  ValuePtrs.resize(N);
79  }
80 
81  void replaceValueWithoutRAUW(unsigned ValNo, Value *NewV) {
82  assert(ValNo < ValuePtrs.size());
83  ValuePtrs[ValNo].first = NewV;
84  }
85 
86  Value *getValueFwdRef(unsigned Idx, Type *Ty, unsigned TyID,
87  BasicBlock *ConstExprInsertBB);
88 
89  Error assignValue(unsigned Idx, Value *V, unsigned TypeID);
90 };
91 
92 } // end namespace llvm
93 
94 #endif // LLVM_LIB_BITCODE_READER_VALUELIST_H
i
i
Definition: README.txt:29
llvm::BitcodeReaderValueList::operator[]
Value * operator[](unsigned i) const
Definition: ValueList.h:60
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::lltok::Error
@ Error
Definition: LLToken.h:21
Error.h
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::max
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:337
size_t
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:55
llvm::BitcodeReaderValueList::clear
void clear()
Definition: ValueList.h:56
llvm::BitcodeReaderValueList::getTypeID
unsigned getTypeID(unsigned ValNo) const
Definition: ValueList.h:65
TypeID
Type::TypeID TypeID
Definition: Mips16HardFloat.cpp:103
llvm::BitcodeReaderValueList
Definition: ValueList.h:28
llvm::BitcodeReaderValueList::back
Value * back() const
Definition: ValueList.h:70
llvm::BitcodeReaderValueList::push_back
void push_back(Value *V, unsigned TypeID)
Definition: ValueList.h:52
llvm::BitcodeReaderValueList::assignValue
Error assignValue(unsigned Idx, Value *V, unsigned TypeID)
Definition: ValueList.cpp:26
TemplateParamKind::Type
@ Type
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::BitcodeReaderValueList::empty
bool empty() const
Definition: ValueList.h:74
llvm::BitcodeReaderValueList::resize
void resize(unsigned N)
Definition: ValueList.h:49
llvm::BitcodeReaderValueList::pop_back
void pop_back()
Definition: ValueList.h:71
llvm::BitcodeReaderValueList::size
unsigned size() const
Definition: ValueList.h:48
llvm::BitcodeReaderValueList::BitcodeReaderValueList
BitcodeReaderValueList(size_t RefsUpperBound, MaterializeValueFnTy MaterializeValueFn)
Definition: ValueList.h:41
llvm::min
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:357
ValueHandle.h
llvm::BitcodeReaderValueList::replaceValueWithoutRAUW
void replaceValueWithoutRAUW(unsigned ValNo, Value *NewV)
Definition: ValueList.h:81
std
Definition: BitVector.h:851
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::BitcodeReaderValueList::shrinkTo
void shrinkTo(unsigned N)
Definition: ValueList.h:76
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
N
#define N
llvm::BitcodeReaderValueList::getValueFwdRef
Value * getValueFwdRef(unsigned Idx, Type *Ty, unsigned TyID, BasicBlock *ConstExprInsertBB)
Definition: ValueList.cpp:55
llvm::Value
LLVM Value Representation.
Definition: Value.h:74