LLVM 19.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
22namespace llvm {
23
24class Error;
25class Type;
26class 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
40public:
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
RelocType Type
Definition: COFFYAML.cpp:391
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Type::TypeID TypeID
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Basic Block Representation.
Definition: BasicBlock.h:60
BitcodeReaderValueList(size_t RefsUpperBound, MaterializeValueFnTy MaterializeValueFn)
Definition: ValueList.h:41
Value * getValueFwdRef(unsigned Idx, Type *Ty, unsigned TyID, BasicBlock *ConstExprInsertBB)
Definition: ValueList.cpp:54
void resize(unsigned N)
Definition: ValueList.h:49
Value * operator[](unsigned i) const
Definition: ValueList.h:60
void push_back(Value *V, unsigned TypeID)
Definition: ValueList.h:52
Value * back() const
Definition: ValueList.h:70
void replaceValueWithoutRAUW(unsigned ValNo, Value *NewV)
Definition: ValueList.h:81
Error assignValue(unsigned Idx, Value *V, unsigned TypeID)
Definition: ValueList.cpp:25
void shrinkTo(unsigned N)
Definition: ValueList.h:76
unsigned getTypeID(unsigned ValNo) const
Definition: ValueList.h:65
unsigned size() const
Definition: ValueList.h:48
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
#define N