[ARM] MVE integer min and max
[llvm-complete.git] / lib / Bitcode / Reader / ValueList.h
blob1c54911650fe8db7e3bd7b5fc4eca7b266faa1e7
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.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_BITCODE_READER_VALUELIST_H
14 #define LLVM_LIB_BITCODE_READER_VALUELIST_H
16 #include "llvm/IR/ValueHandle.h"
17 #include <cassert>
18 #include <utility>
19 #include <vector>
21 namespace llvm {
23 class Constant;
24 class LLVMContext;
25 class Type;
26 class Value;
28 class BitcodeReaderValueList {
29 std::vector<WeakTrackingVH> ValuePtrs;
31 /// Struct containing fully-specified copies of the type of each
32 /// value. When pointers are opaque, this will be contain non-opaque
33 /// variants so that restructuring instructions can determine their
34 /// type correctly even if being loaded from old bitcode where some
35 /// types are implicit.
36 std::vector<Type *> FullTypes;
38 /// As we resolve forward-referenced constants, we add information about them
39 /// to this vector. This allows us to resolve them in bulk instead of
40 /// resolving each reference at a time. See the code in
41 /// ResolveConstantForwardRefs for more information about this.
42 ///
43 /// The key of this vector is the placeholder constant, the value is the slot
44 /// number that holds the resolved value.
45 using ResolveConstantsTy = std::vector<std::pair<Constant *, unsigned>>;
46 ResolveConstantsTy ResolveConstants;
47 LLVMContext &Context;
49 public:
50 BitcodeReaderValueList(LLVMContext &C) : Context(C) {}
52 ~BitcodeReaderValueList() {
53 assert(ResolveConstants.empty() && "Constants not resolved?");
56 // vector compatibility methods
57 unsigned size() const { return ValuePtrs.size(); }
58 void resize(unsigned N) {
59 ValuePtrs.resize(N);
60 FullTypes.resize(N);
62 void push_back(Value *V, Type *Ty) {
63 ValuePtrs.emplace_back(V);
64 FullTypes.emplace_back(Ty);
67 void clear() {
68 assert(ResolveConstants.empty() && "Constants not resolved?");
69 ValuePtrs.clear();
70 FullTypes.clear();
73 Value *operator[](unsigned i) const {
74 assert(i < ValuePtrs.size());
75 return ValuePtrs[i];
78 Value *back() const { return ValuePtrs.back(); }
79 void pop_back() {
80 ValuePtrs.pop_back();
81 FullTypes.pop_back();
83 bool empty() const { return ValuePtrs.empty(); }
85 void shrinkTo(unsigned N) {
86 assert(N <= size() && "Invalid shrinkTo request!");
87 ValuePtrs.resize(N);
88 FullTypes.resize(N);
91 Constant *getConstantFwdRef(unsigned Idx, Type *Ty);
92 Value *getValueFwdRef(unsigned Idx, Type *Ty, Type **FullTy = nullptr);
94 void assignValue(Value *V, unsigned Idx, Type *FullTy);
96 /// Once all constants are read, this method bulk resolves any forward
97 /// references.
98 void resolveConstantForwardRefs();
101 } // end namespace llvm
103 #endif // LLVM_LIB_BITCODE_READER_VALUELIST_H