LLVM 19.0.0git
ValueList.cpp
Go to the documentation of this file.
1//===- ValueList.cpp - Internal BitcodeReader implementation --------------===//
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#include "ValueList.h"
10#include "llvm/IR/Argument.h"
11#include "llvm/IR/Constant.h"
12#include "llvm/IR/Constants.h"
13#include "llvm/IR/GlobalValue.h"
14#include "llvm/IR/Instruction.h"
15#include "llvm/IR/Type.h"
16#include "llvm/IR/User.h"
17#include "llvm/IR/Value.h"
19#include "llvm/Support/Error.h"
21#include <cstddef>
22
23using namespace llvm;
24
26 unsigned TypeID) {
27 if (Idx == size()) {
28 push_back(V, TypeID);
29 return Error::success();
30 }
31
32 if (Idx >= size())
33 resize(Idx + 1);
34
35 auto &Old = ValuePtrs[Idx];
36 if (!Old.first) {
37 Old.first = V;
38 Old.second = TypeID;
39 return Error::success();
40 }
41
42 assert(!isa<Constant>(&*Old.first) && "Shouldn't update constant");
43 // If there was a forward reference to this value, replace it.
44 Value *PrevVal = Old.first;
45 if (PrevVal->getType() != V->getType())
46 return createStringError(
47 std::errc::illegal_byte_sequence,
48 "Assigned value does not match type of forward declaration");
49 Old.first->replaceAllUsesWith(V);
50 PrevVal->deleteValue();
51 return Error::success();
52}
53
55 unsigned TyID,
56 BasicBlock *ConstExprInsertBB) {
57 // Bail out for a clearly invalid value.
58 if (Idx >= RefsUpperBound)
59 return nullptr;
60
61 if (Idx >= size())
62 resize(Idx + 1);
63
64 if (Value *V = ValuePtrs[Idx].first) {
65 // If the types don't match, it's invalid.
66 if (Ty && Ty != V->getType())
67 return nullptr;
68
69 Expected<Value *> MaybeV = MaterializeValueFn(Idx, ConstExprInsertBB);
70 if (!MaybeV) {
71 // TODO: We might want to propagate the precise error message here.
72 consumeError(MaybeV.takeError());
73 return nullptr;
74 }
75 return MaybeV.get();
76 }
77
78 // No type specified, must be invalid reference.
79 if (!Ty)
80 return nullptr;
81
82 // Create and return a placeholder, which will later be RAUW'd.
83 Value *V = new Argument(Ty);
84 ValuePtrs[Idx] = {V, TyID};
85 return V;
86}
This file contains the declarations for the subclasses of Constant, which represent the different fla...
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
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class represents an incoming formal argument to a Function.
Definition: Argument.h:28
LLVM Basic Block Representation.
Definition: BasicBlock.h:60
Value * getValueFwdRef(unsigned Idx, Type *Ty, unsigned TyID, BasicBlock *ConstExprInsertBB)
Definition: ValueList.cpp:54
void resize(unsigned N)
Definition: ValueList.h:49
void push_back(Value *V, unsigned TypeID)
Definition: ValueList.h:52
Error assignValue(unsigned Idx, Value *V, unsigned TypeID)
Definition: ValueList.cpp:25
unsigned size() const
Definition: ValueList.h:48
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:334
Tagged union holding either a T or a Error.
Definition: Error.h:474
Error takeError()
Take ownership of the stored error.
Definition: Error.h:601
reference get()
Returns a reference to the stored T value.
Definition: Error.h:571
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
TypeID
Definitions of all of the base types for the Type system.
Definition: Type.h:54
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
void deleteValue()
Delete a pointer to a generic Value.
Definition: Value.cpp:110
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1244
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1041